1 package C4::Acquisition;
3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
30 use vars qw($VERSION @ISA @EXPORT);
32 # set the version for version checking
33 $VERSION = do { my @v = '$Revision$' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); };
35 # used in receiveorder subroutine
36 # to provide library specific handling
37 my $library_name = C4::Context->preference("LibraryName");
41 C4::Acquisition - Koha functions for dealing with orders and acquisitions
49 The functions in this module deal with acquisitions, managing book
50 orders, basket and parcels.
60 &GetBasket &NewBasket &CloseBasket
61 &GetPendingOrders &GetOrder &GetOrders
62 &GetOrderNumber &GetLateOrders &NewOrder &DelOrder
63 &SearchOrder &GetHistory
64 &ModOrder &ModReceiveOrder &ModOrderBiblioNumber
65 &GetParcels &GetParcel
68 =head2 FUNCTIONS ABOUT BASKETS
74 #------------------------------------------------------------#
80 $aqbasket = &GetBasket($basketnumber);
82 get all basket informations in aqbasket for a given basket
85 informations for a given basket returned as a hashref.
95 my $dbh = C4::Context->dbh;
98 borrowers.firstname+' '+borrowers.surname AS authorisedbyname,
99 borrowers.branchcode AS branch
101 LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
104 my $sth=$dbh->prepare($query);
105 $sth->execute($basketno);
106 return ( $sth->fetchrow_hashref );
109 #------------------------------------------------------------#
115 $basket = &NewBasket();
117 Create a new basket in aqbasket table
123 # FIXME : this function seems to be unused.
126 my ( $booksellerid, $authorisedby ) = @_;
127 my $dbh = C4::Context->dbh;
130 (creationdate,booksellerid,authorisedby)
131 VALUES (now(),'$booksellerid','$authorisedby')
136 #find & return basketno MYSQL dependant, but $dbh->last_insert_id always returns null :-(
137 my $basket = $dbh->{'mysql_insertid'};
141 #------------------------------------------------------------#
147 &CloseBasket($basketno);
149 close a basket (becomes unmodifiable,except for recieves)
157 my $dbh = C4::Context->dbh;
163 my $sth = $dbh->prepare($query);
164 $sth->execute($basketno);
167 #------------------------------------------------------------#
171 =head2 FUNCTIONS ABOUT ORDERS
177 #------------------------------------------------------------#
179 =head3 GetPendingOrders
183 $orders = &GetPendingOrders($booksellerid);
185 Finds pending orders from the bookseller with the given ID. Ignores
186 completed and cancelled orders.
188 C<$orders> is a reference-to-array; each element is a
189 reference-to-hash with the following fields:
193 =item C<authorizedby>
199 These give the value of the corresponding field in the aqorders table
200 of the Koha database.
206 Results are ordered from most to least recent.
210 sub GetPendingOrders {
212 my $dbh = C4::Context->dbh;
214 SELECT count(*),authorisedby,creationdate,aqbasket.basketno,
215 closedate,surname,firstname,aqorders.title
217 LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno
218 LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
220 AND (quantity > quantityreceived OR quantityreceived is NULL)
221 AND datecancellationprinted IS NULL
222 AND (to_days(now())-to_days(closedate) < 180 OR closedate IS NULL)
224 if ( C4::Context->preference("IndependantBranches") ) {
225 my $userenv = C4::Context->userenv;
226 if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
228 " and (borrowers.branchcode = '"
230 . "' or borrowers.branchcode ='')";
233 $strsth .= " group by basketno order by aqbasket.basketno";
234 my $sth = $dbh->prepare($strsth);
235 $sth->execute($supplierid);
237 while ( my $data = $sth->fetchrow_hashref ) {
238 push( @results, $data );
244 #------------------------------------------------------------#
250 @orders = &GetOrders($basketnumber, $orderby);
252 Looks up the pending (non-cancelled) orders with the given basket
253 number. If C<$booksellerID> is non-empty, only orders from that seller
257 C<&basket> returns a two-element array. C<@orders> is an array of
258 references-to-hash, whose keys are the fields from the aqorders,
259 biblio, and biblioitems tables in the Koha database.
266 my ( $basketno, $orderby ) = @_;
267 my $dbh = C4::Context->dbh;
269 SELECT aqorderbreakdown.*,
270 biblio.*,biblioitems.*,
273 FROM aqorders,biblio,biblioitems
274 LEFT JOIN aqorderbreakdown ON
275 aqorders.ordernumber=aqorderbreakdown.ordernumber
277 AND biblio.biblionumber=aqorders.biblionumber
278 AND biblioitems.biblioitemnumber=aqorders.biblioitemnumber
279 AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
282 $orderby = "biblioitems.publishercode" unless $orderby;
283 $query .= " ORDER BY $orderby";
284 my $sth = $dbh->prepare($query);
285 $sth->execute($basketno);
289 while ( my $data = $sth->fetchrow_hashref ) {
290 push @results, $data;
296 #------------------------------------------------------------#
298 =head3 GetOrderNumber
302 $ordernumber = &GetOrderNumber($biblioitemnumber, $biblionumber);
304 Looks up the ordernumber with the given biblionumber and biblioitemnumber.
306 Returns the number of this order.
308 =item C<$ordernumber> is the order number.
314 my ( $biblionumber,$biblioitemnumber ) = @_;
315 my $dbh = C4::Context->dbh;
320 AND biblioitemnumber=?
322 my $sth = $dbh->prepare($query);
323 $sth->execute( $biblionumber, $biblioitemnumber );
325 return $sth->fetchrow;
328 #------------------------------------------------------------#
334 $order = &GetOrder($ordernumber);
336 Looks up an order by order number.
338 Returns a reference-to-hash describing the order. The keys of
339 C<$order> are fields from the biblio, biblioitems, aqorders, and
340 aqorderbreakdown tables of the Koha database.
348 my $dbh = C4::Context->dbh;
351 FROM biblio,biblioitems,aqorders
352 LEFT JOIN aqorderbreakdown ON aqorders.ordernumber=aqorderbreakdown.ordernumber
353 WHERE aqorders.ordernumber=?
354 AND biblio.biblionumber=aqorders.biblionumber
355 AND biblioitems.biblioitemnumber=aqorders.biblioitemnumber
357 my $sth= $dbh->prepare($query);
358 $sth->execute($ordnum);
359 my $data = $sth->fetchrow_hashref;
364 #------------------------------------------------------------#
370 &NewOrder($basket, $biblionumber, $title, $quantity, $listprice,
371 $booksellerid, $who, $notes, $bookfund, $biblioitemnumber, $rrp,
372 $ecost, $gst, $budget, $unitprice, $subscription,
373 $booksellerinvoicenumber);
375 Adds a new order to the database. Any argument that isn't described
376 below is the new value of the field with the same name in the aqorders
377 table of the Koha database.
379 C<$ordnum> is a "minimum order number." After adding the new entry to
380 the aqorders table, C<&neworder> finds the first entry in aqorders
381 with order number greater than or equal to C<$ordnum>, and adds an
382 entry to the aqorderbreakdown table, with the order number just found,
383 and the book fund ID of the newly-added order.
385 C<$budget> is effectively ignored.
387 C<$subscription> may be either "yes", or anything else for "no".
395 $basketno, $bibnum, $title, $quantity,
396 $listprice, $booksellerid, $authorisedby, $notes,
397 $bookfund, $bibitemnum, $rrp, $ecost,
398 $gst, $budget, $cost, $sub,
399 $invoice, $sort1, $sort2
403 my $year = localtime->year() + 1900;
404 my $month = localtime->mon() + 1; # months starts at 0, add 1
406 if ( !$budget || $budget eq 'now' ) {
410 # if month is july or more, budget start is 1 jul, next year.
411 elsif ( $month >= '7' ) {
412 ++$year; # add 1 to year , coz its next year
413 $budget = "'$year-07-01'";
417 # START OF NEW BUDGET, 1ST OF JULY, THIS YEAR
418 $budget = "'$year-07-01'";
421 if ( $sub eq 'yes' ) {
428 # if $basket empty, it's also a new basket, create it
430 $basketno = NewBasket( $booksellerid, $authorisedby );
433 my $dbh = C4::Context->dbh;
436 ( biblionumber,title,basketno,quantity,listprice,notes,
437 biblioitemnumber,rrp,ecost,gst,unitprice,subscription,sort1,sort2,budgetdate,entrydate)
438 VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,$budget,now() )
440 my $sth = $dbh->prepare($query);
443 $bibnum, $title, $basketno, $quantity, $listprice,
444 $notes, $bibitemnum, $rrp, $ecost, $gst,
445 $cost, $sub, $sort1, $sort2
449 #get ordnum MYSQL dependant, but $dbh->last_insert_id returns null
450 my $ordnum = $dbh->{'mysql_insertid'};
452 INSERT INTO aqorderbreakdown (ordernumber,bookfundid)
455 $sth = $dbh->prepare($query);
456 $sth->execute( $ordnum, $bookfund );
458 return ( $basketno, $ordnum );
461 #------------------------------------------------------------#
467 &ModOrder($title, $ordernumber, $quantity, $listprice,
468 $biblionumber, $basketno, $supplier, $who, $notes,
469 $bookfundid, $bibitemnum, $rrp, $ecost, $gst, $budget,
470 $unitprice, $booksellerinvoicenumber);
472 Modifies an existing order. Updates the order with order number
473 C<$ordernumber> and biblionumber C<$biblionumber>. All other arguments
474 update the fields with the same name in the aqorders table of the Koha
477 Entries with order number C<$ordernumber> in the aqorderbreakdown
478 table are also updated to the new book fund ID.
486 $title, $ordnum, $quantity, $listprice, $bibnum,
487 $basketno, $supplier, $who, $notes, $bookfund,
488 $bibitemnum, $rrp, $ecost, $gst, $budget,
489 $cost, $invoice, $sort1, $sort2
492 my $dbh = C4::Context->dbh;
496 quantity=?,listprice=?,basketno=?,
497 rrp=?,ecost=?,unitprice=?,booksellerinvoicenumber=?,
498 notes=?,sort1=?, sort2=?
499 WHERE ordernumber=? AND biblionumber=?
501 my $sth = $dbh->prepare($query);
503 $title, $quantity, $listprice, $basketno, $rrp,
504 $ecost, $cost, $invoice, $notes, $sort1,
505 $sort2, $ordnum, $bibnum
509 UPDATE aqorderbreakdown
513 $sth = $dbh->prepare($query);
515 unless ( $sth->execute( $bookfund, $ordnum ) )
516 { # zero rows affected [Bug 734]
518 INSERT INTO aqorderbreakdown
519 (ordernumber,bookfundid)
522 $sth = $dbh->prepare($query);
523 $sth->execute( $ordnum, $bookfund );
528 #------------------------------------------------------------#
530 =head3 ModOrderBiblioNumber
534 &ModOrderBiblioNumber($biblioitemnumber,$ordnum, $biblionumber);
536 Modifies the biblioitemnumber for an existing order.
537 Updates the order with order number C<$ordernum> and biblionumber C<$biblionumber>.
543 sub ModOrderBiblioNumber {
544 my ($biblioitemnumber,$ordnum, $biblionumber) = @_;
545 my $dbh = C4::Context->dbh;
548 SET biblioitemnumber = ?
549 WHERE ordernumber = ?
550 AND biblionumber = ?";
551 my $sth = $dbh->prepare($query);
552 $sth->execute( $biblioitemnumber, $ordnum, $biblionumber );
555 #------------------------------------------------------------#
557 =head3 ModReceiveOrder
561 &ModReceiveOrder($biblionumber, $ordernumber, $quantityreceived, $user,
562 $unitprice, $booksellerinvoicenumber, $biblioitemnumber,
563 $freight, $bookfund, $rrp);
565 Updates an order, to reflect the fact that it was received, at least
566 in part. All arguments not mentioned below update the fields with the
567 same name in the aqorders table of the Koha database.
569 Updates the order with bibilionumber C<$biblionumber> and ordernumber
572 Also updates the book fund ID in the aqorderbreakdown table.
579 sub ModReceiveOrder {
581 $biblio, $ordnum, $quantrec, $user, $cost,
582 $invoiceno, $freight, $rrp, $bookfund
585 my $dbh = C4::Context->dbh;
588 SET quantityreceived=?,datereceived=now(),booksellerinvoicenumber=?,
589 unitprice=?,freight=?,rrp=?
590 WHERE biblionumber=? AND ordernumber=?
592 my $sth = $dbh->prepare($query);
593 my $suggestionid = GetSuggestionFromBiblionumber( $dbh, $biblio );
595 ModStatus( $suggestionid, 'AVAILABLE', '', $biblio );
597 $sth->execute( $quantrec, $invoiceno, $cost, $freight, $rrp, $biblio,
601 # Allows libraries to change their bookfund during receiving orders
602 # allows them to adjust budgets
603 if ( C4::Context->preferene("LooseBudgets") ) {
605 UPDATE aqorderbreakdown
609 my $sth = $dbh->prepare($query);
610 $sth->execute( $bookfund, $ordnum );
615 #------------------------------------------------------------#
619 @results = &SearchOrder($search, $biblionumber, $complete);
623 C<$search> may take one of several forms: if it is an ISBN,
624 C<&ordersearch> returns orders with that ISBN. If C<$search> is an
625 order number, C<&ordersearch> returns orders with that order number
626 and biblionumber C<$biblionumber>. Otherwise, C<$search> is considered
627 to be a space-separated list of search terms; in this case, all of the
628 terms must appear in the title (matching the beginning of title
631 If C<$complete> is C<yes>, the results will include only completed
632 orders. In any case, C<&ordersearch> ignores cancelled orders.
634 C<&ordersearch> returns an array.
635 C<@results> is an array of references-to-hash with the following keys:
652 my ( $search, $id, $biblio, $catview ) = @_;
653 my $dbh = C4::Context->dbh;
654 my @data = split( ' ', $search );
657 @searchterms = ($id);
659 map { push( @searchterms, "$_%", "% $_%" ) } @data;
660 push( @searchterms, $search, $search, $biblio );
664 "SELECT *,biblio.title FROM aqorders,biblioitems,biblio,aqbasket
665 WHERE aqorders.biblioitemnumber = biblioitems.biblioitemnumber AND
666 aqorders.basketno = aqbasket.basketno
667 AND aqbasket.booksellerid = ?
668 AND biblio.biblionumber=aqorders.biblionumber
669 AND ((datecancellationprinted is NULL)
670 OR (datecancellationprinted = '0000-00-00'))
674 map { "(biblio.title like ? or biblio.title like ?)" } @data )
676 . ") OR biblioitems.isbn=? OR (aqorders.ordernumber=? AND aqorders.biblionumber=?)) ";
681 " SELECT *,biblio.title
682 FROM aqorders,biblioitems,biblio,aqbasket
683 WHERE aqorders.biblioitemnumber = biblioitems.biblioitemnumber
684 AND aqorders.basketno = aqbasket.basketno
685 AND biblio.biblionumber=aqorders.biblionumber
686 AND ((datecancellationprinted is NULL)
687 OR (datecancellationprinted = '0000-00-00'))
688 AND (aqorders.quantityreceived < aqorders.quantity OR aqorders.quantityreceived is NULL)
692 map { "(biblio.title like ? OR biblio.title like ?)" } @data )
694 . ") or biblioitems.isbn=? OR (aqorders.ordernumber=? AND aqorders.biblionumber=?)) ";
696 $query .= " GROUP BY aqorders.ordernumber";
697 my $sth = $dbh->prepare($query);
698 $sth->execute(@searchterms);
705 my $sth2 = $dbh->prepare($query2);
708 FROM aqorderbreakdown
711 my $sth3 = $dbh->prepare($query3);
713 while ( my $data = $sth->fetchrow_hashref ) {
714 $sth2->execute( $data->{'biblionumber'} );
715 my $data2 = $sth2->fetchrow_hashref;
716 $data->{'author'} = $data2->{'author'};
717 $data->{'seriestitle'} = $data2->{'seriestitle'};
718 $sth3->execute( $data->{'ordernumber'} );
719 my $data3 = $sth3->fetchrow_hashref;
720 $data->{'branchcode'} = $data3->{'branchcode'};
721 $data->{'bookfundid'} = $data3->{'bookfundid'};
722 push( @results, $data );
730 #------------------------------------------------------------#
736 &DelOrder($biblionumber, $ordernumber);
738 Cancel the order with the given order and biblio numbers. It does not
739 delete any entries in the aqorders table, it merely marks them as
747 my ( $bibnum, $ordnum ) = @_;
748 my $dbh = C4::Context->dbh;
751 SET datecancellationprinted=now()
752 WHERE biblionumber=? AND ordernumber=?
754 my $sth = $dbh->prepare($query);
755 $sth->execute( $bibnum, $ordnum );
764 =head2 FUNCTIONS ABOUT PARCELS
770 #------------------------------------------------------------#
776 @results = &GetParcel($booksellerid, $code, $date);
778 Looks up all of the received items from the supplier with the given
779 bookseller ID at the given date, for the given code (bookseller Invoice number). Ignores cancelled and completed orders.
781 C<@results> is an array of references-to-hash. The keys of each element are fields from
782 the aqorders, biblio, and biblioitems tables of the Koha database.
784 C<@results> is sorted alphabetically by book title.
792 #gets all orders from a certain supplier, orders them alphabetically
793 my ( $supplierid, $code, $datereceived ) = @_;
794 my $dbh = C4::Context->dbh;
797 if $code; # add % if we search on a given code (otherwise, let him empty)
804 aqorders.biblionumber,
806 aqorders.ordernumber,
808 aqorders.quantityreceived,
813 FROM aqorders,aqbasket
814 LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
815 WHERE aqbasket.basketno=aqorders.basketno
816 AND aqbasket.booksellerid=?
817 AND aqorders.booksellerinvoicenumber LIKE \"$code\"
818 AND aqorders.datereceived= \'$datereceived\'";
820 if ( C4::Context->preference("IndependantBranches") ) {
821 my $userenv = C4::Context->userenv;
822 if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
824 " and (borrowers.branchcode = '"
826 . "' or borrowers.branchcode ='')";
829 $strsth .= " order by aqbasket.basketno";
830 ### parcelinformation : $strsth
831 my $sth = $dbh->prepare($strsth);
832 $sth->execute($supplierid);
833 while ( my $data = $sth->fetchrow_hashref ) {
834 push( @results, $data );
836 ### countparcelbiblio: $count
842 #------------------------------------------------------------#
848 $results = &GetParcels($bookseller, $order, $code, $datefrom, $dateto);
849 get a lists of parcels.
854 is the bookseller this function has to get parcels.
857 To know on what criteria the results list has to be ordered.
860 is the booksellerinvoicenumber.
862 =item $datefrom & $dateto
863 to know on what date this function has to filter its search.
866 a pointer on a hash list containing parcel informations as such :
872 =item Number of biblio
874 =item Number of items
881 my ($bookseller,$order, $code, $datefrom, $dateto) = @_;
882 my $dbh = C4::Context->dbh;
884 SELECT aqorders.booksellerinvoicenumber,
886 count(DISTINCT biblionumber) AS biblio,
887 sum(quantity) AS itemsexpected,
888 sum(quantityreceived) AS itemsreceived
889 FROM aqorders, aqbasket
890 WHERE aqbasket.basketno = aqorders.basketno
891 AND aqbasket.booksellerid = $bookseller and datereceived IS NOT NULL
894 $strsth .= "and aqorders.booksellerinvoicenumber like \"$code%\" " if ($code);
896 $strsth .= "and datereceived >=" . $dbh->quote($datefrom) . " " if ($datefrom);
898 $strsth .= "and datereceived <=" . $dbh->quote($dateto) . " " if ($dateto);
900 $strsth .= "group by aqorders.booksellerinvoicenumber,datereceived ";
901 $strsth .= "order by $order " if ($order);
902 my $sth = $dbh->prepare($strsth);
907 while ( my $data2 = $sth->fetchrow_hashref ) {
908 push @results, $data2;
915 #------------------------------------------------------------#
921 @results = &GetLateOrders;
923 Searches for bookseller with late orders.
926 the table of supplier with late issues. This table is full of hashref.
934 my $supplierid = shift;
937 my $dbh = C4::Context->dbh;
939 #BEWARE, order of parenthesis and LEFT JOIN is important for speed
941 my $dbdriver = C4::Context->config("db_scheme") || "mysql";
944 if ( $dbdriver eq "mysql" ) {
946 SELECT aqbasket.basketno,
947 DATE(aqbasket.closedate) AS orderdate,
948 aqorders.quantity - IFNULL(aqorders.quantityreceived,0) AS quantity,
949 aqorders.rrp AS unitpricesupplier,
950 aqorders.ecost AS unitpricelib,
951 (aqorders.quantity - IFNULL(aqorders.quantityreceived,0)) * aqorders.rrp AS subtotal,
952 aqbookfund.bookfundname AS budget,
953 borrowers.branchcode AS branch,
954 aqbooksellers.name AS supplier,
957 biblioitems.publishercode AS publisher,
958 biblioitems.publicationyear,
959 DATEDIFF(CURDATE( ),closedate) AS latesince
961 (aqorders LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber)
962 LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber)
963 LEFT JOIN aqorderbreakdown ON aqorders.ordernumber = aqorderbreakdown.ordernumber)
964 LEFT JOIN aqbookfund ON aqorderbreakdown.bookfundid = aqbookfund.bookfundid),
965 (aqbasket LEFT JOIN borrowers ON aqbasket.authorisedby = borrowers.borrowernumber)
966 LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
967 WHERE aqorders.basketno = aqbasket.basketno
968 AND (closedate < DATE_SUB(CURDATE( ),INTERVAL $delay DAY))
969 AND ((datereceived = '' OR datereceived is null)
970 OR (aqorders.quantityreceived < aqorders.quantity) )
972 $strsth .= " AND aqbasket.booksellerid = $supplierid " if ($supplierid);
973 $strsth .= " AND borrowers.branchcode like \'" . $branch . "\'"
976 " AND borrowers.branchcode like \'"
977 . C4::Context->userenv->{branch} . "\'"
978 if ( C4::Context->preference("IndependantBranches")
979 && C4::Context->userenv
980 && C4::Context->userenv->{flags} != 1 );
981 $strsth .=" HAVING quantity<>0
982 AND unitpricesupplier<>0
984 ORDER BY latesince,basketno,borrowers.branchcode, supplier
989 SELECT aqbasket.basketno,
990 DATE(aqbasket.closedate) AS orderdate,
991 aqorders.quantity, aqorders.rrp AS unitpricesupplier,
992 aqorders.ecost as unitpricelib,
993 aqorders.quantity * aqorders.rrp AS subtotal
994 aqbookfund.bookfundname AS budget,
995 borrowers.branchcode AS branch,
996 aqbooksellers.name AS supplier,
999 biblioitems.publishercode AS publisher,
1000 biblioitems.publicationyear,
1001 (CURDATE - closedate) AS latesince
1003 (aqorders LEFT JOIN biblio on biblio.biblionumber = aqorders.biblionumber)
1004 LEFT JOIN biblioitems on biblioitems.biblionumber=biblio.biblionumber)
1005 LEFT JOIN aqorderbreakdown on aqorders.ordernumber = aqorderbreakdown.ordernumber)
1006 LEFT JOIN aqbookfund ON aqorderbreakdown.bookfundid = aqbookfund.bookfundid),
1007 (aqbasket LEFT JOIN borrowers on aqbasket.authorisedby = borrowers.borrowernumber) LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
1008 WHERE aqorders.basketno = aqbasket.basketno
1009 AND (closedate < (CURDATE -(INTERVAL $delay DAY))
1010 AND ((datereceived = '' OR datereceived is null)
1011 OR (aqorders.quantityreceived < aqorders.quantity) ) ";
1012 $strsth .= " AND aqbasket.booksellerid = $supplierid " if ($supplierid);
1014 $strsth .= " AND borrowers.branchcode like \'" . $branch . "\'" if ($branch);
1015 $strsth .=" AND borrowers.branchcode like \'". C4::Context->userenv->{branch} . "\'"
1016 if (C4::Context->preference("IndependantBranches") && C4::Context->userenv->{flags} != 1 );
1017 $strsth .=" ORDER BY latesince,basketno,borrowers.branchcode, supplier";
1019 my $sth = $dbh->prepare($strsth);
1023 while ( my $data = $sth->fetchrow_hashref ) {
1024 $data->{hilighted} = $hilighted if ( $hilighted > 0 );
1025 $data->{orderdate} = format_date( $data->{orderdate} );
1026 push @results, $data;
1027 $hilighted = -$hilighted;
1033 #------------------------------------------------------------#
1039 (\@order_loop, $total_qty, $total_price, $total_qtyreceived)=&GetHistory( $title, $author, $name, $from_placed_on, $to_placed_on )
1041 this function get the search history.
1048 my ( $title, $author, $name, $from_placed_on, $to_placed_on ) = @_;
1051 my $total_qtyreceived = 0;
1052 my $total_price = 0;
1054 # don't run the query if there are no parameters (list would be too long for sure !)
1055 if ( $title || $author || $name || $from_placed_on || $to_placed_on ) {
1056 my $dbh = C4::Context->dbh;
1062 name,aqbasket.creationdate,
1063 aqorders.datereceived,
1065 aqorders.quantityreceived,
1067 aqorders.ordernumber
1068 FROM aqorders,aqbasket,aqbooksellers,biblio";
1070 $query .= ",borrowers "
1071 if ( C4::Context->preference("IndependantBranches") );
1074 WHERE aqorders.basketno=aqbasket.basketno
1075 AND aqbasket.booksellerid=aqbooksellers.id
1076 AND biblio.biblionumber=aqorders.biblionumber ";
1078 $query .= " AND aqbasket.authorisedby=borrowers.borrowernumber"
1079 if ( C4::Context->preference("IndependantBranches") );
1081 $query .= " AND biblio.title LIKE " . $dbh->quote( "%" . $title . "%" )
1085 " AND biblio.author LIKE " . $dbh->quote( "%" . $author . "%" )
1088 $query .= " AND name LIKE " . $dbh->quote( "%" . $name . "%" ) if $name;
1090 $query .= " AND creationdate >" . $dbh->quote($from_placed_on)
1093 $query .= " AND creationdate<" . $dbh->quote($to_placed_on)
1096 if ( C4::Context->preference("IndependantBranches") ) {
1097 my $userenv = C4::Context->userenv;
1098 if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
1100 " AND (borrowers.branchcode = '"
1101 . $userenv->{branch}
1102 . "' OR borrowers.branchcode ='')";
1105 $query .= " ORDER BY booksellerid";
1106 my $sth = $dbh->prepare($query);
1109 while ( my $line = $sth->fetchrow_hashref ) {
1110 $line->{count} = $cnt++;
1111 $line->{toggle} = 1 if $cnt % 2;
1112 push @order_loop, $line;
1113 $line->{creationdate} = format_date( $line->{creationdate} );
1114 $line->{datereceived} = format_date( $line->{datereceived} );
1115 $total_qty += $line->{'quantity'};
1116 $total_qtyreceived += $line->{'quantityreceived'};
1117 $total_price += $line->{'quantity'} * $line->{'ecost'};
1120 return \@order_loop, $total_qty, $total_price, $total_qtyreceived;
1123 END { } # module clean-up code here (global destructor)
1133 Koha Developement team <info@koha.org>