(bug #3370) add keyword to MARC field mapping
[srvgit] / C4 / Acquisition.pm
index c4fc0ca..797f0b6 100644 (file)
@@ -37,7 +37,7 @@ BEGIN {
        require Exporter;
        @ISA    = qw(Exporter);
        @EXPORT = qw(
-               &GetBasket &NewBasket &CloseBasket &DelBasket &ModBasket
+               &GetBasket &NewBasket &CloseBasket &CloseBasketgroup &ReOpenBasketgroup &DelBasket &ModBasket
                &ModBasketHeader &GetBasketsByBookseller &GetBasketsByBasketgroup
                &ModBasketgroup &NewBasketgroup &DelBasketgroup &GetBasketgroup
                &GetBasketgroups
@@ -218,6 +218,57 @@ sub CloseBasket {
 
 #------------------------------------------------------------#
 
+=head3 CloseBasketgroup
+
+=over 4
+
+&CloseBasketgroup($basketgroupno);
+
+close a basketgroup
+
+=back
+
+=cut
+
+sub CloseBasketgroup {
+    my ($basketgroupno) = @_;
+    my $dbh        = C4::Context->dbh;
+    my $sth = $dbh->prepare("
+        UPDATE aqbasketgroups
+        SET    closed=1
+        WHERE  id=?
+    ");
+    $sth->execute($basketgroupno);
+}
+
+#------------------------------------------------------------#
+
+=head3 ReOpenBaskergroup($basketgroupno)
+
+=over 4
+
+&ReOpenBaskergroup($basketgroupno);
+
+reopen a basketgroup
+
+=back
+
+=cut
+
+sub ReOpenBasketgroup {
+    my ($basketgroupno) = @_;
+    my $dbh        = C4::Context->dbh;
+    my $sth = $dbh->prepare("
+        UPDATE aqbasketgroups
+        SET    closed=0
+        WHERE  id=?
+    ");
+    $sth->execute($basketgroupno);
+}
+
+#------------------------------------------------------------#
+
+
 =head3 DelBasket
 
 =over 4
@@ -509,12 +560,15 @@ sub ModBasketgroup {
     push(@params, $basketgroupinfo->{'id'});
     my $sth = $dbh->prepare($query);
     $sth->execute(@params);
+    
+    $sth = $dbh->prepare('UPDATE aqbasket SET basketgroupid = NULL WHERE basketgroupid = ?');
+    $sth->execute($basketgroupinfo->{'id'});
+    
     if($basketgroupinfo->{'basketlist'} && @{$basketgroupinfo->{'basketlist'}}){
+        $sth = $dbh->prepare("UPDATE aqbasket SET basketgroupid=? WHERE basketno=?");
         foreach my $basketno (@{$basketgroupinfo->{'basketlist'}}) {
-            my $query2 = "UPDATE aqbasket SET basketgroupid=? WHERE basketno=?";
-            my $sth2 = $dbh->prepare($query2);
-            $sth2->execute($basketgroupinfo->{'id'}, $basketno);
-            $sth2->finish;
+            $sth->execute($basketgroupinfo->{'id'}, $basketno);
+            $sth->finish;
         }
     }
     $sth->finish;
@@ -1170,39 +1224,40 @@ C<@results> is an array of references-to-hash with the following keys:
 
 sub SearchOrder {
 #### -------- SearchOrder-------------------------------
-    my ($ordernumber, $search) = @_;
+    my ($ordernumber, $search, $supplierid, $basket) = @_;
 
-    if ($ordernumber) {
-        my $dbh = C4::Context->dbh;
-        my $query =
-            "SELECT *
-            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)
-                AND (aqorders.ordernumber=?))";
-        my $sth = $dbh->prepare($query);
-        $sth->execute($ordernumber);
-        my $results = $sth->fetchall_arrayref({});
-        $sth->finish;
-        return $results;
-    } else {
-        my $dbh = C4::Context->dbh;
-        my $query =
+    my $dbh = C4::Context->dbh;
+    my @args = ();
+    my $query =
             "SELECT *
             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)
-                AND (biblio.title like ? OR biblioitems.isbn like ?))";
-        my $sth = $dbh->prepare($query);
-        $sth->execute("%$search%","%$search%");
-        my $results = $sth->fetchall_arrayref({});
-        $sth->finish;
-        return $results;
+                WHERE  (datecancellationprinted is NULL)";
+                
+    if($ordernumber){
+        $query .= " AND (aqorders.ordernumber=?)";
+        push @args, $ordernumber;
+    }
+    if($search){
+        $query .= " AND (biblio.title like ? OR biblio.author LIKE ? OR biblioitems.isbn like ?)";
+        push @args, ("%$search%","%$search%","%$search%");
+    }
+    if($supplierid){
+        $query .= "AND aqbasket.booksellerid = ?";
+        push @args, $supplierid;
     }
+    if($basket){
+        $query .= "AND aqorders.basketno = ?";
+        push @args, $basket;
+    }
+
+    my $sth = $dbh->prepare($query);
+    $sth->execute(@args);
+    my $results = $sth->fetchall_arrayref({});
+    $sth->finish;
+    return $results;
 }
 
 #------------------------------------------------------------#