Lines 362-373
sub void {
Link Here
|
362 |
|
362 |
|
363 |
=head3 cancel |
363 |
=head3 cancel |
364 |
|
364 |
|
365 |
$debit_accountline->cancel(); |
365 |
$debit_accountline->cancel({ cancellation_type => $type }); |
366 |
|
366 |
|
367 |
Cancel a charge. It will mark the debit as 'cancelled' by updating its |
367 |
Cancel a charge. It will mark the debit as 'cancelled' by updating its |
368 |
status to 'CANCELLED'. |
368 |
status to 'CANCELLED'. |
369 |
|
369 |
|
370 |
Charges that have been fully or partially paid cannot be cancelled. |
370 |
Charges that have been fully or partially paid will be refunded upto |
|
|
371 |
the amount paid excluding discounts, writeoffs and refunds. |
371 |
|
372 |
|
372 |
Returns the cancellation accountline. |
373 |
Returns the cancellation accountline. |
373 |
|
374 |
|
Lines 392-410
sub cancel {
Link Here
|
392 |
error => 'Account line ' . $self->id . 'is already cancelled' ); |
393 |
error => 'Account line ' . $self->id . 'is already cancelled' ); |
393 |
} |
394 |
} |
394 |
|
395 |
|
395 |
# Make sure it has not be paid yet |
396 |
my $cancellation_type = $params->{cancellation_type} // 'CANCELLATION'; |
|
|
397 |
|
398 |
my $cancellation_amount = $self->amountoutstanding; |
396 |
if ( $self->amount != $self->amountoutstanding ) { |
399 |
if ( $self->amount != $self->amountoutstanding ) { |
397 |
Koha::Exceptions::Account->throw( |
400 |
my $credit_offsets = Koha::Account::Offsets->search( |
398 |
error => 'Account line ' . $self->id . 'is already offset' ); |
401 |
{ |
399 |
} |
402 |
debit_id => $self->id, |
|
|
403 |
credit_id => { '!=' => undef }, # not the debt itself |
404 |
type => { '!=' => [ 'Writeoff', 'REFUND', 'DISCOUNT' ] } |
405 |
, # Don't refund writeoffs, refunds or discounts |
406 |
amount => { '<' => 0 } # credits are negative on the DB |
407 |
} |
408 |
); |
400 |
|
409 |
|
401 |
# Check for mandatory parameters |
410 |
$cancellation_amount += |
402 |
my @mandatory = ( 'staff_id', 'branch' ); |
411 |
$credit_offsets->count > 0 ? $credit_offsets->total * -1 : 0; |
403 |
for my $param (@mandatory) { |
|
|
404 |
unless ( defined( $params->{$param} ) ) { |
405 |
Koha::Exceptions::MissingParameter->throw( |
406 |
error => "The $param parameter is mandatory" ); |
407 |
} |
408 |
} |
412 |
} |
409 |
|
413 |
|
410 |
my $cancellation; |
414 |
my $cancellation; |
Lines 412-445
sub cancel {
Link Here
|
412 |
sub { |
416 |
sub { |
413 |
|
417 |
|
414 |
# A 'cancellation' is a 'credit' |
418 |
# A 'cancellation' is a 'credit' |
415 |
$cancellation = Koha::Account::Line->new( |
419 |
$cancellation = $self->reduce( |
416 |
{ |
420 |
{ |
417 |
date => \'NOW()', |
421 |
reduction_type => $cancellation_type, |
418 |
amount => 0 - $self->amount, |
422 |
amount => $cancellation_amount, |
419 |
credit_type_code => 'CANCELLATION', |
423 |
staff_id => $params->{staff_id}, |
420 |
status => 'ADDED', |
424 |
interface => $params->{interface}, |
421 |
amountoutstanding => 0 - $self->amount, |
425 |
branch => $params->{branch} |
422 |
manager_id => $params->{staff_id}, |
|
|
423 |
borrowernumber => $self->borrowernumber, |
424 |
interface => 'intranet', |
425 |
branchcode => $params->{branch}, |
426 |
} |
426 |
} |
427 |
)->store(); |
427 |
); |
428 |
|
|
|
429 |
my $cancellation_offset = Koha::Account::Offset->new( |
430 |
{ |
431 |
credit_id => $cancellation->accountlines_id, |
432 |
type => 'CREATE', |
433 |
amount => 0 - $self->amount |
434 |
} |
435 |
)->store(); |
436 |
|
437 |
# Link cancellation to charge |
438 |
$cancellation->apply( { debits => [$self] } ); |
439 |
$cancellation->status('APPLIED')->store(); |
440 |
|
441 |
# Update status of original debit |
442 |
$self->status('CANCELLED')->store; |
443 |
} |
428 |
} |
444 |
); |
429 |
); |
445 |
|
430 |
|
Lines 469-474
Reduction type may be one of:
Link Here
|
469 |
|
454 |
|
470 |
* REFUND |
455 |
* REFUND |
471 |
* DISCOUNT |
456 |
* DISCOUNT |
|
|
457 |
* CANCELLATION |
472 |
|
458 |
|
473 |
Returns the reduction accountline (which will be a credit) |
459 |
Returns the reduction accountline (which will be a credit) |
474 |
|
460 |
|
Lines 517-530
sub reduce {
Link Here
|
517 |
"Amount to reduce ($params->{amount}) is higher than original amount ($original)" |
503 |
"Amount to reduce ($params->{amount}) is higher than original amount ($original)" |
518 |
) unless ( $original >= $params->{amount} ); |
504 |
) unless ( $original >= $params->{amount} ); |
519 |
my $reduced = |
505 |
my $reduced = |
520 |
$self->credits( { credit_type_code => [ 'DISCOUNT', 'REFUND' ] } )->total; |
506 |
$self->credits( { credit_type_code => [ 'WRITEOFF', 'DISCOUNT', 'REFUND' ] } )->total; |
521 |
Koha::Exceptions::ParameterTooHigh->throw( error => |
507 |
Koha::Exceptions::ParameterTooHigh->throw( error => |
522 |
"Combined reduction ($params->{amount} + $reduced) is higher than original amount (" |
508 |
"Combined reduction ($params->{amount} + $reduced) is higher than original amount (" |
523 |
. abs($original) |
509 |
. abs($original) |
524 |
. ")" ) |
510 |
. ")" ) |
525 |
unless ( $original >= ( $params->{amount} + abs($reduced) ) ); |
511 |
unless ( $original >= ( $params->{amount} + abs($reduced) ) ); |
526 |
|
512 |
|
527 |
my $status = { 'REFUND' => 'REFUNDED', 'DISCOUNT' => 'DISCOUNTED' }; |
513 |
my $status = { |
|
|
514 |
'REFUND' => 'REFUNDED', |
515 |
'DISCOUNT' => 'DISCOUNTED', |
516 |
'CANCELLATION' => 'CANCELLED' |
517 |
}; |
528 |
|
518 |
|
529 |
my $reduction; |
519 |
my $reduction; |
530 |
$self->_result->result_source->schema->txn_do( |
520 |
$self->_result->result_source->schema->txn_do( |
531 |
- |
|
|