use MARC::Record;
use C4::Suggestions;
use C4::Debug;
+use C4::SQLHelper qw(InsertInTable);
use Time::localtime;
use HTML::Entities;
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
#------------------------------------------------------------#
+=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
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;
=item $hashref->{'uncertainprice'} may be 0 for "the price is known" or 1 for "the price is uncertain"
+=item defaults entrydate to Now
+
The following keys are used: "biblionumber", "title", "basketno", "quantity", "notes", "biblioitemnumber", "rrp", "ecost", "gst", "unitprice", "subscription", "sort1", "sort2", "booksellerinvoicenumber", "listprice", "budgetdate", "purchaseordernumber", "branchcode", "booksellerinvoicenumber", "bookfundid".
=back
} else {
$orderinfo->{'subscription'} = 0;
}
+ $orderinfo->{'entrydate'} ||= C4::Dates->new()->output("iso");
- my $query = "INSERT INTO aqorders (";
- foreach my $orderinfokey (keys %{$orderinfo}) {
- next if $orderinfokey =~ m/branchcode|entrydate/; # skip branchcode and entrydate, branchcode isnt a vaild col, entrydate we add manually with NOW()
- $query .= "$orderinfokey,";
- push(@params, $orderinfo->{$orderinfokey});
- }
-
- $query .= "entrydate) VALUES (";
- foreach (@params) {
- $query .= "?,";
- }
- $query .= " NOW() )"; #ADDING CURRENT DATE TO 'budgetdate, entrydate, purchaseordernumber'...
-
- my $sth = $dbh->prepare($query);
-
- $sth->execute(@params);
- $sth->finish;
-
- #get ordnum MYSQL dependant, but $dbh->last_insert_id returns null
- my $ordnum = $dbh->{'mysql_insertid'};
-
- $sth->finish;
+ my $ordnum=InsertInTable("aqorders",$orderinfo);
return ( $orderinfo->{'basketno'}, $ordnum );
}
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;
}
#------------------------------------------------------------#