[followup] (bug #3348) last fixes
[koha.git] / C4 / Acquisition.pm
index 9888dc1..b3cd99c 100644 (file)
@@ -196,7 +196,7 @@ Results are ordered from most to least recent.
 =cut
 
 sub GetPendingOrders {
-    my ($supplierid,$grouped) = @_;
+    my ($supplierid,$grouped, $closed) = @_;
     my $dbh = C4::Context->dbh;
     my $strsth = "
         SELECT    ".($grouped?"count(*),":"")."aqbasket.basketno,
@@ -206,10 +206,14 @@ sub GetPendingOrders {
         LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno
         LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
         WHERE booksellerid=?
-            AND (quantity > quantityreceived OR quantityreceived is NULL)
             AND datecancellationprinted IS NULL
             AND (to_days(now())-to_days(closedate) < 180 OR closedate IS NULL)
     ";
+    if($closed){
+        $strsth .= "
+        AND (quantity > quantityreceived OR quantityreceived is NULL) 
+        AND closedate IS NOT NULL ";
+    }
     ## FIXME  Why 180 days ???
     my @query_params = ( $supplierid );
     if ( C4::Context->preference("IndependantBranches") ) {
@@ -685,7 +689,17 @@ sub SearchOrder {
     push( @searchterms, $search, $search, $biblionumber );
     my $query;
   ### FIXME  THIS CAN raise a problem if more THAN ONE biblioitem is linked to one biblio  
-    if ($id) {  
+    if($id and $search){
+        @searchterms = ($id, $search);
+        $query =
+          "SELECT *,biblio.title
+             FROM aqorders
+             LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber
+             LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber
+             LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno
+             WHERE aqbasket.booksellerid = ? AND aqorders.ordernumber = ?
+          "
+    }elsif ($id) {  
         $query =
           "SELECT *,biblio.title 
            FROM aqorders 
@@ -721,8 +735,8 @@ sub SearchOrder {
           . ") or biblioitems.isbn=? OR (aqorders.ordernumber=? AND aqorders.biblionumber=?)) ";
     }
     
-    if( $biblionumber and $biblionumber ne "" ){
-        $query .= "AND aqorders.biblionumber = ? ";
+    if ( $biblionumber ) {
+        $query .= "AND biblio.biblionumber = ? ";
         push (@searchterms, $biblionumber);
     }