2 # An object to handle checkin status
5 package C4::SIP::ILS::Transaction::Checkin;
10 # use POSIX qw(strftime);
12 use C4::SIP::ILS::Transaction;
15 use C4::Reserves qw( ModReserveAffect );
16 use C4::Items qw( ModItemTransfer );
19 use parent qw(C4::SIP::ILS::Transaction);
24 collection_code => undef,
27 destination_loc => undef,
28 alert_type => undef, # 00,01,02,03,04 or 99
29 hold_patron_id => undef,
30 hold_patron_name => "",
36 my $self = $class->SUPER::new(); # start with an ILS::Transaction object
38 foreach (keys %fields) {
39 $self->{_permitted}->{$_} = $fields{$_}; # overlaying _permitted
42 @{$self}{keys %fields} = values %fields; # copying defaults into object
43 return bless $self, $class;
49 my $return_date = shift;
53 my $barcode = $self->{item}->id;
55 $return_date = substr( $return_date, 0, 4 )
57 . substr( $return_date, 4, 2 )
59 . substr( $return_date, 6, 2 )
61 . substr( $return_date, 12, 2 )
63 . substr( $return_date, 14, 2 )
65 . substr( $return_date, 16, 2 );
67 $debug and warn "do_checkin() calling AddReturn($barcode, $branch)";
68 my ($return, $messages, $iteminformation, $borrower) = AddReturn($barcode, $branch, undef, undef, $return_date);
69 $self->alert(!$return);
70 # ignoring messages: NotIssued, WasLost, WasTransfered
72 # biblionumber, biblioitemnumber, itemnumber
73 # borrowernumber, reservedate, branchcode
74 # cancellationdate, found, reservenotes, priority, timestamp
75 if( $messages->{DataCorrupted} ) {
76 $self->alert_type('98');
78 if ($messages->{BadBarcode}) {
79 $self->alert_type('99');
81 if ($messages->{withdrawn}) {
82 $self->alert_type('99');
84 if ($messages->{Wrongbranch}) {
85 $self->{item}->destination_loc($messages->{Wrongbranch}->{Rightbranch});
86 $self->alert_type('04'); # send to other branch
88 if ($messages->{WrongTransfer}) {
89 $self->{item}->destination_loc($messages->{WrongTransfer});
90 $self->alert_type('04'); # send to other branch
92 if ($messages->{NeedsTransfer}) {
93 $self->{item}->destination_loc($messages->{NeedsTransfer});
94 $self->alert_type('04'); # send to other branch
96 if ($messages->{WasTransfered}) { # set into transit so tell unit
97 $self->{item}->destination_loc($iteminformation->{homebranch});
98 $self->alert_type('04'); # send to other branch
100 if ($messages->{ResFound}) {
101 $self->hold($messages->{ResFound});
102 if ($branch eq $messages->{ResFound}->{branchcode}) {
103 $self->alert_type('01');
104 ModReserveAffect( $messages->{ResFound}->{itemnumber},
105 $messages->{ResFound}->{borrowernumber}, 0, $messages->{ResFound}->{reserve_id});
108 $self->alert_type('02');
109 ModReserveAffect( $messages->{ResFound}->{itemnumber},
110 $messages->{ResFound}->{borrowernumber}, 1, $messages->{ResFound}->{reserve_id});
111 ModItemTransfer( $messages->{ResFound}->{itemnumber},
113 $messages->{ResFound}->{branchcode}
117 $self->{item}->hold_patron_id( $messages->{ResFound}->{borrowernumber} );
118 $self->{item}->destination_loc( $messages->{ResFound}->{branchcode} );
120 $self->alert(1) if defined $self->alert_type; # alert_type could be "00", hypothetically
126 unless ($self->{item}) {
127 warn "resensitize(): no item found in object to resensitize";
130 return !$self->{item}->magnetic_media;
135 unless ($self->{patron}) {
136 warn "patron_id(): no patron found in object";
139 return $self->{patron}->id;