|
Lines 32-37
use Koha::Patrons;
Link Here
|
| 32 |
use Koha::Account::Lines; |
32 |
use Koha::Account::Lines; |
| 33 |
use Koha::Account::Offsets; |
33 |
use Koha::Account::Offsets; |
| 34 |
use Koha::DateUtils qw( dt_from_string ); |
34 |
use Koha::DateUtils qw( dt_from_string ); |
|
|
35 |
use Koha::Exceptions::Account; |
| 35 |
|
36 |
|
| 36 |
=head1 NAME |
37 |
=head1 NAME |
| 37 |
|
38 |
|
|
Lines 333-339
sub add_credit {
Link Here
|
| 333 |
|
334 |
|
| 334 |
my $schema = Koha::Database->new->schema; |
335 |
my $schema = Koha::Database->new->schema; |
| 335 |
|
336 |
|
| 336 |
my $account_type = $Koha::Account::account_type->{$type}; |
337 |
my $account_type = $Koha::Account::account_type_credit->{$type}; |
| 337 |
$account_type .= $sip |
338 |
$account_type .= $sip |
| 338 |
if defined $sip && |
339 |
if defined $sip && |
| 339 |
$type eq 'payment'; |
340 |
$type eq 'payment'; |
|
Lines 409-414
sub add_credit {
Link Here
|
| 409 |
return $line; |
410 |
return $line; |
| 410 |
} |
411 |
} |
| 411 |
|
412 |
|
|
|
413 |
=head3 add_debit |
| 414 |
|
| 415 |
This method allows adding debits to a patron's account |
| 416 |
|
| 417 |
my $debit_line = Koha::Account->new({ patron_id => $patron_id })->add_debit( |
| 418 |
{ |
| 419 |
amount => $amount, |
| 420 |
description => $description, |
| 421 |
note => $note, |
| 422 |
user_id => $user_id, |
| 423 |
library_id => $library_id, |
| 424 |
type => $debit_type, |
| 425 |
item_id => $item_id, |
| 426 |
issue_id => $issue_id |
| 427 |
} |
| 428 |
); |
| 429 |
|
| 430 |
$debit_type can be any of: |
| 431 |
- fine |
| 432 |
- lost_item |
| 433 |
- new_card |
| 434 |
- account |
| 435 |
- sundry |
| 436 |
- processing |
| 437 |
- rent |
| 438 |
- reserve |
| 439 |
- overdue |
| 440 |
- manual |
| 441 |
|
| 442 |
=cut |
| 443 |
|
| 444 |
sub add_debit { |
| 445 |
|
| 446 |
my ( $self, $params ) = @_; |
| 447 |
|
| 448 |
# amount should always be a positive value |
| 449 |
my $amount = $params->{amount}; |
| 450 |
|
| 451 |
unless ( $amount > 0 ) { |
| 452 |
Koha::Exceptions::Account::AmountNotPositive->throw( |
| 453 |
error => 'Debit amount passed is not positive' |
| 454 |
); |
| 455 |
} |
| 456 |
|
| 457 |
my $description = $params->{description} // q{}; |
| 458 |
my $note = $params->{note} // q{}; |
| 459 |
my $user_id = $params->{user_id}; |
| 460 |
my $library_id = $params->{library_id}; |
| 461 |
my $type = $params->{type}; |
| 462 |
my $item_id = $params->{item_id}; |
| 463 |
my $issue_id = $params->{issue_id}; |
| 464 |
|
| 465 |
my $schema = Koha::Database->new->schema; |
| 466 |
|
| 467 |
unless ( exists($Koha::Account::account_type_debit->{$type}) ) { |
| 468 |
Koha::Exceptions::Account::UnrecognisedType->throw( |
| 469 |
error => 'Type of debit not recognised' |
| 470 |
); |
| 471 |
} |
| 472 |
|
| 473 |
my $account_type = $Koha::Account::account_type_debit->{$type}; |
| 474 |
|
| 475 |
my $line; |
| 476 |
|
| 477 |
$schema->txn_do( |
| 478 |
sub { |
| 479 |
# We should remove accountno, it is no longer needed |
| 480 |
my $last = Koha::Account::Lines->search( { borrowernumber => $self->{patron_id} }, |
| 481 |
{ order_by => 'accountno' } )->next(); |
| 482 |
my $accountno = $last ? $last->accountno + 1 : 1; |
| 483 |
|
| 484 |
# Insert the account line |
| 485 |
$line = Koha::Account::Line->new( |
| 486 |
{ borrowernumber => $self->{patron_id}, |
| 487 |
date => \'NOW()', |
| 488 |
amount => $amount, |
| 489 |
description => $description, |
| 490 |
accounttype => $account_type, |
| 491 |
amountoutstanding => $amount, |
| 492 |
payment_type => undef, |
| 493 |
note => $note, |
| 494 |
manager_id => $user_id, |
| 495 |
itemnumber => $item_id, |
| 496 |
issue_id => $issue_id, |
| 497 |
branchcode => $library_id, |
| 498 |
( $type eq 'fine' ? ( lastincrement => $amount ) : ()), |
| 499 |
} |
| 500 |
)->store(); |
| 501 |
|
| 502 |
# Record the account offset |
| 503 |
my $account_offset = Koha::Account::Offset->new( |
| 504 |
{ debit_id => $line->id, |
| 505 |
type => $Koha::Account::offset_type->{$type}, |
| 506 |
amount => $amount |
| 507 |
} |
| 508 |
)->store(); |
| 509 |
|
| 510 |
if ( C4::Context->preference("FinesLog") ) { |
| 511 |
logaction( |
| 512 |
"FINES", 'CREATE', |
| 513 |
$self->{patron_id}, |
| 514 |
Dumper( |
| 515 |
{ action => "create_$type", |
| 516 |
borrowernumber => $self->{patron_id}, |
| 517 |
accountno => $accountno, |
| 518 |
amount => $amount, |
| 519 |
description => $description, |
| 520 |
amountoutstanding => $amount, |
| 521 |
accounttype => $account_type, |
| 522 |
note => $note, |
| 523 |
itemnumber => $item_id, |
| 524 |
manager_id => $user_id, |
| 525 |
} |
| 526 |
) |
| 527 |
); |
| 528 |
} |
| 529 |
} |
| 530 |
); |
| 531 |
|
| 532 |
return $line; |
| 533 |
} |
| 534 |
|
| 412 |
=head3 balance |
535 |
=head3 balance |
| 413 |
|
536 |
|
| 414 |
my $balance = $self->balance |
537 |
my $balance = $self->balance |
|
Lines 568-581
our $offset_type = {
Link Here
|
| 568 |
'forgiven' => 'Writeoff', |
691 |
'forgiven' => 'Writeoff', |
| 569 |
'lost_item_return' => 'Lost Item', |
692 |
'lost_item_return' => 'Lost Item', |
| 570 |
'payment' => 'Payment', |
693 |
'payment' => 'Payment', |
| 571 |
'writeoff' => 'Writeoff' |
694 |
'writeoff' => 'Writeoff', |
|
|
695 |
'reserve' => 'Reserve Fee', |
| 696 |
'processing' => 'Processing Fee', |
| 697 |
'lost_item' => 'Lost Item', |
| 698 |
'rent' => 'Rental Fee', |
| 699 |
'fine' => 'Fine', |
| 700 |
'manual_debit' => 'Manual Debit', |
| 701 |
'hold_expired' => 'Hold Expired' |
| 572 |
}; |
702 |
}; |
| 573 |
|
703 |
|
| 574 |
=head3 $account_type |
704 |
=head3 $account_type_credit |
| 575 |
|
705 |
|
| 576 |
=cut |
706 |
=cut |
| 577 |
|
707 |
|
| 578 |
our $account_type = { |
708 |
our $account_type_credit = { |
| 579 |
'credit' => 'C', |
709 |
'credit' => 'C', |
| 580 |
'forgiven' => 'FOR', |
710 |
'forgiven' => 'FOR', |
| 581 |
'lost_item_return' => 'CR', |
711 |
'lost_item_return' => 'CR', |
|
Lines 583-590
our $account_type = {
Link Here
|
| 583 |
'writeoff' => 'W' |
713 |
'writeoff' => 'W' |
| 584 |
}; |
714 |
}; |
| 585 |
|
715 |
|
| 586 |
=head1 AUTHOR |
716 |
=head3 $account_type_debit |
|
|
717 |
|
| 718 |
=cut |
| 719 |
|
| 720 |
our $account_type_debit = { |
| 721 |
'fine' => 'FU', |
| 722 |
'lost_item' => 'L', |
| 723 |
'new_card' => 'N', |
| 724 |
'account' => 'A', |
| 725 |
'sundry' => 'M', |
| 726 |
'processing' => 'PF', |
| 727 |
'rent' => 'Rent', |
| 728 |
'reserve' => 'Res', |
| 729 |
'overdue' => 'O', |
| 730 |
'manual_debit' => 'M', |
| 731 |
'hold_expired' => 'HE' |
| 732 |
}; |
| 733 |
|
| 734 |
=head1 AUTHORS |
| 735 |
|
| 736 |
=encoding utf8 |
| 587 |
|
737 |
|
| 588 |
Kyle M Hall <kyle.m.hall@gmail.com> |
738 |
Kyle M Hall <kyle.m.hall@gmail.com> |
|
|
739 |
Tomás Cohen Arazi <tomascohen@gmail.com> |
| 740 |
Martin Renvoize <martin.renvoize@ptfs-europe.com> |
| 589 |
|
741 |
|
| 590 |
=cut |
742 |
=cut |
| 591 |
- |
|
|