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 <jackie.usher@westsussex.gov.uk>
Signed-off-by: Laura_Escamilla <laura.escamilla@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
This commit is contained in:
Martin Renvoize 2026-01-10 10:00:06 +00:00
parent 0442f4ce2c
commit 78f7abc855
No known key found for this signature in database
GPG Key ID: 2D86E0EAEC83711B
2 changed files with 35 additions and 11 deletions

View File

@ -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");

View File

@ -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 );
}