View | Details | Raw Unified | Return to bug 14402
Collapse All | Expand All

(-)a/C4/Accounts.pm (-2 / +7 lines)
Lines 829-838 sub WriteOffFee { Link Here
829
829
830
  purge_zero_balance_fees( $days );
830
  purge_zero_balance_fees( $days );
831
831
832
Delete accountlines entries where amountoutstanding is 0 which are more than a given number of days old.
832
Delete accountlines entries where amountoutstanding is 0 or NULL which are more than a given number of days old.
833
833
834
B<$days> -- Zero balance fees older than B<$days> days old will be deleted.
834
B<$days> -- Zero balance fees older than B<$days> days old will be deleted.
835
835
836
B<Warning:> Because fines and payments are not linked in accountlines, it is
837
possible for a fine to be deleted without the accompanying payment,
838
or vise versa. This won't affect the account balance, but might be
839
confusing to staff.
840
836
=cut
841
=cut
837
842
838
sub purge_zero_balance_fees {
843
sub purge_zero_balance_fees {
Lines 844-850 sub purge_zero_balance_fees { Link Here
844
        q{
849
        q{
845
            DELETE FROM accountlines
850
            DELETE FROM accountlines
846
            WHERE date < date_sub(curdate(), INTERVAL ? DAY)
851
            WHERE date < date_sub(curdate(), INTERVAL ? DAY)
847
              AND amountoutstanding = 0;
852
              AND ( amountoutstanding = 0 or amountoutstanding IS NULL );
848
        }
853
        }
849
    );
854
    );
850
    $sth->execute($days) or die $dbh->errstr;
855
    $sth->execute($days) or die $dbh->errstr;
(-)a/misc/cronjobs/cleanup_database.pl (-1 / +4 lines)
Lines 62-68 Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueu Link Here
62
   --z3950            purge records from import tables that are the result
62
   --z3950            purge records from import tables that are the result
63
                      of Z39.50 searches
63
                      of Z39.50 searches
64
   --fees DAYS        purge entries accountlines older than DAYS days, where
64
   --fees DAYS        purge entries accountlines older than DAYS days, where
65
                      amountoutstanding is 0.
65
                      amountoutstanding is 0 or NULL.
66
                      WARNING: Fees and payments may not be deleted together.
67
                      This will not affect the account balance but may be
68
                      confusing to staff.
66
   --logs DAYS        purge entries from action_logs older than DAYS days.
69
   --logs DAYS        purge entries from action_logs older than DAYS days.
67
                      Defaults to 180 days if no days specified.
70
                      Defaults to 180 days if no days specified.
68
   --searchhistory DAYS  purge entries from search_history older than DAYS days.
71
   --searchhistory DAYS  purge entries from search_history older than DAYS days.
(-)a/t/db_dependent/Accounts.t (-12 / +12 lines)
Lines 18-24 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 18;
21
use Test::More tests => 19;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 90-105 $sth = $dbh->prepare( Link Here
90
my $days = 5;
90
my $days = 5;
91
91
92
my @test_data = (
92
my @test_data = (
93
    { amount => 0  , days_ago => 0         , description =>'purge_zero_balance_fees should not delete 0 balance fees with date today'                     , delete => 0 } ,
93
    { amount => 0     , days_ago => 0         , description =>'purge_zero_balance_fees should not delete 0 balance fees with date today'                     , delete => 0 } ,
94
    { amount => 0  , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete 0 balance fees with date before threshold day'      , delete => 0 } ,
94
    { amount => 0     , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete 0 balance fees with date before threshold day'      , delete => 0 } ,
95
    { amount => 0  , days_ago => $days     , description =>'purge_zero_balance_fees should not delete 0 balance fees with date on threshold day'          , delete => 0 } ,
95
    { amount => 0     , days_ago => $days     , description =>'purge_zero_balance_fees should not delete 0 balance fees with date on threshold day'          , delete => 0 } ,
96
    { amount => 0  , days_ago => $days + 1 , description =>'purge_zero_balance_fees should delete 0 balance fees with date after threshold day'           , delete => 1 } ,
96
    { amount => 0     , days_ago => $days + 1 , description =>'purge_zero_balance_fees should delete 0 balance fees with date after threshold day'           , delete => 1 } ,
97
    { amount => 5  , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with postive amout owed before threshold day'  , delete => 0 } ,
97
    { amount => undef , days_ago => $days + 1 , description =>'purge_zero_balance_fees should delete NULL balance fees with date after threshold day'        , delete => 1 } ,
98
    { amount => 5  , days_ago => $days     , description =>'purge_zero_balance_fees should not delete fees with postive amout owed on threshold day'      , delete => 0 } ,
98
    { amount => 5     , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with postive amout owed before threshold day'  , delete => 0 } ,
99
    { amount => 5  , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with postive amout owed after threshold day'   , delete => 0 } ,
99
    { amount => 5     , days_ago => $days     , description =>'purge_zero_balance_fees should not delete fees with postive amout owed on threshold day'      , delete => 0 } ,
100
    { amount => -5 , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed before threshold day' , delete => 0 } ,
100
    { amount => 5     , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with postive amout owed after threshold day'   , delete => 0 } ,
101
    { amount => -5 , days_ago => $days     , description =>'purge_zero_balance_fees should not delete fees with negative amout owed on threshold day'     , delete => 0 } ,
101
    { amount => -5    , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed before threshold day' , delete => 0 } ,
102
    { amount => -5 , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed after threshold day'  , delete => 0 }
102
    { amount => -5    , days_ago => $days     , description =>'purge_zero_balance_fees should not delete fees with negative amout owed on threshold day'     , delete => 0 } ,
103
    { amount => -5    , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed after threshold day'  , delete => 0 }
103
);
104
);
104
105
105
for my $data  ( @test_data ) {
106
for my $data  ( @test_data ) {
106
- 

Return to bug 14402