View | Details | Raw Unified | Return to bug 40445
Collapse All | Expand All

(-)a/Koha/Cash/Register.pm (-15 / +32 lines)
Lines 291-304 sub start_cashup { Link Here
291
291
292
    my $expected_amount = abs( $self->outstanding_accountlines->total( { payment_type => [ 'CASH', 'SIP00' ] } ) );
292
    my $expected_amount = abs( $self->outstanding_accountlines->total( { payment_type => [ 'CASH', 'SIP00' ] } ) );
293
293
294
    # Create the CASHUP_START action
294
    # Prevent starting a cashup when there are no cash transactions
295
    my $rs = $self->_result->add_to_cash_register_actions(
295
    unless ( $expected_amount > 0 ) {
296
        {
296
        Koha::Exceptions::Object::BadValue->throw(
297
            code       => 'CASHUP_START',
297
            error => "Cannot start cashup with zero cash transactions",
298
            manager_id => $manager_id,
298
            type  => 'amount',
299
            amount     => $expected_amount
299
            value => $expected_amount
300
        );
301
    }
302
303
    # Create the CASHUP_START action using centralized exception handling
304
    my $schema = $self->_result->result_source->schema;
305
    my $rs     = $schema->safe_do(
306
        sub {
307
            return $self->_result->add_to_cash_register_actions(
308
                {
309
                    code       => 'CASHUP_START',
310
                    manager_id => $manager_id,
311
                    amount     => $expected_amount
312
                }
313
            )->discard_changes;
300
        }
314
        }
301
    )->discard_changes;
315
    );
302
316
303
    return Koha::Cash::Register::Cashup->_new_from_dbic($rs);
317
    return Koha::Cash::Register::Cashup->_new_from_dbic($rs);
304
}
318
}
Lines 387-401 sub add_cashup { Link Here
387
401
388
    $schema->txn_do(
402
    $schema->txn_do(
389
        sub {
403
        sub {
390
            # Create the cashup action with actual amount
404
            # Create the cashup action - safe_do handles exception translation
391
            my $rs = $self->_result->add_to_cash_register_actions(
405
            my $rs = $schema->safe_do(
392
                {
406
                sub {
393
                    code       => 'CASHUP',
407
                    return $self->_result->add_to_cash_register_actions(
394
                    manager_id => $manager_id,
408
                        {
395
                    amount     => $amount
409
                            code       => 'CASHUP',
410
                            manager_id => $manager_id,
411
                            amount     => $amount
412
                        }
413
                    )->discard_changes;
396
                }
414
                }
397
            )->discard_changes;
415
            );
398
399
            $cashup = Koha::Cash::Register::Cashup->_new_from_dbic($rs);
416
            $cashup = Koha::Cash::Register::Cashup->_new_from_dbic($rs);
400
417
401
            # Create reconciliation accountline if there's a difference
418
            # Create reconciliation accountline if there's a difference
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt (-1 / +18 lines)
Lines 56-61 Link Here
56
            <div id="error_message" class="alert alert-warning"> A cashup is already in progress for this register. </div>
56
            <div id="error_message" class="alert alert-warning"> A cashup is already in progress for this register. </div>
57
        [% END %]
57
        [% END %]
58
58
59
        [% IF ( error_cashup_no_transactions ) %]
60
            <div id="error_message" class="alert alert-info"> Cannot start cashup - there are no cash transactions in this register since the last cashup. </div>
61
        [% END %]
62
59
        [% IF ( error_no_cashup_start ) %]
63
        [% IF ( error_no_cashup_start ) %]
60
            <div id="error_message" class="alert alert-warning"> No cashup session has been started. Please start a cashup before attempting to complete it. </div>
64
            <div id="error_message" class="alert alert-warning"> No cashup session has been started. Please start a cashup before attempting to complete it. </div>
61
        [% END %]
65
        [% END %]
Lines 68-75 Link Here
68
            <div id="error_message" class="alert alert-warning"> Failed to start cashup. Please try again. </div>
72
            <div id="error_message" class="alert alert-warning"> Failed to start cashup. Please try again. </div>
69
        [% END %]
73
        [% END %]
70
74
75
        [% IF ( error_cashup_missing_param ) %]
76
            <div id="error_message" class="alert alert-warning"> Missing required parameter for cashup: [% error_message | html %] </div>
77
        [% END %]
78
79
        [% IF ( error_cashup_amount_invalid ) %]
80
            <div id="error_message" class="alert alert-warning"> The cashup amount must be a positive number greater than zero. </div>
81
        [% END %]
82
71
        [% IF ( error_cashup_complete ) %]
83
        [% IF ( error_cashup_complete ) %]
72
            <div id="error_message" class="alert alert-warning"> Failed to complete cashup. Please try again. </div>
84
            <div id="error_message" class="alert alert-warning">
85
                Failed to complete cashup. Please try again.
86
                [% IF error_details %]
87
                    <br /><strong>Error details:</strong> [% error_details | html %]
88
                [% END %]
89
            </div>
73
        [% END %]
90
        [% END %]
74
91
75
        [% IF ( error_refund_permission ) %]
92
        [% IF ( error_refund_permission ) %]
(-)a/pos/register.pl (-1 / +9 lines)
Lines 117-122 if ( !$registers->count ) { Link Here
117
            if ($@) {
117
            if ($@) {
118
                if ( $@->isa('Koha::Exceptions::Object::DuplicateID') ) {
118
                if ( $@->isa('Koha::Exceptions::Object::DuplicateID') ) {
119
                    $template->param( error_cashup_in_progress => 1 );
119
                    $template->param( error_cashup_in_progress => 1 );
120
                } elsif ( $@->isa('Koha::Exceptions::Object::BadValue') ) {
121
                    $template->param( error_cashup_no_transactions => 1 );
120
                } else {
122
                } else {
121
                    $template->param( error_cashup_start => 1 );
123
                    $template->param( error_cashup_start => 1 );
122
                }
124
                }
Lines 157-164 if ( !$registers->count ) { Link Here
157
                        $template->param( error_no_cashup_start => 1 );
159
                        $template->param( error_no_cashup_start => 1 );
158
                    } elsif ( $@->isa('Koha::Exceptions::Object::DuplicateID') ) {
160
                    } elsif ( $@->isa('Koha::Exceptions::Object::DuplicateID') ) {
159
                        $template->param( error_cashup_already_completed => 1 );
161
                        $template->param( error_cashup_already_completed => 1 );
162
                    } elsif ( $@->isa('Koha::Exceptions::MissingParameter') ) {
163
                        $template->param( error_cashup_missing_param => 1, error_message => $@ );
164
                    } elsif ( $@->isa('Koha::Exceptions::Account::AmountNotPositive') ) {
165
                        $template->param( error_cashup_amount_invalid => 1 );
160
                    } else {
166
                    } else {
161
                        $template->param( error_cashup_complete => 1 );
167
168
                        # Log the actual exception for debugging
169
                        $template->param( error_cashup_complete => 1, error_details => "$@" );
162
                    }
170
                    }
163
                } else {
171
                } else {
164
172
(-)a/pos/registers.pl (+2 lines)
Lines 98-103 if ( $op eq 'cud-cashup_start' ) { Link Here
98
            if ($@) {
98
            if ($@) {
99
                if ( $@->isa('Koha::Exceptions::Object::DuplicateID') ) {
99
                if ( $@->isa('Koha::Exceptions::Object::DuplicateID') ) {
100
                    push @errors, "Register " . $register->name . ": Cashup already in progress";
100
                    push @errors, "Register " . $register->name . ": Cashup already in progress";
101
                } elsif ( $@->isa('Koha::Exceptions::Object::BadValue') ) {
102
                    push @errors, "Register " . $register->name . ": No cash transactions to cashup";
101
                } else {
103
                } else {
102
                    push @errors, "Register " . $register->name . ": Failed to start cashup";
104
                    push @errors, "Register " . $register->name . ": Failed to start cashup";
103
                }
105
                }
(-)a/t/db_dependent/Koha/Cash/Register.t (-6 / +8 lines)
Lines 1249-1256 subtest 'start_cashup_parameter_validation' => sub { Link Here
1249
            }
1249
            }
1250
        );
1250
        );
1251
1251
1252
        eval { $register3->start_cashup( { manager_id => 99999999 } ); };
1252
        throws_ok {
1253
        ok( $@, 'start_cashup fails with invalid manager_id' );
1253
            $register3->start_cashup( { manager_id => 99999999 } );
1254
        }
1255
        'Koha::Exceptions::Object::FKConstraint', 'start_cashup throws FK constraint exception with invalid manager_id';
1254
    };
1256
    };
1255
1257
1256
    # Test 4: Duplicate start_cashup prevention
1258
    # Test 4: Duplicate start_cashup prevention
Lines 1570-1578 subtest 'add_cashup' => sub { Link Here
1570
1572
1571
        my $register9 = $builder->build_object( { class => 'Koha::Cash::Registers' } );
1573
        my $register9 = $builder->build_object( { class => 'Koha::Cash::Registers' } );
1572
1574
1573
        eval { $register9->add_cashup( { manager_id => 99999999, amount => '10.00' } ); };
1575
        throws_ok {
1574
        ok( $@, 'add_cashup fails with invalid manager_id' );
1576
            $register9->add_cashup( { manager_id => 99999999, amount => '10.00' } );
1575
        diag($@);
1577
        }
1578
        'Koha::Exceptions::Object::FKConstraint', 'add_cashup throws FK constraint exception with invalid manager_id';
1576
    };
1579
    };
1577
1580
1578
    $schema->storage->txn_rollback;
1581
    $schema->storage->txn_rollback;
1579
- 

Return to bug 40445