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 336-344
sub AddCredit {
Link Here
|
336 |
Dumper( $credit->get_columns() ) ); |
333 |
Dumper( $credit->get_columns() ) ); |
337 |
} |
334 |
} |
338 |
|
335 |
|
339 |
$borrower->account_balance( $borrower->account_balance() - $amount ); |
|
|
340 |
$borrower->update(); |
341 |
|
342 |
# If we are given specific debits, pay those ones first. |
336 |
# If we are given specific debits, pay those ones first. |
343 |
if ($debit_id) { |
337 |
if ($debit_id) { |
344 |
my @debit_ids = ref($debit_id) eq "ARRAY" ? @$debit_id : $debit_id; |
338 |
my @debit_ids = ref($debit_id) eq "ARRAY" ? @$debit_id : $debit_id; |
Lines 356-384
sub AddCredit {
Link Here
|
356 |
} |
350 |
} |
357 |
} |
351 |
} |
358 |
|
352 |
|
359 |
# We still have leftover money, or we weren't given a specific debit to pay |
353 |
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 |
|
354 |
|
383 |
return $credit; |
355 |
return $credit; |
384 |
} |
356 |
} |
Lines 497-522
sub NormalizeBalances {
Link Here
|
497 |
|
469 |
|
498 |
croak("Required param 'borrower' not passed in!") unless $borrower; |
470 |
croak("Required param 'borrower' not passed in!") unless $borrower; |
499 |
|
471 |
|
|
|
472 |
my $schema = Koha::Database->new()->schema(); |
473 |
|
500 |
my @credits = |
474 |
my @credits = |
501 |
Koha::Database->new()->schema->resultset('AccountCredit')->search( |
475 |
$schema->resultset('AccountCredit')->search( |
502 |
{ |
476 |
{ |
503 |
borrowernumber => $borrower->borrowernumber(), |
477 |
borrowernumber => $borrower->borrowernumber(), |
504 |
amount_remaining => { '>' => '0' } |
478 |
amount_remaining => { '>' => '0' } |
505 |
} |
479 |
} |
506 |
); |
480 |
); |
507 |
|
481 |
|
508 |
return unless @credits; |
|
|
509 |
|
510 |
my @debits = |
482 |
my @debits = |
511 |
Koha::Database->new()->schema->resultset('AccountDebit')->search( |
483 |
$schema->resultset('AccountDebit')->search( |
512 |
{ |
484 |
{ |
513 |
borrowernumber => $borrower->borrowernumber(), |
485 |
borrowernumber => $borrower->borrowernumber(), |
514 |
amount_outstanding => { '>' => '0' } |
486 |
amount_outstanding => { '>' => '0' } |
515 |
} |
487 |
} |
516 |
); |
488 |
); |
517 |
|
489 |
|
518 |
return unless @debits; |
|
|
519 |
|
520 |
foreach my $credit (@credits) { |
490 |
foreach my $credit (@credits) { |
521 |
foreach my $debit (@debits) { |
491 |
foreach my $debit (@debits) { |
522 |
if ( $credit->amount_remaining() |
492 |
if ( $credit->amount_remaining() |