]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Checkout.pm
adding
[working/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          use Data::Dumper;
33          warn 'ARGS = ' .  Dumper(\@_);
34
35     my $self = $class->SUPER::new(@_);
36
37     my $element;
38
39         foreach $element (keys %fields) {
40                 $self->{_permitted}->{$element} = $fields{$element};
41         }
42
43     @{$self}{keys %fields} = values %fields;
44          
45     return bless $self, $class;
46 }
47
48
49 # if this item is already checked out to the requested patron,
50 # renew the item and set $self->renew_ok to true.  
51 # XXX if it's a renewal and the renewal is not permitted, set 
52 # $self->screen_msg("Item on Hold for Another User"); (or somesuch)
53 # XXX Set $self->ok(0) on any errors
54 sub do_checkout {
55         my $self = shift;
56         syslog('LOG_DEBUG', "OpenILS: performing checkout...");
57
58         my $args = { 
59                 barcode => $self->{item}->id, 
60                 patron_barcode => $self->{patron}->id
61         };
62
63         my $resp = $U->simplereq(
64                 'open-ils.circ',
65                 'open-ils.circ.checkout.permit', 
66                 $self->{authtoken}, $args );
67
68         my $key;
69
70         if( ref($resp) eq 'HASH' and $key = $resp->{payload} ) {
71                 syslog('LOG_INFO', "OpenILS: circ permit key => $key");
72
73         } else {
74                 syslog('LOG_INFO', "OpenILS: Circ permit failed :\n" . Dumper($resp) );
75                 $self->ok(0);
76                 return 0;
77         }
78
79         $args = { 
80                 permit_key              => $key, 
81                 patron_barcode => $self->{patron}->id, 
82                 barcode                 => $self->{item}->id
83         };
84
85         $resp = $U->simplereq(
86                 'open-ils.circ',
87                 'open-ils.circ.checkout', $self->{authtoken}, $args );
88
89         # XXX Check for events
90         if( $resp ) {
91                 syslog('LOG_INFO', "OpenILS: Checkout succeeded");
92                 my $evt = $resp->{ilsevent};
93                 my $circ = $resp->{payload}->{circ};
94
95                 if(!$circ or $evt ne 0) { 
96                         $self->ok(0); 
97                         warn 'CHECKOUT RESPONSE: ' .  Dumper($resp) . "\n";
98                         return 0; 
99                 }
100
101                 $self->{'due'} = $circ->due_date;
102                 $self->ok(1);
103                 return 1;
104         }
105
106         return 0;
107 }
108
109
110
111 1;