From d16710382e21d06bb4a11f616b4f6655a17d2499 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 23 Jan 2020 16:03:06 +0000 Subject: [PATCH] Bug 24082: Add refund action to relevant lines Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize --- .../prog/en/modules/pos/register.tt | 72 ++++++++++++++++++- pos/register.pl | 34 +++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt index bb00a6e736..cc0e5b775f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt @@ -2,6 +2,7 @@ [% USE Asset %] [% USE Koha %] [% USE KohaDates %] +[% USE AuthorisedValues %] [% USE Price %] [% SET footerjs = 1 %] [% PROCESS 'accounts.inc' %] @@ -77,7 +78,13 @@ [% credit.debit.amount | $Price %] - + + [% IF CAN_user_cash_management_anonymous_refund && !(credit.debit.status == 'REFUNDED' ) %] + + [% ELSIF CAN_user_updatecharges_refund && !(credit.debit.status == 'REFUNDED') && credit.debit.borrowernumber %] + + [% END %] + [% END %] [% END %] @@ -138,6 +145,57 @@ + + + [% MACRO jsinclude BLOCK %] [% INCLUDE 'datatables.inc' %] [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %] @@ -162,6 +220,18 @@ } })); + $("#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'); + $("#paid + span").replaceWith(amount); + $("#returned").attr({ "value": amount, "max": amount }); + $("#returned, #transaction_type").focus(); + }); + $(".printReceipt").click(function() { var accountlines_id = $(this).data('accountline'); var win = window.open('/cgi-bin/koha/pos/printreceipt.pl?action=print&accountlines_id=' + accountlines_id, '_blank'); diff --git a/pos/register.pl b/pos/register.pl index 31c5fe6180..343526f257 100755 --- a/pos/register.pl +++ b/pos/register.pl @@ -38,6 +38,7 @@ my ( $template, $loggedinuser, $cookie, $user_flags ) = get_template_and_user( } ); my $logged_in_user = Koha::Patrons->find($loggedinuser) or die "Not logged in"; +my $schema = Koha::Database->new->schema; my $library_id = C4::Context->userenv->{'branch'}; my $registerid = $input->param('registerid'); @@ -78,6 +79,39 @@ else { } ); } + elsif ( $op eq 'refund' ) { + my $amount = $input->param('amount'); + my $quantity = $input->param('quantity'); + my $accountline_id = $input->param('accountline'); + my $transaction_type = $input->param('transaction_type'); + + my $accountline = Koha::Account::Lines->find($accountline_id); + $schema->txn_do( + sub { + + my $refund = $accountline->reduce( + { + reduction_type => 'Refund', + branch => $library_id, + staff_id => $logged_in_user->id, + interface => 'intranet', + amount => $amount + } + ); + my $payout = $refund->payout( + { + payout_type => $transaction_type, + branch => $library_id, + staff_id => $logged_in_user->id, + cash_register => $cash_register->id, + interface => 'intranet', + amount => $amount + } + ); + + } + ); + } } output_html_with_http_headers( $input, $cookie, $template->output ); -- 2.39.5