Lines 22-27
use Modern::Perl;
Link Here
|
22 |
use Carp; |
22 |
use Carp; |
23 |
use Data::Dumper; |
23 |
use Data::Dumper; |
24 |
use List::MoreUtils qw( uniq ); |
24 |
use List::MoreUtils qw( uniq ); |
|
|
25 |
use Try::Tiny; |
25 |
|
26 |
|
26 |
use C4::Circulation qw( ReturnLostItem ); |
27 |
use C4::Circulation qw( ReturnLostItem ); |
27 |
use C4::Letters; |
28 |
use C4::Letters; |
Lines 477-483
sub add_debit {
Link Here
|
477 |
my $user_id = $params->{user_id}; |
478 |
my $user_id = $params->{user_id}; |
478 |
my $interface = $params->{interface}; |
479 |
my $interface = $params->{interface}; |
479 |
my $library_id = $params->{library_id}; |
480 |
my $library_id = $params->{library_id}; |
480 |
my $type = $params->{type}; |
481 |
my $debit_type = $params->{type}; |
481 |
my $item_id = $params->{item_id}; |
482 |
my $item_id = $params->{item_id}; |
482 |
my $issue_id = $params->{issue_id}; |
483 |
my $issue_id = $params->{issue_id}; |
483 |
|
484 |
|
Lines 488-556
sub add_debit {
Link Here
|
488 |
|
489 |
|
489 |
my $schema = Koha::Database->new->schema; |
490 |
my $schema = Koha::Database->new->schema; |
490 |
|
491 |
|
491 |
unless ( exists($Koha::Account::account_type_debit->{$type}) ) { |
492 |
my $offset_type = $Koha::Account::offset_type->{$debit_type} // 'Manual Debit'; |
492 |
Koha::Exceptions::Account::UnrecognisedType->throw( |
|
|
493 |
error => 'Type of debit not recognised' |
494 |
); |
495 |
} |
496 |
|
497 |
my $debit_type_code = $Koha::Account::account_type_debit->{$type}; |
498 |
|
493 |
|
499 |
my $line; |
494 |
my $line; |
500 |
$schema->txn_do( |
495 |
try { |
501 |
sub { |
496 |
$schema->txn_do( |
|
|
497 |
sub { |
502 |
|
498 |
|
503 |
# Insert the account line |
499 |
# Insert the account line |
504 |
$line = Koha::Account::Line->new( |
500 |
$line = Koha::Account::Line->new( |
505 |
{ |
501 |
{ |
506 |
borrowernumber => $self->{patron_id}, |
502 |
borrowernumber => $self->{patron_id}, |
507 |
date => \'NOW()', |
503 |
date => \'NOW()', |
508 |
amount => $amount, |
504 |
amount => $amount, |
509 |
description => $description, |
505 |
description => $description, |
510 |
debit_type_code => $debit_type_code, |
506 |
debit_type_code => $debit_type, |
511 |
amountoutstanding => $amount, |
507 |
amountoutstanding => $amount, |
512 |
payment_type => undef, |
508 |
payment_type => undef, |
513 |
note => $note, |
509 |
note => $note, |
514 |
manager_id => $user_id, |
510 |
manager_id => $user_id, |
515 |
interface => $interface, |
511 |
interface => $interface, |
516 |
itemnumber => $item_id, |
512 |
itemnumber => $item_id, |
517 |
issue_id => $issue_id, |
513 |
issue_id => $issue_id, |
518 |
branchcode => $library_id, |
514 |
branchcode => $library_id, |
519 |
( $type eq 'OVERDUE' ? ( status => 'UNRETURNED' ) : () ), |
515 |
( |
520 |
} |
516 |
$debit_type eq 'OVERDUE' |
521 |
)->store(); |
517 |
? ( status => 'UNRETURNED' ) |
|
|
518 |
: () |
519 |
), |
520 |
} |
521 |
)->store(); |
522 |
|
522 |
|
523 |
# Record the account offset |
523 |
# Record the account offset |
524 |
my $account_offset = Koha::Account::Offset->new( |
524 |
my $account_offset = Koha::Account::Offset->new( |
525 |
{ |
525 |
{ |
526 |
debit_id => $line->id, |
526 |
debit_id => $line->id, |
527 |
type => $Koha::Account::offset_type->{$type}, |
527 |
type => $offset_type, |
528 |
amount => $amount |
528 |
amount => $amount |
|
|
529 |
} |
530 |
)->store(); |
531 |
|
532 |
if ( C4::Context->preference("FinesLog") ) { |
533 |
logaction( |
534 |
"FINES", 'CREATE', |
535 |
$self->{patron_id}, |
536 |
Dumper( |
537 |
{ |
538 |
action => "create_$debit_type", |
539 |
borrowernumber => $self->{patron_id}, |
540 |
amount => $amount, |
541 |
description => $description, |
542 |
amountoutstanding => $amount, |
543 |
debit_type_code => $debit_type, |
544 |
note => $note, |
545 |
itemnumber => $item_id, |
546 |
manager_id => $user_id, |
547 |
} |
548 |
), |
549 |
$interface |
550 |
); |
529 |
} |
551 |
} |
530 |
)->store(); |
552 |
} |
531 |
|
553 |
); |
532 |
if ( C4::Context->preference("FinesLog") ) { |
554 |
} |
533 |
logaction( |
555 |
catch { |
534 |
"FINES", 'CREATE', |
556 |
if ( ref($_) eq 'Koha::Exceptions::Object::FKConstraint' ) { |
535 |
$self->{patron_id}, |
557 |
if ( $_->broken_fk eq 'debit_type_code' ) { |
536 |
Dumper( |
558 |
Koha::Exceptions::Account::UnrecognisedType->throw( |
537 |
{ |
559 |
error => 'Type of debit not recognised' ); |
538 |
action => "create_$type", |
560 |
} |
539 |
borrowernumber => $self->{patron_id}, |
561 |
else { |
540 |
amount => $amount, |
562 |
$_->rethrow; |
541 |
description => $description, |
|
|
542 |
amountoutstanding => $amount, |
543 |
debit_type_code => $debit_type_code, |
544 |
note => $note, |
545 |
itemnumber => $item_id, |
546 |
manager_id => $user_id, |
547 |
} |
548 |
), |
549 |
$interface |
550 |
); |
551 |
} |
563 |
} |
552 |
} |
564 |
} |
553 |
); |
565 |
}; |
554 |
|
566 |
|
555 |
return $line; |
567 |
return $line; |
556 |
} |
568 |
} |
Lines 733-757
our $account_type_credit = {
Link Here
|
733 |
'writeoff' => 'W' |
745 |
'writeoff' => 'W' |
734 |
}; |
746 |
}; |
735 |
|
747 |
|
736 |
=head3 $account_type_debit |
|
|
737 |
|
738 |
=cut |
739 |
|
740 |
our $account_type_debit = { |
741 |
'ACCOUNT' => 'ACCOUNT', |
742 |
'ACCOUNT_RENEW' => 'ACCOUNT_RENEW', |
743 |
'RESERVE_EXPIRED' => 'RESERVE_EXPIRED', |
744 |
'LOST_ITEM' => 'LOST', |
745 |
'NEW_CARD' => 'NEW_CARD', |
746 |
'OVERDUE' => 'OVERDUE', |
747 |
'PROCESSING' => 'PROCESSING', |
748 |
'RENT' => 'RENT', |
749 |
'RENT_DAILY' => 'RENT_DAILY', |
750 |
'RENT_RENEW' => 'RENT_RENEW', |
751 |
'RENT_DAILY_RENEW' => 'RENT_DAILY_RENEW', |
752 |
'RESERVE' => 'RESERVE', |
753 |
}; |
754 |
|
755 |
=head1 AUTHORS |
748 |
=head1 AUTHORS |
756 |
|
749 |
|
757 |
=encoding utf8 |
750 |
=encoding utf8 |