3M SIP2 Extensions groundwork and Patron Info popoulation
[koha-ffzg.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
17 our @ISA = qw(ILS::Transaction);
18
19 my %fields = (
20     magnetic => 0,
21     sort_bin => undef,
22     collection_code  => undef,
23     # 3M extensions:
24     call_number      => undef,
25     destination_loc  => undef,
26     alert_type       => undef,  # 00,01,02,03,04 or 99
27     hold_patron_id   => undef,
28     hold_patron_name => "",
29     hold             => undef,
30 );
31
32 sub new {
33     my $class = shift;
34     my $self = $class->SUPER::new();
35
36     foreach (keys %fields) {
37         $self->{_permitted}->{$_} = $fields{$_};    # overlaying _permitted
38     }
39
40     @{$self}{keys %fields} = values %fields;        # copying defaults into object
41     return bless $self, $class;
42 }
43
44 sub do_checkin {
45     my $self = shift;
46     my $branch = @_ ? shift : 'SIP2' ;
47     my $barcode = $self->{item}->id;
48     my ($return, $messages, $iteminformation, $borrower) = AddReturn($barcode, $branch);
49     $self->alert(!$return);
50     if ($messages->{BadBarcode}) {
51         $self->alert_type('99');
52     }
53     # ignoring: NotIssued, IsPermanent
54     if ($messages->{wthdrawn}) {
55         $self->alert_type('99');
56     }
57     if ($messages->{ResFound}) {
58         if ($self->hold($messages->{ResFound}->{ResFound})) {
59             $self->alert_type('99');
60         }
61     }
62     defined $self->alert_type and $self->alert(1);  # alert_type could be "00"
63     $self->ok($return);
64 }
65
66 sub resensitize {
67         my $self = shift;
68         unless ($self->{item}) {
69                 warn "no item found in object to resensitize";
70                 return;
71         }
72         return !$self->{item}->magnetic;
73 }
74
75 sub patron_id {
76         my $self = shift;
77         unless ($self->{patron}) {
78                 warn "no patron found in object";
79                 return;
80         }
81         return !$self->{patron}->id;
82 }
83
84 1;