Bug 37671: Add new 'PAYOUT' notice template

When a refund is processed through Point of Sale, the system creates:
1. A credit account line (the refund)
2. A debit account line (the payout)

The receipt printing logic currently only accounts for RECEIPTs against
credits.

This patch adds a new 'PAYOUT' template for dealing with the negative
debits that make up a payout so we can construct a proper receipt for
this action.

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 17:22:24 +00:00 committed by Lucas Gass
parent 9499e739f0
commit 02fb697d21
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 198 additions and 1 deletions

View File

@ -0,0 +1,105 @@
use Modern::Perl;
use Koha::Installer::Output qw(say_warning say_success say_info);
return {
bug_number => "37671",
description => "Add PAYOUT notice template for POS refund receipts",
up => sub {
my ($args) = @_;
my ( $dbh, $out ) = @$args{qw(dbh out)};
# Add new PAYOUT letter template for POS
$dbh->do(
q{
INSERT INTO letter (module, code, branchcode, name, is_html, title, content, message_transport_type, lang, updated_on)
VALUES (
'pos', 'PAYOUT', '', 'Point of sale payout receipt', 1, 'Payout receipt',
"[% USE KohaDates %]
[% USE Branches %]
[% USE Price %]
[% USE AuthorisedValues %]
[% PROCESS 'accounts.inc' %]
<table>
[% IF ( LibraryName ) %]
<tr>
<th colspan='2' class='centerednames'>
<h3>[% LibraryName | html %]</h3>
</th>
</tr>
[% END %]
<tr>
<th colspan='2' class='centerednames'>
<h2>[% Branches.GetName( debit.branchcode ) | html %]</h2>
</th>
</tr>
<tr>
<th colspan='2' class='centerednames'>
<h3>[% debit.date | $KohaDates %]</h3>
</tr>
<tr>
<td>Transaction ID: </td>
<td>[% debit.accountlines_id %]</td>
</tr>
<tr>
<td>Operator ID: </td>
<td>[% debit.manager_id %]</td>
</tr>
<tr>
<td>Payout type: </td>
<td>[% AuthorisedValues.GetByCode( 'PAYMENT_TYPE', debit.payment_type ) | html %]</td>
</tr>
<tr></tr>
<tr>
<th colspan='2' class='centerednames'>
<h2><u>Refund Payout Receipt</u></h2>
</th>
</tr>
<tr></tr>
[% IF debit.patron %]
<tr>
<th colspan='2'>
Paid to: [% debit.patron.firstname | html %] [% debit.patron.surname | html %]<br>
Card number: [% debit.patron.cardnumber | html %]
</th>
</tr>
<tr></tr>
[% END %]
<tr>
<th colspan='2'>Refund details</th>
</tr>
<tr>
<th>Item / Original charge</th>
<th>Refund amount</th>
</tr>
[% FOREACH credit IN debit.credits %]
[% FOREACH offset IN credit.credit_offsets %]
[% IF offset.debit && offset.debit.debit_type_code != 'PAYOUT' %]
<tr>
<td>
[% PROCESS account_type_description account=offset.debit %]
[% IF offset.debit.description %] - [% offset.debit.description | html %][% END %]
[% IF offset.debit.itemnumber %]<br><i>[% offset.debit.item.biblio.title | html %]</i>[% END %]
<br>Original charge: [% offset.debit.amount | $Price %]
</td>
<td>[% credit.amount * -1 | $Price %]</td>
</tr>
[% END %]
[% END %]
[% END %]
<tfoot>
<tr class='highlight'>
<td>Total payout: </td>
<td>[% debit.amount | $Price %]</td>
</tr>
</tfoot>
</table>",
'print', 'default', NOW()
)
}
);
say_success( $out, "Added new PAYOUT letter template for POS refunds" );
},
};

View File

