From 3b7498201ba3c6a5d30d9c1e6c033d913e78f0e5 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Tue, 6 Aug 2019 11:13:33 +0300 Subject: [PATCH 1/6] Bug 23415: Notify patron fines when renewing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is possible to renew items for patron who has fines over accepted limit on renew page or from checkout list. This patch adds confirmation alerts to these renew actions when patron has fines over "noissuescharge" syspref. Test plan: 1. Have patron with checkouts and fines over allowed limit 2. Renew checkouts either from renew page or checkout list => renew is successful 3. Apply patch 4. Repeat steps 1 and 2 => On renew page an alert is displayed and user has to confirm renew => When renew is done from checkout list confirmation pop-up is displayed Signed-off-by: Anneli Österman Signed-off-by: Kelly McElligott Signed-off-by: Petro Vashchuk --- circ/circulation.pl | 2 +- circ/renew.pl | 18 +++- .../prog/en/modules/circ/circulation.tt | 4 + .../prog/en/modules/circ/renew.tt | 9 ++ .../prog/en/modules/members/moremember.tt | 4 + koha-tmpl/intranet-tmpl/prog/js/checkouts.js | 90 +++++++++++-------- 6 files changed, 88 insertions(+), 39 deletions(-) diff --git a/circ/circulation.pl b/circ/circulation.pl index 7b35a8c860..a0efd0e125 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -262,7 +262,7 @@ if ($patron) { $template->param( overduecount => $overdues->count, issuecount => $issues->count, - finetotal => $balance, + fines => $balance, ); if ( $patron and $patron->is_debarred ) { diff --git a/circ/renew.pl b/circ/renew.pl index f9434a127b..0ba845dc3a 100755 --- a/circ/renew.pl +++ b/circ/renew.pl @@ -27,6 +27,7 @@ use C4::Circulation qw( barcodedecode CanBookBeRenewed GetLatestAutoRenewDate Ad use Koha::DateUtils qw( dt_from_string ); use Koha::Database; use Koha::BiblioFrameworks; +use Koha::Patrons; my $cgi = CGI->new; @@ -47,10 +48,11 @@ $barcode = barcodedecode($barcode) if $barcode; my $override_limit = $cgi->param('override_limit'); my $override_holds = $cgi->param('override_holds'); my $hard_due_date = $cgi->param('hard_due_date'); +my $override_debt = $cgi->param('override_debt'); my ( $item, $checkout, $patron ); my $error = q{}; -my ( $soonest_renew_date, $latest_auto_renew_date ); +my ( $soonest_renew_date, $latest_auto_renew_date, $balance ); if ($barcode) { $barcode = barcodedecode($barcode) if $barcode; @@ -64,6 +66,9 @@ if ($barcode) { $patron = $checkout->patron; + $balance = $patron->account->balance; + my $amountlimit = C4::Context->preference("noissuescharge"); + if ( ( $patron->is_debarred || q{} ) lt dt_from_string()->ymd() ) { my $can_renew; my $info; @@ -89,6 +94,16 @@ if ($barcode) { $checkout, ); } + + if ( $balance > $amountlimit ) { + $error = "too_much_debt"; + $can_renew = 0; + if($override_debt){ + $can_renew = 1; + $error = undef; + } + } + if ($can_renew) { my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; my $date_due = @@ -128,6 +143,7 @@ if ($barcode) { error => $error, soonestrenewdate => $soonest_renew_date, latestautorenewdate => $latest_auto_renew_date, + balance => $balance, ); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index e2fec123ee..1c2dc85175 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -916,6 +916,10 @@ [% UNLESS ( patron.borrowernumber ) %]window.onload=function(){ $('#findborrower').focus(); };[% END %] + var amountlimit = "[% Koha.Preference('noissuescharge') %]"; + var fines = "[% fines %]"; + var MSG_CONFRIM_RENEW = _("The patron has a debt of %s.\n Are you sure you want to renew checkout(s)?").format(fines); + // On-site checkout function toggle_onsite_checkout(){ if ( $("#onsite_checkout").prop('checked') ) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt index 9b0664a6d1..b644dc8373 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt @@ -2,6 +2,7 @@ [% USE Asset %] [% USE Koha %] [% USE KohaDates %] +[% USE Price %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] @@ -163,6 +164,14 @@ [% ELSIF error == 'recalled' %]

This item has been recalled.

+ [% ELSIF error == "too_much_debt" %] + +
  • The patron has a debt of [% balance | $Price %].
  • +
    + + + +
    [% ELSE %] [% error | html %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt index f95bf98bf2..966347e200 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -710,6 +710,10 @@ table_settings_issues_table = [% TablesSettings.GetTableSettings( 'members', 'moremember', 'issues-table', 'json' ) | $raw %] table_settings_relatives_issues_table = [% TablesSettings.GetTableSettings( 'members', 'moremember', 'relatives-issues-table', 'json' ) | $raw %] + var amountlimit = "[% Koha.Preference('noissuescharge') %]"; + var fines = "[% fines %]"; + var MSG_CONFRIM_RENEW = _("The patron has a debt of %s.\n Are you sure you want to renew checkout(s)?").format(fines); + $(document).ready(function() { $("#info_digests").tooltip(); diff --git a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js index b54b4be768..c802384c31 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js +++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js @@ -152,7 +152,16 @@ $(document).ready(function() { var itemnumber = $(this).val(); - $(this).parent().parent().replaceWith(""); + var can_renew = true; + + if( parseFloat(fines) > parseFloat(amountlimit) ) { + var result = confirm(MSG_CONFRIM_RENEW); + if(result){ + can_renew = true; + }else{ + can_renew = false; + } + } var params = { itemnumber: itemnumber, @@ -176,42 +185,10 @@ $(document).ready(function() { params.date_due = dueDate } - $.post({ - url: "/cgi-bin/koha/svc/renew", - data: params, - success: function( data ) { - var id = "#renew_" + data.itemnumber; - - var content = ""; - if ( data.renew_okay ) { - content = __("Renewed, due:") + " " + data.date_due; - $('#date_due_' + data.itemnumber).replaceWith( data.date_due ); - } else { - content = __("Renew failed:") + " "; - if ( data.error == "no_checkout" ) { - content += __("not checked out"); - } else if ( data.error == "too_many" ) { - content += __("too many renewals"); - } else if ( data.error == "too_unseen" ) { - content += __("too many consecutive renewals without being seen by the library"); - } else if ( data.error == "on_reserve" ) { - content += __("on hold"); - } else if ( data.error == "restriction" ) { - content += __("Not allowed: patron restricted"); - } else if ( data.error == "overdue" ) { - content += __("Not allowed: overdue"); - } else if ( data.error ) { - content += data.error; - } else { - content += __("reason unknown"); - } - } - - $(id).replaceWith( content ); - }, - dataType: "json", - async: false, - }); + if(can_renew) { + $(this).parent().parent().replaceWith(""); + renew(params); + } }); // Refocus on barcode field if it exists @@ -223,6 +200,45 @@ $(document).ready(function() { return false; }); + function renew(params){ + $.post({ + url: "/cgi-bin/koha/svc/renew", + data: params, + success: function( data ) { + var id = "#renew_" + data.itemnumber; + + var content = ""; + if ( data.renew_okay ) { + content = __("Renewed, due:") + " " + data.date_due; + $('#date_due_' + data.itemnumber).replaceWith( data.date_due ); + } else { + content = __("Renew failed:") + " "; + if ( data.error == "no_checkout" ) { + content += __("not checked out"); + } else if ( data.error == "too_many" ) { + content += __("too many renewals"); + } else if ( data.error == "too_unseen" ) { + content += __("too many consecutive renewals without being seen by the library"); + } else if ( data.error == "on_reserve" ) { + content += __("on hold"); + } else if ( data.error == "restriction" ) { + content += __("Not allowed: patron restricted"); + } else if ( data.error == "overdue" ) { + content += __("Not allowed: overdue"); + } else if ( data.error ) { + content += data.error; + } else { + content += __("reason unknown"); + } + } + + $(id).replaceWith( content ); + }, + dataType: "json", + async: false, + }); + } + $("#RenewAll").on("click",function(){ $("#CheckAllRenewals").click(); $("#UncheckAllCheckins").click(); -- 2.34.1