From 67de32a468c53f0a964bb14052aa4fafa93cb5c8 Mon Sep 17 00:00:00 2001
From: Christopher Brannon <cbrannon@cdalibrary.org>
Date: Thu, 1 Nov 2018 20:21:08 +0000
Subject: [PATCH] Bug 21346: Streamline logic in holds and transfers

1) Replaced comparison with string to make testing branch easier.
2) Replaced useless 0 values with undef.

Does not change any behavior, only simplifies code.
---
 circ/returns.pl | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/circ/returns.pl b/circ/returns.pl
index c2f20efd91..4dd74b2452 100755
--- a/circ/returns.pl
+++ b/circ/returns.pl
@@ -415,12 +415,12 @@ if ( $messages->{'ResFound'}) {
     my $reserve    = $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" && C4::Context->preference('HoldsAutoFill') ) {
         my $item = Koha::Items->find( $itemnumber );
         my $biblio = $item->biblio;
 
-        my $diffBranchSend = ($userenv_branch ne $reserve->{branchcode}) ? $reserve->{branchcode} : undef;
+        my $diffBranchSend = !$branchCheck ? $reserve->{branchcode} : undef;
         ModReserveAffect( $reserve->{itemnumber}, $reserve->{borrowernumber}, $diffBranchSend, $reserve->{reserve_id} );
         my ( $messages, $nextreservinfo ) = GetOtherReserves($reserve->{itemnumber});
 
@@ -447,12 +447,12 @@ if ( $messages->{'ResFound'}) {
     elsif ( $reserve->{'ResFound'} eq "Waiting" or $reserve->{'ResFound'} eq "Reserved" ) {
         if ( $reserve->{'ResFound'} eq "Waiting" ) {
             $template->param(
-                waiting      => ($userenv_branch eq $reserve->{'branchcode'} ? 1 : 0 ),
+                waiting      => $branchCheck ? 1 : undef,
             );
         } elsif ( $reserve->{'ResFound'} eq "Reserved" ) {
             $template->param(
-                intransit    => ($userenv_branch eq $reserve->{'branchcode'} ? 0 : 1 ),
-                transfertodo => ($userenv_branch eq $reserve->{'branchcode'} ? 0 : 1 ),
+                intransit    => $branchCheck ? undef : 1,
+                transfertodo => $branchCheck ? undef : 1,
                 reserve_id   => $reserve->{reserve_id},
                 reserved     => 1,
             );
-- 
2.11.0