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;
16 use C4::Items qw( ModItemTransfer );
17 use C4::Reserves qw( ModReserveAffect );
18 use Koha::DateUtils qw( dt_from_string );
20 use parent qw(C4::SIP::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;
51 my $cv_triggers_alert = shift;
56 my $barcode = $self->{item}->id;
58 $return_date = substr( $return_date, 0, 4 )
60 . substr( $return_date, 4, 2 )
62 . substr( $return_date, 6, 2 )
64 . substr( $return_date, 12, 2 )
66 . substr( $return_date, 14, 2 )
68 . substr( $return_date, 16, 2 );
70 $debug and warn "do_checkin() calling AddReturn($barcode, $branch)";
71 my ($return, $messages, $issue, $borrower) = AddReturn($barcode, $branch, undef, dt_from_string($return_date));
72 $self->alert(!$return);
73 # ignoring messages: NotIssued, WasLost, WasTransfered
75 # biblionumber, biblioitemnumber, itemnumber
76 # borrowernumber, reservedate, branchcode
77 # cancellationdate, found, reservenotes, priority, timestamp
78 if( $messages->{DataCorrupted} ) {
79 $self->alert_type('98');
81 if ($messages->{BadBarcode}) {
82 $self->alert_type('99');
84 if ($messages->{withdrawn}) {
85 $self->alert_type('99');
87 if ($messages->{Wrongbranch}) {
88 $self->{item}->destination_loc($messages->{Wrongbranch}->{Rightbranch});
89 $self->alert_type('04'); # send to other branch
91 if ($messages->{WrongTransfer}) {
92 $self->{item}->destination_loc($messages->{WrongTransfer});
93 $self->alert_type('04'); # send to other branch
95 if ($messages->{NeedsTransfer}) {
96 $self->{item}->destination_loc($messages->{NeedsTransfer});
97 $self->alert_type('04'); # send to other branch
99 if ($messages->{WasTransfered}) { # set into transit so tell unit
100 $self->{item}->destination_loc($issue->item->homebranch);
101 $self->alert_type('04'); # send to other branch
103 if ($messages->{ResFound}) {
104 $self->hold($messages->{ResFound});
105 if ($branch eq $messages->{ResFound}->{branchcode}) {
106 $self->alert_type('01');
107 ModReserveAffect( $messages->{ResFound}->{itemnumber},
108 $messages->{ResFound}->{borrowernumber}, 0, $messages->{ResFound}->{reserve_id});
111 $self->alert_type('02');
112 ModReserveAffect( $messages->{ResFound}->{itemnumber},
113 $messages->{ResFound}->{borrowernumber}, 1, $messages->{ResFound}->{reserve_id});
114 ModItemTransfer( $messages->{ResFound}->{itemnumber},
116 $messages->{ResFound}->{branchcode}
120 $self->{item}->hold_patron_id( $messages->{ResFound}->{borrowernumber} );
121 $self->{item}->destination_loc( $messages->{ResFound}->{branchcode} );
124 my $alert = defined $self->alert_type;
125 if ( $cv_triggers_alert ) {
126 $self->alert($alert); # Overwrites existing alert value, should set to 0 if there is no alert type
128 $self->alert($alert) if $alert; # Doesn't affect alert value unless an alert type is set
133 return { messages => $messages };
138 unless ($self->{item}) {
139 warn "resensitize(): no item found in object to resensitize";
142 return !$self->{item}->magnetic_media;
147 unless ($self->{patron}) {
148 warn "patron_id(): no patron found in object";
151 return $self->{patron}->id;