purge_zero_balance_fees( $days );
-Delete accountlines entries where amountoutstanding is 0 which are more than a given number of days old.
+Delete accountlines entries where amountoutstanding is 0 or NULL which are more than a given number of days old.
B<$days> -- Zero balance fees older than B<$days> days old will be deleted.
+B<Warning:> Because fines and payments are not linked in accountlines, it is
+possible for a fine to be deleted without the accompanying payment,
+or vise versa. This won't affect the account balance, but might be
+confusing to staff.
+
=cut
sub purge_zero_balance_fees {
q{
DELETE FROM accountlines
WHERE date < date_sub(curdate(), INTERVAL ? DAY)
- AND amountoutstanding = 0;
+ AND ( amountoutstanding = 0 or amountoutstanding IS NULL );
}
);
$sth->execute($days) or die $dbh->errstr;
use Modern::Perl;
-use Test::More tests => 18;
+use Test::More tests => 19;
use Test::MockModule;
use Test::Warn;
my $days = 5;
my @test_data = (
- { amount => 0 , days_ago => 0 , description =>'purge_zero_balance_fees should not delete 0 balance fees with date today' , delete => 0 } ,
- { amount => 0 , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete 0 balance fees with date before threshold day' , delete => 0 } ,
- { amount => 0 , days_ago => $days , description =>'purge_zero_balance_fees should not delete 0 balance fees with date on threshold day' , delete => 0 } ,
- { amount => 0 , days_ago => $days + 1 , description =>'purge_zero_balance_fees should delete 0 balance fees with date after threshold day' , delete => 1 } ,
- { amount => 5 , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with postive amout owed before threshold day' , delete => 0 } ,
- { amount => 5 , days_ago => $days , description =>'purge_zero_balance_fees should not delete fees with postive amout owed on threshold day' , delete => 0 } ,
- { amount => 5 , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with postive amout owed after threshold day' , delete => 0 } ,
- { amount => -5 , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed before threshold day' , delete => 0 } ,
- { amount => -5 , days_ago => $days , description =>'purge_zero_balance_fees should not delete fees with negative amout owed on threshold day' , delete => 0 } ,
- { amount => -5 , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed after threshold day' , delete => 0 }
+ { amount => 0 , days_ago => 0 , description =>'purge_zero_balance_fees should not delete 0 balance fees with date today' , delete => 0 } ,
+ { amount => 0 , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete 0 balance fees with date before threshold day' , delete => 0 } ,
+ { amount => 0 , days_ago => $days , description =>'purge_zero_balance_fees should not delete 0 balance fees with date on threshold day' , delete => 0 } ,
+ { amount => 0 , days_ago => $days + 1 , description =>'purge_zero_balance_fees should delete 0 balance fees with date after threshold day' , delete => 1 } ,
+ { amount => undef , days_ago => $days + 1 , description =>'purge_zero_balance_fees should delete NULL balance fees with date after threshold day' , delete => 1 } ,
+ { amount => 5 , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with postive amout owed before threshold day' , delete => 0 } ,
+ { amount => 5 , days_ago => $days , description =>'purge_zero_balance_fees should not delete fees with postive amout owed on threshold day' , delete => 0 } ,
+ { amount => 5 , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with postive amout owed after threshold day' , delete => 0 } ,
+ { amount => -5 , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed before threshold day' , delete => 0 } ,
+ { amount => -5 , days_ago => $days , description =>'purge_zero_balance_fees should not delete fees with negative amout owed on threshold day' , delete => 0 } ,
+ { amount => -5 , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed after threshold day' , delete => 0 }
);
for my $data ( @test_data ) {