Followup Adding system preference XSLT*FileName
[koha.git] / C4 / Acquisition.pm
index a599fdd..88f0c6d 100644 (file)
@@ -62,12 +62,8 @@ orders, basket and parcels.
 
 =head1 FUNCTIONS
 
-=over 2
-
 =head2 FUNCTIONS ABOUT BASKETS
 
-=over 2
-
 =head3 GetBasket
 
 =over 4
@@ -81,8 +77,6 @@ informations for a given basket returned as a hashref.
 
 =back
 
-=back
-
 =cut
 
 sub GetBasket {
@@ -162,12 +156,8 @@ sub CloseBasket {
 
 #------------------------------------------------------------#
 
-=back
-
 =head2 FUNCTIONS ABOUT ORDERS
 
-=over 2
-
 =cut
 
 #------------------------------------------------------------#
@@ -206,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,
@@ -216,10 +206,15 @@ 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 ";
+    }else{
+        $strsth .= "AND (to_days(now())-to_days(closedate) < 180 OR closedate IS NULL)";
+    }
     ## FIXME  Why 180 days ???
     my @query_params = ( $supplierid );
     if ( C4::Context->preference("IndependantBranches") ) {
@@ -266,7 +261,7 @@ sub GetOrders {
     my $dbh   = C4::Context->dbh;
     my $query  ="
          SELECT  aqorderbreakdown.*,
-                biblio.*,biblioitems.publishercode,
+                biblio.*,biblioitems.*,
                 aqorders.*,
                 aqbookfund.bookfundname,
                 biblio.title
@@ -300,10 +295,14 @@ sub GetOrders {
 
 $ordernumber = &GetOrderNumber($biblioitemnumber, $biblionumber);
 
+=back
+
 Looks up the ordernumber with the given biblionumber and biblioitemnumber.
 
 Returns the number of this order.
 
+=over 4
+
 =item C<$ordernumber> is the order number.
 
 =back
@@ -370,7 +369,7 @@ sub GetOrder {
   &NewOrder($basket, $biblionumber, $title, $quantity, $listprice,
     $booksellerid, $who, $notes, $bookfund, $biblioitemnumber, $rrp,
     $ecost, $gst, $budget, $unitprice, $subscription,
-    $booksellerinvoicenumber, $purchaseorder);
+    $booksellerinvoicenumber, $purchaseorder, $branchcode);
 
 Adds a new order to the database. Any argument that isn't described
 below is the new value of the field with the same name in the aqorders
@@ -398,7 +397,8 @@ sub NewOrder {
         $listprice, $booksellerid, $authorisedby, $notes,
         $bookfund,  $bibitemnum,   $rrp,          $ecost,
         $gst,       $budget,       $cost,         $sub,
-        $invoice,   $sort1,        $sort2,        $purchaseorder
+        $invoice,   $sort1,        $sort2,        $purchaseorder,
+               $branchcode
       )
       = @_;
 
@@ -454,11 +454,11 @@ sub NewOrder {
     #get ordnum MYSQL dependant, but $dbh->last_insert_id returns null
     my $ordnum = $dbh->{'mysql_insertid'};
     $query = "
-        INSERT INTO aqorderbreakdown (ordernumber,bookfundid)
-        VALUES (?,?)
+        INSERT INTO aqorderbreakdown (ordernumber,bookfundid, branchcode)
+        VALUES (?,?,?)
     ";
     $sth = $dbh->prepare($query);
-    $sth->execute( $ordnum, $bookfund );
+    $sth->execute( $ordnum, $bookfund, $branchcode );
     $sth->finish;
     return ( $basketno, $ordnum );
 }
@@ -679,7 +679,7 @@ C<@results> is an array of references-to-hash with the following keys:
 =cut
 
 sub SearchOrder {
-    my ( $search, $id, $biblionumber, $catview ) = @_;
+    my ( $search, $id, $biblionumber ) = @_;
     my $dbh = C4::Context->dbh;
     my @data = split( ' ', $search );
     my @searchterms;
@@ -690,7 +690,20 @@ 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(not $id and $biblionumber and $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 ((datecancellationprinted is NULL)
+            OR (datecancellationprinted = '0000-00-00'))
+            AND aqorders.biblionumber = ?
+            AND aqorders.ordernumber = ? 
+            ";
+            @searchterms = ($biblionumber, $search);
+    }
+    elsif($id) {  
         $query =
           "SELECT *,biblio.title 
            FROM aqorders 
@@ -706,7 +719,6 @@ sub SearchOrder {
                 map { "(biblio.title like ? or biblio.title like ?)" } @data )
           )
           . ") OR biblioitems.isbn=? OR (aqorders.ordernumber=? AND aqorders.biblionumber=?)) ";
-
     }
     else {
         $query =
@@ -725,6 +737,7 @@ sub SearchOrder {
           )
           . ") or biblioitems.isbn=? OR (aqorders.ordernumber=? AND aqorders.biblionumber=?)) ";
     }
+    
     $query .= " GROUP BY aqorders.ordernumber";
     ### $query
     my $sth = $dbh->prepare($query);
@@ -790,13 +803,8 @@ sub DelOrder {
     $sth->finish;
 }
 
-
-=back
-
 =head2 FUNCTIONS ABOUT PARCELS
 
-=over 2
-
 =cut
 
 #------------------------------------------------------------#
@@ -880,8 +888,12 @@ sub GetParcel {
 $results = &GetParcels($bookseller, $order, $code, $datefrom, $dateto);
 get a lists of parcels.
 
+=back
+
 * Input arg :
 
+=over 4
+
 =item $bookseller
 is the bookseller this function has to get parcels.
 
@@ -1130,6 +1142,7 @@ sub GetHistory {
         
         if ( defined $title ) {
             $query .= " AND biblio.title LIKE ? ";
+            $title =~ s/\s+/%/g;
             push @query_params, "%$title%";
         }
 
@@ -1207,8 +1220,6 @@ sub GetRecentAcqui {
 1;
 __END__
 
-=back
-
 =head1 AUTHOR
 
 Koha Developement team <info@koha.org>