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

(-)a/C4/Accounts.pm (-3 / +12 lines)
Lines 448-456 sub purge_zero_balance_fees { Link Here
448
    my $dbh = C4::Context->dbh;
448
    my $dbh = C4::Context->dbh;
449
    my $sth = $dbh->prepare(
449
    my $sth = $dbh->prepare(
450
        q{
450
        q{
451
            DELETE FROM accountlines
451
            DELETE a1 FROM accountlines a1
452
            WHERE date < date_sub(curdate(), INTERVAL ? DAY)
452
453
              AND ( amountoutstanding = 0 or amountoutstanding IS NULL );
453
            LEFT JOIN account_offsets credit_offset ON ( a1.accountlines_id = credit_offset.credit_id )
454
            LEFT JOIN accountlines a2 ON ( credit_offset.debit_id = a2.accountlines_id )
455
456
            LEFT JOIN account_offsets debit_offset ON ( a1.accountlines_id = debit_offset.debit_id )
457
            LEFT JOIN accountlines a3 ON ( debit_offset.credit_id = a3.accountlines_id )
458
459
            WHERE a1.date < date_sub(curdate(), INTERVAL ? DAY)
460
              AND ( a1.amountoutstanding = 0 OR a1.amountoutstanding IS NULL )
461
              AND ( a2.amountoutstanding = 0 OR a2.amountoutstanding IS NULL )
462
              AND ( a3.amountoutstanding = 0 OR a3.amountoutstanding IS NULL )
454
        }
463
        }
455
    );
464
    );
456
    $sth->execute($days) or die $dbh->errstr;
465
    $sth->execute($days) or die $dbh->errstr;
(-)a/t/db_dependent/Accounts.t (-2 / +32 lines)
Lines 18-24 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 24;
21
use Test::More tests => 30;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 133-138 for my $data (@test_data) { Link Here
133
    is_delete_correct( $data->{delete}, $data->{description});
133
    is_delete_correct( $data->{delete}, $data->{description});
134
}
134
}
135
135
136
$dbh->do(q|DELETE FROM accountlines|);
137
my $debit = Koha::Account::Line->new({ borrowernumber => $borrower->id, date => '1900-01-01', amountoutstanding => 0 })->store();
138
my $credit = Koha::Account::Line->new({ borrowernumber => $borrower->id, date => '1900-01-01', amountoutstanding => -5 })->store();
139
my $offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment' })->store();
140
purge_zero_balance_fees( 1 );
141
my $debit_2 = Koha::Account::Lines->find( $debit->id );
142
my $credit_2 = Koha::Account::Lines->find( $credit->id );
143
ok( $debit_2, 'Debit was correctly not deleted when credit has balance' );
144
ok( $credit_2, 'Credit was correctly not deleted when credit has balance' );
145
146
$dbh->do(q|DELETE FROM accountlines|);
147
$debit = Koha::Account::Line->new({ borrowernumber => $borrower->id, date => '1900-01-01', amountoutstanding => 5 })->store();
148
$credit = Koha::Account::Line->new({ borrowernumber => $borrower->id, date => '1900-01-01', amountoutstanding => 0 })->store();
149
$offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment' })->store();
150
purge_zero_balance_fees( 1 );
151
$debit_2 = $credit_2 = undef;
152
$debit_2 = Koha::Account::Lines->find( $debit->id );
153
$credit_2 = Koha::Account::Lines->find( $credit->id );
154
ok( $debit_2, 'Debit was correctly not deleted when debit has balance' );
155
ok( $credit_2, 'Credit was correctly not deleted when debit has balance' );
156
157
$dbh->do(q|DELETE FROM accountlines|);
158
$debit = Koha::Account::Line->new({ borrowernumber => $borrower->id, date => '1900-01-01', amountoutstanding => 0 })->store();
159
$credit = Koha::Account::Line->new({ borrowernumber => $borrower->id, date => '1900-01-01', amountoutstanding => 0 })->store();
160
$offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment' })->store();
161
purge_zero_balance_fees( 1 );
162
$debit_2 = Koha::Account::Lines->find( $debit->id );
163
$credit_2 = Koha::Account::Lines->find( $credit->id );
164
ok( !$debit_2, 'Debit was correctly deleted' );
165
ok( !$credit_2, 'Credit was correctly deleted' );
166
136
$dbh->do(q|DELETE FROM accountlines|);
167
$dbh->do(q|DELETE FROM accountlines|);
137
168
138
subtest "Koha::Account::pay tests" => sub {
169
subtest "Koha::Account::pay tests" => sub {
139
- 

Return to bug 20325