Bug 25541: (QA follow-up) Rename no_holds_checkin to holds_block_checkin
[koha.git] / C4 / SIP / ILS / Transaction / Checkin.pm
blob07797a0d4d16629d9540f996e8753f9a66caf370
2 # An object to handle checkin status
5 package C4::SIP::ILS::Transaction::Checkin;
7 use warnings;
8 use strict;
10 # use POSIX qw(strftime);
12 use C4::SIP::ILS::Transaction;
14 use C4::Circulation;
15 use C4::Debug;
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);
22 my %fields = (
23 magnetic => 0,
24 sort_bin => undef,
25 collection_code => undef,
26 # 3M extensions:
27 call_number => 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 => "",
32 hold => undef,
35 sub new {
36 my $class = shift;
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;
47 sub do_checkin {
48 my $self = shift;
49 my $branch = shift;
50 my $return_date = shift;
51 my $account = shift;
53 my $checked_in_ok = $account->{checked_in_ok};
54 my $cv_triggers_alert = $account->{cv_triggers_alert};
55 my $holds_block_checkin = $account->{holds_block_checkin};
57 if (!$branch) {
58 $branch = 'SIP2';
60 my $barcode = $self->{item}->id;
62 if ( $return_date ) {
63 $return_date = substr( $return_date, 0, 4 )
64 . '-'
65 . substr( $return_date, 4, 2 )
66 . '-'
67 . substr( $return_date, 6, 2 )
68 . q{ }
69 . substr( $return_date, 12, 2 )
70 . ':'
71 . substr( $return_date, 14, 2 )
72 . ':'
73 . substr( $return_date, 16, 2 );
74 $return_date = dt_from_string($return_date);
77 $debug and warn "do_checkin() calling AddReturn($barcode, $branch)";
78 my ($return, $messages, $issue, $borrower) = AddReturn($barcode, $branch, undef, $return_date);
80 if ( $checked_in_ok ) {
81 delete $messages->{ItemLocationUpdated};
82 delete $messages->{NotIssued};
83 delete $messages->{LocalUse};
84 $return = 1 unless keys %$messages;
87 # biblionumber, biblioitemnumber, itemnumber
88 # borrowernumber, reservedate, branchcode
89 # cancellationdate, found, reservenotes, priority, timestamp
90 if( $messages->{DataCorrupted} ) {
91 $self->alert_type('98');
93 if ($messages->{BadBarcode}) {
94 $self->alert_type('99');
96 if ($messages->{withdrawn}) {
97 $self->alert_type('99');
99 if ($messages->{WasLost}) {
100 $self->alert_type('99') if C4::Context->preference("BlockReturnOfLostItems");
102 if ($messages->{Wrongbranch}) {
103 $self->{item}->destination_loc($messages->{Wrongbranch}->{Rightbranch});
104 $self->alert_type('04'); # send to other branch
106 if ($messages->{WrongTransfer}) {
107 $self->{item}->destination_loc($messages->{WrongTransfer});
108 $self->alert_type('04'); # send to other branch
110 if ($messages->{NeedsTransfer}) {
111 $self->{item}->destination_loc($messages->{NeedsTransfer});
112 $self->alert_type('04'); # send to other branch
114 if ($messages->{WasTransfered}) { # set into transit so tell unit
115 $self->{item}->destination_loc($issue->item->homebranch);
116 $self->alert_type('04'); # send to other branch
118 if ($messages->{ResFound}) {
119 if ($holds_block_checkin) {
120 $self->alert_type('99');
121 $return = 0;
122 } elsif ($branch eq $messages->{ResFound}->{branchcode}) {
123 $self->hold($messages->{ResFound});
124 $self->alert_type('01');
125 ModReserveAffect( $messages->{ResFound}->{itemnumber},
126 $messages->{ResFound}->{borrowernumber}, 0, $messages->{ResFound}->{reserve_id});
128 } else {
129 $self->hold($messages->{ResFound});
130 $self->alert_type('02');
131 ModReserveAffect( $messages->{ResFound}->{itemnumber},
132 $messages->{ResFound}->{borrowernumber}, 1, $messages->{ResFound}->{reserve_id});
133 ModItemTransfer( $messages->{ResFound}->{itemnumber},
134 $branch,
135 $messages->{ResFound}->{branchcode},
136 $messages->{TransferTrigger},
140 $self->{item}->hold_patron_id( $messages->{ResFound}->{borrowernumber} );
141 $self->{item}->destination_loc( $messages->{ResFound}->{branchcode} );
143 # ignoring messages: NotIssued, WasTransfered
145 if ($cv_triggers_alert) {
146 $self->alert( defined $self->alert_type ); # Overwrites existing alert value, should set to 0 if there is no alert type
148 else {
149 $self->alert( !$return || defined $self->alert_type );
152 $self->ok($return);
154 return { messages => $messages };
157 sub resensitize {
158 my $self = shift;
159 unless ($self->{item}) {
160 warn "resensitize(): no item found in object to resensitize";
161 return;
163 return !$self->{item}->magnetic_media;
166 sub patron_id {
167 my $self = shift;
168 unless ($self->{patron}) {
169 warn "patron_id(): no patron found in object";
170 return;
172 return $self->{patron}->id;