2 # An object to handle checkin status
5 package OpenILS::SIP::Transaction::Checkin;
10 use POSIX qw(strftime);
11 use Sys::Syslog qw(syslog);
15 use OpenILS::SIP::Transaction;
16 use OpenILS::Const qw/:const/;
17 use OpenILS::Application::AppUtils;
18 my $U = 'OpenILS::Application::AppUtils';
20 use base qw(OpenILS::SIP::Transaction);
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 => "",
39 my $self = $class->SUPER::new(@_); # start with an Transaction object
41 foreach (keys %fields) {
42 $self->{_permitted}->{$_} = $fields{$_}; # overlaying _permitted
45 @{$self}{keys %fields} = values %fields; # copying defaults into object
47 return bless $self, $class;
52 return !$self->{item}->magnetic;
57 my ($inst_id, $trans_date, $return_date, $current_loc, $item_props) = @_; # most unused
60 my $resp = $U->simplereq(
62 'open-ils.circ.checkin',
64 { barcode => $self->{item}->id }
68 open (DUMP, ">/tmp/sip_do_checkin.dump");
69 print DUMP Dumper($resp);
73 my $code = $U->event_code($resp);
74 my $txt = $code ? $resp->{textcode} : '';
76 $resp->{org} &&= OpenILS::SIP::shortname_from_id($resp->{org}); # Convert id to shortname
78 $self->destination_loc($resp->{org}) if $resp->{org};
80 $debug and warn "Checkin textcode: $txt, org: " . ($resp->{org} || '');
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
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
92 my $payload = $resp->{payload} || {};
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
98 elsif ($payload->{hold}) {
99 $self->item->hold($payload->{hold});
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);
112 $self->alert(1) if defined $self->alert_type; # alert_type could be "00", hypothetically
114 my $circ = $resp->{payload}->{circ} || '';
115 my $copy = $resp->{payload}->{copy} || '';
118 # $self->item->{patron} = OpenILS::SIP::patron_barcode_from_id($circ->usr); # Item.pm already does this for us!
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
124 $self->alert_type('00') unless $self->alert_type; # wasn't checked out, but *something* changed
125 # $self->ok(0); # maybe still ok?
132 Successful Checkin event payload includes:
133 $payload->{copy} (unfleshed)
137 $payload->{cancelled_hold_transit}
143 ASSET_COPY_NOT_FOUND => ,
146 CIRC_CLAIMS_RETURNED => ,
147 COPY_ALERT_MESSAGE => ,
148 COPY_STATUS_LOST => ,
149 COPY_STATUS_MISSING => ,
151 ITEM_DEPOSIT_PAID => ,
153 DATABASE_UPDATE_FAILED => ,
154 DATABASE_QUERY_FAILED => ,
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)