From 34265cf0408d65c47931635d7484f6437e290be9 Mon Sep 17 00:00:00 2001 From: Andrew Isherwood Date: Wed, 23 Oct 2019 15:19:08 +0100 Subject: [PATCH] Bug 23051: (follow-up) Add SIP summary This follow up patch addresses the following parts of Nick's feedback in comment #35: - Ideally SIP would get feedback in a screen message --- C4/SIP/ILS.pm | 8 +++++-- C4/SIP/ILS/Transaction/FeePayment.pm | 20 +++++++++++------ C4/SIP/Sip/MsgType.pm | 42 +++++++++++++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 9 deletions(-) diff --git a/C4/SIP/ILS.pm b/C4/SIP/ILS.pm index b543539dd0..e938f24d4d 100644 --- a/C4/SIP/ILS.pm +++ b/C4/SIP/ILS.pm @@ -271,10 +271,14 @@ sub pay_fee { $trans->screen_msg('Invalid patron barcode.'); return $trans; } - my $ok = $trans->pay( $patron->{borrowernumber}, $fee_amt, $pay_type, $fee_id, $is_writeoff, $disallow_overpayment ); + my $trans_result = $trans->pay( $patron->{borrowernumber}, $fee_amt, $pay_type, $fee_id, $is_writeoff, $disallow_overpayment ); + my $ok = $trans_result->{ok}; $trans->ok($ok); - return $trans; + return { + status => $trans, + pay_response => $trans_result->{pay_response} + }; } sub add_hold { diff --git a/C4/SIP/ILS/Transaction/FeePayment.pm b/C4/SIP/ILS/Transaction/FeePayment.pm index 943176456d..1038d0d982 100644 --- a/C4/SIP/ILS/Transaction/FeePayment.pm +++ b/C4/SIP/ILS/Transaction/FeePayment.pm @@ -57,13 +57,13 @@ sub pay { my $account = Koha::Account->new( { patron_id => $borrowernumber } ); if ($disallow_overpayment) { - return 0 if $account->balance < $amt; + return { ok => 0 } if $account->balance < $amt; } if ($fee_id) { my $fee = Koha::Account::Lines->find($fee_id); if ( $fee ) { - $account->pay( + my $pay_response = $account->pay( { amount => $amt, type => $type, @@ -72,14 +72,19 @@ sub pay { interface => C4::Context->interface } ); - return 1; + return { + ok => 1, + pay_response => $pay_response + }; } else { - return 0; + return { + ok => 0 + }; } } else { - $account->pay( + my $pay_response = $account->pay( { amount => $amt, type => $type, @@ -87,7 +92,10 @@ sub pay { interface => C4::Context->interface } ); - return 1; + return { + ok => 1, + pay_response => $pay_response + }; } } diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm index 425ff76552..c5123081f1 100644 --- a/C4/SIP/Sip/MsgType.pm +++ b/C4/SIP/Sip/MsgType.pm @@ -20,6 +20,7 @@ use CGI qw ( -utf8 ); use C4::Auth qw(&check_api_auth); use Koha::Patron::Attributes; +use Koha::Items; use UNIVERSAL::can; @@ -1103,7 +1104,46 @@ sub handle_fee_paid { $ils->check_inst_id( $inst_id, "handle_fee_paid" ); - $status = $ils->pay_fee( $patron_id, $patron_pwd, $fee_amt, $fee_type, $pay_type, $fee_id, $trans_id, $currency, $is_writeoff, $disallow_overpayment ); + my $pay_result = $ils->pay_fee( $patron_id, $patron_pwd, $fee_amt, $fee_type, $pay_type, $fee_id, $trans_id, $currency, $is_writeoff, $disallow_overpayment ); + $status = $pay_result->{status}; + my $pay_response = $pay_result->{pay_response}; + + my $failmap = { + "no_item" => "No matching item could be found", + "no_checkout" => "Item is not checked out", + "too_soon" => "Cannot yet be renewed", + "too_many" => "Renewed the maximum number of times", + "auto_too_soon" => "Scheduled for automatic renewal and cannot yet be renewed", + "auto_too_late" => "Scheduled for automatic renewal and cannot yet be any more", + "auto_account_expired" => "Scheduled for automatic renewal and cannot be renewed because the patron's account has expired", + "auto_renew" => "Scheduled for automatic renewal", + "auto_too_much_oweing" => "Scheduled for automatic renewal", + "on_reserve" => "On hold for another patron", + "patron_restricted" => "Patron is currently restricted", + "item_denied_renewal" => "Item is not allowed renewal", + "onsite_checkout" => "Item is an onsite checkout" + }; + my @success = (); + my @fail = (); + foreach my $result( @{$pay_response->{renew_result}} ) { + my $item = Koha::Items->find({ itemnumber => $result->{itemnumber} }); + if ($result->{success}) { + push @success, '"' . $item->biblio->title . '"'; + } else { + push @fail, '"' . $item->biblio->title . '" : ' . $failmap->{$result->{error}}; + } + } + + my $msg = ""; + if (scalar @success > 0) { + $msg.="The following items were renewed: " . join(", ", @success) . ". "; + } + if (scalar @fail > 0) { + $msg.="The following items were not renewed: " . join(", ", @fail) . "."; + } + if (length $msg > 0) { + $status->screen_msg($status->screen_msg . " $msg"); + } $resp .= ( $status->ok ? 'Y' : 'N' ) . timestamp; $resp .= add_field( FID_INST_ID, $inst_id, $server ); -- 2.11.0