From b75ccdd4c03ab1e9a699083aa13fbea81fbd79da Mon Sep 17 00:00:00 2001 From: Barton Chittenden Date: Sat, 18 Jul 2015 11:41:38 -0700 Subject: [PATCH] Bug 14402: Add function purge_zero_balance_fees to C4/Accounts.pm http://bugs.koha-community.org/show_bug.cgi?id=14402 Signed-off-by: Nancy Keener Signed-off-by: Jonathan Druart --- C4/Accounts.pm | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/C4/Accounts.pm b/C4/Accounts.pm index 9ca87e3..4b67dce 100644 --- a/C4/Accounts.pm +++ b/C4/Accounts.pm @@ -46,9 +46,10 @@ BEGIN { &getrefunds &chargelostitem &ReversePayment - &makepartialpayment - &recordpayment_selectaccts - &WriteOffFee + &makepartialpayment + &recordpayment_selectaccts + &WriteOffFee + &purge_zero_balance_fees ); } @@ -824,6 +825,31 @@ sub WriteOffFee { } +=head2 purge_zero_balance_fees + + purge_zero_balance_fees( $days ); + +Delete accountlines entries where amountoutstanding is 0 which are more than a given number of days old. + +B<$days> -- Zero balance fees older than B<$days> days old will be deleted. + +=cut + +sub purge_zero_balance_fees { + my $days = shift; + my $count = 0; + + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare( + q{ + DELETE FROM accountlines + WHERE date < date_sub(curdate(), INTERVAL ? DAY) + AND amountoutstanding = 0; + } + ); + $sth->execute($days) or die $dbh->errstr; +} + END { } # module clean-up code here (global destructor) 1; -- 2.1.0