Bug 13368 Holds priority messed up on checkout
[srvgit] / C4 / Reserves.pm
index abefa2d..22a9ecb 100644 (file)
@@ -136,6 +136,8 @@ BEGIN {
         &SuspendAll
 
         &GetReservesControlBranch
+
+        IsItemOnHoldAndFound
     );
     @EXPORT_OK = qw( MergeHolds );
 }    
@@ -205,6 +207,7 @@ sub AddReserve {
         $const,          $priority,     $notes,   $checkitem,
         $found,          $waitingdate, $expdate
     );
+    my $reserve_id = $sth->{mysql_insertid};
 
     # Send e-mail to librarian if syspref is active
     if(C4::Context->preference("emailLibrarianWhenHoldIsPlaced")){
@@ -248,7 +251,7 @@ sub AddReserve {
         $sth->execute($borrowernumber, $biblionumber, $resdate, $_);
     }
         
-    return;     # FIXME: why not have a useful return value?
+    return $reserve_id;
 }
 
 =head2 GetReserve
@@ -1306,7 +1309,7 @@ sub ModReserveFill {
     # now fix the priority on the others (if the priority wasn't
     # already sorted!)....
     unless ( $priority == 0 ) {
-        _FixPriority({ reserve_id => $reserve_id });
+        _FixPriority({ reserve_id => $reserve_id, biblionumber => $biblionumber });
     }
 }
 
@@ -2051,10 +2054,12 @@ sub _koha_notify_reserve {
     };
 
     while ( my ( $mtt, $letter_code ) = each %{ $messagingprefs->{transports} } ) {
-        if ( ($mtt eq 'email' and not $to_address) or ($mtt eq 'sms' and not $borrower->{smsalertnumber}) ) {
-            # email or sms is requested but not exist
-            next;
-        }
+        next if (
+               ( $mtt eq 'email' and not $to_address ) # No email address
+            or ( $mtt eq 'sms'   and not $borrower->{smsalertnumber} ) # No SMS number
+            or ( $mtt eq 'phone' and C4::Context->preference('TalkingTechItivaPhoneNotification') ) # Notice is handled by TalkingTech_itiva_outbound.pl
+        );
+
         &$send_notification($mtt, $letter_code);
         $notification_sent++;
     }
@@ -2411,6 +2416,30 @@ sub CalculatePriority {
     return @row ? $row[0]+1 : 1;
 }
 
+=head2 IsItemOnHoldAndFound
+
+    my $bool = IsItemFoundHold( $itemnumber );
+
+    Returns true if the item is currently on hold
+    and that hold has a non-null found status ( W, T, etc. )
+
+=cut
+
+sub IsItemOnHoldAndFound {
+    my ($itemnumber) = @_;
+
+    my $rs = Koha::Database->new()->schema()->resultset('Reserve');
+
+    my $found = $rs->count(
+        {
+            itemnumber => $itemnumber,
+            found      => { '!=' => undef }
+        }
+    );
+
+    return $found;
+}
+
 =head1 AUTHOR
 
 Koha Development Team <http://koha-community.org/>