From 78f7abc855ab537c714279b1579bd03accd315cb 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 Signed-off-by: Jackie Usher Signed-off-by: Laura_Escamilla Signed-off-by: Martin Renvoize --- .../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 25c9a152e8..4728744f58 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt @@ -646,6 +646,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 3e785dbf18..3b162746e1 100755 --- a/pos/register.pl +++ b/pos/register.pl @@ -138,19 +138,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 ); }