From 9a1a341146ca0055fa0de12debb34530afc5d512 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Sat, 10 Jan 2026 10:00:06 +0000 Subject: [PATCH] Bug 41585: Fix cash refund payouts not appearing in register transactions This patch fixes two issues with cash refunds on the register page: 1. Payouts were not appearing in the transactions table after being created because accountlines were fetched before the refund operation completed. 2. Account credit (AC) refunds were incorrectly creating payout transactions when no cash should leave the register. Changes: - Only create payout for non-AC refund types - Use explicit registerid from page context for payout - Add POST/REDIRECT/GET pattern after refund to refresh page data - Add client-side validation for cash register requirement on patron account page Test plan: 1. Navigate to POS register page with transactions 2. Issue a cash refund on a transaction 3. Verify the payout appears in the transactions table 4. Issue an account credit (AC) refund 5. Verify no payout is created (only the refund credit) 6. On patron account page, attempt cash refund without register 7. Verify validation message appears --- .../prog/en/modules/members/boraccount.tt | 19 +++++++++++++ pos/register.pl | 27 +++++++++++-------- 2 files changed, 35 insertions(+), 11 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 d4a337786ef..f185f68adad 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt @@ -638,6 +638,25 @@ $("#returned, #refund_type").focus(); }); + // Validate cash register requirement for refunds + [% IF Koha.Preference('UseCashRegisters') %] + $("#refund_form").on("submit", function(e) { + var refund_type = $("#refund_type").val(); + var register = $("#refund_registerid").val(); + + // Only require register for non-AC refunds with CASH or SIP00 payment types + if (refund_type && refund_type !== 'AC' && (refund_type === 'CASH' || refund_type.match(/^SIP\d{2}$/))) { + if (!register || register === '') { + e.preventDefault(); + alert(_("Cash register is required for cash refunds")); + $("#refund_registerid").focus(); + return false; + } + } + return true; + }); + [% END %] + $("#applyDiscountModal").on("shown.bs.modal", function(e){ var button = $(e.relatedTarget); var item = button.data('item'); diff --git a/pos/register.pl b/pos/register.pl index 66e0533c74a..8972b3da003 100755 --- a/pos/register.pl +++ b/pos/register.pl @@ -137,19 +137,24 @@ if ( !$registers->count ) { amount => $amount } ); - my $payout = $refund->payout( - { - payout_type => $refund_type, - branch => $library_id, - staff_id => $logged_in_user->id, - cash_register => $cash_register->id, - interface => 'intranet', - amount => $amount - } - ); - + unless ( $refund_type eq 'AC' ) { + my $payout = $refund->payout( + { + payout_type => $refund_type, + branch => $library_id, + staff_id => $logged_in_user->id, + cash_register => $registerid, + interface => 'intranet', + amount => $amount + } + ); + } } ); + + # Redirect to prevent duplicate submissions (POST/REDIRECT/GET pattern) + print $input->redirect( "/cgi-bin/koha/pos/register.pl?registerid=" . $registerid ); + exit; } else { $template->param( error_refund_permission => 1 ); } -- 2.52.0