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

(-)a/C4/Overdues.pm (-4 / +1 lines)
Lines 573-584 sub UpdateFine { Link Here
573
    }
573
    }
574
574
575
    if ( $data ) {
575
    if ( $data ) {
576
        # we're updating an existing fine.  Only modify if amount changed
577
        # Note that in the current implementation, you cannot pay against an accruing fine
578
        # (i.e. , of accounttype 'FU').  Doing so will break accrual.
579
        if ( $data->{'amount'} != $amount ) {
576
        if ( $data->{'amount'} != $amount ) {
580
            my $accountline = Koha::Account::Lines->find( $data->{accountlines_id} );
577
            my $accountline = Koha::Account::Lines->find( $data->{accountlines_id} );
581
            $accountline->adjust({ amount => $amount, type => 'fine_increment' });
578
            $accountline->adjust({ amount => $amount, type => 'fine_update' });
582
        }
579
        }
583
    } else {
580
    } else {
584
        if ( $amount ) { # Don't add new fines with an amount of 0
581
        if ( $amount ) { # Don't add new fines with an amount of 0
(-)a/Koha/Account/Line.pm (-13 / +10 lines)
Lines 220-226 This method allows updating a debit or credit on a patron's account Link Here
220
    );
220
    );
221
221
222
$update_type can be any of:
222
$update_type can be any of:
223
  - fine_increment
223
  - fine_update
224
224
225
Authors Note: The intention here is that this method is only used
225
Authors Note: The intention here is that this method is only used
226
to adjust accountlines where the final amount is not yet known/fixed.
226
to adjust accountlines where the final amount is not yet known/fixed.
Lines 236-242 sub adjust { Link Here
236
    my $amount       = $params->{amount};
236
    my $amount       = $params->{amount};
237
    my $update_type  = $params->{type};
237
    my $update_type  = $params->{type};
238
238
239
    unless ( exists($Koha::Account::Line::offset_type->{$update_type}) ) {
239
    unless ( exists($Koha::Account::Line::allowed_update->{$update_type}) ) {
240
        Koha::Exceptions::Account::UnrecognisedType->throw(
240
        Koha::Exceptions::Account::UnrecognisedType->throw(
241
            error => 'Update type not recognised'
241
            error => 'Update type not recognised'
242
        );
242
        );
Lines 259-264 sub adjust { Link Here
259
            my $difference                = $amount - $amount_before;
259
            my $difference                = $amount - $amount_before;
260
            my $new_outstanding           = $amount_outstanding_before + $difference;
260
            my $new_outstanding           = $amount_outstanding_before + $difference;
261
261
262
            my $offset_type = substr( $update_type, 0, index( $update_type, '_' ) );
263
            $offset_type .= ( $difference > 0 ) ? "_increment" : "_decrement";
264
262
            # Catch cases that require patron refunds
265
            # Catch cases that require patron refunds
263
            if ( $new_outstanding < 0 ) {
266
            if ( $new_outstanding < 0 ) {
264
                my $account =
267
                my $account =
Lines 268-274 sub adjust { Link Here
268
                        amount      => $new_outstanding * -1,
271
                        amount      => $new_outstanding * -1,
269
                        description => 'Overpayment refund',
272
                        description => 'Overpayment refund',
270
                        type        => 'credit',
273
                        type        => 'credit',
271
                        ( $update_type eq 'fine_increment' ? ( item_id => $self->itemnumber ) : ()),
274
                        ( $update_type eq 'fine_update' ? ( item_id => $self->itemnumber ) : ()),
272
                    }
275
                    }
273
                );
276
                );
274
                $new_outstanding = 0;
277
                $new_outstanding = 0;
Lines 280-286 sub adjust { Link Here
280
                    date              => \'NOW()',
283
                    date              => \'NOW()',
281
                    amount            => $amount,
284
                    amount            => $amount,
282
                    amountoutstanding => $new_outstanding,
285
                    amountoutstanding => $new_outstanding,
283
                    ( $update_type eq 'fine_increment' ? ( lastincrement => $difference ) : ()),
286
                    ( $update_type eq 'fine_update' ? ( lastincrement => $difference ) : ()),
284
                }
287
                }
285
            )->store();
288
            )->store();
286
289
Lines 288-294 sub adjust { Link Here
288
            my $account_offset = Koha::Account::Offset->new(
291
            my $account_offset = Koha::Account::Offset->new(
289
                {
292
                {
290
                    debit_id => $self->id,
293
                    debit_id => $self->id,
291
                    type     => $Koha::Account::Line::offset_type->{$update_type},
294
                    type     => $offset_type,
292
                    amount   => $difference
295
                    amount   => $difference
293
                }
296
                }
294
            )->store();
297
            )->store();
Lines 310-316 sub adjust { Link Here
310
                            manager_id        => undef,
313
                            manager_id        => undef,
311
                        }
314
                        }
312
                    )
315
                    )
