From 525db7609c094e304bf3a13bbef9dc1ec7776010 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 4 Nov 2020 11:25:14 -0500 Subject: [PATCH] LP1901930 renew all Signed-off-by: Bill Erickson --- .../src/perlmods/lib/OpenILS/Application/SIP2.pm | 53 ++++++++++++++++++++++ .../lib/OpenILS/Application/SIP2/Checkout.pm | 48 ++++++++++++++++++-- 2 files changed, 97 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm index 51720622f4..38cc2f83c2 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm @@ -74,6 +74,7 @@ sub dispatch_sip2_request { '29' => \&handle_renew, '37' => \&handle_payment, '63' => \&handle_patron_info, + '65' => \&handle_renew_all, 'XS' => \&handle_end_session }; @@ -484,6 +485,58 @@ sub checkout_renew_common { }, $circ_details); } +sub handle_renew_all { + my ($session, $message) = @_; + my $config = $session->config; + + my $patron_barcode = $SC->get_field_value($message, 'AA'); + my $fee_ack = $SC->get_field_value($message, 'BO'); + + my $patron_details = OpenILS::Application::SIP2::Patron->get_patron_details( + $session, barcode => $patron_barcode + ); + + return { + code => '66', + fixed_fields => [ + 0, # ok + $SC->count4(0), # renewed count + $SC->count4(0), # unrenewed count + $SC->sipdate, # transaction date + ], + fields => [ + {AA => $patron_barcode}, + {AO => $config->{institution}}, + ] + } unless $patron_details; + + my $circ_details = OpenILS::Application::SIP2::Checkout->renew_all( + $session, $patron_details, fee_ack => $fee_ack + ); + + my $screen_msg = $circ_details->{screen_msg}; + my @renewed = @{$circ_details->{items_renewed}}; + my @unrenewed = @{$circ_details->{items_unrenewed}}; + + return { + code => '66', + fixed_fields => [ + 1, # ok + $SC->count4(scalar(@renewed)), + $SC->count4(scalar(@unrenewed)), + $SC->sipdate, + ], + fields => [ + {AA => $patron_barcode}, + {AO => $config->{institution}}, + @{ [ map { {BM => $_} } @renewed ] }, + @{ [ map { {BN => $_} } @unrenewed ] }, + $screen_msg ? {AF => $screen_msg} : () + ] + }; +} + + sub handle_checkin { my ($session, $message) = @_; my $config = $session->config; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Checkout.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Checkout.pm index f73ba94a2e..2c6f33ab44 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Checkout.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Checkout.pm @@ -32,6 +32,44 @@ sub checkout { return $circ_details; } +sub renew_all { + my ($class, $session, $patron_details, %params) = @_; + + my $circ_details = {}; + + my @circ_ids = ( + @{$patron_details->{items_out_ids}}, + @{$patron_details->{items_overdue_ids}} + ); + + my @renewed; + my @unrenewed; + for my $circ_id (@circ_ids) { + + my $circ = $session->editor->retrieve_action_circulation([ + $circ_id, {flesh => 1, flesh_fields => {circ => ['target_copy']}}]); + + my $item_barcode = $circ->target_copy->barcode; + + my $detail = $class->checkout($session, + item_barcode => $item_barcode, + fee_ack => $params{fee_ack}, + is_renew => 1 + ); + + if ($detail->{ok}) { + push(@renewed, $item_barcode); + } else { + push(@unrenewed, $item_barcode); + } + } + + $circ_details->{items_renewed} = \@renewed; + $circ_details->{items_unrenewed} = \@unrenewed; + + return $circ_details; +} + # Returns 1 if the checkout should be performed again with override. # Returns 0 if there's nothing left to do (final success / error) # Updates $circ_details along the way. @@ -39,6 +77,8 @@ sub perform_checkout { my ($session, $circ_details, $override, %params) = @_; my $config = $session->config; + my $action = $params{is_renew} ? 'renew' : 'checkout'; + my $args = { copy_barcode => $params{item_barcode}, # During renewal, the circ API will confirm the specified @@ -46,7 +86,7 @@ sub perform_checkout { patron_barcode => $params{patron_barcode} }; - my $method = $params{is_renew} ? + my $method = $action eq 'renew' ? 'open-ils.circ.renew' : 'open-ils.circ.checkout.full'; $method .= '.override' if $override; @@ -78,7 +118,7 @@ sub perform_checkout { } if (!$override) { - if ($config->{"checkout.override.$textcode"}) { + if ($config->{"$action.override.$textcode"}) { # Event type is configured for override; return 1; @@ -94,8 +134,8 @@ sub perform_checkout { $circ_details->{screen_msg} = 'This item is already checked out'; } else { - $circ_details->{screen_msg} = # TODO messages - 'Patron is not allowed to check out the selected item'; + $circ_details->{screen_msg} = # TODO messages / renew + 'Patron is not allowed to checkout the selected item'; } } -- 2.11.0