]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Checkout.pm
8e0165ab9173df16f1c5195d4a0d81445ec592c7
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / SIP / Transaction / Checkout.pm
1 #
2 # An object to handle checkout status
3 #
4
5 package OpenILS::SIP::Transaction::Checkout;
6
7 use warnings;
8 use strict;
9
10 use POSIX qw(strftime);
11
12 use OpenILS::SIP;
13 use OpenILS::SIP::Transaction;
14 use Sys::Syslog qw(syslog);
15
16 use OpenILS::Application::AppUtils;
17 my $U = 'OpenILS::Application::AppUtils';
18
19
20 our @ISA = qw(OpenILS::SIP::Transaction);
21
22 # Most fields are handled by the Transaction superclass
23 my %fields = (
24               security_inhibit => 0,
25               due              => undef,
26               renew_ok         => 0,
27               );
28
29 sub new {
30          my $class = shift;
31
32     my $self = $class->SUPER::new(@_);
33
34     my $element;
35
36         foreach $element (keys %fields) {
37                 $self->{_permitted}->{$element} = $fields{$element};
38         }
39
40     @{$self}{keys %fields} = values %fields;
41          
42     return bless $self, $class;
43 }
44
45
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
51 sub do_checkout {
52         my $self = shift;
53         syslog('LOG_DEBUG', "OILS: performing checkout...");
54
55         $self->ok(0); 
56
57         my $args = { 
58                 barcode => $self->{item}->id, 
59                 patron_barcode => $self->{patron}->id
60         };
61
62         my $resp = $U->simplereq(
63                 'open-ils.circ',
64                 'open-ils.circ.checkout.permit', 
65                 $self->{authtoken}, $args );
66
67         if( ref($resp) eq 'ARRAY' ) {
68                 my @e;
69                 push( @e, $_->{textcode} ) for @$resp;
70                 syslog('LOG_INFO', "OILS: Checkout permit failed with events: @e");
71                 return 0;
72         }
73
74         if( my $code = $U->event_code($resp) ) {
75                 my $txt = $resp->{textcode};
76                 syslog('LOG_INFO', "OILS: Checkout permit failed with event $code : $txt");
77                 return 0; 
78         }
79
80         my $key;
81
82         if( $key = $resp->{payload} ) {
83                 syslog('LOG_INFO', "OILS: circ permit key => $key");
84
85         } else {
86                 syslog('LOG_WARN', "OILS: Circ permit failed :\n" . Dumper($resp) );
87                 return 0;
88         }
89
90         # Now do the actual checkout
91
92         $args = { 
93                 permit_key              => $key, 
94                 patron_barcode => $self->{patron}->id, 
95                 barcode                 => $self->{item}->id
96         };
97
98         $resp = $U->simplereq(
99                 'open-ils.circ',
100                 'open-ils.circ.checkout', $self->{authtoken}, $args );
101
102         # XXX Check for events
103         if( $resp ) {
104
105                 if( my $code = $U->event_code($resp) ) {
106                         my $txt = $resp->{textcode};
107                         syslog('LOG_INFO', "OILS: Checkout failed with event $code : $txt");
108                         return 0; 
109                 }
110
111                 syslog('LOG_INFO', "OILS: Checkout succeeded");
112
113                 my $circ = $resp->{payload}->{circ};
114                 $self->{'due'} = $circ->due_date;
115                 $self->ok(1);
116
117                 return 1;
118         }
119
120         return 0;
121 }
122
123
124
125 1;