d3a4700f5e4edfe860596b1f6706fde7c99964eb
[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::Debug;
17
18 our @ISA = qw(ILS::Transaction);
19
20 my %fields = (
21     magnetic => 0,
22     sort_bin => undef,
23     collection_code  => undef,
24     # 3M extensions:
25     call_number      => undef,
26     destination_loc  => undef,
27     alert_type       => undef,  # 00,01,02,03,04 or 99
28     hold_patron_id   => undef,
29     hold_patron_name => "",
30     hold             => undef,
31 );
32
33 sub new {
34     my $class = shift;
35     my $self = $class->SUPER::new();                # start with an ILS::Transaction object
36
37     foreach (keys %fields) {
38         $self->{_permitted}->{$_} = $fields{$_};    # overlaying _permitted
39     }
40
41     @{$self}{keys %fields} = values %fields;        # copying defaults into object
42     return bless $self, $class;
43 }
44
45 sub do_checkin {
46     my $self = shift;
47     my $branch = @_ ? shift : 'SIP2' ;
48     my $barcode = $self->{item}->id;
49     $debug and warn "do_checkin() calling AddReturn($barcode, $branch)";
50     my ($return, $messages, $iteminformation, $borrower) = AddReturn($barcode, $branch);
51     $self->alert(!$return);
52     # ignoring messages: NotIssued, IsPermanent, WasLost, WasTransfered
53
54     # biblionumber, biblioitemnumber, itemnumber
55     # borrowernumber, reservedate, branchcode
56     # cancellationdate, found, reservenotes, priority, timestamp
57
58     if ($messages->{BadBarcode}) {
59         $self->alert_type('99');
60     }
61     if ($messages->{wthdrawn}) {
62         $self->alert_type('99');
63     }
64     if ($messages->{Wrongbranch}) {
65         $self->destination_loc($messages->{Wrongbranch}->{Rightbranch});
66         $self->alert_type('04');            # send to other branch
67     }
68     if ($messages->{WrongTransfer}) {
69         $self->destination_loc($messages->{WrongTransfer});
70         $self->alert_type('04');            # send to other branch
71     }
72     if ($messages->{NeedsTransfer}) {
73         $self->destination_loc($iteminformation->{homebranch});
74         $self->alert_type('04');            # send to other branch
75     }
76     if ($messages->{ResFound}) {
77         $self->hold($messages->{ResFound});
78         $debug and warn "Item returned at $branch reserved at $messages->{ResFound}->{branchcode}";
79         $self->alert_type(($branch eq $messages->{ResFound}->{branchcode}) ? '01' : '02');
80     }
81     $self->alert(1) if defined $self->alert_type;  # alert_type could be "00", hypothetically
82     $self->ok($return);
83 }
84
85 sub resensitize {
86         my $self = shift;
87         unless ($self->{item}) {
88                 warn "resensitize(): no item found in object to resensitize";
89                 return;
90         }
91         return !$self->{item}->magnetic_media;
92 }
93
94 sub patron_id {
95         my $self = shift;
96         unless ($self->{patron}) {
97                 warn "patron_id(): no patron found in object";
98                 return;
99         }
100         return $self->{patron}->id;
101 }
102
103 1;