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;
52 my $checked_in_ok = shift;
57 my $barcode = $self->{item}->id;
59 $return_date = substr( $return_date, 0, 4 )
61 . substr( $return_date, 4, 2 )
63 . substr( $return_date, 6, 2 )
65 . substr( $return_date, 12, 2 )
67 . substr( $return_date, 14, 2 )
69 . substr( $return_date, 16, 2 );
71 $debug and warn "do_checkin() calling AddReturn($barcode, $branch)";
72 my ($return, $messages, $issue, $borrower) = AddReturn($barcode, $branch, undef, dt_from_string($return_date));
74 $debug and warn 'not raising alert when AddReturn() does not return a value for $return due to $checked_in_ok being set to true';
77 $self->alert(!$return);
79 # ignoring messages: NotIssued, WasLost, WasTransfered
81 # biblionumber, biblioitemnumber, itemnumber
82 # borrowernumber, reservedate, branchcode
83 # cancellationdate, found, reservenotes, priority, timestamp
84 if( $messages->{DataCorrupted} ) {
85 $self->alert_type('98');
87 if ($messages->{BadBarcode}) {
88 $self->alert_type('99');
90 if ($messages->{withdrawn}) {
91 $self->alert_type('99');
93 if ($messages->{Wrongbranch}) {
94 $self->{item}->destination_loc($messages->{Wrongbranch}->{Rightbranch});
95 $self->alert_type('04'); # send to other branch
97 if ($messages->{WrongTransfer}) {
98 $self->{item}->destination_loc($messages->{WrongTransfer});
99 $self->alert_type('04'); # send to other branch
101 if ($messages->{NeedsTransfer}) {
102 $self->{item}->destination_loc($messages->{NeedsTransfer});
103 $self->alert_type('04'); # send to other branch
105 if ($messages->{WasTransfered}) { # set into transit so tell unit
106 $self->{item}->destination_loc($issue->item->homebranch);
107 $self->alert_type('04'); # send to other branch
109 if ($messages->{ResFound}) {
110 $self->hold($messages->{ResFound});
111 if ($branch eq $messages->{ResFound}->{branchcode}) {
112 $self->alert_type('01');
113 ModReserveAffect( $messages->{ResFound}->{itemnumber},
114 $messages->{ResFound}->{borrowernumber}, 0, $messages->{ResFound}->{reserve_id});
117 $self->alert_type('02');
118 ModReserveAffect( $messages->{ResFound}->{itemnumber},
119 $messages->{ResFound}->{borrowernumber}, 1, $messages->{ResFound}->{reserve_id});
120 ModItemTransfer( $messages->{ResFound}->{itemnumber},
122 $messages->{ResFound}->{branchcode}
126 $self->{item}->hold_patron_id( $messages->{ResFound}->{borrowernumber} );
127 $self->{item}->destination_loc( $messages->{ResFound}->{branchcode} );
130 my $alert = defined $self->alert_type;
131 if ( $cv_triggers_alert ) {
132 $self->alert($alert); # Overwrites existing alert value, should set to 0 if there is no alert type
134 $self->alert($alert) if $alert; # Doesn't affect alert value unless an alert type is set
139 return { messages => $messages };
144 unless ($self->{item}) {
145 warn "resensitize(): no item found in object to resensitize";
148 return !$self->{item}->magnetic_media;
153 unless ($self->{patron}) {
154 warn "patron_id(): no patron found in object";
157 return $self->{patron}->id;