From 20e67d93e111e2526cad89607d5f2a6361c7d96e Mon Sep 17 00:00:00 2001
From: Matthias Meusburger <matthias.meusburger@biblibre.com>
Date: Wed, 25 Sep 2019 15:30:51 +0200
Subject: [PATCH] Bug 25812: Display overdue fines for the document on SIP
 checkin.

Test plan:

 - Using SIP, checkin an item that has one or several overdue fines.
 - Check that the following message is displayed (AF field):
   "You owe {correctly formatted price} for this document."
---
 C4/SIP/ILS.pm | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/C4/SIP/ILS.pm b/C4/SIP/ILS.pm
index 7cff9c0579..5a7cef0335 100644
--- a/C4/SIP/ILS.pm
+++ b/C4/SIP/ILS.pm
@@ -239,6 +239,21 @@ sub checkin {
         delete $item->{borrowernumber};
         delete $item->{due_date};
         $patron->{items} = [ grep { $_ ne $item_id } @{ $patron->{items} } ];
+        # Check for overdue fines to display
+        my $kohaitem = Koha::Items->find( { barcode => $item_id } );
+        if ($kohaitem) {
+            my $charges = Koha::Account::Lines->search(
+                {
+                    borrowernumber    => $patron->{borrowernumber},
+                    amountoutstanding => { '>' => 0 },
+                    accounttype       => [ 'OVERDUE' ],
+                    itemnumber        => $kohaitem->itemnumber
+                },
+            );
+            if ($charges) {
+                $circ->screen_msg("You owe " . Koha::Number::Price->new( $charges->total_outstanding )->format({ with_symbol => 1}) . " for this document.");
+            }
+        }
     } else {
         # Checkin failed: Wrongbranch or withdrawn?
         # Bug 10748 with pref BlockReturnOfLostItems adds another case to come
-- 
2.11.0