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 return bless $self, $class;
47 # if this item is already checked out to the requested patron,
48 # renew the item and set $self->renew_ok to true.
49 # XXX if it's a renewal and the renewal is not permitted, set
50 # $self->screen_msg("Item on Hold for Another User"); (or somesuch)
51 # XXX Set $self->ok(0) on any errors
54 syslog('LOG_DEBUG', "OILS: performing checkout...");
59 barcode => $self->{item}->id,
60 patron_barcode => $self->{patron}->id
63 my $resp = $U->simplereq(
65 'open-ils.circ.checkout.permit',
66 $self->{authtoken}, $args );
68 $resp = [$resp] unless ref $resp eq 'ARRAY';
72 syslog('LOG_DEBUG', "OILS: Checkout permit returned event: " . OpenSRF::Utils::JSON->perl2JSON($resp));
74 if( @$resp == 1 and ! $U->event_code($$resp[0]) ) {
75 $key = $$resp[0]->{payload};
76 syslog('LOG_INFO', "OILS: circ permit key => $key");
80 # We got one or more non-success events
81 $self->screen_msg('');
84 if( my $code = $U->event_code($resp) ) {
85 my $txt = $resp->{textcode};
86 syslog('LOG_INFO', "OILS: Checkout permit failed with event $code : $txt");
88 if( $txt eq 'OPEN_CIRCULATION_EXISTS' ) {
89 $self->screen_msg(OILS_SIP_MSG_CIRC_EXISTS);
92 $self->screen_msg(OILS_SIP_MSG_CIRC_PERMIT_FAILED);
99 # --------------------------------------------------------------------
100 # Now do the actual checkout
101 # --------------------------------------------------------------------
105 patron_barcode => $self->{patron}->id,
106 barcode => $self->{item}->id
109 $resp = $U->simplereq(
111 'open-ils.circ.checkout', $self->{authtoken}, $args );
114 syslog('LOG_DEBUG', "OILS: Checkout returned event: " . OpenSRF::Utils::JSON->perl2JSON($resp));
116 # XXX Check for events
119 if( my $code = $U->event_code($resp) ) {
120 my $txt = $resp->{textcode};
121 syslog('LOG_INFO', "OILS: Checkout failed with event $code : $txt");
122 $self->screen_msg('Checkout failed. Please contact a librarian');
126 syslog('LOG_INFO', "OILS: Checkout succeeded");
128 my $circ = $resp->{payload}->{circ};
129 $self->{'due'} = OpenILS::SIP->format_date($circ->due_date, 'due');