Lines 45-50
BEGIN {
Link Here
|
45 |
&chargelostitem |
45 |
&chargelostitem |
46 |
&ReversePayment |
46 |
&ReversePayment |
47 |
&purge_zero_balance_fees |
47 |
&purge_zero_balance_fees |
|
|
48 |
&updatepayment |
48 |
); |
49 |
); |
49 |
} |
50 |
} |
50 |
|
51 |
|
Lines 379-387
sub purge_zero_balance_fees {
Link Here
|
379 |
$sth->execute($days) or die $dbh->errstr; |
380 |
$sth->execute($days) or die $dbh->errstr; |
380 |
} |
381 |
} |
381 |
|
382 |
|
|
|
383 |
sub updatepayment { |
384 |
my ( $borrowernumber, $account_id, $date, $itemnum, $desc, $type, $amount, $oldamount, $note ) = @_; |
385 |
my $manager_id = 0; |
386 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
387 |
my $dbh = C4::Context->dbh; |
388 |
my $notifyid = 0; |
389 |
my $amountleft = $amount; |
390 |
|
391 |
if ( ( $type eq 'L' ) |
392 |
or ( $type eq 'F' ) |
393 |
or ( $type eq 'A' ) |
394 |
or ( $type eq 'N' ) |
395 |
or ( $type eq 'M' ) ) |
396 |
{ |
397 |
$notifyid = 1; |
398 |
} |
399 |
|
400 |
if ( $type eq 'Pay' ) { |
401 |
$amountleft = 0.0; |
402 |
my $amontdif = $amount - $oldamount; |
403 |
|
404 |
if ( $amontdif <= 0 ) { |
405 |
my $debtamount = abs($amontdif); |
406 |
$amountleft = addfinetoaccountlines( $borrowernumber, $debtamount ); |
407 |
|
408 |
} |
409 |
else { |
410 |
$amountleft = reducefinefromaccountlines( $borrowernumber, $amontdif ); |
411 |
} |
412 |
$amount = -$amount; |
413 |
} |
414 |
|
415 |
my $sth = $dbh->prepare( |
416 |
'UPDATE accountlines |
417 |
SET date=?, amount=?, description=?, accounttype=?, amountoutstanding=?, |
418 |
itemnumber=?,notify_id=?, note=?, manager_id=? |
419 |
WHERE accountlines_id=?' |
420 |
); |
421 |
$sth->execute( $date, $amount, $desc, $type, $amountleft, $itemnum, $notifyid, $note, $manager_id, $account_id ) || return $sth->errstr; |
422 |
|
423 |
if ( C4::Context->preference("FinesLog") ) { |
424 |
logaction( |
425 |
"FINES", 'MODIFY', |
426 |
$borrowernumber, |
427 |
Dumper( |
428 |
{ accountno => $account_id, |
429 |
amount => $amount, |
430 |
description => $desc, |
431 |
accounttype => $type, |
432 |
amountoutstanding => $amountleft, |
433 |
notify_id => $notifyid, |
434 |
note => $note, |
435 |
itemnumber => $itemnum, |
436 |
manager_id => $manager_id, |
437 |
} |
438 |
) |
439 |
); |
440 |
} |
441 |
return 0; |
442 |
} |
443 |
|
444 |
sub addfinetoaccountlines { |
445 |
|
446 |
#here we update the account lines |
447 |
my ( $borrowernumber, $debtamount ) = @_; |
448 |
my $newamtos = 0; |
449 |
my $dbh = C4::Context->dbh; |
450 |
my $accdata = ""; |
451 |
|
452 |
# get lines with outstanding amounts to offset |
453 |
my $sth = $dbh->prepare( |
454 |
"SELECT * FROM accountlines |
455 |
WHERE (borrowernumber = ?) AND (amountoutstanding<>amount) and (amountoutstanding>=0) and (accounttype <> 'Pay') |
456 |
ORDER BY date" |
457 |
); |
458 |
$sth->execute($borrowernumber); |
459 |
my @ids; |
460 |
|
461 |
# offset transactions |
462 |
while ( ( $accdata = $sth->fetchrow_hashref ) and ( $debtamount > 0 ) ) { |
463 |
if ( $accdata->{'amount'} - $accdata->{'amountoutstanding'} < $debtamount ) { |
464 |
$debtamount = $debtamount - ( $accdata->{'amount'} - $accdata->{'amountoutstanding'} ); |
465 |
$newamtos = $accdata->{'amount'}; |
466 |
} |
467 |
else { |
468 |
$newamtos = $accdata->{'amountoutstanding'} + $debtamount; |
469 |
$debtamount = 0; |
470 |
} |
471 |
my $thisacct = $accdata->{accountlines_id}; |
472 |
my $usth = $dbh->prepare( |
473 |
"UPDATE accountlines SET amountoutstanding= ? |
474 |
WHERE (accountlines_id = ?)" |
475 |
); |
476 |
$usth->execute( $newamtos, $thisacct ); |
477 |
|
478 |
if ( C4::Context->preference("FinesLog") ) { |
479 |
my $manager_id = 0; |
480 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
481 |
$accdata->{'amountoutstanding_new'} = $newamtos; |
482 |
logaction( |
483 |
"FINES", 'MODIFY', |
484 |
$borrowernumber, |
485 |
Dumper( |
486 |
{ action => 'fee_payment', |
487 |
borrowernumber => $accdata->{'borrowernumber'}, |
488 |
old_amountoutstanding => $accdata->{'amountoutstanding'}, |
489 |
new_amountoutstanding => $newamtos, |
490 |
amount_paid => $accdata->{'amountoutstanding'} - $newamtos, |
491 |
accountlines_id => $accdata->{'accountlines_id'}, |
492 |
accountno => $accdata->{'accountno'}, |
493 |
manager_id => $manager_id, |
494 |
} |
495 |
) |
496 |
); |
497 |
push( @ids, $accdata->{'accountlines_id'} ); |
498 |
} |
499 |
} |
500 |
return $debtamount; |
501 |
} |
502 |
|
503 |
sub reducefinefromaccountlines { |
504 |
|
505 |
#here we update the account lines |
506 |
my ( $borrowernumber, $amountpayed ) = @_; |
507 |
my $amountleft = $amountpayed; |
508 |
my $newamtos = 0; |
509 |
my $dbh = C4::Context->dbh; |
510 |
my $accdata = ""; |
511 |
|
512 |
# get lines with outstanding amounts to offset |
513 |
my $sth = $dbh->prepare( |
514 |
"SELECT * FROM accountlines |
515 |
WHERE (borrowernumber = ?) AND (amountoutstanding<>0) |
516 |
ORDER BY date" |
517 |
); |
518 |
$sth->execute($borrowernumber); |
519 |
my @ids; |
520 |
|
521 |
# offset transactions |
522 |
while ( ( $accdata = $sth->fetchrow_hashref ) and ( $amountleft > 0 ) ) { |
523 |
if ( $accdata->{'amountoutstanding'} < $amountleft ) { |
524 |
$newamtos = 0; |
525 |
$amountleft -= $accdata->{'amountoutstanding'}; |
526 |
} |
527 |
else { |
528 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
529 |
$amountleft = 0; |
530 |
} |
531 |
my $thisacct = $accdata->{accountlines_id}; |
532 |
my $usth = $dbh->prepare( |
533 |
"UPDATE accountlines SET amountoutstanding= ? |
534 |
WHERE (accountlines_id = ?)" |
535 |
); |
536 |
$usth->execute( $newamtos, $thisacct ); |
537 |
|
538 |
if ( C4::Context->preference("FinesLog") ) { |
539 |
my $manager_id = 0; |
540 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
541 |
$accdata->{'amountoutstanding_new'} = $newamtos; |
542 |
logaction( |
543 |
"FINES", 'MODIFY', |
544 |
$borrowernumber, |
545 |
Dumper( |
546 |
{ action => 'fee_payment', |
547 |
borrowernumber => $accdata->{'borrowernumber'}, |
548 |
old_amountoutstanding => $accdata->{'amountoutstanding'}, |
549 |
new_amountoutstanding => $newamtos, |
550 |
amount_paid => $accdata->{'amountoutstanding'} - $newamtos, |
551 |
accountlines_id => $accdata->{'accountlines_id'}, |
552 |
accountno => $accdata->{'accountno'}, |
553 |
manager_id => $manager_id, |
554 |
} |
555 |
) |
556 |
); |
557 |
push( @ids, $accdata->{'accountlines_id'} ); |
558 |
} |
559 |
} |
560 |
return $amountleft; |
561 |
} |
562 |
|
563 |
|
382 |
END { } # module clean-up code here (global destructor) |
564 |
END { } # module clean-up code here (global destructor) |
383 |
|
565 |
|
384 |
1; |
566 |
1; |
|
|
567 |
|
385 |
__END__ |
568 |
__END__ |
386 |
|
569 |
|
387 |
=head1 SEE ALSO |
570 |
=head1 SEE ALSO |