|
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 |