From ee612c3ae11817cf9b89e9a08f8b9259b7ac4960 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 https://bugs.koha-community.org/show_bug.cgi?id=23355 --- .../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 dc3685e9f2..0f1715c7b6 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' %] @@ -97,7 +98,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 %] @@ -147,6 +154,57 @@ + + + [% MACRO jsinclude BLOCK %] [% INCLUDE 'datatables.inc' %] [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %] @@ -171,6 +229,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 a7fde86ce2..382aeab44c 100755 --- a/pos/register.pl +++ b/pos/register.pl @@ -39,6 +39,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'); @@ -79,6 +80,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.20.1