Bug 10550: Fix database typo wthdrawn
[koha.git] / C4 / SIP / ILS / Transaction / Checkin.pm
blobdb1f1021a1956c07163bf31065cb67b14765e144
2 # An object to handle checkin status
5 package ILS::Transaction::Checkin;
7 use warnings;
8 use strict;
10 # use POSIX qw(strftime);
12 use ILS;
13 use ILS::Transaction;
15 use C4::Circulation;
16 use C4::Reserves qw( ModReserveAffect );
17 use C4::Items qw( ModItemTransfer );
18 use C4::Debug;
20 use parent qw(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 if (!$branch) {
51 $branch = 'SIP2';
53 my $barcode = $self->{item}->id;
54 $debug and warn "do_checkin() calling AddReturn($barcode, $branch)";
55 my ($return, $messages, $iteminformation, $borrower) = AddReturn($barcode, $branch);
56 $self->alert(!$return);
57 # ignoring messages: NotIssued, IsPermanent, WasLost, WasTransfered
59 # biblionumber, biblioitemnumber, itemnumber
60 # borrowernumber, reservedate, branchcode
61 # cancellationdate, found, reservenotes, priority, timestamp
63 if ($messages->{BadBarcode}) {
64 $self->alert_type('99');
66 if ($messages->{withdrawn}) {
67 $self->alert_type('99');
69 if ($messages->{Wrongbranch}) {
70 $self->destination_loc($messages->{Wrongbranch}->{Rightbranch});
71 $self->alert_type('04'); # send to other branch
73 if ($messages->{WrongTransfer}) {
74 $self->destination_loc($messages->{WrongTransfer});
75 $self->alert_type('04'); # send to other branch
77 if ($messages->{NeedsTransfer}) {
78 $self->destination_loc($iteminformation->{homebranch});
79 $self->alert_type('04'); # send to other branch
81 if ($messages->{ResFound}) {
82 $self->hold($messages->{ResFound});
83 if ($branch eq $messages->{ResFound}->{branchcode}) {
84 $self->alert_type('01');
85 ModReserveAffect( $messages->{ResFound}->{itemnumber},
86 $messages->{ResFound}->{borrowernumber}, 0);
88 } else {
89 $self->alert_type('02');
90 ModReserveAffect( $messages->{ResFound}->{itemnumber},
91 $messages->{ResFound}->{borrowernumber}, 1);
92 ModItemTransfer( $messages->{ResFound}->{itemnumber},
93 $branch,
94 $messages->{ResFound}->{branchcode}
98 $self->{item}->hold_patron_id( $messages->{ResFound}->{borrowernumber} );
99 $self->{item}->destination_loc( $messages->{ResFound}->{branchcode} );
101 $self->alert(1) if defined $self->alert_type; # alert_type could be "00", hypothetically
102 $self->ok($return);
105 sub resensitize {
106 my $self = shift;
107 unless ($self->{item}) {
108 warn "resensitize(): no item found in object to resensitize";
109 return;
111 return !$self->{item}->magnetic_media;
114 sub patron_id {
115 my $self = shift;
116 unless ($self->{patron}) {
117 warn "patron_id(): no patron found in object";
118 return;
120 return $self->{patron}->id;