@@ -, +, @@ --- C4/Overdues.pm | 5 +--- Koha/Account/Line.pm | 23 ++++++++----------- .../data/mysql/atomicupdate/bug_21747.perl | 21 +++++++++++++++++ 3 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_21747.perl --- a/C4/Overdues.pm +++ a/C4/Overdues.pm @@ -573,12 +573,9 @@ sub UpdateFine { } if ( $data ) { - # we're updating an existing fine. Only modify if amount changed - # Note that in the current implementation, you cannot pay against an accruing fine - # (i.e. , of accounttype 'FU'). Doing so will break accrual. if ( $data->{'amount'} != $amount ) { my $accountline = Koha::Account::Lines->find( $data->{accountlines_id} ); - $accountline->adjust({ amount => $amount, type => 'fine_increment' }); + $accountline->adjust({ amount => $amount, type => 'fine_update' }); } } else { if ( $amount ) { # Don't add new fines with an amount of 0 --- a/Koha/Account/Line.pm +++ a/Koha/Account/Line.pm @@ -220,7 +220,7 @@ This method allows updating a debit or credit on a patron's account ); $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. @@ -236,7 +236,7 @@ sub adjust { 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' ); @@ -258,6 +258,9 @@ sub adjust { my $amount_outstanding_before = $self->amountoutstanding; my $difference = $amount - $amount_before; my $new_outstanding = $amount_outstanding_before + $difference; + my $offset_type = + substr( $update_type, 0, index( $update_type, '_' ) ) + . ( $difference > 0 ) ? "_increment" : "_decrement"; # Catch cases that require patron refunds if ( $new_outstanding < 0 ) { @@ -268,7 +271,7 @@ sub adjust { 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; @@ -280,7 +283,7 @@ sub adjust { date => \'NOW()', amount => $amount, amountoutstanding => $new_outstanding, - ( $update_type eq 'fine_increment' ? ( lastincrement => $difference ) : ()), + ( $update_type eq 'fine_update' ? ( lastincrement => $difference ) : ()), } )->store(); @@ -288,7 +291,7 @@ sub adjust { 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(); @@ -310,7 +313,7 @@ sub adjust { manager_id => undef, } ) - ) if ( $update_type eq 'fine_increment' ); + ) if ( $update_type eq 'fine_update' ); } } ); @@ -358,17 +361,11 @@ sub _type { =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 --- a/installer/data/mysql/atomicupdate/bug_21747.perl +++ a/installer/data/mysql/atomicupdate/bug_21747.perl @@ -0,0 +1,21 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + $dbh->do(q{ + INSERT IGNORE INTO account_offset_types ( type ) VALUES ( 'fine_increment', 'fine_decrement' ); + }); + + $dbh->do(q{ + UPDATE account_offsets SET type = 'fine_increment' WHERE type = 'Fine Update' AND amount > 0; + }); + + $dbh->do(q{ + UPDATE account_offsets SET type = 'fine_decrement' WHERE type = 'Fine Update' AND amount < 0; + }); + + $dbh->do(q{ + DELETE FROM account_offset_types WHERE type = 'Fine Update'; + }); + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 21747 - Update account_offset_types to include 'fine_increment' and 'fine_decrement')\n"; +} --