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

(-)a/C4/Overdues.pm (-2 / +2 lines)
Lines 564-570 sub UpdateFine { Link Here
564
            $accountline->adjust(
564
            $accountline->adjust(
565
                {
565
                {
566
                    amount    => $amount,
566
                    amount    => $amount,
567
                    type      => 'fine_update',
567
                    type      => 'overdue_update',
568
                    interface => C4::Context->interface
568
                    interface => C4::Context->interface
569
                }
569
                }
570
            );
570
            );
Lines 587-593 sub UpdateFine { Link Here
587
                    user_id     => undef,
587
                    user_id     => undef,
588
                    interface   => C4::Context->interface,
588
                    interface   => C4::Context->interface,
589
                    library_id  => undef, #FIXME: Should we grab the checkout or circ-control branch here perhaps?
589
                    library_id  => undef, #FIXME: Should we grab the checkout or circ-control branch here perhaps?
590
                    type        => 'fine',
590
                    type        => 'overdue',
591
                    item_id     => $itemnum,
591
                    item_id     => $itemnum,
592
                    issue_id    => $issue_id,
592
                    issue_id    => $issue_id,
593
                }
593
                }
(-)a/Koha/Account/Line.pm (-2 / +2 lines)
Lines 286-293 sub adjust { Link Here
286
            my $difference                = $amount - $amount_before;
286
            my $difference                = $amount - $amount_before;
287
            my $new_outstanding           = $amount_outstanding_before + $difference;
287
            my $new_outstanding           = $amount_outstanding_before + $difference;
288
288
289
            my $offset_type = substr( $update_type, 0, index( $update_type, '_' ) );
289
            my $offset_type = $account_type;
290
            $offset_type .= ( $difference > 0 ) ? "_increase" : "_decrease";
290
            $offset_type .= ( $difference > 0 ) ? "_INCREASE" : "_DECREASE";
291
291
292
            # Catch cases that require patron refunds
292
            # Catch cases that require patron refunds
293
            if ( $new_outstanding < 0 ) {
293
            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 685-691 my ( $reused_itemnumber_1, $reused_itemnumber_2 ); Link Here
685
            {
685
            {
686
                amount      => $fines_amount,
686
                amount      => $fines_amount,
687
                interface   => 'test',
687
                interface   => 'test',
688
                type        => 'fine',
688
                type        => 'overdue',
689
                item_id     => $item_to_auto_renew->{itemnumber},
689
                item_id     => $item_to_auto_renew->{itemnumber},
690
                description => "Some fines"
690
                description => "Some fines"
691
            }
691
            }
Lines 699-705 my ( $reused_itemnumber_1, $reused_itemnumber_2 ); Link Here
699
            {
699
            {
700
                amount      => $fines_amount,
700
                amount      => $fines_amount,
701
                interface   => 'test',
701
                interface   => 'test',
702
                type        => 'fine',
702
                type        => 'overdue',
703
                item_id     => $item_to_auto_renew->{itemnumber},
703
                item_id     => $item_to_auto_renew->{itemnumber},
704
                description => "Some fines"
704
                description => "Some fines"
705
            }
705
            }
Lines 713-719 my ( $reused_itemnumber_1, $reused_itemnumber_2 ); Link Here
713
            {
713
            {
714
                amount      => $fines_amount,
714
                amount      => $fines_amount,
715
                interface   => 'test',
715
                interface   => 'test',
716
                type        => 'fine',
716
                type        => 'overdue',
717
                item_id     => $item_to_auto_renew->{itemnumber},
717
                item_id     => $item_to_auto_renew->{itemnumber},
718
                description => "Some fines"
718
                description => "Some fines"
719
            }
719
            }
Lines 858-864 my ( $reused_itemnumber_1, $reused_itemnumber_2 ); Link Here
858
    is( $line->issue_id, $issue->id, 'Account line issue id matches' );
858
    is( $line->issue_id, $issue->id, 'Account line issue id matches' );
859
859
860
    my $offset = Koha::Account::Offsets->search({ debit_id => $line->id })->next();
860
    my $offset = Koha::Account::Offsets->search({ debit_id => $line->id })->next();
861
    is( $offset->type, 'Fine', 'Account offset type is Fine' );
861
    is( $offset->type, 'OVERDUE', 'Account offset type is Fine' );
862
    is( $offset->amount, '15.000000', 'Account offset amount is 15.00' );
862
    is( $offset->amount, '15.000000', 'Account offset amount is 15.00' );
863
863
864
    t::lib::Mocks::mock_preference('WhenLostForgiveFine','0');
864
    t::lib::Mocks::mock_preference('WhenLostForgiveFine','0');
Lines 2348-2354 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2348
        );
2348
        );
