From cd6e655c8e5e644f0e6a9df066553fef4ed0df45 Mon Sep 17 00:00:00 2001
From: Josef Moravec <josef.moravec@gmail.com>
Date: Wed, 31 Oct 2018 07:47:55 +0000
Subject: [PATCH] Bug 21678: Use Koha::Account->add_debit

---
 C4/Circulation.pm |  9 ++++++---
 C4/Reserves.pm    | 12 +++++++++---
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index 6b73829..37275a5 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -2878,9 +2878,12 @@ sub AddRenewal {
             . $biblio->title
             . " $item->{'barcode'}";
 
-        C4::Accounts::manualinvoice(
-            $borrowernumber, $itemnumber, $description, 'Rent', $charge
-        );
+        $patron->account->add_debit({
+            amount => $charge,
+            description => $description,
+            type => 'rent',
+            item_id => $itemnumber,
+        });
     }
 
     # Send a renewal slip according to checkout alert preferencei
diff --git a/C4/Reserves.pm b/C4/Reserves.pm
index 464a315..447549e 100644
--- a/C4/Reserves.pm
+++ b/C4/Reserves.pm
@@ -570,9 +570,15 @@ sub ChargeReserveFee {
 
     return if !$fee || $fee == 0;    # the last test is needed to include 0.00
 
-    C4::Accounts::manualinvoice(
-        $borrowernumber, undef, "Reserve Charge - $title", 'Res', $fee
-    );
+    #FIXME - patron should be passed as param, not fetched agian
+    my $patron = Koha::Patrons->find( $borrowernumber );
+    return unless $patron;
+
+    $patron->account->add_debit({
+        amount => $fee,
+        type => 'reserve',
+        description => $title,
+    });
 }
 
 =head2 GetReserveFee
-- 
2.1.4