Merge commit 'kc/master'
[koha.git] / C4 / Reserves.pm
index 4ca555f..bcb27bb 100644 (file)
@@ -57,7 +57,8 @@ This modules provides somes functions to deal with reservations.
   - priority >0      : then the reserve is at 1st stage, and not yet affected to any item.
              =0      : then the reserve is being dealed
   - found : NULL       : means the patron requested the 1st available, and we haven't choosen the item
-            W(aiting)  : the reserve has an itemnumber affected, and is on the way
+            T(ransit)  : the reserve is linked to an item but is in transit to the pickup branch
+            W(aiting)  : the reserve is linked to an item, is at the pickup branch, and is waiting on the hold shelf
             F(inished) : the reserve has been completed, and is done
   - itemnumber : empty : the reserve is still unaffected to an item
                  filled: the reserve is attached to an item
@@ -67,15 +68,15 @@ This modules provides somes functions to deal with reservations.
   a library having it run "transfertodo", and clic on the list    
          if there is no transfer to do, the reserve waiting
          patron can pick it up                                    P =0, F=W,    I=filled 
-         if there is a transfer to do, write in branchtransfer    P =0, F=NULL, I=filled
+         if there is a transfer to do, write in branchtransfer    P =0, F=T,    I=filled
            The pickup library recieve the book, it check in       P =0, F=W,    I=filled
   The patron borrow the book                                      P =0, F=F,    I=filled
   
   ==== 2nd use case ====
   patron requests a document, a given item,
     If pickup is holding branch                                   P =0, F=W,   I=filled
-    If transfer needed, write in branchtransfer                   P =0, F=NULL, I=filled
-        The pickup library recieve the book, it checks it in      P =0, F=W,    I=filled
+    If transfer needed, write in branchtransfer                   P =0, F=T,    I=filled
+        The pickup library receive the book, it checks it in      P =0, F=W,    I=filled
   The patron borrow the book                                      P =0, F=F,    I=filled
 
 =head1 FUNCTIONS
@@ -1005,7 +1006,7 @@ sub CancelReserve {
         $sth->execute( $biblio, $borr );
 
         # now fix the priority on the others....
-        _FixPriority( $priority, $biblio );
+        _FixPriority( $biblio, $borr );
     }
 }
 
@@ -1151,7 +1152,7 @@ sub ModReserveFill {
     # now fix the priority on the others (if the priority wasn't
     # already sorted!)....
     unless ( $priority == 0 ) {
-        _FixPriority( $priority, $biblionumber );
+        _FixPriority( $biblionumber, $borrowernumber );
     }
 }
 
@@ -1222,7 +1223,8 @@ sub ModReserveAffect {
     $query = "
         UPDATE reserves
         SET    priority = 0,
-               itemnumber = ?
+               itemnumber = ?,
+               found = 'T'
         WHERE borrowernumber = ?
           AND biblionumber = ?
     ";
@@ -1509,13 +1511,13 @@ sub _FixPriority {
      }
     if ( $rank eq "W" || $rank eq "0" ) {
 
-        # make sure priority for waiting items is 0
+        # make sure priority for waiting or in-transit items is 0
         my $query = qq/
             UPDATE reserves
             SET    priority = 0
             WHERE biblionumber = ?
               AND borrowernumber = ?
-              AND found ='W'
+              AND found IN ('W', 'T')
         /;
         my $sth = $dbh->prepare($query);
         $sth->execute( $biblio, $borrowernumber );
@@ -1532,7 +1534,7 @@ sub _FixPriority {
         SELECT borrowernumber, reservedate, constrainttype
         FROM   reserves
         WHERE  biblionumber   = ?
-          AND  ((found <> 'W') or found is NULL)
+          AND  ((found <> 'W' AND found <> 'T') or found is NULL)
         ORDER BY priority ASC
     /;
     my $sth = $dbh->prepare($query);