# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
-# $Id$
use strict;
require Exporter;
use C4::Context;
-use C4::Date;
+use C4::Dates qw(format_date);
use MARC::Record;
use C4::Suggestions;
use Time::localtime;
use vars qw($VERSION @ISA @EXPORT);
# set the version for version checking
-$VERSION = do { my @v = '$Revision$' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); };
+$VERSION = 3.01;
# used in receiveorder subroutine
# to provide library specific handling
my $dbh = C4::Context->dbh;
my $query = "
SELECT aqbasket.*,
- borrowers.firstname+' '+borrowers.surname AS authorisedbyname,
- borrowers.branchcode AS branch
+ concat( b.firstname,' ',b.surname) AS authorisedbyname,
+ b.branchcode AS branch
FROM aqbasket
- LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
+ LEFT JOIN borrowers b ON aqbasket.authorisedby=b.borrowernumber
WHERE basketno=?
";
my $sth=$dbh->prepare($query);
$sth->execute($basketno);
- return ( $sth->fetchrow_hashref );
+ my $basket = $sth->fetchrow_hashref;
+ return ( $basket );
}
#------------------------------------------------------------#
my $dbh = C4::Context->dbh;
my $query ="
SELECT aqorderbreakdown.*,
- biblio.*,biblioitems.*,
+ biblio.*,biblioitems.publishercode,
aqorders.*,
aqbookfund.bookfundname,
biblio.title
FROM aqorders
LEFT JOIN aqorderbreakdown ON aqorders.ordernumber=aqorderbreakdown.ordernumber
- LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber
- LEFT JOIN biblioitems ON biblioitems.biblioitemnumber=aqorders.biblioitemnumber
LEFT JOIN aqbookfund ON aqbookfund.bookfundid=aqorderbreakdown.bookfundid
+ LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber
+ LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber
WHERE basketno=?
AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
";
- $orderby = "biblioitems.publishercode" unless $orderby;
+ $orderby = "biblioitems.publishercode,biblio.title" unless $orderby;
$query .= " ORDER BY $orderby";
my $sth = $dbh->prepare($query);
$sth->execute($basketno);
&NewOrder($basket, $biblionumber, $title, $quantity, $listprice,
$booksellerid, $who, $notes, $bookfund, $biblioitemnumber, $rrp,
$ecost, $gst, $budget, $unitprice, $subscription,
- $booksellerinvoicenumber);
+ $booksellerinvoicenumber, $purchaseorder);
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
$listprice, $booksellerid, $authorisedby, $notes,
$bookfund, $bibitemnum, $rrp, $ecost,
$gst, $budget, $cost, $sub,
- $invoice, $sort1, $sort2
+ $invoice, $sort1, $sort2, $purchaseorder
)
= @_;
my $query = "
INSERT INTO aqorders
( biblionumber,title,basketno,quantity,listprice,notes,
- biblioitemnumber,rrp,ecost,gst,unitprice,subscription,sort1,sort2,budgetdate,entrydate)
- VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,$budget,now() )
+ biblioitemnumber,rrp,ecost,gst,unitprice,subscription,sort1,sort2,budgetdate,entrydate,purchaseordernumber)
+ VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,$budget,now(),? )
";
my $sth = $dbh->prepare($query);
$sth->execute(
$bibnum, $title, $basketno, $quantity, $listprice,
$notes, $bibitemnum, $rrp, $ecost, $gst,
- $cost, $sub, $sort1, $sort2
+ $cost, $sub, $sort1, $sort2, $purchaseorder
);
$sth->finish;
$title, $ordnum, $quantity, $listprice, $bibnum,
$basketno, $supplier, $who, $notes, $bookfund,
$bibitemnum, $rrp, $ecost, $gst, $budget,
- $cost, $invoice, $sort1, $sort2
+ $cost, $invoice, $sort1, $sort2, $purchaseorder
)
= @_;
my $dbh = C4::Context->dbh;
SET title=?,
quantity=?,listprice=?,basketno=?,
rrp=?,ecost=?,unitprice=?,booksellerinvoicenumber=?,
- notes=?,sort1=?, sort2=?
+ notes=?,sort1=?, sort2=?, purchaseordernumber=?
WHERE ordernumber=? AND biblionumber=?
";
my $sth = $dbh->prepare($query);
$sth->execute(
$title, $quantity, $listprice, $basketno, $rrp,
$ecost, $cost, $invoice, $notes, $sort1,
- $sort2, $ordnum, $bibnum
+ $sort2, $purchaseorder,
+ $ordnum, $bibnum
);
$sth->finish;
$query = "
in part. All arguments not mentioned below update the fields with the
same name in the aqorders table of the Koha database.
+If a partial order is received, splits the order into two. The received
+portion must have a booksellerinvoicenumber.
+
Updates the order with bibilionumber C<$biblionumber> and ordernumber
C<$ordernumber>.
sub ModReceiveOrder {
my (
$biblionumber, $ordnum, $quantrec, $user, $cost,
- $invoiceno, $freight, $rrp, $bookfund, $daterecieved
+ $invoiceno, $freight, $rrp, $bookfund, $datereceived
)
= @_;
my $dbh = C4::Context->dbh;
# warn "DATE BEFORE : $daterecieved";
- $daterecieved=POSIX::strftime("%Y-%m-%d",CORE::localtime) unless $daterecieved;
+# $daterecieved=POSIX::strftime("%Y-%m-%d",CORE::localtime) unless $daterecieved;
# warn "DATE REC : $daterecieved";
- my $query = "
- UPDATE aqorders
- SET quantityreceived=?,datereceived=?,booksellerinvoicenumber=?,
- unitprice=?,freight=?,rrp=?
- WHERE biblionumber=? AND ordernumber=?
- ";
- my $sth = $dbh->prepare($query);
+ $datereceived = C4::Dates->output('iso') unless $datereceived;
my $suggestionid = GetSuggestionFromBiblionumber( $dbh, $biblionumber );
if ($suggestionid) {
ModStatus( $suggestionid, 'AVAILABLE', '', $biblionumber );
}
- $sth->execute( $quantrec,$daterecieved, $invoiceno, $cost, $freight, $rrp, $biblionumber,
- $ordnum);
- $sth->finish;
-
# Allows libraries to change their bookfund during receiving orders
# allows them to adjust budgets
- if ( C4::Context->preferene("LooseBudgets") ) {
+ if ( C4::Context->preference("LooseBudgets") && $bookfund ) {
my $query = "
UPDATE aqorderbreakdown
SET bookfundid=?
$sth->execute( $bookfund, $ordnum );
$sth->finish;
}
- return $daterecieved;
+
+ my $sth=$dbh->prepare("SELECT * FROM aqorders LEFT JOIN aqorderbreakdown ON aqorders.ordernumber=aqorderbreakdown.ordernumber
+ WHERE biblionumber=? AND aqorders.ordernumber=?");
+ $sth->execute($biblionumber,$ordnum);
+ my $order = $sth->fetchrow_hashref();
+ $sth->finish();
+
+ if ( $order->{quantity} > $quantrec ) {
+ $sth=$dbh->prepare("update aqorders
+ set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?,
+ unitprice=?,freight=?,rrp=?,quantity=?
+ where biblionumber=? and ordernumber=?");
+ $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$quantrec,$biblionumber,$ordnum);
+ $sth->finish;
+ # create a new order for the remaining items, and set its bookfund.
+ my $newOrder = NewOrder($order->{'basketno'},$order->{'biblionumber'},$order->{'title'}, $order->{'quantity'} - $quantrec,
+ $order->{'listprice'},$order->{'booksellerid'},$order->{'authorisedby'},$order->{'notes'},
+ $order->{'bookfundid'},$order->{'biblioitemnumber'},$order->{'rrp'},$order->{'ecost'},$order->{'gst'},
+ $order->{'budget'},$order->{'unitcost'},$order->{'sub'},'',$order->{'sort1'},$order->{'sort2'},$order->{'purchaseordernumber'});
+
+ $sth=$dbh->prepare(" insert into aqorderbreakdown (ordernumber, branchcode, bookfundid) values (?,?,?)");
+ $sth->execute($newOrder,$order->{branch},$order->{bookfundid});
+ } else {
+ $sth=$dbh->prepare("update aqorders
+ set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?,
+ unitprice=?,freight=?,rrp=?
+ where biblionumber=? and ordernumber=?");
+ $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblionumber,$ordnum);
+ $sth->finish;
+ }
+ return $datereceived;
}
-
#------------------------------------------------------------#
=head3 SearchOrder
aqorders.listprice,
aqorders.rrp,
aqorders.ecost
- FROM aqorders,aqbasket
+ FROM aqorders
+ LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno
LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
- WHERE aqbasket.basketno=aqorders.basketno
- AND aqbasket.booksellerid=?
+ WHERE
+ aqbasket.booksellerid=?
AND aqorders.booksellerinvoicenumber LIKE \"$code\"
AND aqorders.datereceived= \'$datereceived\'";
my $userenv = C4::Context->userenv;
if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
$strsth .=
- " and (borrowers.branchcode = '"
+ " AND (borrowers.branchcode = '"
. $userenv->{branch}
- . "' or borrowers.branchcode ='')";
+ . "' OR borrowers.branchcode ='')";
}
}
- $strsth .= " order by aqbasket.basketno";
+ $strsth .= " ORDER BY aqbasket.basketno";
### parcelinformation : $strsth
+ # warn "STH : $strsth";
my $sth = $dbh->prepare($strsth);
$sth->execute($supplierid);
while ( my $data = $sth->fetchrow_hashref ) {
my $dbh = C4::Context->dbh;
my $strsth ="
SELECT aqorders.booksellerinvoicenumber,
- datereceived,
+ datereceived,purchaseordernumber,
count(DISTINCT biblionumber) AS biblio,
sum(quantity) AS itemsexpected,
sum(quantityreceived) AS itemsreceived
aqorders.ecost,
aqorders.ordernumber,
aqorders.booksellerinvoicenumber as invoicenumber,
- aqbooksellers.id as id
+ aqbooksellers.id as id,
+ aqorders.biblionumber
FROM aqorders
LEFT JOIN aqbasket ON aqorders.basketno=aqbasket.basketno
- LEFT JOIN aqbooksellers ON aqorders.basketno=aqbasket.basketno
+ LEFT JOIN aqbooksellers ON aqbasket.booksellerid=aqbooksellers.id
LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber";
$query .= " LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber"
$query .= " AND creationdate<" . $dbh->quote($to_placed_on)
if $to_placed_on;
+ $query .= " AND (datecancellationprinted is NULL or datecancellationprinted='0000-00-00')";
if ( C4::Context->preference("IndependantBranches") ) {
my $userenv = C4::Context->userenv;