Bug 40305: Fix 'tendered' vs 'collected' variable name inconsistency

"One Ring to rule them all, one Ring to find them, One Ring to bring
them all and in the darkness bind them"

We've been battling against this for years, with a mixed use of
terminology and thus confusion in templates vs controllers and notice
templates.  I've decided to just try and make sure all the terminology
matches throughout, and use the more popular 'tendered' term over the
'collected' term.

This patch standardizes the terminology used throughout the payment
  system to consistently use 'tendered' instead of the mixed usage of
  'collected' and 'tendered' that has caused confusion over the years.

Changes include:
  - Update all payment form templates to use 'tendered' input names
  - Update JavaScript validation and change calculation logic
  - Update controller parameter handling in pos/pay.pl, pos/printreceipt.pl,
    and members/paycollect.pl
  - Update sample notice templates (RECEIPT) to use 'tendered' variable
  - Add null check for $total_tendered to prevent perl warnings

Test plan:
  1. Test Point of Sale payments with tendered amounts and change calculation
  2. Test member account payments with tendered amounts
  3. Test receipt generation (both print and email)
  4. Verify JavaScript validation works correctly
  5. Confirm no perl warnings when tendered amount is undefined

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit f91310306c)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Martin Renvoize 2025-07-04 09:20:30 +01:00 committed by Paul Derscheid
parent ebb450e036
commit 86b3f2f08e
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
6 changed files with 32 additions and 29 deletions

View File

@ -1865,7 +1865,7 @@ tables:
- " </tr>"
- " <tr>"
- " <td>Tendered: </td>"
- " <td>[% collected | $Price %]</td>"
- " <td>[% tendered | $Price %]</td>"
- " </tr>"
- " <tr>"
- " <td>Change: </td>"
@ -1941,7 +1941,7 @@ tables:
- " </tr>"
- " <tr>"
- " <td>Tendered: </td>"
- " <td>[% collected | $Price %]</td>"
- " <td>[% tendered | $Price %]</td>"
- " </tr>"
- " <tr>"
- " <td>Change given:</td>"

View File

