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 Sys::Syslog qw(syslog);
16 use OpenILS::Application::AppUtils;
17 my $U = 'OpenILS::Application::AppUtils';
20 our @ISA = qw(OpenILS::SIP::Transaction);
22 # Most fields are handled by the Transaction superclass
24 security_inhibit => 0,
32 my $self = $class->SUPER::new(@_);
36 foreach $element (keys %fields) {
37 $self->{_permitted}->{$element} = $fields{$element};
40 @{$self}{keys %fields} = values %fields;
42 return bless $self, $class;
46 # if this item is already checked out to the requested patron,
47 # renew the item and set $self->renew_ok to true.
48 # XXX if it's a renewal and the renewal is not permitted, set
49 # $self->screen_msg("Item on Hold for Another User"); (or somesuch)
50 # XXX Set $self->ok(0) on any errors
53 syslog('LOG_DEBUG', "OILS: performing checkout...");
58 barcode => $self->{item}->id,
59 patron_barcode => $self->{patron}->id
62 my $resp = $U->simplereq(
64 'open-ils.circ.checkout.permit',
65 $self->{authtoken}, $args );
67 if( ref($resp) eq 'ARRAY' ) {
69 push( @e, $_->{textcode} ) for @$resp;
70 syslog('LOG_INFO', "OILS: Checkout permit failed with events: @e");
71 $self->screen_msg('Patron is not allowed to check out the selected item');
75 if( my $code = $U->event_code($resp) ) {
76 my $txt = $resp->{textcode};
77 syslog('LOG_INFO', "OILS: Checkout permit failed with event $code : $txt");
78 $self->screen_msg('Patron is not allowed to check out the selected item');
84 if( $key = $resp->{payload} ) {
85 syslog('LOG_INFO', "OILS: circ permit key => $key");
88 syslog('LOG_WARN', "OILS: Circ permit failed :\n" . Dumper($resp) );
89 $self->screen_msg('Patron is not allowed to check out the selected item');
93 # Now do the actual checkout
97 patron_barcode => $self->{patron}->id,
98 barcode => $self->{item}->id
101 $resp = $U->simplereq(
103 'open-ils.circ.checkout', $self->{authtoken}, $args );
105 # XXX Check for events
108 if( my $code = $U->event_code($resp) ) {
109 my $txt = $resp->{textcode};
110 syslog('LOG_INFO', "OILS: Checkout failed with event $code : $txt");
111 $self->screen_msg('Checkout failed. Please contact a librarian');
115 syslog('LOG_INFO', "OILS: Checkout succeeded");
117 my $circ = $resp->{payload}->{circ};
118 $self->{'due'} = OpenILS::SIP->format_date($circ->due_date);