@@ -, +, @@ C4/Accounts.pm --- C4/Accounts.pm | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) --- a/C4/Accounts.pm +++ a/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; --