]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction/RenewAll.pm
663be7d71fcc405d431a1f8e49ffed3ebb7fcd75
[working/Evergreen.git] / Open-ILS / src / perlmods / lib / OpenILS / SIP / Transaction / RenewAll.pm
1 package OpenILS::SIP::Transaction::RenewAll;
2 use warnings; use strict;
3
4 use Sys::Syslog qw(syslog);
5 use OpenILS::SIP;
6 use OpenILS::SIP::Transaction;
7 use OpenILS::SIP::Transaction::Renew;
8 use OpenILS::Application::AppUtils;
9 my $U = 'OpenILS::Application::AppUtils';
10
11 our @ISA = qw(OpenILS::SIP::Transaction);
12
13 my %fields = (
14     renewed => [],
15     unrenewed => []
16 );
17
18 sub new {
19         my $class = shift;;
20         my $self = $class->SUPER::new(@_);
21
22         $self->{_permitted}->{$_} = $fields{$_} for keys %fields;
23         @{$self}{keys %fields} = values %fields;
24
25         return bless $self, $class;
26 }
27
28 sub do_renew_all {
29     my $self = shift;
30     my $sip = shift;
31
32     my $barcodes = $self->patron->charged_items(undef, undef, 1);
33
34     syslog('LOG_INFO', "OILS: RenewalAll for user ".
35         $self->patron->{id} ." and items [@$barcodes]");
36
37     for my $barcode (@$barcodes) {
38         my $item = $sip->find_item($barcode);
39
40         if ($item and $item->{patron} and $item->{patron} eq $self->patron->{id}) {
41
42             my $renew = OpenILS::SIP::Transaction::Renew->new(authtoken => $self->{authtoken});
43             $renew->patron($self->patron);
44             $renew->item($item);
45             $renew->do_renew; # renew this single item
46
47             if ($renew->renewal_ok) {
48                 push(@{$self->renewed}, $barcode);
49                
50             } else {
51                 push(@{$self->unrenewed}, $barcode);
52             }
53
54         } else {
55             syslog('LOG_INFO', "OILS: RenewalAll item " . $item->{id} . 
56                 " is not checked out to user " . $self->patron->{id} . 
57                 ". It's checked out to user " . $item->{patron});
58
59             push(@{$self->unrenewed}, $barcode);
60         }
61     }
62
63     syslog('LOG_INFO', "OILS: RenewalAll ".
64         "ok=[@{$self->renewed}]; not-ok=[@{$self->unrenewed}]");
65
66     $self->ok(1);
67     return $self;
68 }
69