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 19-25 Link Here
19
use strict;
19
use strict;
20
use warnings;
20
use warnings;
21
21
22
use Test::More tests => 25;
22
use Test::More tests => 26;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
BEGIN {
25
BEGIN {
Lines 192-207 $sth = $dbh->prepare( Link Here
192
my $days = 5;
192
my $days = 5;
193
193
194
my @test_data = (
194
my @test_data = (
195
    { amount => 0  , days_ago => 0         , description =>'purge_zero_balance_fees should not delete 0 balance fees with date today'                     , delete => 0 } ,
195
    { amount => 0     , days_ago => 0         , description =>'purge_zero_balance_fees should not delete 0 balance fees with date today'                     , delete => 0 } ,
196
    { amount => 0  , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete 0 balance fees with date before threshold day'      , delete => 0 } ,
196
    { amount => 0     , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete 0 balance fees with date before threshold day'      , delete => 0 } ,
197
    { amount => 0  , days_ago => $days     , description =>'purge_zero_balance_fees should not delete 0 balance fees with date on threshold day'          , delete => 0 } ,
197
    { amount => 0     , days_ago => $days     , description =>'purge_zero_balance_fees should not delete 0 balance fees with date on threshold day'          , delete => 0 } ,
198
    { amount => 0  , days_ago => $days + 1 , description =>'purge_zero_balance_fees should delete 0 balance fees with date after threshold day'           , delete => 1 } ,
198
    { amount => 0     , days_ago => $days + 1 , description =>'purge_zero_balance_fees should delete 0 balance fees with date after threshold day'           , delete => 1 } ,
199
    { amount => 5  , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with postive amout owed before threshold day'  , delete => 0 } ,
199
    { amount => undef , days_ago => $days + 1 , description =>'purge_zero_balance_fees should delete NULL balance fees with date after threshold day'        , delete => 1 } ,
200
    { amount => 5  , days_ago => $days     , description =>'purge_zero_balance_fees should not delete fees with postive amout owed on threshold day'      , delete => 0 } ,
200
    { amount => 5     , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with postive amout owed before threshold day'  , delete => 0 } ,
201
    { amount => 5  , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with postive amout owed after threshold day'   , delete => 0 } ,
201
    { amount => 5     , days_ago => $days     , description =>'purge_zero_balance_fees should not delete fees with postive amout owed on threshold day'      , delete => 0 } ,
202
    { amount => -5 , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed before threshold day' , delete => 0 } ,
202
    { amount => 5     , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with postive amout owed after threshold day'   , delete => 0 } ,
203
    { amount => -5 , days_ago => $days     , description =>'purge_zero_balance_fees should not delete fees with negative amout owed on threshold day'     , delete => 0 } ,
203
    { amount => -5    , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed before threshold day' , delete => 0 } ,
204
    { amount => -5 , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed after threshold day'  , delete => 0 }
204
    { amount => -5    , days_ago => $days     , description =>'purge_zero_balance_fees should not delete fees with negative amout owed on threshold day'     , delete => 0 } ,
205
    { amount => -5    , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed after threshold day'  , delete => 0 }
205
);
206
);
206
207
207
for my $data  ( @test_data ) {
208
for my $data  ( @test_data ) {
208
- 

Return to bug 14402