From 1276f688c36230e42cfb302af7c1e3808c9f7de5 Mon Sep 17 00:00:00 2001
From: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi>
Date: Tue, 23 Feb 2016 11:52:17 +0200
Subject: [PATCH] Bug 9525 - group floating rules - added logging ALWAYS and
 CODITIONAL floats.

SELECT * FROM action_logs WHERE module = "FLOATING";
---
 C4/Circulation.pm | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index 039f9b7..4d14ee0 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -2041,6 +2041,21 @@ sub AddReturn {
             $messages->{'NeedsTransfer'} = 1;   # TODO: instead of 1, specify branchcode that the transfer SHOULD go to, $item->{homebranch}
         }
     }
+    #This elsif-clause copypastes the upper if-clause. This is horrible and I cry, but cannot refactor this mess now :( due to Koha upstream master stuff looming.
+    elsif (($doreturn or $messages->{'NotIssued'})
+        and !$resfound and ($branch ne $hbr)
+        and not($messages->{'WrongTransfer'})
+        && $floatingType){ #So if we would otherwise transfer, but we have a floating rule overriding it.
+                           #We can infer that the transfer was averted because of a floating rule.
+        #Make sure we dont log the same floating denial multiple times
+        #So first check if we already logged this operation.
+        my $logs = C4::Log::GetLogs(DateTime->now(time_zone => C4::Context->tz),
+                                    DateTime->now(time_zone => C4::Context->tz),
+                                    undef, ['FLOATING'], undef, $item->{'itemnumber'}, "$branch -> $hbr denied");
+        if (not($logs) || (ref($logs) eq 'ARRAY' && scalar(@$logs) == 0)) {
+            C4::Log::logaction("FLOATING", $floatingType, $item->{'itemnumber'}, "$branch -> $hbr denied");
+        }
+    }
     return ( $doreturn, $messages, $issue, $borrower );
 }
 
-- 
1.9.1