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 );
21 use parent qw(ILS::Transaction);
26 collection_code => undef,
29 destination_loc => undef,
30 alert_type => undef, # 00,01,02,03,04 or 99
31 hold_patron_id => undef,
32 hold_patron_name => "",
38 my $self = $class->SUPER::new(); # start with an ILS::Transaction object
40 foreach (keys %fields) {
41 $self->{_permitted}->{$_} = $fields{$_}; # overlaying _permitted
44 @{$self}{keys %fields} = values %fields; # copying defaults into object
45 return bless $self, $class;
51 my $return_date = shift;
55 my $barcode = $self->{item}->id;
57 $return_date = substr( $return_date, 0, 4 )
59 . substr( $return_date, 4, 2 )
61 . substr( $return_date, 6, 2 )
63 . substr( $return_date, 12, 2 )
65 . substr( $return_date, 14, 2 )
67 . substr( $return_date, 16, 2 );
69 $debug and warn "do_checkin() calling AddReturn($barcode, $branch)";
70 my ($return, $messages, $iteminformation, $borrower) = AddReturn($barcode, $branch, undef, undef, $return_date);
71 $self->alert(!$return);
72 # ignoring messages: NotIssued, IsPermanent, WasLost, WasTransfered
74 # biblionumber, biblioitemnumber, itemnumber
75 # borrowernumber, reservedate, branchcode
76 # cancellationdate, found, reservenotes, priority, timestamp
78 if ($messages->{BadBarcode}) {
79 $self->alert_type('99');
81 if ($messages->{withdrawn}) {
82 $self->alert_type('99');
84 if ($messages->{Wrongbranch}) {
85 $self->destination_loc($messages->{Wrongbranch}->{Rightbranch});
86 $self->alert_type('04'); # send to other branch
88 if ($messages->{WrongTransfer}) {
89 $self->destination_loc($messages->{WrongTransfer});
90 $self->alert_type('04'); # send to other branch
92 if ($messages->{NeedsTransfer}) {
93 $self->destination_loc($iteminformation->{homebranch});
94 $self->alert_type('04'); # send to other branch
96 if ($messages->{ResFound}) {
97 $self->hold($messages->{ResFound});
98 if ($branch eq $messages->{ResFound}->{branchcode}) {
99 $self->alert_type('01');
100 ModReserveAffect( $messages->{ResFound}->{itemnumber},
101 $messages->{ResFound}->{borrowernumber}, 0);
104 $self->alert_type('02');
105 ModReserveAffect( $messages->{ResFound}->{itemnumber},
106 $messages->{ResFound}->{borrowernumber}, 1);
107 ModItemTransfer( $messages->{ResFound}->{itemnumber},
109 $messages->{ResFound}->{branchcode}
113 $self->{item}->hold_patron_id( $messages->{ResFound}->{borrowernumber} );
114 $self->{item}->destination_loc( $messages->{ResFound}->{branchcode} );
116 $self->alert(1) if defined $self->alert_type; # alert_type could be "00", hypothetically
122 unless ($self->{item}) {
123 warn "resensitize(): no item found in object to resensitize";
126 return !$self->{item}->magnetic_media;
131 unless ($self->{patron}) {
132 warn "patron_id(): no patron found in object";
135 return $self->{patron}->id;