2349
2349
2350
        my $manual_debit_amount = 80;
2350
        my $manual_debit_amount = 80;
2351
        $account->add_debit( { amount => $manual_debit_amount, type => 'fine', interface =>'test' } );
2351
        $account->add_debit( { amount => $manual_debit_amount, type => 'overdue', interface =>'test' } );
2352
2352
2353
        is( $account->balance, $manual_debit_amount + $replacement_amount - $payment_amount, 'Manual debit applied' );
2353
        is( $account->balance, $manual_debit_amount + $replacement_amount - $payment_amount, 'Manual debit applied' );
2354
2354
(-)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
        interface      => 'commandline',
63
        interface      => 'commandline',
63
    })->store;
64
    })->store;
Lines 85-91 subtest 'total_outstanding() tests' => sub { Link Here
85
86
86
    my $debit_1 = Koha::Account::Line->new(
87
    my $debit_1 = Koha::Account::Line->new(
87
        {   borrowernumber    => $patron->id,
88
        {   borrowernumber    => $patron->id,
88
            accounttype       => "F",
89
            accounttype       => "OVERDUE",
90
            status            => "RETURNED",
89
            amount            => 10,
91
            amount            => 10,
90
            amountoutstanding => 10,
92
            amountoutstanding => 10,
91
            interface         => 'commandline',
93
            interface         => 'commandline',
Lines 94-100 subtest 'total_outstanding() tests' => sub { Link Here
94
96
95
    my $debit_2 = Koha::Account::Line->new(
97
    my $debit_2 = Koha::Account::Line->new(
96
        {   borrowernumber    => $patron->id,
98
        {   borrowernumber    => $patron->id,
97
            accounttype       => "F",
99
            accounttype       => "OVERDUE",
100
            status            => "RETURNED",
98
            amount            => 10,
101
            amount            => 10,
99
            amountoutstanding => 10,
102
            amountoutstanding => 10,
100
            interface         => 'commandline',
103
            interface         => 'commandline',
Lines 106-112 subtest 'total_outstanding() tests' => sub { Link Here
106
109
107
    my $credit_1 = Koha::Account::Line->new(
110
    my $credit_1 = Koha::Account::Line->new(
108
        {   borrowernumber    => $patron->id,
111
        {   borrowernumber    => $patron->id,
109
            accounttype       => "F",
112
            accounttype       => "OVERDUE",
113
            status            => "RETURNED",
110
            amount            => -10,
114
            amount            => -10,
111
            amountoutstanding => -10,
115
            amountoutstanding => -10,
112
            interface         => 'commandline',
116
            interface         => 'commandline',
Lines 118-124 subtest 'total_outstanding() tests' => sub { Link Here
118
122
119
    my $credit_2 = Koha::Account::Line->new(
123
    my $credit_2 = Koha::Account::Line->new(
120
        {   borrowernumber    => $patron->id,
124
        {   borrowernumber    => $patron->id,
121
            accounttype       => "F",
125
            accounttype       => "OVERDUE",
126
            status            => "RETURNED",
122
            amount            => -10,
127
            amount            => -10,
123
            amountoutstanding => -10,
128
            amountoutstanding => -10,
124
            interface         => 'commandline',
129
            interface         => 'commandline',
Lines 130-136 subtest 'total_outstanding() tests' => sub { Link Here
130
135
131
    my $credit_3 = Koha::Account::Line->new(
136
    my $credit_3 = Koha::Account::Line->new(
132
        {   borrowernumber    => $patron->id,
137
        {   borrowernumber    => $patron->id,
133
            accounttype       => "F",
138
            accounttype       => "OVERDUE",
139
            status            => "RETURNED",
134
            amount            => -100,
140
            amount            => -100,
135
            amountoutstanding => -100,
141
            amountoutstanding => -100,
136
            interface         => 'commandline',
142
            interface         => 'commandline',
Lines 160-166 subtest 'is_credit() and is_debit() tests' => sub { Link Here
160
    my $debit = Koha::Account::Line->new(
166
    my $debit = Koha::Account::Line->new(
161
    {
167
    {
162
        borrowernumber => $patron->id,
168
        borrowernumber => $patron->id,
163
        accounttype    => "F",
169
        accounttype    => "OVERDUE",
170
        status         => "RETURNED",
164
        amount         => 10,
171
        amount         => 10,
165
        interface      => 'commandline',
172
        interface      => 'commandline',
166
    })->store;
173
    })->store;
Lines 184-190 subtest 'apply() tests' => sub { Link Here
184
191
185
    my $debit_1 = Koha::Account::Line->new(
192
    my $debit_1 = Koha::Account::Line->new(
186
        {   borrowernumber    => $patron->id,
193
        {   borrowernumber    => $patron->id,
187
            accounttype       => "F",
194
            accounttype       => "OVERDUE",
195
            status            => "RETURNED",
188
            amount            => 10,
196
            amount            => 10,
189
            amountoutstanding => 10,
197
            amountoutstanding => 10,
190
            interface         => 'commandline',
198
            interface         => 'commandline',
Lines 193-199 subtest 'apply() tests' => sub { Link Here
193
201
194
    my $debit_2 = Koha::Account::Line->new(
202
    my $debit_2 = Koha::Account::Line->new(
195
        {   borrowernumber    => $patron->id,
203
        {   borrowernumber    => $patron->id,
196
            accounttype       => "F",
204
            accounttype       => "OVERDUE",
205
            status            => "RETURNED",
197
            amount            => 100,
206
            amount            => 100,
198
            amountoutstanding => 100,
207
            amountoutstanding => 100,
199
            interface         => 'commandline',
208
            interface         => 'commandline',
Lines 255-261 subtest 'apply() tests' => sub { Link Here
255
    my $credit_2 = $account->add_credit({ amount => 20, interface => 'commandline' });
264
    my $credit_2 = $account->add_credit({ amount => 20, interface => 'commandline' });
256
    my $debit_3  = Koha::Account::Line->new(
265
    my $debit_3  = Koha::Account::Line->new(
257
        {   borrowernumber    => $patron->id,
266
        {   borrowernumber    => $patron->id,
258
            accounttype       => "F",
267
            accounttype       => "OVERDUE",
268
            status            => "RETURNED",
259
            amount            => 100,
269
            amount            => 100,
260
            amountoutstanding => 100,
270
            amountoutstanding => 100,
261
            interface         => 'commandline',
271
            interface         => 'commandline',
Lines 304-310 subtest 'Keep account info when related patron, staff or item is deleted' => sub Link Here
304
        borrowernumber => $patron->borrowernumber,
314
        borrowernumber => $patron->borrowernumber,
305
        manager_id     => $staff->borrowernumber,
315
        manager_id     => $staff->borrowernumber,
306
        itemnumber     => $item->itemnumber,
316
        itemnumber     => $item->itemnumber,
307
        accounttype    => "F",
317
        accounttype    => "OVERDUE",
318
        status         => "RETURNED",
308
        amount         => 10,
319
        amount         => 10,
309
        interface      => 'commandline',
320
        interface      => 'commandline',
310
    })->store;
321
    })->store;
Lines 342-348 subtest 'adjust() tests' => sub { Link Here
342
353
343
    my $debit_1 = Koha::Account::Line->new(
354
    my $debit_1 = Koha::Account::Line->new(
344
        {   borrowernumber    => $patron->id,
355
        {   borrowernumber    => $patron->id,
345
            accounttype       => "F",
356
            accounttype       => "OVERDUE",
357
            status            => "RETURNED",
346
            amount            => 10,
358
            amount            => 10,
347
            amountoutstanding => 10,
359
            amountoutstanding => 10,
348
            interface         => 'commandline',
360
            interface         => 'commandline',
Lines 351-357 subtest 'adjust() tests' => sub { Link Here
351
363
352
    my $debit_2 = Koha::Account::Line->new(
364
    my $debit_2 = Koha::Account::Line->new(
353
        {   borrowernumber    => $patron->id,
365
        {   borrowernumber    => $patron->id,
354
            accounttype       => "FU",
366
            accounttype       => "OVERDUE",
367
            status            => "UNRETURNED",
355
            amount            => 100,
368
            amount            => 100,
356
            amountoutstanding => 100,
369
            amountoutstanding => 100,
357
            interface         => 'commandline'
370
            interface         => 'commandline'
Lines 363-374 subtest 'adjust() tests' => sub { Link Here
363
    throws_ok { $debit_1->adjust( { amount => 50, type => 'bad', interface => 'commandline' } ) }
376
    throws_ok { $debit_1->adjust( { amount => 50, type => 'bad', interface => 'commandline' } ) }
364
    qr/Update type not recognised/, 'Exception thrown for unrecognised type';
377
    qr/Update type not recognised/, 'Exception thrown for unrecognised type';
365
378
366
    throws_ok { $debit_1->adjust( { amount => 50, type => 'fine_update', interface => 'commandline' } ) }
379
    throws_ok { $debit_1->adjust( { amount => 50, type => 'overdue_update', interface => 'commandline' } ) }
367
    qr/Update type not allowed on this accounttype/,
380
    qr/Update type not allowed on this accounttype/,
368
      'Exception thrown for type conflict';
381
      'Exception thrown for type conflict';
369
382
370
    # Increment an unpaid fine
383
    # Increment an unpaid fine
371
    $debit_2->adjust( { amount => 150, type => 'fine_update', interface => 'commandline' } )->discard_changes;
384
    $debit_2->adjust( { amount => 150, type => 'overdue_update', interface => 'commandline' } )->discard_changes;
372
385
373
    is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' );
386
    is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' );
374
    is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' );
387
    is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' );
Lines 378-384 subtest 'adjust() tests' => sub { Link Here
378
    is( $offsets->count, 1, 'An offset is generated for the increment' );
391
    is( $offsets->count, 1, 'An offset is generated for the increment' );
379
    my $THIS_offset = $offsets->next;
392
    my $THIS_offset = $offsets->next;
380
    is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' );
393
    is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' );
381
    is( $THIS_offset->type, 'fine_increase', 'Adjust type stored correctly' );
394
    is( $THIS_offset->type, 'OVERDUE_INCREASE', 'Adjust type stored correctly' );
382
395
383
    is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' );
396
    is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' );
384
397
Lines 394-400 subtest 'adjust() tests' => sub { Link Here
394
    t::lib::Mocks::mock_preference( 'FinesLog', 1 );
407
    t::lib::Mocks::mock_preference( 'FinesLog', 1 );
395
408
396
    # Increment the partially paid fine
409
    # Increment the partially paid fine
397
    $debit_2->adjust( { amount => 160, type => 'fine_update', interface => 'commandline' } )->discard_changes;
410
    $debit_2->adjust( { amount => 160, type => 'overdue_update', interface => 'commandline' } )->discard_changes;
398
411
399
    is( $debit_2->amount * 1, 160, 'Fine amount was updated in full' );
412
    is( $debit_2->amount * 1, 160, 'Fine amount was updated in full' );
400
    is( $debit_2->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' );
413
    is( $debit_2->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' );
Lines 403-414 subtest 'adjust() tests' => sub { Link Here
403
    is( $offsets->count, 3, 'An offset is generated for the increment' );
416
    is( $offsets->count, 3, 'An offset is generated for the increment' );
404
    $THIS_offset = $offsets->last;
417
    $THIS_offset = $offsets->last;
405
    is( $THIS_offset->amount * 1, 10, 'Amount was calculated correctly (increment by 10)' );
418
    is( $THIS_offset->amount * 1, 10, 'Amount was calculated correctly (increment by 10)' );
406
    is( $THIS_offset->type, 'fine_increase', 'Adjust type stored correctly' );
419
    is( $THIS_offset->type, 'OVERDUE_INCREASE', 'Adjust type stored correctly' );
407
420
408
    is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' );
421
    is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' );
409
422
410
    # Decrement the partially paid fine, less than what was paid
423
    # Decrement the partially paid fine, less than what was paid
411
    $debit_2->adjust( { amount => 50, type => 'fine_update', interface => 'commandline' } )->discard_changes;
424
    $debit_2->adjust( { amount => 50, type => 'overdue_update', interface => 'commandline' } )->discard_changes;
412
425
413
    is( $debit_2->amount * 1, 50, 'Fine amount was updated in full' );
426
    is( $debit_2->amount * 1, 50, 'Fine amount was updated in full' );
414
    is( $debit_2->amountoutstanding * 1, 10, 'Fine amountoutstanding was updated by difference' );
427
    is( $debit_2->amountoutstanding * 1, 10, 'Fine amountoutstanding was updated by difference' );
Lines 417-426 subtest 'adjust() tests' => sub { Link Here
417
    is( $offsets->count, 4, 'An offset is generated for the decrement' );
430
    is( $offsets->count, 4, 'An offset is generated for the decrement' );
418
    $THIS_offset = $offsets->last;
431
    $THIS_offset = $offsets->last;
419
    is( $THIS_offset->amount * 1, -110, 'Amount was calculated correctly (decrement by 110)' );
432
    is( $THIS_offset->amount * 1, -110, 'Amount was calculated correctly (decrement by 110)' );
420
    is( $THIS_offset->type, 'fine_decrease', 'Adjust type stored correctly' );
433
    is( $THIS_offset->type, 'OVERDUE_DECREASE', 'Adjust type stored correctly' );
421
434
422
    # Decrement the partially paid fine, more than what was paid
435
    # Decrement the partially paid fine, more than what was paid
423
    $debit_2->adjust( { amount => 30, type => 'fine_update', interface => 'commandline' } )->discard_changes;
436
    $debit_2->adjust( { amount => 30, type => 'overdue_update', interface => 'commandline' } )->discard_changes;
424
    is( $debit_2->amount * 1, 30, 'Fine amount was updated in full' );
437
    is( $debit_2->amount * 1, 30, 'Fine amount was updated in full' );
425
    is( $debit_2->amountoutstanding * 1, 0, 'Fine amountoutstanding was zeroed (payment was 40)' );
438
    is( $debit_2->amountoutstanding * 1, 0, 'Fine amountoutstanding was zeroed (payment was 40)' );
426
439
Lines 428-434 subtest 'adjust() tests' => sub { Link Here
428
    is( $offsets->count, 5, 'An offset is generated for the decrement' );
441
    is( $offsets->count, 5, 'An offset is generated for the decrement' );
429
    $THIS_offset = $offsets->last;
442
    $THIS_offset = $offsets->last;
430
    is( $THIS_offset->amount * 1, -20, 'Amount was calculated correctly (decrement by 20)' );
443
    is( $THIS_offset->amount * 1, -20, 'Amount was calculated correctly (decrement by 20)' );
431
    is( $THIS_offset->type, 'fine_decrease', 'Adjust type stored correctly' );
444
    is( $THIS_offset->type, 'OVERDUE_DECREASE', 'Adjust type stored correctly' );
432
445
433
    my $overpayment_refund = $account->lines->last;
446
    my $overpayment_refund = $account->lines->last;
434
    is( $overpayment_refund->amount * 1, -10, 'A new credit has been added' );
447
    is( $overpayment_refund->amount * 1, -10, 'A new credit has been added' );
Lines 455-461 subtest 'checkout() tests' => sub { Link Here
455
        interface => 'commandline',
468
        interface => 'commandline',
456
        item_id   => $item->itemnumber,
469
        item_id   => $item->itemnumber,
457
        issue_id  => $checkout->issue_id,
470
        issue_id  => $checkout->issue_id,
458
        type      => 'fine',
471
        type      => 'overdue',
459
    });
472
    });
460
473
461
    my $line_checkout = $line->checkout;
474
    my $line_checkout = $line->checkout;
462
- 

Return to bug 22521