Lines 140-148
sub AddDebit {
Link Here
|
140 |
); |
140 |
); |
141 |
|
141 |
|
142 |
if ($debit) { |
142 |
if ($debit) { |
143 |
$borrower->account_balance( $borrower->account_balance() + $amount ); |
|
|
144 |
$borrower->update(); |
145 |
|
146 |
NormalizeBalances( { borrower => $borrower } ); |
143 |
NormalizeBalances( { borrower => $borrower } ); |
147 |
|
144 |
|
148 |
if ( C4::Context->preference("FinesLog") ) { |
145 |
if ( C4::Context->preference("FinesLog") ) { |
Lines 356-384
sub AddCredit {
Link Here
|
356 |
} |
353 |
} |
357 |
} |
354 |
} |
358 |
|
355 |
|
359 |
# We still have leftover money, or we weren't given a specific debit to pay |
356 |
NormalizeBalances( { borrower => $borrower } ); |
360 |
if ( $credit->amount_remaining() > 0 ) { |
|
|
361 |
my @debits = |
362 |
Koha::Database->new()->schema->resultset('AccountDebit')->search( |
363 |
{ |
364 |
borrowernumber => $borrower->borrowernumber(), |
365 |
amount_outstanding => { '>' => '0' } |
366 |
} |
367 |
); |
368 |
|
369 |
foreach my $debit (@debits) { |
370 |
if ( $credit->amount_remaining() > 0 ) { |
371 |
CreditDebit( |
372 |
{ |
373 |
credit => $credit, |
374 |
debit => $debit, |
375 |
borrower => $borrower, |
376 |
type => $type, |
377 |
} |
378 |
); |
379 |
} |
380 |
} |
381 |
} |
382 |
|
357 |
|
383 |
return $credit; |
358 |
return $credit; |
384 |
} |
359 |
} |
Lines 497-522
sub NormalizeBalances {
Link Here
|
497 |
|
472 |
|
498 |
croak("Required param 'borrower' not passed in!") unless $borrower; |
473 |
croak("Required param 'borrower' not passed in!") unless $borrower; |
499 |
|
474 |
|
|
|
475 |
my $schema = Koha::Database->new()->schema(); |
476 |
|
500 |
my @credits = |
477 |
my @credits = |
501 |
Koha::Database->new()->schema->resultset('AccountCredit')->search( |
478 |
$schema->resultset('AccountCredit')->search( |
502 |
{ |
479 |
{ |
503 |
borrowernumber => $borrower->borrowernumber(), |
480 |
borrowernumber => $borrower->borrowernumber(), |
504 |
amount_remaining => { '>' => '0' } |
481 |
amount_remaining => { '>' => '0' } |
505 |
} |
482 |
} |
506 |
); |
483 |
); |
507 |
|
484 |
|
508 |
return unless @credits; |
|
|
509 |
|
510 |
my @debits = |
485 |
my @debits = |
511 |
Koha::Database->new()->schema->resultset('AccountDebit')->search( |
486 |
$schema->resultset('AccountDebit')->search( |
512 |
{ |
487 |
{ |
513 |
borrowernumber => $borrower->borrowernumber(), |
488 |
borrowernumber => $borrower->borrowernumber(), |
514 |
amount_outstanding => { '>' => '0' } |
489 |
amount_outstanding => { '>' => '0' } |
515 |
} |
490 |
} |
516 |
); |
491 |
); |
517 |
|
492 |
|
518 |
return unless @debits; |
|
|
519 |
|
520 |
foreach my $credit (@credits) { |
493 |
foreach my $credit (@credits) { |
521 |
foreach my $debit (@debits) { |
494 |
foreach my $debit (@debits) { |
522 |
if ( $credit->amount_remaining() |
495 |
if ( $credit->amount_remaining() |