]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Checkin.pm
SIP Callnumber extensions, POD
[working/Evergreen.git] / Open-ILS / src / perlmods / OpenILS / SIP / Transaction / Checkin.pm
1 #
2 # An object to handle checkin status
3 #
4
5 package OpenILS::SIP::Transaction::Checkin;
6
7 use warnings;
8 use strict;
9
10 use POSIX qw(strftime);
11 use Sys::Syslog qw(syslog);
12 use Data::Dumper;
13
14 use OpenILS::SIP;
15 use OpenILS::SIP::Transaction;
16 use OpenILS::Const qw/:const/;
17 use OpenILS::Application::AppUtils;
18 my $U = 'OpenILS::Application::AppUtils';
19
20 use base qw(OpenILS::SIP::Transaction);
21
22 my $debug = 0;
23
24 my %fields = (
25     magnetic => 0,
26     sort_bin => undef,
27     # 3M extensions: (most of the data is stored under Item)
28 #   collection_code  => undef,
29 #   call_number      => undef,
30     destination_loc  => undef,
31     alert_type       => undef,  # 00,01,02,03,04 or 99
32 #   hold_patron_id   => undef,
33 #   hold_patron_name => "",
34 #   hold             => undef,
35 );
36
37 sub new {
38     my $class = shift;;
39     my $self = $class->SUPER::new(@_);              # start with an Transaction object
40
41     foreach (keys %fields) {
42         $self->{_permitted}->{$_} = $fields{$_};    # overlaying _permitted
43     }
44
45     @{$self}{keys %fields} = values %fields;        # copying defaults into object
46
47     return bless $self, $class;
48 }
49
50 sub resensitize {
51     my $self = shift;
52     return !$self->{item}->magnetic;
53 }
54
55 sub do_checkin {
56     my $self = shift;
57     my ($inst_id, $trans_date, $return_date, $current_loc, $item_props) = @_; # most unused
58     $inst_id ||= '';
59
60     my $resp = $U->simplereq(
61         'open-ils.circ',
62         'open-ils.circ.checkin',
63         $self->{authtoken},
64         { barcode => $self->{item}->id }
65     );
66
67     if ($debug) {
68         open (DUMP, ">/tmp/sip_do_checkin.dump");
69         print DUMP Dumper($resp);
70         close DUMP;
71     }
72
73     my $code = $U->event_code($resp);
74     my $txt  = $code ? $resp->{textcode} : '';
75
76     $resp->{org} &&= OpenILS::SIP::shortname_from_id($resp->{org}); # Convert id to shortname
77
78     $self->destination_loc($resp->{org}) if $resp->{org};
79
80     $debug and warn "Checkin textcode: $txt, org: " . ($resp->{org} || '');
81
82     if ($txt eq 'ROUTE_ITEM') {
83         # $self->destination_loc($resp->{org});   # org value already converted and added (above)
84         $self->alert_type('04');            # send to other branch
85     }
86     elsif ($txt and $txt ne 'NO_CHANGE' and $txt ne 'SUCCESS') {
87         syslog('LOG_WARNING', "OILS: Checkin returned unrecognized event $code : $txt");
88         # $self->ok(0);   # maybe still ok?
89         $self->alert_type('00');            # unknown
90     }
91     
92     my $payload = $resp->{payload} || {};
93
94     # Two places to look for hold data.  These are more important and more definitive than above.
95     if ($payload->{remote_hold}) {
96         $self->item->hold($payload->{remote_hold});     # actually only used for checkin at non-owning branch w/ hold at same branch
97     }
98     elsif ($payload->{hold}) {
99         $self->item->hold($payload->{hold});
100     }
101
102     if ($self->item->hold) {
103         my $holder = OpenILS::SIP->find_patron('usr' => $self->item->hold->usr)
104             or warn "OpenILS::SIP->find_patron cannot find hold usr => '" . $self->item->hold->usr . "'";
105         $self->item->hold_patron_bcode( $holder->id   );
106         $self->item->hold_patron_name(  $holder->name );     # Item already had the holder ID, we really just needed the name
107         $self->item->destination_loc( OpenILS::SIP::shortname_from_id($self->item->hold->pickup_lib) );   # must use pickup_lib as method
108         my $atype = ($self->item->destination_loc eq $inst_id)  ? '01' : '02';
109         $self->alert_type($atype);
110     }
111
112     $self->alert(1) if defined $self->alert_type;  # alert_type could be "00", hypothetically
113
114     my $circ = $resp->{payload}->{circ} || '';
115     my $copy = $resp->{payload}->{copy} || '';
116
117     if ( $circ ) {
118         # $self->item->{patron} = OpenILS::SIP::patron_barcode_from_id($circ->usr);     # Item.pm already does this for us!
119         $self->ok(1);
120     } elsif ($txt eq 'NO_CHANGE' or $txt eq 'SUCCESS' or $txt eq 'ROUTE_ITEM') {
121         $self->ok(1);       # NO_CHANGE means it wasn't checked out anyway, no problem
122     } else {
123         $self->alert(1);
124         $self->alert_type('00') unless $self->alert_type;   # wasn't checked out, but *something* changed
125         # $self->ok(0);     # maybe still ok?
126     }
127 }
128
129 1;
130 __END__
131
132 Successful Checkin event payload includes:
133     $payload->{copy}   (unfleshed)
134     $payload->{record} 
135     $payload->{circ}   
136     $payload->{transit}
137     $payload->{cancelled_hold_transit}
138     $payload->{hold}   
139     $payload->{patron} 
140
141 Some EVENT strings:
142     SUCCESS                => ,
143     ASSET_COPY_NOT_FOUND   => ,
144     NO_CHANGE              => ,
145     PERM_FAILURE           => ,
146     CIRC_CLAIMS_RETURNED   => ,
147     COPY_ALERT_MESSAGE     => ,
148     COPY_STATUS_LOST       => ,
149     COPY_STATUS_MISSING    => ,
150     COPY_BAD_STATUS        => ,
151     ITEM_DEPOSIT_PAID      => ,
152     ROUTE_ITEM             => ,
153     DATABASE_UPDATE_FAILED => ,
154     DATABASE_QUERY_FAILED  => ,
155
156 # alert_type:
157 #   00 - Unknown
158 #   01 - hold in local library
159 #   02 - hold for other branch
160 #   03 - hold for ILL (not used in EG)
161 #   04 - send to other branch (no hold)
162 #   99 - Other