2 # An object to handle checkin status
5 package ILS::Transaction::Checkin;
10 # use POSIX qw(strftime);
16 use C4::Reserves qw( ModReserveAffect );
17 use C4::Items qw( ModItemTransfer );
20 use parent qw(ILS::Transaction);
25 collection_code => undef,
28 destination_loc => undef,
29 alert_type => undef, # 00,01,02,03,04 or 99
30 hold_patron_id => undef,
31 hold_patron_name => "",
37 my $self = $class->SUPER::new(); # start with an ILS::Transaction object
39 foreach (keys %fields) {
40 $self->{_permitted}->{$_} = $fields{$_}; # overlaying _permitted
43 @{$self}{keys %fields} = values %fields; # copying defaults into object
44 return bless $self, $class;
50 my $return_date = shift;
54 my $barcode = $self->{item}->id;
56 $return_date = substr( $return_date, 0, 4 )
58 . substr( $return_date, 4, 2 )
60 . substr( $return_date, 6, 2 )
62 . substr( $return_date, 12, 2 )
64 . substr( $return_date, 14, 2 )
66 . substr( $return_date, 16, 2 );
68 $debug and warn "do_checkin() calling AddReturn($barcode, $branch)";
69 my ($return, $messages, $iteminformation, $borrower) = AddReturn($barcode, $branch, undef, undef, $return_date);
70 $self->alert(!$return);
71 # ignoring messages: NotIssued, IsPermanent, WasLost, WasTransfered
73 # biblionumber, biblioitemnumber, itemnumber
74 # borrowernumber, reservedate, branchcode
75 # cancellationdate, found, reservenotes, priority, timestamp
77 if ($messages->{BadBarcode}) {
78 $self->alert_type('99');
80 if ($messages->{withdrawn}) {
81 $self->alert_type('99');
83 if ($messages->{Wrongbranch}) {
84 $self->destination_loc($messages->{Wrongbranch}->{Rightbranch});
85 $self->alert_type('04'); # send to other branch
87 if ($messages->{WrongTransfer}) {
88 $self->destination_loc($messages->{WrongTransfer});
89 $self->alert_type('04'); # send to other branch
91 if ($messages->{NeedsTransfer}) {
92 $self->destination_loc($iteminformation->{homebranch});
93 $self->alert_type('04'); # send to other branch
95 if ($messages->{ResFound}) {
96 $self->hold($messages->{ResFound});
97 if ($branch eq $messages->{ResFound}->{branchcode}) {
98 $self->alert_type('01');
99 ModReserveAffect( $messages->{ResFound}->{itemnumber},
100 $messages->{ResFound}->{borrowernumber}, 0);
103 $self->alert_type('02');
104 ModReserveAffect( $messages->{ResFound}->{itemnumber},
105 $messages->{ResFound}->{borrowernumber}, 1);
106 ModItemTransfer( $messages->{ResFound}->{itemnumber},
108 $messages->{ResFound}->{branchcode}
112 $self->{item}->hold_patron_id( $messages->{ResFound}->{borrowernumber} );
113 $self->{item}->destination_loc( $messages->{ResFound}->{branchcode} );
115 $self->alert(1) if defined $self->alert_type; # alert_type could be "00", hypothetically
121 unless ($self->{item}) {
122 warn "resensitize(): no item found in object to resensitize";
125 return !$self->{item}->magnetic_media;
130 unless ($self->{patron}) {
131 warn "patron_id(): no patron found in object";
134 return $self->{patron}->id;