From 2de6c5891887901fc72ac6e10e8d9779590b3aad Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 3 Mar 2020 19:22:49 +0000 Subject: [PATCH] Bug 24081: Add discount action to boraccount This patch adds the ability to apply discounts to existing patron charges from the boraccount page. Test plan 1/ Carry out some accounting actions that end up with debts on the patron record. (Add a manual invoice for example) 2/ Note a new 'Apply discount' action button on the unpaid debt 3/ Paid debts do not display the action button 4/ Click the button 5/ Enter an amount into the resulting modal and click confirm 6/ Confirm that the outstanding debt has been reduced by the amount you specified. 7/ Confirm that a new 'Discount' line appears on the patrons account 8/ Confirm that in the 'details' view of the debt that the discount line was used against the debt to create the reduction. 9/ Signoff Signed-off-by: Michal Denar Signed-off-by: Tomas Cohen Arazi --- .../prog/en/modules/members/boraccount.tt | 62 +++++++++++++++++-- members/boraccount.pl | 20 ++++++ 2 files changed, 78 insertions(+), 4 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt index c93eb6fa09..73010320e9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt @@ -90,6 +90,9 @@ [% IF CAN_user_updatecharges_refund && account.is_debit && ( account.amountoutstanding != account.amount ) && !(account.status == 'REFUNDED') && !(account.debit_type_code == 'PAYOUT') %] [% END %] + [% IF CAN_user_updatecharges_discount && account.is_debit && ( account.amountoutstanding == account.amount ) && !(account.debit_type_code == 'PAYOUT') %] + + [% END %] @@ -147,7 +150,7 @@ [% IF payment_types > 3 %]
  • - [% FOREACH pt IN payment_types %] [% UNLESS excluded.grep("^$pt.authorised_value\$").size %] @@ -214,7 +217,7 @@ [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
  • - [% IF payment_types %] [% FOREACH pt IN payment_types %] @@ -252,6 +255,45 @@ + + + [% MACRO jsinclude BLOCK %] [% INCLUDE 'datatables.inc' %] [% INCLUDE 'columns_settings.inc' %] @@ -304,7 +346,7 @@ var amount = button.data('amount') * -1; $("#paid + span").replaceWith(amount); $("#amount").attr({ "value": amount, "max": amount }); - $("#amount, #transaction_type").focus(); + $("#amount, #payout_transaction_type").focus(); }); $("#issueRefundModal").on("shown.bs.modal", function(e){ @@ -318,7 +360,19 @@ var paid = amount - amountoutstanding; $("#paid + span").replaceWith(paid); $("#returned").attr({ "value": paid, "max": paid }); - $("#returned, #transaction_type").focus(); + $("#returned, #refund_transaction_type").focus(); + }); + + $("#applyDiscountModal").on("shown.bs.modal", function(e){ + var button = $(e.relatedTarget); + var item = button.data('item'); + $("#item + span").replaceWith(item); + var accountline = button.data('accountline'); + $('#discountline').val(accountline); + var amount = button.data('amount'); + $("#charged + span").replaceWith(amount); + $("#discount").attr({ "max": amount }); + $("#discount").focus(); }); }); diff --git a/members/boraccount.pl b/members/boraccount.pl index 8dfe35d92e..dae6a5a484 100755 --- a/members/boraccount.pl +++ b/members/boraccount.pl @@ -151,6 +151,26 @@ if ( $action eq 'refund' ) { ); } +if ( $action eq 'discount' ) { + my $charge_id = scalar $input->param('accountlines_id'); + my $charge = Koha::Account::Lines->find($charge_id); + my $amount = scalar $input->param('amount'); + $schema->txn_do( + sub { + + my $discount = $charge->reduce( + { + reduction_type => 'DISCOUNT', + branch => $library_id, + staff_id => $logged_in_user->id, + interface => 'intranet', + amount => $amount + } + ); + } + ); +} + #get account details my $total = $patron->account->balance; -- 2.25.0