LP#1296937: move the $force_bc parameter of ->charged_items() to an implementation...
[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     $self->renewed([]);
25     $self->unrenewed([]);
26
27     return bless $self, $class;
28 }
29
30 sub do_renew_all {
31     my $self = shift;
32     my $sip = shift;
33
34     my $barcodes = $self->patron->charged_items_impl(undef, undef, 1);
35
36     syslog('LOG_INFO', "OILS: RenewalAll for user ".
37         $self->patron->{id} ." and items [@$barcodes]");
38
39     for my $barcode (@$barcodes) {
40         my $item = $sip->find_item($barcode);
41
42         if ($item and $item->{patron} and $item->{patron} eq $self->patron->{id}) {
43
44             my $renew = OpenILS::SIP::Transaction::Renew->new(authtoken => $self->{authtoken});
45             $renew->patron($self->patron);
46             $renew->item($item);
47             $renew->do_renew; # renew this single item
48
49             if ($renew->renewal_ok) {
50                 push(@{$self->renewed}, $barcode);
51                
52             } else {
53                 push(@{$self->unrenewed}, $barcode);
54             }
55
56         } else {
57             syslog('LOG_INFO', "OILS: RenewalAll item " . $item->{id} . 
58                 " is not checked out to user " . $self->patron->{id} . 
59                 ". It's checked out to user " . $item->{patron});
60
61             push(@{$self->unrenewed}, $barcode);
62         }
63     }
64
65     syslog('LOG_INFO', "OILS: RenewalAll ".
66         "ok=[@{$self->renewed}]; not-ok=[@{$self->unrenewed}]");
67
68     $self->ok(1);
69     return $self;
70 }
71