From 87f94ed1a22063514a294693b522171595a972f3 Mon Sep 17 00:00:00 2001 From: Pierre-Marc Thibault Date: Wed, 26 Sep 2018 08:26:52 -0400 Subject: [PATCH] Bug 11373: System preference added, dialog removed, disabled input added to show the change in the form. This patch removes the dialog because it was redundant with the form. As the numbers fields are formated when they are changed, it is convenient to calculate and show the change at the same time. When the change value cannot be calculated (amount collected < amount paid), its value is brought back to 0.00. This includes also a new system preference called FineChange which enables or disables the feature. Test plan : - Apply patch. - Make sure FineChange is at ENABLE in System preferences > Patrons. - Select a patron with a fine. - Go to Fines > Pay fines. - Click the button pay. - Choose the amount paid equal to the outstanding amount (exemple : 3$). - Choose the amount collected to be more than the outstanding amount (exemple : 5$) - Confirm that the change is correct (example : 5$ - 3$ = 2$) - Click the button confirm. - Confirm that the payment has been made. - Make sure FineChange is at DISABLE in System preferences > Patrons. - Select a patron with a fine and go to Fines > Pay fines. - Confirm that the input change is gone. - Choose an amount collected (exemple : 3$). - Click the button confirm. - Confirm that the payment has been made. https://bugs.koha-community.org/show_bug.cgi?id=11373 Signed-off-by: Michal Denar Signed-off-by: Michal Denar --- .../prog/en/modules/admin/preferences/patrons.pref | 6 ++ .../prog/en/modules/members/paycollect.tt | 80 +++++++++++----------- members/paycollect.pl | 18 +---- 3 files changed, 48 insertions(+), 56 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref index 8c8227d4..2a6dbaf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -213,6 +213,12 @@ Patrons: yes: Allow only superlibrarians no: Allow all permitted users - "to access/change superlibrarian privileges. Note: A permitted user needs to have the 'permissions' flag (if no superlibrarian)." + - + - pref: FineChange + choices: + yes: Enable + no: Disable + - fine change display when a user pays a fine. Privacy: - - Use the following URL diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt index 3b85e73..62cd227 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt @@ -1,7 +1,6 @@ [% USE raw %] [% USE Asset %] [% USE Koha %] -[% USE Price %] [% USE Branches %] [% USE AuthorisedValues %] [% USE Price %] @@ -71,15 +70,6 @@
[% END %] -[% IF (give_change) %] -
- The amount collected is greater than the total amount paid.
- Change to give back: [% give_change | $Price %]

- - Cancel -
-[% END %] - [% IF ( pay_individual ) %] @@ -117,31 +107,25 @@
    - [% IF ( give_change ) %] + [% IF FineChange %]
  1. - - - [% amount_paid | $Price %] +
  2. - - [% amount_collected | $Price %] + +
  3. - [% give_change | $Price %] +
  4. [% ELSE %]
  5. - - - [% amount_paid | $Price %] -
  6. -
  7. - - + +
  8. + [% END %] [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %] [% IF payment_types %]
  9. @@ -154,7 +138,6 @@
  10. [% END %] - [% END %]
@@ -231,35 +214,35 @@ Total amount outstanding: [% total | $Price %] - [% IF ( give_change ) %] + [% IF FineChange %]
  • - - - [% amount_paid | $Price %] + +
  • - - - [% amount_collected | $Price %] + [% IF type == 'writeoff' %] + + [% ELSE %] + + [% END %] + +
  • - [% give_change | $Price %] +
  • [% ELSE %]
  • - - -
  • -
  • [% IF type == 'writeoff' %] - + [% ELSE %] - + [% END %] - +
  • + [% END %] [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %] [% IF payment_types %]
  • @@ -272,7 +255,6 @@
  • [% END %] - [% END %]
  • @@ -302,6 +284,11 @@ $('#payindivfine, #payfine, #payform').preventDoubleFormSubmit(); $("#paid").on("change",function(){ moneyFormat( this ); + updateChangeInput(); + }); + $("#collected").on("change",function(){ + moneyFormat( this ); + updateChangeInput(); }); }); @@ -371,6 +358,17 @@ textObj.value = dolAmount + "." + decAmount; } + + function updateChangeInput() { + var change = $('#change')[0]; + change.value = Math.round(($('#collected')[0].value - $('#paid')[0].value) * 100) / 100; + + if (change.value < 0) { + change.value = change.defaultValue; + } else { + moneyFormat(change); + } + } [% END %] diff --git a/members/paycollect.pl b/members/paycollect.pl index 4296208..57290d5 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -61,6 +61,7 @@ my $user = $input->remote_user; my $branch = C4::Context->userenv->{'branch'}; my $total_due = $patron->account->outstanding_debits->total_outstanding; +my $fine_change = C4::Context->preference('FineChange'); my $total_paid = $input->param('paid'); my $total_collected = $input->param('collected'); @@ -112,24 +113,10 @@ if ( $total_paid and $total_paid ne '0.00' ) { error_negative => 1, ); } - elsif (($total_collected - $total_paid) < 0) { + elsif ($fine_change and ($total_collected - $total_paid) < 0) { $template->param( error_collected_less => 1, ); - } - elsif ($total_paid >= $total_due and $total_collected ne $total_paid) { - $template->param( - amount_paid => $total_due, - amount_collected => $total_collected, - give_change => $total_collected-$total_due, - ); - } - elsif ($total_paid < $total_due and $total_collected ne $total_paid) { - $template->param( - amount_paid => $total_paid, - amount_collected => $total_collected, - give_change => $total_collected-$total_paid, - ); } else { die "Wrong CSRF token" unless Koha::Token->new->check_csrf( { @@ -213,6 +200,7 @@ $template->param( patron => $patron, total => $total_due, ExtendedPatronAttributes => C4::Context->preference('ExtendedPatronAttributes'), + FineChange => $fine_change, csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $input->cookie('CGISESSID') }), ); -- 2.1.4