SIP RenewAll
authorBill Erickson <berick@esilibrary.com>
Mon, 26 Nov 2012 19:51:27 +0000 (14:51 -0500)
committerMike Rylander <mrylander@gmail.com>
Fri, 7 Jun 2013 16:26:10 +0000 (12:26 -0400)
Adds SIP plugin support for SIP message types 65/66 (Renew All).  When
requested, the plugin performs a renewal on all items currently checked
out for the user.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/examples/oils_sip.xml.example
Open-ILS/src/perlmods/lib/OpenILS/SIP.pm
Open-ILS/src/perlmods/lib/OpenILS/SIP/Item.pm
Open-ILS/src/perlmods/lib/OpenILS/SIP/Patron.pm
Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction/Renew.pm
Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction/RenewAll.pm [new file with mode: 0644]

index d6c5d88..c986ca1 100644 (file)
@@ -87,7 +87,7 @@
                                        <item name='patron enable' value='false'/>
                                        <item name='hold' value='false'/>
                                        <item name='renew' value='true'/>
-                                       <item name='renew all' value='false'/>
+                                       <item name='renew all' value='true'/>
                                </supports>
                                <options>
                                        <!-- msg64, the patron information request can be
index da2528c..2e5f3f1 100644 (file)
@@ -14,6 +14,7 @@ use OpenILS::SIP::Transaction;
 use OpenILS::SIP::Transaction::Checkout;
 use OpenILS::SIP::Transaction::Checkin;
 use OpenILS::SIP::Transaction::Renew;
+use OpenILS::SIP::Transaction::RenewAll;
 use OpenILS::SIP::Transaction::FeePayment;
 
 use OpenSRF::System;
@@ -709,7 +710,29 @@ sub renew {
 }
 
 
+sub renew_all {
+    my ($self, $patron_id, $patron_pwd, $fee_ack) = @_;
 
+    $self->verify_session;
+
+    my $trans = OpenILS::SIP::Transaction::RenewAll->new(authtoken => $self->{authtoken});
+    $trans->patron($self->find_patron($patron_id));
+
+    if(!$trans->patron) {
+        $trans->screen_msg("Invalid patron barcode.");
+        $trans->ok(0);
+        return $trans;
+    }
+
+    if(!$trans->patron->renew_ok) {
+        $trans->screen_msg("Renewals not allowed.");
+        $trans->ok(0);
+        return $trans;
+    }
+
+    $trans->do_renew_all($self);
+    return $trans;
+}
 
 
 #
index 71a823d..69787e6 100644 (file)
@@ -104,8 +104,11 @@ sub new {
     my $circ = $e->search_action_circulation([
         {
             target_copy => $copy->id,
-            stop_fines_time => undef, 
-            checkin_time => undef
+            checkin_time => undef,
+            '-or' => [
+                {stop_fines => undef},
+                {stop_fines => ["MAXFINES","LONGOVERDUE"]},
+            ]
         },
         {
             flesh => 2,
index 5ce70e9..d40be97 100644 (file)
@@ -593,8 +593,9 @@ sub __circ_to_title {
         $e->retrieve_asset_copy($circ->target_copy) );
 }
 
+# force_bc -- return barcode data regardless of msg64_summary_datatype
 sub charged_items {
-    my ($self, $start, $end) = shift;
+    my ($self, $start, $end, $force_bc) = shift;
 
     $self->__patron_items_info();
 
@@ -612,7 +613,7 @@ sub charged_items {
 
     for my $circid (@charges) {
         next unless $circid;
-        if($return_datatype eq 'barcode') {
+        if($return_datatype eq 'barcode' or $force_bc) {
             push( @c, __circ_to_barcode($self->{editor}, $circid));
         } else {
             push( @c, OpenILS::SIP::clean_text(__circ_to_title($self->{editor}, $circid)));
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction/RenewAll.pm b/Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction/RenewAll.pm
new file mode 100644 (file)
index 0000000..663be7d
--- /dev/null
@@ -0,0 +1,69 @@
+package OpenILS::SIP::Transaction::RenewAll;
+use warnings; use strict;
+
+use Sys::Syslog qw(syslog);
+use OpenILS::SIP;
+use OpenILS::SIP::Transaction;
+use OpenILS::SIP::Transaction::Renew;
+use OpenILS::Application::AppUtils;
+my $U = 'OpenILS::Application::AppUtils';
+
+our @ISA = qw(OpenILS::SIP::Transaction);
+
+my %fields = (
+    renewed => [],
+    unrenewed => []
+);
+
+sub new {
+       my $class = shift;;
+       my $self = $class->SUPER::new(@_);
+
+       $self->{_permitted}->{$_} = $fields{$_} for keys %fields;
+       @{$self}{keys %fields} = values %fields;
+
+       return bless $self, $class;
+}
+
+sub do_renew_all {
+    my $self = shift;
+    my $sip = shift;
+
+    my $barcodes = $self->patron->charged_items(undef, undef, 1);
+
+    syslog('LOG_INFO', "OILS: RenewalAll for user ".
+        $self->patron->{id} ." and items [@$barcodes]");
+
+    for my $barcode (@$barcodes) {
+        my $item = $sip->find_item($barcode);
+
+        if ($item and $item->{patron} and $item->{patron} eq $self->patron->{id}) {
+
+            my $renew = OpenILS::SIP::Transaction::Renew->new(authtoken => $self->{authtoken});
+            $renew->patron($self->patron);
+            $renew->item($item);
+            $renew->do_renew; # renew this single item
+
+            if ($renew->renewal_ok) {
+                push(@{$self->renewed}, $barcode);
+               
+            } else {
+                push(@{$self->unrenewed}, $barcode);
+            }
+
+        } else {
+            syslog('LOG_INFO', "OILS: RenewalAll item " . $item->{id} . 
+                " is not checked out to user " . $self->patron->{id} . 
+                ". It's checked out to user " . $item->{patron});
+
+            push(@{$self->unrenewed}, $barcode);
+        }
+    }
+
+    syslog('LOG_INFO', "OILS: RenewalAll ".
+        "ok=[@{$self->renewed}]; not-ok=[@{$self->unrenewed}]");
+
+    $self->ok(1);
+    return $self;
+}
+