From 8a61535e636de534faeff95eab88cb8d49ec96a2 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 7 Nov 2025 16:39:54 +0000 Subject: [PATCH] Bug 40445: Prevent starting cashup with zero cash transactions In the two-phase cashup workflow, users could start a cashup session when there were no cash transactions, but then get trapped unable to complete it because the completion validation requires amount > 0. This creates a poor user experience where: 1. User starts cashup (allowed with 0 expected amount) 2. Modal shows "Expected cashup amount: 0.00" 3. User enters "0" as actual amount 4. Validation fails: "amount must be positive number greater than zero" 5. User is stuck - cannot complete, cashup session remains open This patch prevents the trap by validating at cashup start time: Backend changes: - start_cashup() now checks if expected_amount > 0 - Throws Koha::Exceptions::Object::BadValue if no transactions exist - Prevents creating a cashup session that cannot be completed Error handling: - pos/register.pl catches BadValue and displays informative message - pos/registers.pl catches BadValue for multi-register cashup - Error message clearly explains no transactions exist to cashup UI changes: - Added error_cashup_no_transactions template parameter - Displays as alert-info (informational) rather than alert-warning - Message: "Cannot start cashup - there are no cash transactions in this register since the last cashup" This validates the business rule consistently: cashups require cash transactions. Users are informed upfront rather than getting trapped in an incomplete workflow. Test plan: 1. Start a register with no cash transactions since last cashup 2. Attempt to start a cashup (two-phase workflow) 3. Verify error message appears preventing cashup start 4. Add a cash transaction to the register 5. Attempt to start cashup again 6. Verify cashup starts successfully 7. Test multi-register cashup on registers page 8. Verify appropriate error for registers with no transactions --- Koha/Cash/Register.pm | 9 +++++++++ koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt | 4 ++++ pos/register.pl | 2 ++ pos/registers.pl | 2 ++ 4 files changed, 17 insertions(+) diff --git a/Koha/Cash/Register.pm b/Koha/Cash/Register.pm index efb4d8620b4..3261ca1ff11 100644 --- a/Koha/Cash/Register.pm +++ b/Koha/Cash/Register.pm @@ -291,6 +291,15 @@ sub start_cashup { my $expected_amount = abs( $self->outstanding_accountlines->total( { payment_type => [ 'CASH', 'SIP00' ] } ) ); + # Prevent starting a cashup when there are no cash transactions + unless ( $expected_amount > 0 ) { + Koha::Exceptions::Object::BadValue->throw( + error => "Cannot start cashup with zero cash transactions", + type => 'amount', + value => $expected_amount + ); + } + # Create the CASHUP_START action using centralized exception handling my $schema = $self->_result->result_source->schema; my $rs = $schema->safe_do( 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 53ec4dbda88..a23383c01e0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt @@ -56,6 +56,10 @@
A cashup is already in progress for this register.
[% END %] + [% IF ( error_cashup_no_transactions ) %] +
Cannot start cashup - there are no cash transactions in this register since the last cashup.
+ [% END %] + [% IF ( error_no_cashup_start ) %]
No cashup session has been started. Please start a cashup before attempting to complete it.
[% END %] diff --git a/pos/register.pl b/pos/register.pl index 41d62fff656..3a9524adfe4 100755 --- a/pos/register.pl +++ b/pos/register.pl @@ -117,6 +117,8 @@ if ( !$registers->count ) { if ($@) { if ( $@->isa('Koha::Exceptions::Object::DuplicateID') ) { $template->param( error_cashup_in_progress => 1 ); + } elsif ( $@->isa('Koha::Exceptions::Object::BadValue') ) { + $template->param( error_cashup_no_transactions => 1 ); } else { $template->param( error_cashup_start => 1 ); } diff --git a/pos/registers.pl b/pos/registers.pl index 071a4a17824..2dc7e0fa441 100755 --- a/pos/registers.pl +++ b/pos/registers.pl @@ -98,6 +98,8 @@ if ( $op eq 'cud-cashup_start' ) { if ($@) { if ( $@->isa('Koha::Exceptions::Object::DuplicateID') ) { push @errors, "Register " . $register->name . ": Cashup already in progress"; + } elsif ( $@->isa('Koha::Exceptions::Object::BadValue') ) { + push @errors, "Register " . $register->name . ": No cash transactions to cashup"; } else { push @errors, "Register " . $register->name . ": Failed to start cashup"; } -- 2.51.1