From 199d2c56b7814e9d2260625dcd1114246ffbf3f3 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 21 Nov 2019 13:09:47 +0000 Subject: [PATCH] Bug 23442: Add refund option to patron account page This enhancement adds a refined workflow to allow librarians to refund payments to patrons and record these refunds on the patrons account. The use case is that a patron has paid for something before then performing an action that may require some level of refund to be actioned. Perhaps they are returning a lost and paid for book. Test plan: 1) Undertake a series of transactions that result in a debit accountline being partially or fully paid off. 2) Note that a new 'Issue refund' button appears next to a debit (but only if your user has the refund permission or is a superlibrarian) 3) Click the 'Issue refund' button and a modal should appear pre-populated with the amount - amountoutstanding. 4) You should be able to edit the amount you wish to refund, record the refund or cancel. 5) Signoff Signed-off-by: Kyle M Hall Signed-off-by: Josef Moravec Signed-off-by: Martin Renvoize --- .../prog/en/modules/members/boraccount.tt | 85 +++++++++++++++++++ members/boraccount.pl | 33 +++++++ 2 files changed, 118 insertions(+) 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 dc7f0cc544..faf180da3e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt @@ -87,6 +87,9 @@ [% IF CAN_user_updatecharges_payout && account.is_credit && ( account.amountoutstanding < 0 ) %] [% END %] + [% IF CAN_user_updatecharges_refund && account.is_debit && ( account.amountoutstanding != account.amount ) && !(account.status == 'REFUNDED' ) %] + + [% END %] @@ -180,6 +183,74 @@ + + + [% MACRO jsinclude BLOCK %] [% INCLUDE 'datatables.inc' %] [% INCLUDE 'columns_settings.inc' %] @@ -234,6 +305,20 @@ $("#amount").attr({ "value": amount, "max": amount }); $("#amount, #transaction_type").focus(); }); + + $("#issueRefundModal").on("shown.bs.modal", function(e){ + var button = $(e.relatedTarget); + var item = button.data('item'); + $("#item + span").replaceWith(item); + var accountline = button.data('accountline'); + $('#refundline').val(accountline); + var amount = button.data('amount'); + var amountoutstanding = button.data('amountoutstanding'); + var paid = amount - amountoutstanding; + $("#paid + span").replaceWith(paid); + $("#returned").attr({ "value": paid, "max": paid }); + $("#returned, #transaction_type").focus(); + }); }); [% END %] diff --git a/members/boraccount.pl b/members/boraccount.pl index df2ad35815..f5d7256499 100755 --- a/members/boraccount.pl +++ b/members/boraccount.pl @@ -118,6 +118,39 @@ if ( $action eq 'payout' ) { ); } +if ( $action eq 'refund' ) { + my $charge_id = scalar $input->param('accountlines_id'); + my $charge = Koha::Account::Lines->find($charge_id); + my $amount = scalar $input->param('amount'); + my $transaction_type = scalar $input->param('transaction_type'); + $schema->txn_do( + sub { + + my $refund = $charge->reduce( + { + reduction_type => 'REFUND', + branch => $library_id, + staff_id => $logged_in_user->id, + interface => 'intranet', + amount => $amount + } + ); + unless ( $transaction_type eq 'AC' ) { + my $payout = $refund->payout( + { + payout_type => $transaction_type, + branch => $library_id, + staff_id => $logged_in_user->id, + cash_register => $registerid, + interface => 'intranet', + amount => $amount + } + ); + } + } + ); +} + #get account details my $total = $patron->account->balance; -- 2.39.5