From 4a1006bd3ff760bab8b6b0dbe727578797e2cadd Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 2 Feb 2026 15:59:16 +0000 Subject: [PATCH] Bug 37671: Fix POS receipt printing for refunds The receipt printing logic was failing because it always expected a credit but the "Print receipt" button was passing the payout debit line ID. This fix: - Updates pos/printreceipt.pl to use previously added PAYOUT template based on account line type - Uses RECEIPT template for credits, PAYOUT template for PAYOUT debits - Throws proper error for unsupported transaction types Test plan: 1. Make a purchase through Point of Sale 2. Go to transaction history for the register used 3. Issue a refund for the purchase 4. Click "Print receipt" button for the refund 5. Verify receipt prints correctly with payout details --- pos/printreceipt.pl | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/pos/printreceipt.pl b/pos/printreceipt.pl index 321e3db6040..e24ad26692b 100755 --- a/pos/printreceipt.pl +++ b/pos/printreceipt.pl @@ -36,8 +36,8 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( ); my $payment_id = $input->param('accountlines_id'); -my $payment = Koha::Account::Lines->find($payment_id); -my $patron = $payment->patron; +my $accountline = Koha::Account::Lines->find($payment_id); +my $patron = $accountline->patron; my $logged_in_user = Koha::Patrons->find($loggedinuser) or die "Not logged in"; output_and_exit_if_error( @@ -51,14 +51,28 @@ output_and_exit_if_error( ) if $patron; # Payment could have been anonymous my $lang = $patron ? $patron->lang : $template->lang; +# Determine template and table based on account line type +my ($letter_code, $table_key, $table_id); +if ($accountline->is_credit) { + $letter_code = 'RECEIPT'; + $table_key = 'credits'; + $table_id = $accountline->accountlines_id; +} elsif ($accountline->is_debit && $accountline->debit_type_code eq 'PAYOUT') { + $letter_code = 'PAYOUT'; + $table_key = 'debits'; + $table_id = $accountline->accountlines_id; +} else { + die "Account line " . $payment_id . " is not a credit or supported payout transaction"; +} + my $letter = C4::Letters::GetPreparedLetter( module => 'pos', - letter_code => 'RECEIPT', + letter_code => $letter_code, branchcode => C4::Context::mybranch, message_transport_type => 'print', lang => $lang, tables => { - credits => $payment_id, + $table_key => $table_id, borrowers => $patron ? $patron->borrowernumber : undef }, substitute => { -- 2.52.0