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;
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
};
60 my $barcode = $self->{item
}->id;
63 $return_date = substr( $return_date, 0, 4 )
65 . substr( $return_date, 4, 2 )
67 . substr( $return_date, 6, 2 )
69 . substr( $return_date, 12, 2 )
71 . substr( $return_date, 14, 2 )
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');
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
});
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
},
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
149 $self->alert( !$return || defined $self->alert_type );
154 return { messages
=> $messages };
159 unless ($self->{item
}) {
160 warn "resensitize(): no item found in object to resensitize";
163 return !$self->{item
}->magnetic_media;
168 unless ($self->{patron
}) {
169 warn "patron_id(): no patron found in object";
172 return $self->{patron
}->id;