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

(-)a/C4/Overdues.pm (-2 / +2 lines)
Lines 560-566 sub UpdateFine { Link Here
560
560
561
    if ( $accountline ) {
561
    if ( $accountline ) {
562
        if ( $accountline->amount != $amount ) {
562
        if ( $accountline->amount != $amount ) {
563
            $accountline->adjust({ amount => $amount, type => 'fine_update' });
563
            $accountline->adjust({ amount => $amount, type => 'overdue_update' });
564
        }
564
        }
565
    } else {
565
    } else {
566
        if ( $amount ) { # Don't add new fines with an amount of 0
566
        if ( $amount ) { # Don't add new fines with an amount of 0
Lines 579-585 sub UpdateFine { Link Here
579
                    note        => undef,
579
                    note        => undef,
580
                    user_id     => undef,
580
                    user_id     => undef,
581
                    library_id  => undef,
581
                    library_id  => undef,
582
                    type        => 'fine',
582
                    type        => 'overdue',
583
                    item_id     => $itemnum,
583
                    item_id     => $itemnum,
584
                    issue_id    => $issue_id,
584
                    issue_id    => $issue_id,
585
                }
585
                }
(-)a/Koha/Account/Line.pm (-2 / +2 lines)
Lines 284-291 sub adjust { Link Here
284
            my $difference                = $amount - $amount_before;
284
            my $difference                = $amount - $amount_before;
285
            my $new_outstanding           = $amount_outstanding_before + $difference;
285
            my $new_outstanding           = $amount_outstanding_before + $difference;
286
286
287
            my $offset_type = substr( $update_type, 0, index( $update_type, '_' ) );
287
            my $offset_type = $account_type;
288
            $offset_type .= ( $difference > 0 ) ? "_increase" : "_decrease";
288
            $offset_type .= ( $difference > 0 ) ? "_INCREASE" : "_DECREASE";
289
289
290
            # Catch cases that require patron refunds
290
            # Catch cases that require patron refunds
291
            if ( $new_outstanding < 0 ) {
291
            if ( $new_outstanding < 0 ) {
(-)a/installer/data/mysql/account_offset_types.sql (-3 / +3 lines)
Lines 12-19 INSERT INTO account_offset_types ( type ) VALUES Link Here
12
('Rental Fee'),
12
('Rental Fee'),
13
('Reserve Fee'),
13
('Reserve Fee'),
14
('Hold Expired'),
14
('Hold Expired'),
15
('fine_increase'),
15
('OVERDUE_INCREASE'),
16
('fine_decrease'),
16
('OVERDUE_DECREASE'),
17
('Fine'),
17
('OVERDUE'),
18
('Void Payment'),
18
('Void Payment'),
19
('Credit Applied');
19
('Credit Applied');
(-)a/installer/data/mysql/atomicupdate/bug_22521.perl (+27 lines)
Lines 1-6 Link Here
1
$DBversion = 'XXX';    # will be replaced by the RM
1
$DBversion = 'XXX';    # will be replaced by the RM
2
if ( CheckVersion($DBversion) ) {
2
if ( CheckVersion($DBversion) ) {
3
3
4
    $dbh->do(qq{
5
        UPDATE
6
          `account_offset_types`
7
        SET
8
          type = 'OVERDUE'
9
        WHERE
10
          type = 'Fine';
11
    });
12
13
    $dbh->do(qq{
14
        UPDATE
15
          `account_offset_types`
16
        SET
17
          type = 'OVERDUE_INCREASE'
18
        WHERE
19
          type = 'fine_increase';
20
    });
21
22
    $dbh->do(qq{
23
        UPDATE
24
          `account_offset_types`
25
        SET
26
          type = 'OVERDUE_DECREASE'
27
        WHERE
28
          type = 'fine_decrease';
29
    });
30
4
    if ( column_exists( 'accountlines', 'accounttype' ) ) {
31
    if ( column_exists( 'accountlines', 'accounttype' ) ) {
5
        $dbh->do(
32
        $dbh->do(
6
            qq{
33
            qq{
(-)a/t/db_dependent/Circulation.t (-5 / +5 lines)
Lines 684-690 my ( $reused_itemnumber_1, $reused_itemnumber_2 ); Link Here
684
        $account->add_debit(
684
        $account->add_debit(
685
            {
685
            {
686
                amount      => $fines_amount,
686
                amount      => $fines_amount,
687
                type        => 'fine',
687
                type        => 'overdue',
688
                item_id     => $item_to_auto_renew->{itemnumber},
688
                item_id     => $item_to_auto_renew->{itemnumber},
689
                description => "Some fines"
689
                description => "Some fines"
690
            }
690
            }
Lines 697-703 my ( $reused_itemnumber_1, $reused_itemnumber_2 ); Link Here
697
        $account->add_debit(
697
        $account->add_debit(
698
            {
698
            {
699
                amount      => $fines_amount,
699
                amount      => $fines_amount,
700
                type        => 'fine',
700
                type        => 'overdue',
701
                item_id     => $item_to_auto_renew->{itemnumber},
701
                item_id     => $item_to_auto_renew->{itemnumber},
702
                description => "Some fines"
702
                description => "Some fines"
703
            }
703
            }
Lines 710-716 my ( $reused_itemnumber_1, $reused_itemnumber_2 ); Link Here
710
        $account->add_debit(
710
        $account->add_debit(
711
            {
711
            {
712
                amount      => $fines_amount,
712
                amount      => $fines_amount,
713
                type        => 'fine',
713
                type        => 'overdue',
714
                item_id     => $item_to_auto_renew->{itemnumber},
714
                item_id     => $item_to_auto_renew->{itemnumber},
715
                description => "Some fines"
715
                description => "Some fines"
716
            }
716
            }
Lines 856-862 my ( $reused_itemnumber_1, $reused_itemnumber_2 ); Link Here
856
    is( $line->issue_id, $issue->id, 'Account line issue id matches' );
856
    is( $line->issue_id, $issue->id, 'Account line issue id matches' );
857
857
858
    my $offset = Koha::Account::Offsets->search({ debit_id => $line->id })->next();
858
    my $offset = Koha::Account::Offsets->search({ debit_id => $line->id })->next();
859
    is( $offset->type, 'Fine', 'Account offset type is Fine' );
859
    is( $offset->type, 'OVERDUE', 'Account offset type is Fine' );
860
    is( $offset->amount, '15.000000', 'Account offset amount is 15.00' );
860
    is( $offset->amount, '15.000000', 'Account offset amount is 15.00' );
861
861
862
    t::lib::Mocks::mock_preference('WhenLostForgiveFine','0');
862
    t::lib::Mocks::mock_preference('WhenLostForgiveFine','0');
Lines 2337-2343 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2337
        );
2337
        );
2338
2338
2339
        my $manual_debit_amount = 80;
2339
        my $manual_debit_amount = 80;
2340
        $account->add_debit( { amount => $manual_debit_amount, type => 'fine' } );
2340
        $account->add_debit( { amount => $manual_debit_amount, type => 'overdue' } );
2341
2341
2342
        is( $account->balance, $manual_debit_amount + $replacement_amount - $payment_amount, 'Manual debit applied' );
2342
        is( $account->balance, $manual_debit_amount + $replacement_amount - $payment_amount, 'Manual debit applied' );
2343
2343
(-)a/t/db_dependent/Koha/Account/Lines.t (-24 / +36 lines)
Lines 57-63 subtest 'item() tests' => sub { Link Here
57
    {
57
    {
58
        borrowernumber => $patron->{borrowernumber},
58
        borrowernumber => $patron->{borrowernumber},
59
        itemnumber     => $item->itemnumber,
59
        itemnumber     => $item->itemnumber,
60
        accounttype    => "F",
60
        accounttype    => "OVERDUE",
61
        status         => "RETURNED",
61
        amount         => 10,
62
        amount         => 10,
62
    })->store;
63
    })->store;
63
64
Lines 84-90 subtest 'total_outstanding() tests' => sub { Link Here
84
85
85
    my $debit_1 = Koha::Account::Line->new(
86
    my $debit_1 = Koha::Account::Line->new(
86
        {   borrowernumber    => $patron->id,
87
        {   borrowernumber    => $patron->id,
87
            accounttype       => "F",
88
            accounttype       => "OVERDUE",
89
            status            => "RETURNED",
88
            amount            => 10,
90
            amount            => 10,
89
            amountoutstanding => 10
91
            amountoutstanding => 10
90
        }
92
        }
Lines 92-98 subtest 'total_outstanding() tests' => sub { Link Here
92
94
93
    my $debit_2 = Koha::Account::Line->new(
95
    my $debit_2 = Koha::Account::Line->new(
94
        {   borrowernumber    => $patron->id,
96
        {   borrowernumber    => $patron->id,
95
            accounttype       => "F",
97
            accounttype       => "OVERDUE",
98
            status            => "RETURNED",
96
            amount            => 10,
99
            amount            => 10,
97
            amountoutstanding => 10
100
            amountoutstanding => 10
98
        }
101
        }
Lines 103-109 subtest 'total_outstanding() tests' => sub { Link Here
103
106
104
    my $credit_1 = Koha::Account::Line->new(
107
    my $credit_1 = Koha::Account::Line->new(
105
        {   borrowernumber    => $patron->id,
108
        {   borrowernumber    => $patron->id,
106
            accounttype       => "F",
109
            accounttype       => "OVERDUE",
110
            status            => "RETURNED",
107
            amount            => -10,
111
            amount            => -10,
108
            amountoutstanding => -10
112
            amountoutstanding => -10
109
        }
113
        }
Lines 114-120 subtest 'total_outstanding() tests' => sub { Link Here
114
118
115
    my $credit_2 = Koha::Account::Line->new(
119
    my $credit_2 = Koha::Account::Line->new(
116
        {   borrowernumber    => $patron->id,
120
        {   borrowernumber    => $patron->id,
117
            accounttype       => "F",
121
            accounttype       => "OVERDUE",
122
            status            => "RETURNED",
118
            amount            => -10,
123
            amount            => -10,
119
            amountoutstanding => -10
124
            amountoutstanding => -10
120
        }
125
        }
Lines 125-131 subtest 'total_outstanding() tests' => sub { Link Here
125
130
126
    my $credit_3 = Koha::Account::Line->new(
131
    my $credit_3 = Koha::Account::Line->new(
127
        {   borrowernumber    => $patron->id,
132
        {   borrowernumber    => $patron->id,
128
            accounttype       => "F",
133
            accounttype       => "OVERDUE",
134
            status            => "RETURNED",
129
            amount            => -100,
135
            amount            => -100,
130
            amountoutstanding => -100
136
            amountoutstanding => -100
131
        }
137
        }
Lines 154-160 subtest 'is_credit() and is_debit() tests' => sub { Link Here
154
    my $debit = Koha::Account::Line->new(
160
    my $debit = Koha::Account::Line->new(
155
    {
161
    {
156
        borrowernumber => $patron->id,
162
        borrowernumber => $patron->id,
157
        accounttype    => "F",
163
        accounttype    => "OVERDUE",
164
        status         => "RETURNED",
158
        amount         => 10,
165
        amount         => 10,
159
    })->store;
166
    })->store;
160
167
Lines 177-183 subtest 'apply() tests' => sub { Link Here
177
184
178
    my $debit_1 = Koha::Account::Line->new(
185
    my $debit_1 = Koha::Account::Line->new(
179
        {   borrowernumber    => $patron->id,
186
        {   borrowernumber    => $patron->id,
180
            accounttype       => "F",
187
            accounttype       => "OVERDUE",
188
            status            => "RETURNED",
181
            amount            => 10,
189
            amount            => 10,
182
            amountoutstanding => 10
190
            amountoutstanding => 10
183
        }
191
        }
Lines 185-191 subtest 'apply() tests' => sub { Link Here
185
193
186
    my $debit_2 = Koha::Account::Line->new(
194
    my $debit_2 = Koha::Account::Line->new(
187
        {   borrowernumber    => $patron->id,
195
        {   borrowernumber    => $patron->id,
188
            accounttype       => "F",
196
            accounttype       => "OVERDUE",
197
            status            => "RETURNED",
189
            amount            => 100,
198
            amount            => 100,
190
            amountoutstanding => 100
199
            amountoutstanding => 100
191
        }
200
        }
Lines 246-252 subtest 'apply() tests' => sub { Link Here
246
    my $credit_2 = $account->add_credit({ amount => 20 });
255
    my $credit_2 = $account->add_credit({ amount => 20 });
247
    my $debit_3  = Koha::Account::Line->new(
256
    my $debit_3  = Koha::Account::Line->new(
248
        {   borrowernumber    => $patron->id,
257
        {   borrowernumber    => $patron->id,
249
            accounttype       => "F",
258
            accounttype       => "OVERDUE",
259
            status            => "RETURNED",
250
            amount            => 100,
260
            amount            => 100,
251
            amountoutstanding => 100
261
            amountoutstanding => 100
252
        }
262
        }
Lines 294-300 subtest 'Keep account info when related patron, staff or item is deleted' => sub Link Here
294
        borrowernumber => $patron->borrowernumber,
304
        borrowernumber => $patron->borrowernumber,
295
        manager_id     => $staff->borrowernumber,
305
        manager_id     => $staff->borrowernumber,
296
        itemnumber     => $item->itemnumber,
306
        itemnumber     => $item->itemnumber,
297
        accounttype    => "F",
307
        accounttype    => "OVERDUE",
308
        status         => "RETURNED",
298
        amount         => 10,
309
        amount         => 10,
299
    })->store;
310
    })->store;
300
311
Lines 331-337 subtest 'adjust() tests' => sub { Link Here
331
342
332
    my $debit_1 = Koha::Account::Line->new(
343
    my $debit_1 = Koha::Account::Line->new(
333
        {   borrowernumber    => $patron->id,
344
        {   borrowernumber    => $patron->id,
334
            accounttype       => "F",
345
            accounttype       => "OVERDUE",
346
            status            => "RETURNED",
335
            amount            => 10,
347
            amount            => 10,
336
            amountoutstanding => 10
348
            amountoutstanding => 10
337
        }
349
        }
Lines 339-345 subtest 'adjust() tests' => sub { Link Here
339
351
340
    my $debit_2 = Koha::Account::Line->new(
352
    my $debit_2 = Koha::Account::Line->new(
341
        {   borrowernumber    => $patron->id,
353
        {   borrowernumber    => $patron->id,
342
            accounttype       => "FU",
354
            accounttype       => "OVERDUE",
355
            status            => "UNRETURNED",
343
            amount            => 100,
356
            amount            => 100,
344
            amountoutstanding => 100
357
            amountoutstanding => 100
345
        }
358
        }
Lines 350-361 subtest 'adjust() tests' => sub { Link Here
350
    throws_ok { $debit_1->adjust( { amount => 50, type => 'bad' } ) }
363
    throws_ok { $debit_1->adjust( { amount => 50, type => 'bad' } ) }
351
    qr/Update type not recognised/, 'Exception thrown for unrecognised type';
364
    qr/Update type not recognised/, 'Exception thrown for unrecognised type';
352
365
353
    throws_ok { $debit_1->adjust( { amount => 50, type => 'fine_update' } ) }
366
    throws_ok { $debit_1->adjust( { amount => 50, type => 'overdue_update' } ) }
354
    qr/Update type not allowed on this accounttype/,
367
    qr/Update type not allowed on this accounttype/,
355
      'Exception thrown for type conflict';
368
      'Exception thrown for type conflict';
356
369
357
    # Increment an unpaid fine
370
    # Increment an unpaid fine
358
    $debit_2->adjust( { amount => 150, type => 'fine_update' } )->discard_changes;
371
    $debit_2->adjust( { amount => 150, type => 'overdue_update' } )->discard_changes;
359
372
360
    is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' );
373
    is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' );
361
    is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' );
374
    is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' );
Lines 366-372 subtest 'adjust() tests' => sub { Link Here
366
    is( $offsets->count, 1, 'An offset is generated for the increment' );
379
    is( $offsets->count, 1, 'An offset is generated for the increment' );
367
    my $THIS_offset = $offsets->next;
380
    my $THIS_offset = $offsets->next;
368
    is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' );
381
    is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' );
369
    is( $THIS_offset->type, 'fine_increase', 'Adjust type stored correctly' );
382
    is( $THIS_offset->type, 'OVERDUE_INCREASE', 'Adjust type stored correctly' );
370
383
371
    is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' );
384
    is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' );
372
385
Lines 382-388 subtest 'adjust() tests' => sub { Link Here
382
    t::lib::Mocks::mock_preference( 'FinesLog', 1 );
395
    t::lib::Mocks::mock_preference( 'FinesLog', 1 );
383
396
384
    # Increment the partially paid fine
397
    # Increment the partially paid fine
385
    $debit_2->adjust( { amount => 160, type => 'fine_update' } )->discard_changes;
398
    $debit_2->adjust( { amount => 160, type => 'overdue_update' } )->discard_changes;
386
399
387
    is( $debit_2->amount * 1, 160, 'Fine amount was updated in full' );
400
    is( $debit_2->amount * 1, 160, 'Fine amount was updated in full' );
388
    is( $debit_2->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' );
401
    is( $debit_2->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' );
Lines 392-403 subtest 'adjust() tests' => sub { Link Here
392
    is( $offsets->count, 3, 'An offset is generated for the increment' );
405
    is( $offsets->count, 3, 'An offset is generated for the increment' );
393
    $THIS_offset = $offsets->last;
406
    $THIS_offset = $offsets->last;
394
    is( $THIS_offset->amount * 1, 10, 'Amount was calculated correctly (increment by 10)' );
407
    is( $THIS_offset->amount * 1, 10, 'Amount was calculated correctly (increment by 10)' );
395
    is( $THIS_offset->type, 'fine_increase', 'Adjust type stored correctly' );
408
    is( $THIS_offset->type, 'OVERDUE_INCREASE', 'Adjust type stored correctly' );
396
409
397
    is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' );
410
    is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' );
398
411
399
    # Decrement the partially paid fine, less than what was paid
412
    # Decrement the partially paid fine, less than what was paid
400
    $debit_2->adjust( { amount => 50, type => 'fine_update' } )->discard_changes;
413
    $debit_2->adjust( { amount => 50, type => 'overdue_update' } )->discard_changes;
401
414
402
    is( $debit_2->amount * 1, 50, 'Fine amount was updated in full' );
415
    is( $debit_2->amount * 1, 50, 'Fine amount was updated in full' );
403
    is( $debit_2->amountoutstanding * 1, 10, 'Fine amountoutstanding was updated by difference' );
416
    is( $debit_2->amountoutstanding * 1, 10, 'Fine amountoutstanding was updated by difference' );
Lines 407-416 subtest 'adjust() tests' => sub { Link Here
407
    is( $offsets->count, 4, 'An offset is generated for the decrement' );
420
    is( $offsets->count, 4, 'An offset is generated for the decrement' );
408
    $THIS_offset = $offsets->last;
421
    $THIS_offset = $offsets->last;
409
    is( $THIS_offset->amount * 1, -110, 'Amount was calculated correctly (decrement by 110)' );
422
    is( $THIS_offset->amount * 1, -110, 'Amount was calculated correctly (decrement by 110)' );
410
    is( $THIS_offset->type, 'fine_decrease', 'Adjust type stored correctly' );
423
    is( $THIS_offset->type, 'OVERDUE_DECREASE', 'Adjust type stored correctly' );
411
424
412
    # Decrement the partially paid fine, more than what was paid
425
    # Decrement the partially paid fine, more than what was paid
413
    $debit_2->adjust( { amount => 30, type => 'fine_update' } )->discard_changes;
426
    $debit_2->adjust( { amount => 30, type => 'overdue_update' } )->discard_changes;
414
    is( $debit_2->amount * 1, 30, 'Fine amount was updated in full' );
427
    is( $debit_2->amount * 1, 30, 'Fine amount was updated in full' );
415
    is( $debit_2->amountoutstanding * 1, 0, 'Fine amountoutstanding was zeroed (payment was 40)' );
428
    is( $debit_2->amountoutstanding * 1, 0, 'Fine amountoutstanding was zeroed (payment was 40)' );
416
    is( $debit_2->lastincrement * 1, -20, 'lastincrement is the to the right value' );
429
    is( $debit_2->lastincrement * 1, -20, 'lastincrement is the to the right value' );
Lines 419-425 subtest 'adjust() tests' => sub { Link Here
419
    is( $offsets->count, 5, 'An offset is generated for the decrement' );
432
    is( $offsets->count, 5, 'An offset is generated for the decrement' );
420
    $THIS_offset = $offsets->last;
433
    $THIS_offset = $offsets->last;
421
    is( $THIS_offset->amount * 1, -20, 'Amount was calculated correctly (decrement by 20)' );
434
    is( $THIS_offset->amount * 1, -20, 'Amount was calculated correctly (decrement by 20)' );
422
    is( $THIS_offset->type, 'fine_decrease', 'Adjust type stored correctly' );
435
    is( $THIS_offset->type, 'OVERDUE_DECREASE', 'Adjust type stored correctly' );
423
436
424
    my $overpayment_refund = $account->lines->last;
437
    my $overpayment_refund = $account->lines->last;
425
    is( $overpayment_refund->amount * 1, -10, 'A new credit has been added' );
438
    is( $overpayment_refund->amount * 1, -10, 'A new credit has been added' );
Lines 445-451 subtest 'checkout() tests' => sub { Link Here
445
        amount   => 10,
458
        amount   => 10,
446
        item_id  => $item->itemnumber,
459
        item_id  => $item->itemnumber,
447
        issue_id => $checkout->issue_id,
460
        issue_id => $checkout->issue_id,
448
        type     => 'fine',
461
        type     => 'overdue',
449
    });
462
    });
450
463
451
    my $line_checkout = $line->checkout;
464
    my $line_checkout = $line->checkout;
452
- 

Return to bug 22521