LP1901930 Renewals
authorBill Erickson <berickxx@gmail.com>
Tue, 3 Nov 2020 21:29:08 +0000 (16:29 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 30 Nov 2020 16:38:26 +0000 (08:38 -0800)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Checkin.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Checkout.pm

index a8fcc30..5172062 100644 (file)
@@ -71,6 +71,7 @@ sub dispatch_sip2_request {
         '11' => \&handle_checkout,
         '17' => \&handle_item_info,
         '23' => \&handle_patron_status,
+        '29' => \&handle_renew,
         '37' => \&handle_payment,
         '63' => \&handle_patron_info,
         'XS' => \&handle_end_session
@@ -386,13 +387,32 @@ sub patron_response_common_data {
     };
 }
 
+
 sub handle_checkout {
     my ($session, $message) = @_;
 
+    my ($msg, $details) = checkout_renew_common($session, $message);
+
+    # No modifications required
+    return $msg;
+}
+
+sub handle_renew {
+    my ($session, $message) = @_;
+
+    my ($msg, $details) = checkout_renew_common($session, $message, 1);
+
+    # No modifications required
+    return $msg;
+}
+
+sub checkout_renew_common {
+    my ($session, $message, $is_renewal) = @_;
+    my $config = $session->config;
+
     my $patron_barcode = $SC->get_field_value($message, 'AA');
     my $item_barcode = $SC->get_field_value($message, 'AB');
     my $fee_ack = $SC->get_field_value($message, 'BO');
-    my $config = $session->config;
 
     my $item_details = OpenILS::Application::SIP2::Item->get_item_details(
         $session, barcode => $item_barcode
@@ -402,8 +422,10 @@ sub handle_checkout {
         $session, barcode => $patron_barcode
     );
 
-    return {
-        code => '12',
+    my $code = $is_renewal ? '30' : '12';
+
+    return ({
+        code => $code,
         fixed_fields => [
             0,                  # checkout ok
             $SC->sipbool(0),    # renewal ok
@@ -415,13 +437,14 @@ sub handle_checkout {
             {AA => $patron_barcode},
             {AB => $item_barcode}
         ]
-    } unless ($item_details && $patron_details);
+    }) unless ($item_details && $patron_details);
 
     my $circ_details = OpenILS::Application::SIP2::Checkout->checkout(
         $session, 
         patron_barcode => $patron_barcode, 
         item_barcode => $item_barcode,
-        fee_ack => $fee_ack
+        fee_ack => $fee_ack,
+        is_renew => $is_renewal
     );
 
     my $magnetic = $item_details->{magnetic_media};
@@ -436,8 +459,8 @@ sub handle_checkout {
             && $circ->renewal_remaining > 0;
     }
 
-    return {
-        code => '12',
+    return ({
+        code => $code,
         fixed_fields => [
             $circ ? 1 : 0,              # checkout ok
             $SC->sipbool($can_renew),   # renewal ok
@@ -458,15 +481,18 @@ sub handle_checkout {
             $circ       ? {BK => $circ->id}     : (),
             $deposit    ? {BV => $deposit}      : (),
         ]
-    };
+    }, $circ_details);
 }
 
 sub handle_checkin {
     my ($session, $message) = @_;
     my $config = $session->config;
 
+    my @fixed_fields = @{$message->{fixed_fields} || []};
+
     my $item_barcode = $SC->get_field_value($message, 'AB');
     my $current_loc = $SC->get_field_value($message, 'AP');
+    my $return_date = $fixed_fields[2];
 
     my $item_details = OpenILS::Application::SIP2::Item->get_item_details(
         $session, barcode => $item_barcode
@@ -492,7 +518,8 @@ sub handle_checkin {
         $session, 
         item_barcode => $item_barcode,
         current_loc => $current_loc,
-        item_details => $item_details
+        item_details => $item_details,
+        return_date => $return_date
     );
 
     my $screen_msg = $checkin_details->{screen_msg};
index 0f01462..1df5f80 100644 (file)
@@ -22,8 +22,7 @@ sub checkin {
 
     for (0, 1) { # 2 checkin requests max
 
-        $override = 
-            $class->perform_checkin($session, $details, $override, %params);
+        $override = perform_checkin($session, $details, $override, %params);
 
         last unless $override;
     }
@@ -36,7 +35,7 @@ sub checkin {
 # Returns 0 if there's nothing left to do (final success / error)
 # Updates $details along the way.
 sub perform_checkin {
-    my ($class, $session, $details, $override, %params) = @_;
+    my ($session, $details, $override, %params) = @_;
     my $config = $session->config;
     my $item_details = $params{item_details};
 
@@ -45,6 +44,12 @@ sub perform_checkin {
         hold_as_transit => $config->{checkin_hold_as_transit}
     };
 
+    if (my $backdate = $params{return_date}) {
+        $backdate =~ s/(\d{4})(\d{2})(\d{2}).*/$1-$2-$3/; # YYYYMMDD => ISO
+        $logger->info("Checking in with backdate $backdate");
+        $args->{backdate} = $backdate;
+    }
+
     $args->{circ_lib} = 
         $SC->org_id_from_sn($session, $params{corrent_loc}) 
         || $session->editor->requestor->ws_ou;
@@ -93,7 +98,7 @@ sub perform_checkin {
             $usr->card->barcode if $usr && $usr->card;
     }
 
-    $class->handle_hold($session, $details, $payload, %params);
+    handle_hold($session, $details, $payload, %params);
 
     if ($textcode eq 'NO_CHANGE' || $textcode eq 'SUCCESS') {
 
@@ -116,7 +121,7 @@ sub perform_checkin {
 }
 
 sub handle_hold {
-    my ($class, $session, $details, $payload, %params) = @_;
+    my ($session, $details, $payload, %params) = @_;
 
     my $hold = $payload->{remote_hold} || $payload->{hold};
 
index 662f14f..f73ba94 100644 (file)
@@ -23,8 +23,8 @@ sub checkout {
 
     for (0, 1) { # 2 checkout requests max
 
-        $override = $class->perform_checkout(
-            $session, $circ_details, $override, %params);
+        $override = 
+            perform_checkout($session, $circ_details, $override, %params);
 
         last unless $override;
     }
@@ -36,11 +36,13 @@ sub checkout {
 # Returns 0 if there's nothing left to do (final success / error)
 # Updates $circ_details along the way.
 sub perform_checkout {
-    my ($class, $session, $circ_details, $override, %params) = @_;
+    my ($session, $circ_details, $override, %params) = @_;
     my $config = $session->config;
 
     my $args = {
         copy_barcode => $params{item_barcode},
+        # During renewal, the circ API will confirm the specified
+        # patron has the specified item checked out before renewing.
         patron_barcode => $params{patron_barcode}
     };