313
                ) if ( $update_type eq 'fine_increment' );
316
                ) if ( $update_type eq 'fine_update' );
314
            }
317
            }
315
        }
318
        }
316
    );
319
    );
Lines 358-374 sub _type { Link Here
358
361
359
=head2 Name mappings
362
=head2 Name mappings
360
363
361
=head3 $offset_type
362
363
=cut
364
365
our $offset_type = { 'fine_increment' => 'Fine Update', };
366
367
=head3 $allowed_update
364
=head3 $allowed_update
368
365
369
=cut
366
=cut
370
367
371
our $allowed_update = { 'fine_increment' => 'FU', };
368
our $allowed_update = { 'fine_update' => 'FU', };
372
369
373
=head1 AUTHORS
370
=head1 AUTHORS
374
371
(-)a/installer/data/mysql/atomicupdate/bug_21747.perl (+21 lines)
Line 0 Link Here
1
$DBversion = 'XXX';  # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do(q{
4
        INSERT IGNORE INTO account_offset_types ( type ) VALUES ( 'fine_increment' ), ( 'fine_decrement' );
5
    });
6
7
    $dbh->do(q{
8
        UPDATE account_offsets SET type = 'fine_increment' WHERE type = 'Fine Update' AND amount > 0;
9
    });
10
11
    $dbh->do(q{
12
        UPDATE account_offsets SET type = 'fine_decrement' WHERE type = 'Fine Update' AND amount < 0;
13
    });
14
15
    $dbh->do(q{
16
        DELETE FROM account_offset_types WHERE type = 'Fine Update';
17
    });
18
19
    SetVersion( $DBversion );
20
    print "Upgrade to $DBversion done (Bug 21747 - Update account_offset_types to include 'fine_increment' and 'fine_decrement')\n";
