Bug 21747: Use Koha::Account:: routines in UpdateFine
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 1 Nov 2018 14:55:15 +0000 (14:55 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Wed, 27 Feb 2019 14:14:21 +0000 (09:14 -0500)
Set to use Koha::Account->add_debit and Koha::Account::Line->adjust

Known Side Effect: The format of the FinesLog, if enabled, is changed
after this patch. Prior to this patch the $actionname was left undefined
and the $infos field contained the string:

`"due=".$due."  amount=".$amount." itemnumber=".$itemnum`

After this patch, the logs are more consistent with other FINES logs,
with an $actionname of 'CREATE' or 'UPDATE' and the $infos field
containing a Dumper of fine data.

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
C4/Overdues.pm

index 98e7bbf..7f0394f 100644 (file)
@@ -578,28 +578,7 @@ sub UpdateFine {
         # (i.e. , of accounttype 'FU').  Doing so will break accrual.
         if ( $data->{'amount'} != $amount ) {
             my $accountline = Koha::Account::Lines->find( $data->{accountlines_id} );
-            my $diff = $amount - $data->{'amount'};
-
-            #3341: diff could be positive or negative!
-            my $out   = $data->{'amountoutstanding'} + $diff;
-
-            $accountline->set(
-                {
-                    date          => dt_from_string(),
-                    amount        => $amount,
-                    amountoutstanding   => $out,
-                    lastincrement => $diff,
-                    accounttype   => 'FU',
-                }
-            )->store();
-
-            Koha::Account::Offset->new(
-                {
-                    debit_id => $accountline->id,
-                    type     => 'Fine Update',
-                    amount   => $diff,
-                }
-            )->store();
+            $accountline->adjust({ amount => $amount, type => 'fine_increment' });
         }
     } else {
         if ( $amount ) { # Don't add new fines with an amount of 0
@@ -608,42 +587,23 @@ sub UpdateFine {
             );
             $sth4->execute($itemnum);
             my $title = $sth4->fetchrow;
-
-            my $nextaccntno = C4::Accounts::getnextacctno($borrowernumber);
-
             my $desc = "$title $due";
 
-            my $accountline = Koha::Account::Line->new(
-                {
-                    borrowernumber    => $borrowernumber,
-                    itemnumber        => $itemnum,
-                    date              => dt_from_string(),
-                    amount            => $amount,
-                    description       => $desc,
-                    accounttype       => 'FU',
-                    amountoutstanding => $amount,
-                    lastincrement     => $amount,
-                    accountno         => $nextaccntno,
-                    issue_id          => $issue_id,
-                }
-            )->store();
-
-            Koha::Account::Offset->new(
+            my $account = Koha::Account->new({ patron_id => $borrowernumber });
+            my $accountline = $account->add_debit(
                 {
-                    debit_id => $accountline->id,
-                    type     => 'Fine',
-                    amount   => $amount,
+                    amount      => $amount,
+                    description => $desc,
+                    note        => undef,
+                    user_id     => undef,
+                    library_id  => undef,
+                    type        => 'fine',
+                    item_id     => $itemnum,
+                    issue_id    => $issue_id,
                 }
-            )->store();
+            );
         }
     }
-    # logging action
-    &logaction(
-        "FINES",
-        undef,
-        $borrowernumber,
-        "due=".$due."  amount=".$amount." itemnumber=".$itemnum
-        ) if C4::Context->preference("FinesLog");
 }
 
 =head2 BorType