);
$update_type can be any of:
- - fine_increment
+ - fine_update
Authors Note: The intention here is that this method is only used
to adjust accountlines where the final amount is not yet known/fixed.
my $amount = $params->{amount};
my $update_type = $params->{type};
- unless ( exists($Koha::Account::Line::offset_type->{$update_type}) ) {
+ unless ( exists($Koha::Account::Line::allowed_update->{$update_type}) ) {
Koha::Exceptions::Account::UnrecognisedType->throw(
error => 'Update type not recognised'
);
my $difference = $amount - $amount_before;
my $new_outstanding = $amount_outstanding_before + $difference;
+ my $offset_type = substr( $update_type, 0, index( $update_type, '_' ) );
+ $offset_type .= ( $difference > 0 ) ? "_increase" : "_decrease";
+
# Catch cases that require patron refunds
if ( $new_outstanding < 0 ) {
my $account =
amount => $new_outstanding * -1,
description => 'Overpayment refund',
type => 'credit',
- ( $update_type eq 'fine_increment' ? ( item_id => $self->itemnumber ) : ()),
+ ( $update_type eq 'fine_update' ? ( item_id => $self->itemnumber ) : ()),
}
);
$new_outstanding = 0;
date => \'NOW()',
amount => $amount,
amountoutstanding => $new_outstanding,
- ( $update_type eq 'fine_increment' ? ( lastincrement => $difference ) : ()),
+ ( $update_type eq 'fine_update' ? ( lastincrement => $difference ) : ()),
}
)->store();
my $account_offset = Koha::Account::Offset->new(
{
debit_id => $self->id,
- type => $Koha::Account::Line::offset_type->{$update_type},
+ type => $offset_type,
amount => $difference
}
)->store();
manager_id => undef,
}
)
- ) if ( $update_type eq 'fine_increment' );
+ ) if ( $update_type eq 'fine_update' );
}
}
);
=head2 Name mappings
-=head3 $offset_type
-
-=cut
-
-our $offset_type = { 'fine_increment' => 'Fine Update', };
-
=head3 $allowed_update
=cut
-our $allowed_update = { 'fine_increment' => 'FU', };
+our $allowed_update = { 'fine_update' => 'FU', };
=head1 AUTHORS
throws_ok { $debit_1->adjust( { amount => 50, type => 'bad' } ) }
qr/Update type not recognised/, 'Exception thrown for unrecognised type';
- throws_ok { $debit_1->adjust( { amount => 50, type => 'fine_increment' } ) }
+ throws_ok { $debit_1->adjust( { amount => 50, type => 'fine_update' } ) }
qr/Update type not allowed on this accounttype/,
'Exception thrown for type conflict';
# Increment an unpaid fine
- $debit_2->adjust( { amount => 150, type => 'fine_increment' } )->discard_changes;
+ $debit_2->adjust( { amount => 150, type => 'fine_update' } )->discard_changes;
is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' );
is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' );
is( $offsets->count, 1, 'An offset is generated for the increment' );
my $THIS_offset = $offsets->next;
is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' );
- is( $THIS_offset->type, 'Fine Update', 'Adjust type stored correctly' );
+ is( $THIS_offset->type, 'fine_increase', 'Adjust type stored correctly' );
is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' );
t::lib::Mocks::mock_preference( 'FinesLog', 1 );
# Increment the partially paid fine
- $debit_2->adjust( { amount => 160, type => 'fine_increment' } )->discard_changes;
+ $debit_2->adjust( { amount => 160, type => 'fine_update' } )->discard_changes;
is( $debit_2->amount * 1, 160, 'Fine amount was updated in full' );
is( $debit_2->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' );
is( $offsets->count, 3, 'An offset is generated for the increment' );
$THIS_offset = $offsets->last;
is( $THIS_offset->amount * 1, 10, 'Amount was calculated correctly (increment by 10)' );
- is( $THIS_offset->type, 'Fine Update', 'Adjust type stored correctly' );
+ is( $THIS_offset->type, 'fine_increase', 'Adjust type stored correctly' );
is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' );
# Decrement the partially paid fine, less than what was paid
- $debit_2->adjust( { amount => 50, type => 'fine_increment' } )->discard_changes;
+ $debit_2->adjust( { amount => 50, type => 'fine_update' } )->discard_changes;
is( $debit_2->amount * 1, 50, 'Fine amount was updated in full' );
is( $debit_2->amountoutstanding * 1, 10, 'Fine amountoutstanding was updated by difference' );
is( $offsets->count, 4, 'An offset is generated for the decrement' );
$THIS_offset = $offsets->last;
is( $THIS_offset->amount * 1, -110, 'Amount was calculated correctly (decrement by 110)' );
- is( $THIS_offset->type, 'Fine Update', 'Adjust type stored correctly' );
+ is( $THIS_offset->type, 'fine_decrease', 'Adjust type stored correctly' );
# Decrement the partially paid fine, more than what was paid
- $debit_2->adjust( { amount => 30, type => 'fine_increment' } )->discard_changes;
+ $debit_2->adjust( { amount => 30, type => 'fine_update' } )->discard_changes;
is( $debit_2->amount * 1, 30, 'Fine amount was updated in full' );
is( $debit_2->amountoutstanding * 1, 0, 'Fine amountoutstanding was zeroed (payment was 40)' );
is( $debit_2->lastincrement * 1, -20, 'lastincrement is the to the right value' );
is( $offsets->count, 5, 'An offset is generated for the decrement' );
$THIS_offset = $offsets->last;
is( $THIS_offset->amount * 1, -20, 'Amount was calculated correctly (decrement by 20)' );
- is( $THIS_offset->type, 'Fine Update', 'Adjust type stored correctly' );
+ is( $THIS_offset->type, 'fine_decrease', 'Adjust type stored correctly' );
my $overpayment_refund = $account->lines->last;
is( $overpayment_refund->amount * 1, -10, 'A new credit has been added' );