From db26976957026848a874cb31f846ac4c9c944348 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Fri, 3 May 2019 15:44:35 +0100
Subject: [PATCH] Bug 19919: Do not record payments for a writeoff

---
 C4/Circulation.pm | 18 ++++++++++--------
 Koha/Account.pm   |  2 +-
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index b9ff0f2824..c66a85855b 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -3663,16 +3663,18 @@ sub DeleteBranchTransferLimits {
 }
 
 sub ReturnLostItem{
-    my ( $borrowernumber, $itemnum ) = @_;
+    my ( $borrowernumber, $itemnum, $offset_type ) = @_;
 
     MarkIssueReturned( $borrowernumber, $itemnum );
-    my $patron = Koha::Patrons->find( $borrowernumber );
-    my $item = Koha::Items->find($itemnum);
-    my $old_note = ($item->paidfor && ($item->paidfor ne q{})) ? $item->paidfor.' / ' : q{};
-    my @datearr = localtime(time);
-    my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
-    my $bor = $patron->firstname . ' ' . $patron->surname . ' ' . $patron->cardnumber;
-    ModItem({ paidfor =>  $old_note."Paid for by $bor $date" }, undef, $itemnum);
+    if ( $offset_type ne 'Writeoff' ) {
+        my $patron = Koha::Patrons->find( $borrowernumber );
+        my $item = Koha::Items->find($itemnum);
+        my $old_note = ($item->paidfor && ($item->paidfor ne q{})) ? $item->paidfor.' / ' : q{};
+        my @datearr = localtime(time);
+        my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
+        my $bor = $patron->firstname . ' ' . $patron->surname . ' ' . $patron->cardnumber;
+        ModItem({ paidfor =>  $old_note."Paid for by $bor $date" }, undef, $itemnum);
+    }
 }
 
 
diff --git a/Koha/Account.pm b/Koha/Account.pm
index 9d66e70f7c..b84f989003 100644
--- a/Koha/Account.pm
+++ b/Koha/Account.pm
@@ -110,7 +110,7 @@ sub pay {
 
         if ( $fine->itemnumber && $fine->accounttype && ( $fine->accounttype eq 'L' ) )
         {
-            C4::Circulation::ReturnLostItem( $self->{patron_id}, $fine->itemnumber );
+            C4::Circulation::ReturnLostItem( $self->{patron_id}, $fine->itemnumber, $offset_type );
         }
 
         my $account_offset = Koha::Account::Offset->new(
-- 
2.20.1