2 # An object to handle checkout status
5 package OpenILS::SIP::Transaction::Checkout;
10 use POSIX qw(strftime);
13 use OpenILS::SIP::Transaction;
14 use OpenILS::SIP::Msg qw/:const/;
15 use Sys::Syslog qw(syslog);
17 use OpenILS::Application::AppUtils;
18 my $U = 'OpenILS::Application::AppUtils';
21 our @ISA = qw(OpenILS::SIP::Transaction);
23 # Most fields are handled by the Transaction superclass
25 security_inhibit => 0,
33 my $self = $class->SUPER::new(@_);
37 foreach $element (keys %fields) {
38 $self->{_permitted}->{$element} = $fields{$element};
41 @{$self}{keys %fields} = values %fields;
43 $self->load_override_events;
45 return bless $self, $class;
48 # Lifted from Checkin.pm to load the list of events that we'll try to
49 # override if they occur during checkout or renewal.
51 sub load_override_events {
52 return if %override_events;
53 my $override = OpenILS::SIP->config->{implementation_config}->{checkout_override};
54 return unless $override;
55 my $events = $override->{event};
56 $events = [$events] unless ref $events eq 'ARRAY';
57 $override_events{$_} = 1 for @$events;
60 # if this item is already checked out to the requested patron,
61 # renew the item and set $self->renew_ok to true.
62 # XXX if it's a renewal and the renewal is not permitted, set
63 # $self->screen_msg("Item on Hold for Another User"); (or somesuch)
64 # XXX Set $self->ok(0) on any errors
67 my $is_renew = shift || 0;
72 barcode => $self->{item}->id,
73 patron_barcode => $self->{patron}->id
81 $method = 'open-ils.circ.renew';
83 $method = 'open-ils.circ.checkout.full';
87 $method .= '.override' if ($override);
88 $resp = $U->simplereq('open-ils.circ', $method, $self->{authtoken}, $args);
90 $resp = [$resp] unless ref $resp eq 'ARRAY';
92 syslog('LOG_DEBUG', "OILS: $method returned event: " . OpenSRF::Utils::JSON->perl2JSON($resp));
94 my $first_code = $U->event_code($$resp[0]);
95 if (@$resp > 1 || !defined $first_code || $first_code ne '0') {
96 # We got one or more non-success events
97 $self->screen_msg('');
99 my $code = $U->event_code($r);
100 my $txt = $r->{textcode};
101 syslog('LOG_INFO', "OILS: $method failed with event $code : $txt");
103 if ($override_events{$txt} && $method !~ /override$/) {
104 # Found an event we've been configured to override.
106 } elsif ($txt =~ /ITEM_(?:DEPOSIT|RENTAL)_FEE_REQUIRED/ && $self->fee_ack) {
107 # Patron acknowledged the fee.
109 } elsif ( $txt eq 'OPEN_CIRCULATION_EXISTS' ) {
110 $self->screen_msg(OILS_SIP_MSG_CIRC_EXISTS);
113 $self->screen_msg(OILS_SIP_MSG_CIRC_PERMIT_FAILED);
117 # This looks potentially dangerous, but we shouldn't
118 # end up here if the loop iterated with $override = 1;
119 next if ($override && $method !~ /override$/);
121 # We appear to have success.
122 # De-arrayify the response.
125 syslog('LOG_INFO', "OILS: $method succeeded");
127 my $circ = $resp->{payload}->{circ};
128 $self->{'due'} = OpenILS::SIP->format_date($circ->due_date, 'due');
133 last if ($method =~ /override$/);