Bug 7904 Change SIP modules to use standard LIB path
[koha.git] / C4 / SIP / ILS / Transaction / Checkin.pm
blobc7b959ec757d2feb8f3097bad94b3588da9ca18f
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::Reserves qw( ModReserveAffect );
16 use C4::Items qw( ModItemTransfer );
17 use C4::Debug;
19 use parent qw(C4::SIP::ILS::Transaction);
21 my %fields = (
22 magnetic => 0,
23 sort_bin => undef,
24 collection_code => undef,
25 # 3M extensions:
26 call_number => undef,
27 destination_loc => undef,
28 alert_type => undef, # 00,01,02,03,04 or 99
29 hold_patron_id => undef,
30 hold_patron_name => "",
31 hold => undef,
34 sub new {
35 my $class = shift;
36 my $self = $class->SUPER::new(); # start with an ILS::Transaction object
38 foreach (keys %fields) {
39 $self->{_permitted}->{$_} = $fields{$_}; # overlaying _permitted
42 @{$self}{keys %fields} = values %fields; # copying defaults into object
43 return bless $self, $class;
46 sub do_checkin {
47 my $self = shift;
48 my $branch = shift;
49 my $return_date = shift;
50 if (!$branch) {
51 $branch = 'SIP2';
53 my $barcode = $self->{item}->id;
55 $return_date = substr( $return_date, 0, 4 )
56 . '-'
57 . substr( $return_date, 4, 2 )
58 . '-'
59 . substr( $return_date, 6, 2 )
60 . q{ }
61 . substr( $return_date, 12, 2 )
62 . ':'
63 . substr( $return_date, 14, 2 )
64 . ':'
65 . substr( $return_date, 16, 2 );
67 $debug and warn "do_checkin() calling AddReturn($barcode, $branch)";
68 my ($return, $messages, $iteminformation, $borrower) = AddReturn($barcode, $branch, undef, undef, $return_date);
69 $self->alert(!$return);
70 # ignoring messages: NotIssued, IsPermanent, WasLost, WasTransfered
72 # biblionumber, biblioitemnumber, itemnumber
73 # borrowernumber, reservedate, branchcode
74 # cancellationdate, found, reservenotes, priority, timestamp
76 if ($messages->{BadBarcode}) {
77 $self->alert_type('99');
79 if ($messages->{withdrawn}) {
80 $self->alert_type('99');
82 if ($messages->{Wrongbranch}) {
83 $self->destination_loc($messages->{Wrongbranch}->{Rightbranch});
84 $self->alert_type('04'); # send to other branch
86 if ($messages->{WrongTransfer}) {
87 $self->destination_loc($messages->{WrongTransfer});
88 $self->alert_type('04'); # send to other branch
90 if ($messages->{NeedsTransfer}) {
91 $self->destination_loc($iteminformation->{homebranch});
92 $self->alert_type('04'); # send to other branch
94 if ($messages->{ResFound}) {
95 $self->hold($messages->{ResFound});
96 if ($branch eq $messages->{ResFound}->{branchcode}) {
97 $self->alert_type('01');
98 ModReserveAffect( $messages->{ResFound}->{itemnumber},
99 $messages->{ResFound}->{borrowernumber}, 0);
101 } else {
102 $self->alert_type('02');
103 ModReserveAffect( $messages->{ResFound}->{itemnumber},
104 $messages->{ResFound}->{borrowernumber}, 1);
105 ModItemTransfer( $messages->{ResFound}->{itemnumber},
106 $branch,
107 $messages->{ResFound}->{branchcode}
111 $self->{item}->hold_patron_id( $messages->{ResFound}->{borrowernumber} );
112 $self->{item}->destination_loc( $messages->{ResFound}->{branchcode} );
114 $self->alert(1) if defined $self->alert_type; # alert_type could be "00", hypothetically
115 $self->ok($return);
118 sub resensitize {
119 my $self = shift;
120 unless ($self->{item}) {
121 warn "resensitize(): no item found in object to resensitize";
122 return;
124 return !$self->{item}->magnetic_media;
127 sub patron_id {
128 my $self = shift;
129 unless ($self->{patron}) {
130 warn "patron_id(): no patron found in object";
131 return;
133 return $self->{patron}->id;