a705f5715b3ee0d05cdbd4ec76999b9f79628e37
[koha.git] / C4 / SIP / ILS / Transaction / Checkin.pm
1 #
2 # An object to handle checkin status
3 #
4
5 package ILS::Transaction::Checkin;
6
7 use warnings;
8 use strict;
9
10 # use POSIX qw(strftime);
11
12 use ILS;
13 use ILS::Transaction;
14
15 use C4::Circulation;
16 use C4::Reserves qw( ModReserveAffect );
17 use C4::Debug;
18
19 our @ISA = qw(ILS::Transaction);
20
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,
32 );
33
34 sub new {
35     my $class = shift;
36     my $self = $class->SUPER::new();                # start with an ILS::Transaction object
37
38     foreach (keys %fields) {
39         $self->{_permitted}->{$_} = $fields{$_};    # overlaying _permitted
40     }
41
42     @{$self}{keys %fields} = values %fields;        # copying defaults into object
43     return bless $self, $class;
44 }
45
46 sub do_checkin {
47     my $self = shift;
48     my $branch = @_ ? shift : 'SIP2' ;
49     my $barcode = $self->{item}->id;
50     $debug and warn "do_checkin() calling AddReturn($barcode, $branch)";
51     my ($return, $messages, $iteminformation, $borrower) = AddReturn($barcode, $branch);
52     $self->alert(!$return);
53     # ignoring messages: NotIssued, IsPermanent, WasLost, WasTransfered
54
55     # biblionumber, biblioitemnumber, itemnumber
56     # borrowernumber, reservedate, branchcode
57     # cancellationdate, found, reservenotes, priority, timestamp
58
59     if ($messages->{BadBarcode}) {
60         $self->alert_type('99');
61     }
62     if ($messages->{wthdrawn}) {
63         $self->alert_type('99');
64     }
65     if ($messages->{Wrongbranch}) {
66         $self->destination_loc($messages->{Wrongbranch}->{Rightbranch});
67         $self->alert_type('04');            # send to other branch
68     }
69     if ($messages->{WrongTransfer}) {
70         $self->destination_loc($messages->{WrongTransfer});
71         $self->alert_type('04');            # send to other branch
72     }
73     if ($messages->{NeedsTransfer}) {
74         $self->destination_loc($iteminformation->{homebranch});
75         $self->alert_type('04');            # send to other branch
76     }
77     if ($messages->{ResFound}) {
78         $self->hold($messages->{ResFound});
79         if ($branch eq $messages->{ResFound}->{branchcode}) {
80             $self->alert_type('01');
81             ModReserveAffect( $messages->{ResFound}->{itemnumber},
82                 $messages->{ResFound}->{borrowernumber}, 0);
83
84         } else {
85             $self->alert_type('02');
86             ModReserveAffect( $messages->{ResFound}->{itemnumber},
87                 $messages->{ResFound}->{borrowernumber}, 1);
88
89         }
90         $self->{item}->hold_patron_id( $messages->{ResFound}->{borrowernumber} );
91         $self->{item}->destination_loc( $messages->{ResFound}->{branchcode} );
92     }
93     $self->alert(1) if defined $self->alert_type;  # alert_type could be "00", hypothetically
94     $self->ok($return);
95 }
96
97 sub resensitize {
98         my $self = shift;
99         unless ($self->{item}) {
100                 warn "resensitize(): no item found in object to resensitize";
101                 return;
102         }
103         return !$self->{item}->magnetic_media;
104 }
105
106 sub patron_id {
107         my $self = shift;
108         unless ($self->{patron}) {
109                 warn "patron_id(): no patron found in object";
110                 return;
111         }
112         return $self->{patron}->id;
113 }
114
115 1;