|
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 340-346
sub add_credit {
Link Here
|
| 340 |
|
341 |
|
| 341 |
my $schema = Koha::Database->new->schema; |
342 |
my $schema = Koha::Database->new->schema; |
| 342 |
|
343 |
|
| 343 |
my $account_type = $Koha::Account::account_type->{$type}; |
344 |
my $account_type = $Koha::Account::account_type_credit->{$type}; |
| 344 |
$account_type .= $sip |
345 |
$account_type .= $sip |
| 345 |
if defined $sip && |
346 |
if defined $sip && |
| 346 |
$type eq 'payment'; |
347 |
$type eq 'payment'; |
|
Lines 411-416
sub add_credit {
Link Here
|
| 411 |
return $line; |
412 |
return $line; |
| 412 |
} |
413 |
} |
| 413 |
|
414 |
|
|
|
415 |
=head3 add_debit |
| 416 |
|
| 417 |
This method allows adding debits to a patron's account |
| 418 |
|
| 419 |
my $debit_line = Koha::Account->new({ patron_id => $patron_id })->add_debit( |
| 420 |
{ |
| 421 |
amount => $amount, |
| 422 |
description => $description, |
| 423 |
note => $note, |
| 424 |
user_id => $user_id, |
| 425 |
library_id => $library_id, |
| 426 |
sip => $sip, |
| 427 |
invoice_type => $invoice_type, |
| 428 |
type => $debit_type, |
| 429 |
item_id => $item_id |
| 430 |
} |
| 431 |
); |
| 432 |
|
| 433 |
$debit_type can be any of: |
| 434 |
- 'fine' |
| 435 |
- 'lost' |
| 436 |
- 'processing' |
| 437 |
- 'management' |
| 438 |
- 'sundry' |
| 439 |
- 'card' |
| 440 |
|
| 441 |
=cut |
| 442 |
|
| 443 |
sub add_debit { |
| 444 |
|
| 445 |
my ( $self, $params ) = @_; |
| 446 |
|
| 447 |
# amount should always be a positive value |
| 448 |
my $amount = $params->{amount}; |
| 449 |
|
| 450 |
unless ( $amount > 0 ) { |
| 451 |
Koha::Exceptions::Account::AmountNotPositive->throw( |
| 452 |
error => 'Debit amount passed is not positive' |
| 453 |
); |
| 454 |
} |
| 455 |
|
| 456 |
my $description = $params->{description} // q{}; |
| 457 |
my $note = $params->{note} // q{}; |
| 458 |
my $user_id = $params->{user_id}; |
| 459 |
my $library_id = $params->{library_id}; |
| 460 |
my $sip = $params->{sip}; |
| 461 |
my $invoice_type = $params->{invoice_type}; |
| 462 |
my $type = $params->{type}; |
| 463 |
my $item_id = $params->{item_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 |
invoice_type => $invoice_type, |
| 493 |
note => $note, |
| 494 |
manager_id => $user_id, |
| 495 |
itemnumber => $item_id |
| 496 |
} |
| 497 |
)->store(); |
| 498 |
|
| 499 |
# Record the account offset |
| 500 |
my $account_offset = Koha::Account::Offset->new( |
| 501 |
{ debit_id => $line->id, |
| 502 |
type => $Koha::Account::offset_type->{$type}, |
| 503 |
amount => $amount |
| 504 |
} |
| 505 |
)->store(); |
| 506 |
|
| 507 |
UpdateStats( |
| 508 |
{ branch => $library_id, |
| 509 |
type => $type, |
| 510 |
amount => $amount, |
| 511 |
borrowernumber => $self->{patron_id}, |
| 512 |
accountno => $accountno, |
| 513 |
} |
| 514 |
) if grep { $type eq $_ } ('renew', 'issue', 'localuse', 'return', 'onsite_checkout' ) ; |
| 515 |
|
| 516 |
if ( C4::Context->preference("FinesLog") ) { |
| 517 |
logaction( |
| 518 |
"FINES", 'CREATE', |
| 519 |
$self->{patron_id}, |
| 520 |
Dumper( |
| 521 |
{ action => "create_$type", |
| 522 |
borrowernumber => $self->{patron_id}, |
| 523 |
accountno => $accountno, |
| 524 |
amount => $amount, |
| 525 |
description => $description, |
| 526 |
amountoutstanding => $amount, |
| 527 |
accounttype => $account_type, |
| 528 |
note => $note, |
| 529 |
itemnumber => $item_id, |
| 530 |
manager_id => $user_id, |
| 531 |
} |
| 532 |
) |
| 533 |
); |
| 534 |
} |
| 535 |
} |
| 536 |
); |
| 537 |
|
| 538 |
return $line; |
| 539 |
} |
| 540 |
|
| 414 |
=head3 balance |
541 |
=head3 balance |
| 415 |
|
542 |
|
| 416 |
my $balance = $self->balance |
543 |
my $balance = $self->balance |
|
Lines 540-550
our $offset_type = {
Link Here
|
| 540 |
'writeoff' => 'Writeoff' |
667 |
'writeoff' => 'Writeoff' |
| 541 |
}; |
668 |
}; |
| 542 |
|
669 |
|
| 543 |
=head3 $account_type |
670 |
=head3 $account_type_credit |
| 544 |
|
671 |
|
| 545 |
=cut |
672 |
=cut |
| 546 |
|
673 |
|
| 547 |
our $account_type = { |
674 |
our $account_type_credit = { |
| 548 |
'credit' => 'C', |
675 |
'credit' => 'C', |
| 549 |
'forgiven' => 'FOR', |
676 |
'forgiven' => 'FOR', |
| 550 |
'lost_item_return' => 'CR', |
677 |
'lost_item_return' => 'CR', |
|
Lines 552-559
our $account_type = {
Link Here
|
| 552 |
'writeoff' => 'W' |
679 |
'writeoff' => 'W' |
| 553 |
}; |
680 |
}; |
| 554 |
|
681 |
|
|
|
682 |
=head3 $account_type_debit |
| 683 |
|
| 684 |
=cut |
| 685 |
|
| 686 |
our $account_type_debit = { |
| 687 |
'new_card' => 'N', |
| 688 |
'fine' => 'F', |
| 689 |
'fine_updating' => 'FU', |
| 690 |
'account' => 'A', |
| 691 |
'lost' => 'L', |
| 692 |
'sundry' => 'M', |
| 693 |
'processing' => 'PF', |
| 694 |
'rent' => 'R', |
| 695 |
'reserve' => 'Res', |
| 696 |
'overdue' => 'O' |
| 697 |
}; |
| 698 |
|
| 555 |
=head1 AUTHOR |
699 |
=head1 AUTHOR |
| 556 |
|
700 |
|
| 557 |
Kyle M Hall <kyle.m.hall@gmail.com> |
701 |
Kyle M Hall <kyle.m.hall@gmail.com> |
|
|
702 |
Tomás Cohen Arazi <tomascohen@gmail.com> |
| 703 |
Martin Renvoize <martin.renvoize@ptfs-europe.com> |
| 558 |
|
704 |
|
| 559 |
=cut |
705 |
=cut |