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

Sponsored-by: OpenFifth <https://openfifth.co.uk/>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2026-02-02 15:59:16 +00:00 committed by Lucas Gass
parent 02fb697d21
commit e92dfc5ab0
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 18 additions and 4 deletions

View File

@ -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 => {