@ -183,8 +183,8 @@
<input name="paid" id="paid" type="text" step="0.01" min="0" value="[% amountoutstanding | $Price on_editing => 1 %]" />
</li>
<li>
<label for="collected">Amount tendered: </label>
<input name="collected" id="collected" type="text" step="0.01" min="0" value="[% amountoutstanding | $Price on_editing => 1 %]" />
<label for="tendered">Amount tendered: </label>
<input name="tendered" id="tendered" type="text" step="0.01" min="0" value="[% amountoutstanding | $Price on_editing => 1 %]" />
</li>
<li>
<label>Change to give: </label>
@ -364,8 +364,8 @@
</li>
[% IF type != 'WRITEOFF' %]
<li>
<label for="collected">Amount tendered: </label>
<input name="collected" id="collected" type="text" step="0.01" min="0" value="[% total | $Price on_editing => 1 %]" />
<label for="tendered">Amount tendered: </label>
<input name="tendered" id="tendered" type="text" step="0.01" min="0" value="[% total | $Price on_editing => 1 %]" />
</li>
<li>
<label>Change to give: </label>
@ -453,7 +453,7 @@
var change = $('#change')[0];
$('#payindivfine, #payfine').preventDoubleFormSubmit();
$("#paid, #collected").on("change",function() {
$("#paid, #tendered").on("change",function() {
moneyFormat( this );
if (change != undefined) {
updateChangeValues();
@ -483,7 +483,7 @@
$( "#payindivfine, #payfine" ).validate({
rules: {
paid: { required: true },
collected: {
tendered: {
required: true
},
[% IF Koha.Preference('UseCashRegisters') %]
@ -577,11 +577,11 @@
function updateChangeValues() {
var change = $('#change')[0];
change.innerHTML = Math.round(($('#collected')[0].value - $('#paid')[0].value) * 100) / 100;
change.innerHTML = Math.round(($('#tendered')[0].value - $('#paid')[0].value) * 100) / 100;
if (change.innerHTML <= 0) {
var paid = $('#paid')[0];
moneyFormat(paid);
$('#collected').rules( "add", { min: Number(paid.value) });
$('#tendered').rules( "add", { min: Number(paid.value) });
$( "#payindivfine, #payfine" ).valid();
change.innerHTML = "0.00";
$('input[name="change_given"]').val('0.00');

View File

@ -51,7 +51,7 @@
<div class="alert alert-info audio-alert-action">
<p>Payment received</p>
<p>
<a target="_blank" href="/cgi-bin/koha/pos/printreceipt.pl?action=print&accountlines_id=[% payment_id | uri %]&collected=[% collected | uri %]&change=[% change | uri %]" class="btn btn-default"
<a target="_blank" href="/cgi-bin/koha/pos/printreceipt.pl?action=print&accountlines_id=[% payment_id | uri %]&tendered=[% tendered | uri %]&change=[% change | uri %]" class="btn btn-default"
><i class="fa fa-print"></i> Print receipt</a
>
<a href="#" data-bs-toggle="modal" data-bs-target="#emailReceiptModal" class="btn btn-default"><i class="fa-solid fa-envelope"></i> Email receipt</a>
@ -138,8 +138,8 @@
<input type="text" inputmode="none" pattern="[0-9]*" name="paid" id="paid" value="" readonly />
</li>
<li>
<label for="collected" class="required">Amount tendered: </label>
<input type="text" inputmode="numeric" pattern="[0-9]*" name="collected" id="collected" value="" class="required" required="required" />
<label for="tendered" class="required">Amount tendered: </label>
<input type="text" inputmode="numeric" pattern="[0-9]*" name="tendered" id="tendered" value="" class="required" required="required" />
<span class="required">Required</span>
</li>
<li>
@ -181,7 +181,7 @@
<form id="email_form" action="/cgi-bin/koha/pos/pay.pl" method="post" enctype="multipart/form-data" class="validated">
[% INCLUDE 'csrf-token.inc' %]
<input type="hidden" name="payment_id" value="[% payment_id | uri %]" />
<input type="hidden" name="collected" value="[% collected | uri %]" />
<input type="hidden" name="tendered" value="[% tendered | uri %]" />
<input type="hidden" name="change" value="[% change | uri %]" />"
<div class="modal-dialog">
<div class="modal-content">
@ -316,11 +316,11 @@
function updateChangeValues() {
var change = $('#change')[0];
var zero_formatted = "[% 0 | $Price %]";
change.innerHTML = Math.round(($('#collected')[0].value - $('#paid')[0].value) * 100) / 100;
change.innerHTML = Math.round(($('#tendered')[0].value - $('#paid')[0].value) * 100) / 100;
if (change.innerHTML <= 0) {
var paid = $('#paid')[0];
moneyFormat(paid);
$('#collected').rules( "add", { min: Number(paid.value) });
$('#tendered').rules( "add", { min: Number(paid.value) });
change.innerHTML = zero_formatted;
$(':input[name="change"]').val(zero_formatted);
} else {
@ -456,7 +456,7 @@
// Change calculation and modal
var change = $('#change')[0];
$("#paid, #collected").on("change",function() {
$("#paid, #tendered").on("change",function() {
moneyFormat( this );
if (change != undefined) {
updateChangeValues();
@ -474,7 +474,7 @@
paid: {
required: true
},
collected: {
tendered: {
required: true
},
payment_type: {
@ -518,7 +518,7 @@
[% IF payment_id && Koha.Preference('FinePaymentAutoPopup') %]
$("#printReceipt").click(function() {
var win = window.open('/cgi-bin/koha/pos/printreceipt.pl?action=print&accountlines_id=[% payment_id | uri %]&collected=[% collected | uri %]&change=[% change | uri %]', '_blank');
var win = window.open('/cgi-bin/koha/pos/printreceipt.pl?action=print&accountlines_id=[% payment_id | uri %]&tendered=[% tendered | uri %]&change=[% change | uri %]', '_blank');
win.focus();
});
$("#printReceipt").click();

View File

@ -72,8 +72,8 @@ my $user = $input->remote_user;
my $library_id = C4::Context->userenv->{'branch'};
my $total_due = $account->outstanding_debits->total_outstanding;
my $total_paid = $input->param('paid');
my $total_collected = $input->param('collected');
my $total_paid = $input->param('paid');
my $total_tendered = $input->param('tendered');
my $selected_lines = $input->param('selected'); # comes from pay.pl
my $pay_individual = $input->param('pay_individual');
@ -151,7 +151,10 @@ if ( $total_paid and $total_paid ne '0.00' ) {
error_over => 1,
total_due => $total_due
);
} elsif ( $total_collected < $total_paid && !( $op eq 'cud-writeoff_individual' || $type eq 'WRITEOFF' ) ) {
} elsif ( defined $total_tendered
&& $total_tendered < $total_paid
&& !( $op eq 'cud-writeoff_individual' || $type eq 'WRITEOFF' ) )
{
$template->param(
error_under => 1,
total_paid => $total_paid

View File

@ -80,7 +80,7 @@ if ( $op eq 'cud-pay' ) {
$template->param(
payment_id => $payment->accountlines_id,
collected => scalar $input->param('collected'),
tendered => scalar $input->param('tendered'),
change => scalar $input->param('change')
);
}
@ -89,7 +89,7 @@ if ( $op eq 'cud-pay' ) {
if ( $op eq 'cud-send' ) {
my $payment_id = $input->param('payment_id');
my $change = $input->param('change');
my $collected = $input->param('collected');
my $tendered = $input->param('tendered');
my $toaddr = $input->param('toaddr');
# Create our letter from the template
@ -102,8 +102,8 @@ if ( $op eq 'cud-send' ) {
credits => $payment_id,
},
substitute => {
collected => $collected,
change => $change
tendered => $tendered,
change => $change
}
);
@ -123,7 +123,7 @@ if ( $op eq 'cud-send' ) {
# Set variables for template to allow printing still
$template->param(
payment_id => $payment_id,
collected => $collected,
tendered => $tendered,
change => $change
);
}

View File

@ -62,8 +62,8 @@ my $letter = C4::Letters::GetPreparedLetter(
borrowers => $patron ? $patron->borrowernumber : undef
},
substitute => {
collected => scalar $input->param('collected'),
change => scalar $input->param('change')
tendered => scalar $input->param('tendered'),
change => scalar $input->param('change')
}
);