From 63ba57a76e66d62de1d33de660b29b0901f59c48 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Tue, 6 Aug 2019 11:13:33 +0300 Subject: [PATCH] Bug 23415: Notify patron fines when renewing 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 --- circ/circulation.pl | 2 +- circ/renew.pl | 20 +++++- .../prog/en/modules/circ/circulation.tt | 3 + .../prog/en/modules/circ/renew.tt | 10 +++ .../prog/en/modules/members/moremember.tt | 5 +- koha-tmpl/intranet-tmpl/prog/js/checkouts.js | 64 +++++++++++-------- 6 files changed, 74 insertions(+), 30 deletions(-) diff --git a/circ/circulation.pl b/circ/circulation.pl index e7b4459184..cc24a05d8c 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -306,7 +306,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 a431a2c4a3..07f8032725 100755 --- a/circ/renew.pl +++ b/circ/renew.pl @@ -28,6 +28,7 @@ use C4::Koha; use Koha::DateUtils; use Koha::Database; use Koha::BiblioFrameworks; +use Koha::Patrons; my $cgi = new CGI; @@ -48,10 +49,11 @@ $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespae $barcode = barcodedecode($barcode) if( $barcode && C4::Context->preference('itemBarcodeInputFilter')); my $override_limit = $cgi->param('override_limit'); my $override_holds = $cgi->param('override_holds'); +my $override_debt = $cgi->param('override_debt'); my ( $item, $issue, $borrower ); my $error = q{}; -my ( $soonest_renew_date, $latest_auto_renew_date ); +my ( $soonest_renew_date, $latest_auto_renew_date, $balance ); if ($barcode) { $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace @@ -64,7 +66,10 @@ if ($barcode) { if ($issue) { $borrower = $issue->borrower(); - + my $patron = Koha::Patrons->find($borrower->borrowernumber); + $balance = $patron->account->balance; + my $amountlimit = C4::Context->preference("noissuescharge"); + if ( ( $borrower->debarred() || q{} ) lt dt_from_string()->ymd() ) { my $can_renew; ( $can_renew, $error ) = @@ -93,6 +98,16 @@ if ($barcode) { $item->itemnumber(), ); } + + 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 = AddRenewal( undef, $item->itemnumber(), $branchcode, dt_from_string( scalar $cgi->param('renewonholdduedate')) ); @@ -118,6 +133,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 84c3833d71..d4e6171717 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -1044,6 +1044,9 @@ [% UNLESS ( patron.borrowernumber ) %][% UNLESS ( borrowers ) %]window.onload=function(){ $('#findborrower').focus(); };[% END %][% END %] + var amountlimit = "[% Koha.Preference('noissuescharge') %]"; + var fines = "[% 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 608ed5c84d..783ab1c651 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' %] @@ -135,8 +136,17 @@

Item is not allowed renewal.

[% ELSIF error == "onsite_checkout" %] +

Item cannot be renewed because it's an onsite checkout

+ + [% 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 05cb6c9478..328be1f030 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -870,7 +870,10 @@ var MSG_CONFIRM_DELETE_MESSAGE = _("Are you sure you want to delete this message? This cannot be undone."); columns_settings_issues_table = [% ColumnsSettings.GetColumns( 'members', 'moremember', 'issues-table', 'json' ) | $raw %] - + + var amountlimit = "[% Koha.Preference('noissuescharge') %]"; + var fines = "[% fines %]"; + $(document).ready(function() { if ( $('#clubs-tab').length ) { $('#clubs-tab-link').on('click', function() { diff --git a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js index da69276e4a..529c86980f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js +++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js @@ -153,34 +153,15 @@ $(document).ready(function() { params.date_due = dueDate } - $.post( "/cgi-bin/koha/svc/renew", params, function( data ) { - var id = "#renew_" + data.itemnumber; - - var content = ""; - if ( data.renew_okay ) { - content = CIRCULATION_RENEWED_DUE + " " + data.date_due; - $('#date_due_' + data.itemnumber).replaceWith( data.date_due ); - } else { - content = CIRCULATION_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 == "on_reserve" ) { - content += ON_RESERVE; - } else if ( data.error == "restriction" ) { - content += NOT_RENEWABLE_RESTRICTION; - } else if ( data.error == "overdue" ) { - content += NOT_RENEWABLE_OVERDUE; - } else if ( data.error ) { - content += data.error; - } else { - content += REASON_UNKNOWN; - } + if( parseFloat(fines) > parseFloat(amountlimit) ) { + + if(confirm("The patron has a debt of "+ fines +".\n Are you sure you want to renew checkout(s)?")){ + renew(params); } - $(id).replaceWith( content ); - }, "json") + } else { + renew(params); + } }); // Refocus on barcode field if it exists @@ -192,6 +173,37 @@ $(document).ready(function() { return false; }); + function renew(params){ + $.post( "/cgi-bin/koha/svc/renew", params, function( data ) { + var id = "#renew_" + data.itemnumber; + + var content = ""; + if ( data.renew_okay ) { + content = CIRCULATION_RENEWED_DUE + " " + data.date_due; + $('#date_due_' + data.itemnumber).replaceWith( data.date_due ); + } else { + content = CIRCULATION_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 == "on_reserve" ) { + content += ON_RESERVE; + } else if ( data.error == "restriction" ) { + content += NOT_RENEWABLE_RESTRICTION; + } else if ( data.error == "overdue" ) { + content += NOT_RENEWABLE_OVERDUE; + } else if ( data.error ) { + content += data.error; + } else { + content += REASON_UNKNOWN; + } + } + + $(id).replaceWith( content ); + }, "json") + } + $("#RenewAll").on("click",function(){ $("#CheckAllRenewals").click(); $("#UncheckAllCheckins").click(); -- 2.17.1