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 );
21 use parent qw(C4::SIP::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;
54 my $checked_in_ok = $account->{checked_in_ok};
55 my $cv_triggers_alert = $account->{cv_triggers_alert};
56 my $holds_block_checkin = $account->{holds_block_checkin};
61 my $barcode = $self->{item}->id;
64 $return_date = substr( $return_date, 0, 4 )
66 . substr( $return_date, 4, 2 )
68 . substr( $return_date, 6, 2 )
70 . substr( $return_date, 12, 2 )
72 . substr( $return_date, 14, 2 )
74 . substr( $return_date, 16, 2 );
75 $return_date = dt_from_string($return_date);
78 my ( $return, $messages, $issue, $borrower );
80 my $item = Koha::Items->find( { barcode => $barcode } );
82 my $human_required = 0;
83 if ( C4::Context->preference("CircConfirmItemParts")
88 $messages->{additional_materials} = 1;
91 my $checkin_blocked_by_holds = $holds_block_checkin && $item->biblio->holds->count;
93 $debug and warn "do_checkin() calling AddReturn($barcode, $branch)";
94 ( $return, $messages, $issue, $borrower ) =
95 AddReturn( $barcode, $branch, undef, $return_date )
96 unless $human_required || $checkin_blocked_by_holds;
98 if ( $checked_in_ok ) {
99 delete $messages->{ItemLocationUpdated};
100 delete $messages->{NotIssued};
101 delete $messages->{LocalUse};
102 $return = 1 unless keys %$messages;
105 # biblionumber, biblioitemnumber, itemnumber
106 # borrowernumber, reservedate, branchcode
107 # cancellationdate, found, reservenotes, priority, timestamp
108 if ($messages->{additional_materials}) {
109 $self->alert_type('99');
111 if( $messages->{DataCorrupted} ) {
112 $self->alert_type('98');
114 if ($messages->{BadBarcode}) {
115 $self->alert_type('99');
117 if ($messages->{withdrawn}) {
118 $self->alert_type('99');
120 if ($messages->{WasLost}) {
121 $self->alert_type('99') if C4::Context->preference("BlockReturnOfLostItems");
123 if ($messages->{Wrongbranch}) {
124 $self->{item}->destination_loc($messages->{Wrongbranch}->{Rightbranch});
125 $self->alert_type('04'); # send to other branch
127 if ($messages->{WrongTransfer}) {
128 $self->{item}->destination_loc($messages->{WrongTransfer});
129 $self->alert_type('04'); # send to other branch
131 if ($messages->{NeedsTransfer}) {
132 $self->{item}->destination_loc($messages->{NeedsTransfer});
133 $self->alert_type('04'); # send to other branch
135 if ($messages->{WasTransfered}) { # set into transit so tell unit
136 $self->{item}->destination_loc($issue->item->homebranch);
137 $self->alert_type('04'); # send to other branch
139 if ($messages->{ResFound} || $checkin_blocked_by_holds ) {
140 if ($checkin_blocked_by_holds) {
141 $self->alert_type('99');
143 } elsif ($branch eq $messages->{ResFound}->{branchcode}) {
144 $self->hold($messages->{ResFound});
145 $self->alert_type('01');
146 ModReserveAffect( $messages->{ResFound}->{itemnumber},
147 $messages->{ResFound}->{borrowernumber}, 0, $messages->{ResFound}->{reserve_id});
150 $self->hold($messages->{ResFound});
151 $self->alert_type('02');
152 ModReserveAffect( $messages->{ResFound}->{itemnumber},
153 $messages->{ResFound}->{borrowernumber}, 1, $messages->{ResFound}->{reserve_id});
154 ModItemTransfer( $messages->{ResFound}->{itemnumber},
156 $messages->{ResFound}->{branchcode},
157 $messages->{TransferTrigger},
161 $self->{item}->hold_patron_id( $messages->{ResFound}->{borrowernumber} );
162 $self->{item}->destination_loc( $messages->{ResFound}->{branchcode} );
164 # ignoring messages: NotIssued, WasTransfered
166 if ($cv_triggers_alert) {
167 $self->alert( defined $self->alert_type ); # Overwrites existing alert value, should set to 0 if there is no alert type
170 $self->alert( !$return || defined $self->alert_type );
175 return { messages => $messages };
180 unless ($self->{item}) {
181 warn "resensitize(): no item found in object to resensitize";
184 return !$self->{item}->magnetic_media;
189 unless ($self->{patron}) {
190 warn "patron_id(): no patron found in object";
193 return $self->{patron}->id;