|
Lines 118-125
was made.
Link Here
|
| 118 |
sub makepayment { |
118 |
sub makepayment { |
| 119 |
my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note ) = @_; |
119 |
my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note ) = @_; |
| 120 |
|
120 |
|
|
|
121 |
my $line = Koha::Account::Lines->find( $accountlines_id ); |
| 122 |
|
| 121 |
return Koha::Account->new( { patron_id => $borrowernumber } ) |
123 |
return Koha::Account->new( { patron_id => $borrowernumber } ) |
| 122 |
->pay( { accountlines_id => $accountlines_id, amount => $amount, library_id => $branch, note => $payment_note } ); |
124 |
->pay( { lines => [ $line ], amount => $amount, library_id => $branch, note => $payment_note } ); |
| 123 |
} |
125 |
} |
| 124 |
|
126 |
|
| 125 |
=head2 getnextacctno |
127 |
=head2 getnextacctno |
|
Lines 426-514
will be credited to the next one.
Link Here
|
| 426 |
sub recordpayment_selectaccts { |
428 |
sub recordpayment_selectaccts { |
| 427 |
my ( $borrowernumber, $amount, $accts, $note ) = @_; |
429 |
my ( $borrowernumber, $amount, $accts, $note ) = @_; |
| 428 |
|
430 |
|
| 429 |
my $dbh = C4::Context->dbh; |
431 |
my @lines = Koha::Account::Lines->search( |
| 430 |
my $newamtos = 0; |
432 |
{ |
| 431 |
my $accdata = q{}; |
433 |
borrowernumber => $borrowernumber, |
| 432 |
my $branch = C4::Context->userenv->{branch}; |
434 |
amountoutstanding => { '<>' => 0 }, |
| 433 |
my $amountleft = $amount; |
435 |
accountno => { 'IN' => $accts }, |
| 434 |
my $manager_id = 0; |
436 |
}, |
| 435 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
437 |
{ order_by => 'date' } |
| 436 |
my $sql = 'SELECT * FROM accountlines WHERE (borrowernumber = ?) ' . |
438 |
); |
| 437 |
'AND (amountoutstanding<>0) '; |
|
|
| 438 |
if (@{$accts} ) { |
| 439 |
$sql .= ' AND accountno IN ( ' . join ',', @{$accts}; |
| 440 |
$sql .= ' ) '; |
| 441 |
} |
| 442 |
$sql .= ' ORDER BY date'; |
| 443 |
# begin transaction |
| 444 |
my $nextaccntno = getnextacctno($borrowernumber); |
| 445 |
|
| 446 |
# get lines with outstanding amounts to offset |
| 447 |
my $rows = $dbh->selectall_arrayref($sql, { Slice => {} }, $borrowernumber); |
| 448 |
|
| 449 |
# offset transactions |
| 450 |
my $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' . |
| 451 |
'WHERE accountlines_id=?'); |
| 452 |
|
439 |
|
| 453 |
my @ids; |
440 |
return Koha::Account->new( |
| 454 |
for my $accdata ( @{$rows} ) { |
441 |
{ |
| 455 |
if ($amountleft == 0) { |
442 |
patron_id => $borrowernumber, |
| 456 |
last; |
|
|
| 457 |
} |
| 458 |
if ( $accdata->{amountoutstanding} < $amountleft ) { |
| 459 |
$newamtos = 0; |
| 460 |
$amountleft -= $accdata->{amountoutstanding}; |
| 461 |
} |
443 |
} |
| 462 |
else { |
444 |
)->pay( |
| 463 |
$newamtos = $accdata->{amountoutstanding} - $amountleft; |
445 |
{ |
| 464 |
$amountleft = 0; |
446 |
amount => $amount, |
|
|
447 |
lines => \@lines, |
| 448 |
note => $note |
| 465 |
} |
449 |
} |
| 466 |
my $thisacct = $accdata->{accountlines_id}; |
450 |
); |
| 467 |
$sth->execute( $newamtos, $thisacct ); |
|
|
| 468 |
|
| 469 |
if ( C4::Context->preference("FinesLog") ) { |
| 470 |
logaction("FINES", 'MODIFY', $borrowernumber, Dumper({ |
| 471 |
action => 'fee_payment', |
| 472 |
borrowernumber => $borrowernumber, |
| 473 |
old_amountoutstanding => $accdata->{'amountoutstanding'}, |
| 474 |
new_amountoutstanding => $newamtos, |
| 475 |
amount_paid => $accdata->{'amountoutstanding'} - $newamtos, |
| 476 |
accountlines_id => $accdata->{'accountlines_id'}, |
| 477 |
accountno => $accdata->{'accountno'}, |
| 478 |
manager_id => $manager_id, |
| 479 |
})); |
| 480 |
push( @ids, $accdata->{'accountlines_id'} ); |
| 481 |
} |
| 482 |
|
| 483 |
} |
| 484 |
|
| 485 |
# create new line |
| 486 |
$sql = 'INSERT INTO accountlines ' . |
| 487 |
'(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,note) ' . |
| 488 |
q|VALUES (?,?,now(),?,'','Pay',?,?,?)|; |
| 489 |
$dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id, $note ); |
| 490 |
UpdateStats({ |
| 491 |
branch => $branch, |
| 492 |
type => 'payment', |
| 493 |
amount => $amount, |
| 494 |
borrowernumber => $borrowernumber, |
| 495 |
accountno => $nextaccntno} |
| 496 |
); |
| 497 |
|
| 498 |
if ( C4::Context->preference("FinesLog") ) { |
| 499 |
logaction("FINES", 'CREATE',$borrowernumber,Dumper({ |
| 500 |
action => 'create_payment', |
| 501 |
borrowernumber => $borrowernumber, |
| 502 |
accountno => $nextaccntno, |
| 503 |
amount => 0 - $amount, |
| 504 |
amountoutstanding => 0 - $amountleft, |
| 505 |
accounttype => 'Pay', |
| 506 |
accountlines_paid => \@ids, |
| 507 |
manager_id => $manager_id, |
| 508 |
})); |
| 509 |
} |
| 510 |
|
| 511 |
return; |
| 512 |
} |
451 |
} |
| 513 |
|
452 |
|
| 514 |
# makepayment needs to be fixed to handle partials till then this separate subroutine |
453 |
# makepayment needs to be fixed to handle partials till then this separate subroutine |