Bug 14402: Add function purge_zero_balance_fees to C4/Accounts.pm
authorBarton Chittenden <barton@bywatersolutions.com>
Sat, 18 Jul 2015 18:41:38 +0000 (11:41 -0700)
committerTomas Cohen Arazi <tomascohen@theke.io>
Mon, 9 Nov 2015 17:56:52 +0000 (14:56 -0300)
http://bugs.koha-community.org/show_bug.cgi?id=14402

Signed-off-by: Nancy Keener <nkeener@washoecounty.us>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
C4/Accounts.pm

index 9ca87e3..4b67dce 100644 (file)
@@ -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;