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