@@ -, +, @@ --- Koha/Account.pm | 26 ++++++++++++++----- Koha/REST/V1/Patrons/Account.pm | 2 +- .../prog/en/includes/renew_error_strings.inc | 30 ++++++++++++++++++++++ .../prog/en/modules/members/boraccount.tt | 8 ++++++ .../intranet-tmpl/prog/en/modules/members/pay.tt | 8 ++++++ members/boraccount.pl | 12 +++++++++ members/pay.pl | 12 +++++++++ members/paycollect.pl | 29 ++++++++++++++++----- t/db_dependent/Accounts.t | 16 ++++++------ t/db_dependent/Koha/Account.t | 4 +-- t/db_dependent/Koha/Account/Lines.t | 2 +- 11 files changed, 125 insertions(+), 24 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/renew_error_strings.inc --- a/Koha/Account.pm +++ a/Koha/Account.pm @@ -273,7 +273,7 @@ sub pay { # If we have overdue unreturned items that have had payments made # against them, check whether the balance on those items is now zero # and, if the syspref is set, renew them - _maybe_renew($overdue_unreturned, $self->{patron_id}); + my $renew_result = _maybe_renew($overdue_unreturned, $self->{patron_id}); if ( C4::Context->preference("FinesLog") ) { logaction( @@ -322,7 +322,7 @@ sub pay { } } - return $payment->id; + return { payment_id => $payment->id, renew_result => $renew_result }; } =head3 add_credit @@ -758,18 +758,24 @@ and, if the syspref is set, renew them sub _maybe_renew { my ($items, $patron_id) = @_; + my $results = { + ok => [], + not_ok => [] + }; + if ( C4::Context->preference('RenewAccruingItemWhenPaid') && keys %{$items} ) { + foreach my $itemnumber (keys %{$items}) { # Only do something if this item has no fines left on it my $fine = C4::Overdues::GetFine( $itemnumber, $patron_id ); next if $fine && $fine > 0; - my ( $renew_ok, $error ) = + my ( $can_renew, $error ) = C4::Circulation::CanBookBeRenewed($patron_id, $itemnumber); - if ( $renew_ok ) { + if ( $can_renew ) { my $due_date = C4::Circulation::AddRenewal( $patron_id, $itemnumber, @@ -778,12 +784,20 @@ sub _maybe_renew { undef, 1 ); - return $due_date; + push @{$results->{ok}}, { + itemnumber => $itemnumber, + due_date => $due_date + }; } else { - return $error; + push @{$results->{not_ok}}, { + itemnumber => $itemnumber, + error => $error + }; } } + return $results; } + return $results; } 1; --- a/Koha/REST/V1/Patrons/Account.pm +++ a/Koha/REST/V1/Patrons/Account.pm @@ -132,7 +132,7 @@ sub add_credit { my $outstanding_credit = $credit->amountoutstanding; if ($debits) { # pay them! - $outstanding_credit = $credit->apply({ debits => [ $debits->as_list ], offset_type => 'payment' }); + $outstanding_credit = $credit->apply({ debits => [ $debits->as_list ], offset_type => 'payment' })->{outstanding_amount}; } if ($outstanding_credit) { --- a/koha-tmpl/intranet-tmpl/prog/en/includes/renew_error_strings.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/renew_error_strings.inc @@ -0,0 +1,30 @@ +[% SWITCH error %] +[% CASE 'no_item' %] + No matching item could be found +[% CASE 'no_checkout' %] + Item is not checked out +[% CASE 'too_soon' %] + Cannot yet be renewed +[% CASE 'too_many' %] + Renewed the maximum number of times +[% CASE 'auto_too_soon' %] + Scheduled for automatic renewal and cannot yet be renewed +[% CASE 'auto_too_late' %] + Scheduled for automatic renewal and cannot yet be any more +[% CASE 'auto_account_expired' %] + Scheduled for automatic renewal and cannot be renewed because the patron's account has expired +[% CASE 'auto_renew' %] + Scheduled for automatic renewal +[% CASE 'auto_too_much_oweing' %] + Scheduled for automatic renewal +[% CASE 'on_reserve' %] + On hold for another patron +[% CASE 'patron_restricted' %] + Patron is currently restricted +[% CASE 'item_denied_renewal' %] + Item is not allowed renewal +[% CASE 'onsite_checkout' %] + Item is an onsite checkout +[% CASE %] + Unknown error +[% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt @@ -39,6 +39,14 @@
[% INCLUDE 'biblio-title.inc' biblio=problem.item.biblio %] ( [% problem.item.barcode | html %] ): [% INCLUDE 'renew_error_strings.inc' error=problem.error %]
+ [% END %] +