From ee888ed062b30482f2c598f5b0d4505e4dede690 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joonas=20Kylm=C3=A4l=C3=A4?= <joonas.kylmala@helsinki.fi>
Date: Tue, 13 Apr 2021 11:34:55 +0300
Subject: [PATCH] Bug 28139: Simplify logic for handling found holds in
 returns.pl

We are handling in this if-else block 3 cases:
 - Hold found and waiting
 - Hold found but not waiting AND whether HoldsAutoFill is enabled
 - Hold found but not waiting AND whether HoldsAutoFill disabled

If we simply first handle hold found = Waiting case first then we
don't have to individually list all those other found cases and that
simplifies this code a lot.

To test:
 1. Apply patch
 2. Make sure HoldsAutoFill is disabled
 3. Make item-level hold on branch A
 4. Check-in the item at branch A and you should get pop-up confirming
    the hold, ignore it
 5. Set HoldsAutoFill is enabled
 4. Check-in the item again and you now the hold should have been
    automatically filled
---
 circ/returns.pl | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/circ/returns.pl b/circ/returns.pl
index 07e28f4c47..5e2b0e26e4 100755
--- a/circ/returns.pl
+++ b/circ/returns.pl
@@ -417,7 +417,11 @@ if ( $messages->{'ResFound'}) {
     my $patron = Koha::Patrons->find( $reserve->{borrowernumber} );
     my $holdmsgpreferences =  C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $reserve->{'borrowernumber'}, message_name   => 'Hold_Filled' } );
     my $branchCheck = ( $userenv_branch eq $reserve->{branchcode} );
-    if ( ( $reserve->{'ResFound'} eq "Reserved" || $reserve->{'ResFound'} eq "Processing" || $reserve->{'ResFound'} eq "Transferred" ) && C4::Context->preference('HoldsAutoFill') ) {
+    if ( $reserve->{'ResFound'} eq "Waiting" ) {
+        $template->param(
+            waiting      => $branchCheck ? 1 : undef,
+        );
+    } elsif ( C4::Context->preference('HoldsAutoFill') ) {
         my $item = Koha::Items->find( $itemnumber );
         my $biblio = $item->biblio;
 
@@ -439,18 +443,14 @@ if ( $messages->{'ResFound'}) {
                 diffbranch       => 1,
             );
         }
-    } elsif ( $reserve->{'ResFound'} eq "Waiting" ) {
-        $template->param(
-            waiting      => $branchCheck ? 1 : undef,
-        );
-    } elsif ( $reserve->{'ResFound'} eq "Reserved" || $reserve->{'ResFound'} eq "Processing" || $reserve->{'ResFound'} eq "Transferred" ) {
+    } else {
         $template->param(
             intransit    => $branchCheck ? undef : 1,
             transfertodo => $branchCheck ? undef : 1,
             reserve_id   => $reserve->{reserve_id},
             reserved     => 1,
         );
-    } # else { ; }  # error?
+    }
 
     # same params for Waiting or Reserved
     $template->param(
-- 
2.11.0