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 258-263 sub adjust { Link Here
258
            my $amount_outstanding_before = $self->amountoutstanding;
258
            my $amount_outstanding_before = $self->amountoutstanding;
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
            my $offset_type =
262
              substr( $update_type, 0, index( $update_type, '_' ) )
263
              . ( $difference > 0 ) ? "_increment" : "_decrement";
261
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 ) {
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 (-1 / +21 lines)
Line 0 Link Here
0
- 
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
}

Return to bug 21747