From 9ddb0afc6668efc6a49fb1512faa9a18526fe70b Mon Sep 17 00:00:00 2001 From: "Joe Atzberger (siptest" Date: Wed, 4 Jun 2008 18:14:42 -0500 Subject: [PATCH] Add do_renew_all function, necessary for implementation. Signed-off-by: Joshua Ferraro --- C4/SIP/ILS/Transaction/RenewAll.pm | 59 ++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/C4/SIP/ILS/Transaction/RenewAll.pm b/C4/SIP/ILS/Transaction/RenewAll.pm index 6f3b90d0e4..c8e81fd06e 100644 --- a/C4/SIP/ILS/Transaction/RenewAll.pm +++ b/C4/SIP/ILS/Transaction/RenewAll.pm @@ -6,24 +6,59 @@ package ILS::Transaction::RenewAll; use strict; use warnings; -our @ISA = qw(ILS::Transaction); +use Sys::Syslog qw(syslog); + +use ILS::Item; +use ILS::Transaction::Renew; + +use C4::Members; # GetMember + +our @ISA = qw(ILS::Transaction::Renew); my %fields = ( - renewed => [], - unrenewed => [], - ); + renewed => [], + unrenewed => [], +); + sub new { - my $class = shift;; - my $self = $class->SUPER::new(); - my $element; + my $class = shift; + my $self = $class->SUPER::new(); + my $element; - foreach $element (keys %fields) { - $self->{_permitted}->{$element} = $fields{$element}; - } + foreach $element (keys %fields) { + $self->{_permitted}->{$element} = $fields{$element}; + } - @{$self}{keys %fields} = values %fields; + @{$self}{keys %fields} = values %fields; + return bless $self, $class; +} - return bless $self, $class; +sub do_renew_all { + my $self = shift; + my $patron = $self->{patron}; # SIP's patron + my $borrower = GetMember($patron->id, 'cardnumber'); # Koha's patron + my $all_ok = 1; + foreach my $itemx (@{$patron->{items}}) { + my $item_id = $itemx->{barcode}; + my $item = new ILS::Item $item_id; + if (!defined($item)) { + syslog("LOG_WARNING", + "renew_all: Invalid item id '%s' associated with patron '%s'", + $item_id, $patron->id); + $all_ok = 0; + next; + } + $self->{item} = $item; + $self->do_renew_for($borrower); + if ($self->ok) { + $item->{due_date} = $self->{due}; + push @{$self->renewed }, $item_id; + } else { + push @{$self->unrenewed}, $item_id; + } + } + $self->ok($all_ok); + return $self; } 1; -- 2.39.5