@ -1808,6 +1808,7 @@ tables:
- "[% USE KohaDates %]"
- "[% USE Branches %]"
- "[% USE Price %]"
- "[% USE AuthorisedValues %]"
- "[% PROCESS \"accounts.inc\" %]"
- "<table>"
- "[% IF ( LibraryName ) %]"
@ -1836,7 +1837,7 @@ tables:
- "</tr>"
- "<tr>"
- " <td>Payment type: </td>"
- " <td>[% credit.payment_type %]</td>"
- " <td>[% AuthorisedValues.GetByCode( 'PAYMENT_TYPE', credit.payment_type ) | html %]</td>"
- "</tr>"
- " <tr></tr>"
- " <tr>"
@ -1949,6 +1950,97 @@ tables:
- " </tfoot>"
- "</table>"
- module: pos
code: PAYOUT
branchcode: ""
name: "Point of sale payout receipt"
is_html: 1
title: "Payout receipt"
message_transport_type: print
lang: default
content:
- "[% USE KohaDates %]"
- "[% USE Branches %]"
- "[% USE Price %]"
- "[% USE AuthorisedValues %]"
- "[% PROCESS \"accounts.inc\" %]"
- "<table>"
- "[% IF ( LibraryName ) %]"
- " <tr>"
- " <th colspan=\"2\" class=\"centerednames\">"
- " <h3>[% LibraryName | html %]</h3>"
- " </th>"
- " </tr>"
- "[% END %]"
- " <tr>"
- " <th colspan=\"2\" class=\"centerednames\">"
- " <h2>[% Branches.GetName( debit.branchcode ) | html %]</h2>"
- " </th>"
- " </tr>"
- "<tr>"
- " <th colspan=\"2\" class=\"centerednames\">"
- " <h3>[% debit.date | $KohaDates %]</h3>"
- "</tr>"
- "<tr>"
- " <td>Transaction ID: </td>"
- " <td>[% debit.accountlines_id %]</td>"
- "</tr>"
- "<tr>"
- " <td>Operator ID: </td>"
- " <td>[% debit.manager_id %]</td>"
- "</tr>"
- "<tr>"
- " <td>Payout type: </td>"
- " <td>[% AuthorisedValues.GetByCode( \"PAYMENT_TYPE\", debit.payment_type ) | html %]</td>"
- "</tr>"
- " <tr></tr>"
- " <tr>"
- " <th colspan=\"2\" class=\"centerednames\">"
- " <h2><u>Refund Payout Receipt</u></h2>"
- " </th>"
- " </tr>"
- " <tr></tr>"
- " [% IF debit.patron %]"
- " <tr>"
- " <th colspan=\"2\">"
- " Paid to: [% debit.patron.firstname | html %] [% debit.patron.surname | html %]<br>"
- " Card number: [% debit.patron.cardnumber | html %]"
- " </th>"
- " </tr>"
- " <tr></tr>"
- " [% END %]"
- " <tr>"
- " <th colspan=\"2\">Refund details</th>"
- " </tr>"
- " <tr>"
- " <th>Item / Original charge</th>"
- " <th>Refund amount</th>"
- " </tr>"
- ""
- " [% FOREACH credit IN debit.credits %]"
- " [% FOREACH offset IN credit.credit_offsets %]"
- " [% IF offset.debit && offset.debit.debit_type_code != 'PAYOUT' %]"
- " <tr>"
- " <td>"
- " [% PROCESS account_type_description account=offset.debit %]"
- " [% IF offset.debit.description %] - [% offset.debit.description | html %][% END %]"
- " [% IF offset.debit.itemnumber %]<br><i>[% offset.debit.item.biblio.title | html %]</i>[% END %]"
- " <br>Original charge: [% offset.debit.amount | $Price %]"
- " </td>"
- " <td>[% credit.amount * -1 | $Price %]</td>"
- " </tr>"
- " [% END %]"
- " [% END %]"
- " [% END %]"
- ""
- "<tfoot>"
- " <tr class=\"highlight\">"
- " <td>Total payout: </td>"
- " <td>[% debit.amount | $Price %]</td>"
- " </tr>"
- "</tfoot>"
- "</table>"
- module: reserves
code: CANCEL_HOLD_ON_LOST
branchcode: ""