From c17326d5c5a6dd078e2692510a1d6beacabd8dc7 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 12 Jan 2026 15:14:41 +0000 Subject: [PATCH] Bug 40445: (follow-up) Fix backend validation for non-cash transactions The previous commits fixed the frontend to allow cashup buttons when there are non-cash transactions, but the backend validation was still restricting cashups to cash-only scenarios. This patch fixes the backend validation in Koha::Cash::Register: 1. start_cashup() - Changed validation to check for ANY transactions instead of only CASH/SIP00 transactions. This allows starting a cashup when there are Card or other non-cash payment types. 2. add_cashup() - Removed the requirement that amount must be non-zero. When there are only non-cash transactions, the cashup amount can legitimately be 0.00 (no cash to count/remove). 3. Updated error messages in register.tt to reflect the new validation logic (removed references to "cash transactions" and "non-zero"). Without these backend fixes, the frontend changes would still result in validation errors when users attempted cashups with only non-cash transactions. Test plan: 1. Create transactions on a register using only Card payment type 2. Attempt to start a cashup - should succeed (not throw BadValue exception) 3. Enter 0.00 as the cashup amount - should complete successfully 4. Verify no surplus/deficit lines are created (balanced cashup) 5. Attempt to start cashup with zero transactions - should still fail with appropriate error message --- Koha/Cash/Register.pm | 15 ++++++++------- .../intranet-tmpl/prog/en/modules/pos/register.tt | 7 ++++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Koha/Cash/Register.pm b/Koha/Cash/Register.pm index ba2a9e5aa5c..aa9168b541e 100644 --- a/Koha/Cash/Register.pm +++ b/Koha/Cash/Register.pm @@ -291,12 +291,13 @@ sub start_cashup { my $expected_amount = $self->outstanding_accountlines->total( { payment_type => [ 'CASH', 'SIP00' ] } ) * -1; - # Prevent starting a cashup when there are no cash transactions - unless ( $expected_amount != 0 ) { + # Prevent starting a cashup when there are no transactions at all + my $total_transactions = $self->outstanding_accountlines->total() * -1; + unless ( $total_transactions != 0 ) { Koha::Exceptions::Object::BadValue->throw( - error => "Cannot start cashup with zero cash transactions", + error => "Cannot start cashup with no transactions", type => 'amount', - value => $expected_amount + value => $total_transactions ); } @@ -345,10 +346,10 @@ sub add_cashup { } my $manager_id = $params->{manager_id}; - # Validate amount is a non-zero number + # Validate amount is a valid number my $amount = $params->{amount}; - unless ( looks_like_number($amount) && $amount != 0 ) { - Koha::Exceptions::Account::AmountNotPositive->throw( error => 'Cashup amount must be a non-zero number' ); + unless ( looks_like_number($amount) ) { + Koha::Exceptions::Account::AmountNotPositive->throw( error => 'Cashup amount must be a valid number' ); } # Sanitize reconciliation note - treat empty/whitespace-only as undef diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt index 41b43563ce0..22d5decef0e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt @@ -57,7 +57,7 @@ [% END %] [% IF ( error_cashup_no_transactions ) %] -
Cannot start cashup - there are no cash transactions in this register since the last cashup.
+
Cannot start cashup - there are no transactions in this register since the last cashup.
[% END %] [% IF ( error_no_cashup_start ) %] @@ -77,7 +77,7 @@ [% END %] [% IF ( error_cashup_amount_invalid ) %] -
The cashup amount must be a positive number greater than zero.
+
The cashup amount must be a valid number.
[% END %] [% IF ( error_reconciliation_note_required ) %] @@ -109,12 +109,13 @@ [% END %] [% SET total_bankable = accountlines.total( payment_type => [ 'CASH', 'SIP00' ]) * -1 %] + [% SET total_transactions = accountlines.total() * -1 %] [% IF ( CAN_user_cash_management_cashup ) %]
[% IF cashup_in_progress %] [% ELSE %] - [% END %] -- 2.52.0