21
}
(-)a/t/db_dependent/Koha/Account/Lines.t (-10 / +9 lines)
Lines 336-347 subtest 'adjust() tests' => sub { Link Here
336
    throws_ok { $debit_1->adjust( { amount => 50, type => 'bad' } ) }
336
    throws_ok { $debit_1->adjust( { amount => 50, type => 'bad' } ) }
337
    qr/Update type not recognised/, 'Exception thrown for unrecognised type';
337
    qr/Update type not recognised/, 'Exception thrown for unrecognised type';
338
338
339
    throws_ok { $debit_1->adjust( { amount => 50, type => 'fine_increment' } ) }
339
    throws_ok { $debit_1->adjust( { amount => 50, type => 'fine_update' } ) }
340
    qr/Update type not allowed on this accounttype/,
340
    qr/Update type not allowed on this accounttype/,
341
      'Exception thrown for type conflict';
341
      'Exception thrown for type conflict';
342
342
343
    # Increment an unpaid fine
343
    # Increment an unpaid fine
344
    $debit_2->adjust( { amount => 150, type => 'fine_increment' } )->discard_changes;
344
    $debit_2->adjust( { amount => 150, type => 'fine_update' } )->discard_changes;
345
345
346
    is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' );
346
    is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' );
347
    is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' );
347
    is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' );
Lines 352-358 subtest 'adjust() tests' => sub { Link Here
352
    is( $offsets->count, 1, 'An offset is generated for the increment' );
352
    is( $offsets->count, 1, 'An offset is generated for the increment' );
353
    my $THIS_offset = $offsets->next;
353
    my $THIS_offset = $offsets->next;
354
    is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' );
354
    is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' );
355
    is( $THIS_offset->type, 'Fine Update', 'Adjust type stored correctly' );
355
    is( $THIS_offset->type, 'fine_increment', 'Adjust type stored correctly' );
356
356
357
    is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' );
357
    is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' );
358
358
Lines 368-374 subtest 'adjust() tests' => sub { Link Here
368
    t::lib::Mocks::mock_preference( 'FinesLog', 1 );
368
    t::lib::Mocks::mock_preference( 'FinesLog', 1 );
369
369
370
    # Increment the partially paid fine
370
    # Increment the partially paid fine
371
    $debit_2->adjust( { amount => 160, type => 'fine_increment' } )->discard_changes;
371
    $debit_2->adjust( { amount => 160, type => 'fine_update' } )->discard_changes;
372
372
373
    is( $debit_2->amount * 1, 160, 'Fine amount was updated in full' );
373
    is( $debit_2->amount * 1, 160, 'Fine amount was updated in full' );
374
    is( $debit_2->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' );
374
    is( $debit_2->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' );
Lines 378-389 subtest 'adjust() tests' => sub { Link Here
378
    is( $offsets->count, 3, 'An offset is generated for the increment' );
378
    is( $offsets->count, 3, 'An offset is generated for the increment' );
379
    $THIS_offset = $offsets->last;
379
    $THIS_offset = $offsets->last;
380
    is( $THIS_offset->amount * 1, 10, 'Amount was calculated correctly (increment by 10)' );
380
    is( $THIS_offset->amount * 1, 10, 'Amount was calculated correctly (increment by 10)' );
381
    is( $THIS_offset->type, 'Fine Update', 'Adjust type stored correctly' );
381
    is( $THIS_offset->type, 'fine_increment', 'Adjust type stored correctly' );
382
382
383
    is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' );
383
    is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' );
384
384
385
    # Decrement the partially paid fine, less than what was paid
385
    # Decrement the partially paid fine, less than what was paid
386
    $debit_2->adjust( { amount => 50, type => 'fine_increment' } )->discard_changes;
386
    $debit_2->adjust( { amount => 50, type => 'fine_update' } )->discard_changes;
387
387
388
    is( $debit_2->amount * 1, 50, 'Fine amount was updated in full' );
388
    is( $debit_2->amount * 1, 50, 'Fine amount was updated in full' );
389
    is( $debit_2->amountoutstanding * 1, 10, 'Fine amountoutstanding was updated by difference' );
389
    is( $debit_2->amountoutstanding * 1, 10, 'Fine amountoutstanding was updated by difference' );
Lines 393-402 subtest 'adjust() tests' => sub { Link Here
393
    is( $offsets->count, 4, 'An offset is generated for the decrement' );
393
    is( $offsets->count, 4, 'An offset is generated for the decrement' );
394
    $THIS_offset = $offsets->last;
394
    $THIS_offset = $offsets->last;
395
    is( $THIS_offset->amount * 1, -110, 'Amount was calculated correctly (decrement by 110)' );
395
    is( $THIS_offset->amount * 1, -110, 'Amount was calculated correctly (decrement by 110)' );
396
    is( $THIS_offset->type, 'Fine Update', 'Adjust type stored correctly' );
396
    is( $THIS_offset->type, 'fine_decrement', 'Adjust type stored correctly' );
397
397
398
    # Decrement the partially paid fine, more than what was paid
398
    # Decrement the partially paid fine, more than what was paid
399
    $debit_2->adjust( { amount => 30, type => 'fine_increment' } )->discard_changes;
399
    $debit_2->adjust( { amount => 30, type => 'fine_update' } )->discard_changes;
400
    is( $debit_2->amount * 1, 30, 'Fine amount was updated in full' );
400
    is( $debit_2->amount * 1, 30, 'Fine amount was updated in full' );
401
    is( $debit_2->amountoutstanding * 1, 0, 'Fine amountoutstanding was zeroed (payment was 40)' );
401
    is( $debit_2->amountoutstanding * 1, 0, 'Fine amountoutstanding was zeroed (payment was 40)' );
402
    is( $debit_2->lastincrement * 1, -20, 'lastincrement is the to the right value' );
402
    is( $debit_2->lastincrement * 1, -20, 'lastincrement is the to the right value' );
Lines 405-411 subtest 'adjust() tests' => sub { Link Here
405
    is( $offsets->count, 5, 'An offset is generated for the decrement' );
405
    is( $offsets->count, 5, 'An offset is generated for the decrement' );
406
    $THIS_offset = $offsets->last;
406
    $THIS_offset = $offsets->last;
407
    is( $THIS_offset->amount * 1, -20, 'Amount was calculated correctly (decrement by 20)' );
407
    is( $THIS_offset->amount * 1, -20, 'Amount was calculated correctly (decrement by 20)' );
408
    is( $THIS_offset->type, 'Fine Update', 'Adjust type stored correctly' );
408
    is( $THIS_offset->type, 'fine_decrement', 'Adjust type stored correctly' );
409
409
410
    my $overpayment_refund = $account->lines->last;
410
    my $overpayment_refund = $account->lines->last;
411
    is( $overpayment_refund->amount * 1, -10, 'A new credit has been added' );
411
    is( $overpayment_refund->amount * 1, -10, 'A new credit has been added' );
412
- 

Return to bug 21747