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
69 =head2 FUNCTIONS ABOUT BASKETS
75 #------------------------------------------------------------#
81 $aqbasket = &GetBasket($basketnumber);
83 get all basket informations in aqbasket for a given basket
86 informations for a given basket returned as a hashref.
96 my $dbh = C4::Context->dbh;
99 borrowers.firstname+' '+borrowers.surname AS authorisedbyname,
100 borrowers.branchcode AS branch
102 LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
105 my $sth=$dbh->prepare($query);
106 $sth->execute($basketno);
107 return ( $sth->fetchrow_hashref );
110 #------------------------------------------------------------#
116 $basket = &NewBasket();
118 Create a new basket in aqbasket table
124 # FIXME : this function seems to be unused.
127 my ( $booksellerid, $authorisedby ) = @_;
128 my $dbh = C4::Context->dbh;
131 (creationdate,booksellerid,authorisedby)
132 VALUES (now(),'$booksellerid','$authorisedby')
137 #find & return basketno MYSQL dependant, but $dbh->last_insert_id always returns null :-(
138 my $basket = $dbh->{'mysql_insertid'};
142 #------------------------------------------------------------#
148 &CloseBasket($basketno);
150 close a basket (becomes unmodifiable,except for recieves)
158 my $dbh = C4::Context->dbh;
164 my $sth = $dbh->prepare($query);
165 $sth->execute($basketno);
168 #------------------------------------------------------------#
172 =head2 FUNCTIONS ABOUT ORDERS
178 #------------------------------------------------------------#
180 =head3 GetPendingOrders
184 $orders = &GetPendingOrders($booksellerid);
186 Finds pending orders from the bookseller with the given ID. Ignores
187 completed and cancelled orders.
189 C<$orders> is a reference-to-array; each element is a
190 reference-to-hash with the following fields:
194 =item C<authorizedby>
200 These give the value of the corresponding field in the aqorders table
201 of the Koha database.
207 Results are ordered from most to least recent.
211 sub GetPendingOrders {
213 my $dbh = C4::Context->dbh;
215 SELECT count(*),authorisedby,creationdate,aqbasket.basketno,
216 closedate,surname,firstname,aqorders.title
218 LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno
219 LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
221 AND (quantity > quantityreceived OR quantityreceived is NULL)
222 AND datecancellationprinted IS NULL
223 AND (to_days(now())-to_days(closedate) < 180 OR closedate IS NULL)
225 if ( C4::Context->preference("IndependantBranches") ) {
226 my $userenv = C4::Context->userenv;
227 if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
229 " and (borrowers.branchcode = '"
231 . "' or borrowers.branchcode ='')";
234 $strsth .= " group by basketno order by aqbasket.basketno";
235 my $sth = $dbh->prepare($strsth);
236 $sth->execute($supplierid);
238 while ( my $data = $sth->fetchrow_hashref ) {
239 push( @results, $data );
245 #------------------------------------------------------------#
251 @orders = &GetOrders($basketnumber, $orderby);
253 Looks up the pending (non-cancelled) orders with the given basket
254 number. If C<$booksellerID> is non-empty, only orders from that seller
258 C<&basket> returns a two-element array. C<@orders> is an array of
259 references-to-hash, whose keys are the fields from the aqorders,
260 biblio, and biblioitems tables in the Koha database.
267 my ( $basketno, $orderby ) = @_;
268 my $dbh = C4::Context->dbh;
270 SELECT aqorderbreakdown.*,
275 LEFT JOIN aqorderbreakdown ON
276 aqorders.ordernumber=aqorderbreakdown.ordernumber
278 AND biblio.biblionumber=aqorders.biblionumber
279 AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
282 $orderby = "biblio.title" 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
306 Returns the number of this order.
308 =item C<$ordernumber> is the order number.
314 my ( $biblionumber ) = @_;
315 my $dbh = C4::Context->dbh;
322 my $sth = $dbh->prepare($query);
323 $sth->execute( $biblionumber );
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, , aqorders, and
340 aqorderbreakdown tables of the Koha database.
348 my $dbh = C4::Context->dbh;
352 LEFT JOIN aqorderbreakdown ON aqorders.ordernumber=aqorderbreakdown.ordernumber
353 WHERE aqorders.ordernumber=?
354 AND biblio.biblionumber=aqorders.biblionumber
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, $biblionumber, $title, $quantity,
396 $listprice, $booksellerid, $authorisedby, $notes,
397 $bookfund, $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 rrp,ecost,gst,unitprice,subscription,sort1,sort2,budgetdate,entrydate)
438 VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,$budget,now() )
440 my $sth = $dbh->prepare($query);
443 $biblionumber, $title, $basketno, $quantity, $listprice,
444 $notes, $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, $biblionumber,
487 $basketno, $supplier, $who, $notes, $bookfund,
488 $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, $biblionumber
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>.
544 #------------------------------------------------------------#
546 =head3 ModReceiveOrder
550 &ModReceiveOrder($biblionumber, $ordernumber, $quantityreceived, $user,
551 $unitprice, $booksellerinvoicenumber, $biblioitemnumber,
552 $freight, $bookfund, $rrp);
554 Updates an order, to reflect the fact that it was received, at least
555 in part. All arguments not mentioned below update the fields with the
556 same name in the aqorders table of the Koha database.
558 Updates the order with bibilionumber C<$biblionumber> and ordernumber
561 Also updates the book fund ID in the aqorderbreakdown table.
568 sub ModReceiveOrder {
570 $biblionumber, $ordnum, $quantrec, $user, $cost,
571 $invoiceno, $freight, $rrp, $bookfund
574 my $dbh = C4::Context->dbh;
577 SET quantityreceived=?,datereceived=now(),booksellerinvoicenumber=?,
578 unitprice=?,freight=?,rrp=?
579 WHERE biblionumber=? AND ordernumber=?
581 my $sth = $dbh->prepare($query);
582 my $suggestionid = GetSuggestionFromBiblionumber( $dbh, $biblionumber );
584 ModStatus( $suggestionid, 'AVAILABLE', '', $biblionumber );
586 $sth->execute( $quantrec, $invoiceno, $cost, $freight, $rrp, $biblionumber,
590 # Allows libraries to change their bookfund during receiving orders
591 # allows them to adjust budgets
592 if ( C4::Context->preferene("LooseBudgets") ) {
594 UPDATE aqorderbreakdown
598 my $sth = $dbh->prepare($query);
599 $sth->execute( $bookfund, $ordnum );
604 #------------------------------------------------------------#
608 @results = &SearchOrder($search, $biblionumber, $complete);
612 C<$search> may take one of several forms: if it is an ISBN,
613 C<&ordersearch> returns orders with that ISBN. If C<$search> is an
614 order number, C<&ordersearch> returns orders with that order number
615 and biblionumber C<$biblionumber>. Otherwise, C<$search> is considered
616 to be a space-separated list of search terms; in this case, all of the
617 terms must appear in the title (matching the beginning of title
620 If C<$complete> is C<yes>, the results will include only completed
621 orders. In any case, C<&ordersearch> ignores cancelled orders.
623 C<&ordersearch> returns an array.
624 C<@results> is an array of references-to-hash with the following keys:
641 ### Requires fixing for KOHA 3 API for performance. Currently just fiixed so it works
642 ## Very CPU expensive searches seems to be repeated!!
643 ## This search can be directed to ZEBRA for title,isbn etc. ordernumber ,booksellerid to acquiorders
644 my ( $search, $id, $biblio, $catview ) = @_;
645 my $dbh = C4::Context->dbh;
646 my @data = split( ' ', $search );
649 @searchterms = ($id);
651 map { push( @searchterms, "$_%", "% $_%" ) } @data;
652 push( @searchterms, $search, $search, $biblio );
656 "SELECT *,biblio.title FROM aqorders,biblio,aqbasket
657 WHERE biblio.biblionumber=aqorders.biblionumber AND
658 aqorders.basketno = aqbasket.basketno
659 AND aqbasket.booksellerid = ?
661 AND ((datecancellationprinted is NULL)
662 OR (datecancellationprinted = '0000-00-00'))
666 map { "(biblio.title like ? or biblio.title like ?)" } @data )
668 . ") OR biblio.isbn=? OR (aqorders.ordernumber=? AND aqorders.biblionumber=?)) ";
673 " SELECT *,biblio.title
674 FROM aqorders,biblio,aqbasket
675 WHERE aqorders.biblionumber = biblio.biblionumber
676 AND aqorders.basketno = aqbasket.basketno
678 AND ((datecancellationprinted is NULL)
679 OR (datecancellationprinted = '0000-00-00'))
680 AND (aqorders.quantityreceived < aqorders.quantity OR aqorders.quantityreceived is NULL)
684 map { "(biblio.title like ? OR biblio.title like ?)" } @data )
686 . ") or biblio.isbn=? OR (aqorders.ordernumber=? AND aqorders.biblionumber=?)) ";
688 $query .= " GROUP BY aqorders.ordernumber";
689 my $sth = $dbh->prepare($query);
690 $sth->execute(@searchterms);
697 FROM aqorderbreakdown
700 my $sth3 = $dbh->prepare($query3);
702 while ( my $data = $sth->fetchrow_hashref ) {
703 ## Retrieving a whole marc record just to extract seriestitle is very poor performance
704 ## Rewrite these searches
705 my $record=MARCgetbiblio($dbh,$data->{'biblionumber'});
706 my $data2=MARCmarc2koha($dbh,$record,"biblios");
708 $data->{'author'} = $data2->{'author'};
709 $data->{'seriestitle'} = $data2->{'seriestitle'};
710 $sth3->execute( $data->{'ordernumber'} );
711 my $data3 = $sth3->fetchrow_hashref;
712 $data->{'branchcode'} = $data3->{'branchcode'};
713 $data->{'bookfundid'} = $data3->{'bookfundid'};
714 push( @results, $data );
722 #------------------------------------------------------------#
728 &DelOrder($biblionumber, $ordernumber);
730 Cancel the order with the given order and biblio numbers. It does not
731 delete any entries in the aqorders table, it merely marks them as
739 my ( $biblionumber, $ordnum ) = @_;
740 my $dbh = C4::Context->dbh;
743 SET datecancellationprinted=now()
744 WHERE biblionumber=? AND ordernumber=?
746 my $sth = $dbh->prepare($query);
747 $sth->execute( $biblionumber, $ordnum );
756 =head2 FUNCTIONS ABOUT PARCELS
762 #------------------------------------------------------------#
768 @results = &GetParcel($booksellerid, $code, $date);
770 Looks up all of the received items from the supplier with the given
771 bookseller ID at the given date, for the given code (bookseller Invoice number). Ignores cancelled and completed orders.
773 C<@results> is an array of references-to-hash. The keys of each element are fields from
774 the aqorders, biblio tables of the Koha database.
776 C<@results> is sorted alphabetically by book title.
784 #gets all orders from a certain supplier, orders them alphabetically
785 my ( $supplierid, $code, $datereceived ) = @_;
786 my $dbh = C4::Context->dbh;
789 if $code; # add % if we search on a given code (otherwise, let him empty)
796 aqorders.biblionumber,
798 aqorders.ordernumber,
800 aqorders.quantityreceived,
805 FROM aqorders,aqbasket
806 LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
807 WHERE aqbasket.basketno=aqorders.basketno
808 AND aqbasket.booksellerid=?
809 AND aqorders.booksellerinvoicenumber LIKE \"$code\"
810 AND aqorders.datereceived= \'$datereceived\'";
812 if ( C4::Context->preference("IndependantBranches") ) {
813 my $userenv = C4::Context->userenv;
814 if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
816 " and (borrowers.branchcode = '"
818 . "' or borrowers.branchcode ='')";
821 $strsth .= " order by aqbasket.basketno";
822 ### parcelinformation : $strsth
823 my $sth = $dbh->prepare($strsth);
824 $sth->execute($supplierid);
825 while ( my $data = $sth->fetchrow_hashref ) {
826 push( @results, $data );
828 ### countparcelbiblio: $count
834 #------------------------------------------------------------#
840 $results = &GetParcels($bookseller, $order, $code, $datefrom, $dateto);
841 get a lists of parcels.
846 is the bookseller this function has to get parcels.
849 To know on what criteria the results list has to be ordered.
852 is the booksellerinvoicenumber.
854 =item $datefrom & $dateto
855 to know on what date this function has to filter its search.
858 a pointer on a hash list containing parcel informations as such :
864 =item Number of biblio
866 =item Number of items
873 my ($bookseller,$order, $code, $datefrom, $dateto) = @_;
874 my $dbh = C4::Context->dbh;
876 SELECT aqorders.booksellerinvoicenumber,
878 count(DISTINCT biblionumber) AS biblio,
879 sum(quantity) AS itemsexpected,
880 sum(quantityreceived) AS itemsreceived
881 FROM aqorders, aqbasket
882 WHERE aqbasket.basketno = aqorders.basketno
883 AND aqbasket.booksellerid = $bookseller and datereceived IS NOT NULL
886 $strsth .= "and aqorders.booksellerinvoicenumber like \"$code%\" " if ($code);
888 $strsth .= "and datereceived >=" . $dbh->quote($datefrom) . " " if ($datefrom);
890 $strsth .= "and datereceived <=" . $dbh->quote($dateto) . " " if ($dateto);
892 $strsth .= "group by aqorders.booksellerinvoicenumber,datereceived ";
893 $strsth .= "order by $order " if ($order);
894 my $sth = $dbh->prepare($strsth);
899 while ( my $data2 = $sth->fetchrow_hashref ) {
900 push @results, $data2;
907 #------------------------------------------------------------#
913 @results = &GetLateOrders;
915 Searches for bookseller with late orders.
918 the table of supplier with late issues. This table is full of hashref.
925 ## requirse fixing for KOHA 3 API. Currently does not return publisher
927 my $supplierid = shift;
930 my $dbh = C4::Context->dbh;
932 #BEWARE, order of parenthesis and LEFT JOIN is important for speed
934 my $dbdriver = C4::Context->config("db_scheme") || "mysql";
937 if ( $dbdriver eq "mysql" ) {
939 SELECT aqbasket.basketno,
940 DATE(aqbasket.closedate) AS orderdate,
941 aqorders.quantity - IFNULL(aqorders.quantityreceived,0) AS quantity,
942 aqorders.rrp AS unitpricesupplier,
943 aqorders.ecost AS unitpricelib,
944 (aqorders.quantity - IFNULL(aqorders.quantityreceived,0)) * aqorders.rrp AS subtotal,
945 aqbookfund.bookfundname AS budget,
946 borrowers.branchcode AS branch,
947 aqbooksellers.name AS supplier,
951 DATEDIFF(CURDATE( ),closedate) AS latesince
953 (aqorders LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber)
955 LEFT JOIN aqorderbreakdown ON aqorders.ordernumber = aqorderbreakdown.ordernumber)
956 LEFT JOIN aqbookfund ON aqorderbreakdown.bookfundid = aqbookfund.bookfundid),
957 (aqbasket LEFT JOIN borrowers ON aqbasket.authorisedby = borrowers.borrowernumber)
958 LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
959 WHERE aqorders.basketno = aqbasket.basketno
960 AND (closedate < DATE_SUB(CURDATE( ),INTERVAL $delay DAY))
961 AND ((datereceived = '' OR datereceived is null)
962 OR (aqorders.quantityreceived < aqorders.quantity) )
964 $strsth .= " AND aqbasket.booksellerid = $supplierid " if ($supplierid);
965 $strsth .= " AND borrowers.branchcode like \'" . $branch . "\'"
968 " AND borrowers.branchcode like \'"
969 . C4::Context->userenv->{branch} . "\'"
970 if ( C4::Context->preference("IndependantBranches")
971 && C4::Context->userenv
972 && C4::Context->userenv->{flags} != 1 );
973 $strsth .=" HAVING quantity<>0
974 AND unitpricesupplier<>0
976 ORDER BY latesince,basketno,borrowers.branchcode, supplier
981 SELECT aqbasket.basketno,
982 DATE(aqbasket.closedate) AS orderdate,
983 aqorders.quantity, aqorders.rrp AS unitpricesupplier,
984 aqorders.ecost as unitpricelib,
985 aqorders.quantity * aqorders.rrp AS subtotal
986 aqbookfund.bookfundname AS budget,
987 borrowers.branchcode AS branch,
988 aqbooksellers.name AS supplier,
992 (CURDATE - closedate) AS latesince
994 (aqorders LEFT JOIN biblio on biblio.biblionumber = aqorders.biblionumber)
996 LEFT JOIN aqorderbreakdown on aqorders.ordernumber = aqorderbreakdown.ordernumber)
997 LEFT JOIN aqbookfund ON aqorderbreakdown.bookfundid = aqbookfund.bookfundid),
998 (aqbasket LEFT JOIN borrowers on aqbasket.authorisedby = borrowers.borrowernumber) LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
999 WHERE aqorders.basketno = aqbasket.basketno
1000 AND (closedate < (CURDATE -(INTERVAL $delay DAY))
1001 AND ((datereceived = '' OR datereceived is null)
1002 OR (aqorders.quantityreceived < aqorders.quantity) ) ";
1003 $strsth .= " AND aqbasket.booksellerid = $supplierid " if ($supplierid);
1005 $strsth .= " AND borrowers.branchcode like \'" . $branch . "\'" if ($branch);
1006 $strsth .=" AND borrowers.branchcode like \'". C4::Context->userenv->{branch} . "\'"
1007 if (C4::Context->preference("IndependantBranches") && C4::Context->userenv->{flags} != 1 );
1008 $strsth .=" ORDER BY latesince,basketno,borrowers.branchcode, supplier";
1010 my $sth = $dbh->prepare($strsth);
1014 while ( my $data = $sth->fetchrow_hashref ) {
1015 $data->{hilighted} = $hilighted if ( $hilighted > 0 );
1016 $data->{orderdate} = format_date( $data->{orderdate} );
1017 push @results, $data;
1018 $hilighted = -$hilighted;
1024 #------------------------------------------------------------#
1030 (\@order_loop, $total_qty, $total_price, $total_qtyreceived)=&GetHistory( $title, $author, $name, $from_placed_on, $to_placed_on )
1032 this function get the search history.
1039 my ( $title, $author, $name, $from_placed_on, $to_placed_on ) = @_;
1042 my $total_qtyreceived = 0;
1043 my $total_price = 0;
1045 # don't run the query if there are no parameters (list would be too long for sure !)
1046 if ( $title || $author || $name || $from_placed_on || $to_placed_on ) {
1047 my $dbh = C4::Context->dbh;
1053 name,aqbasket.creationdate,
1054 aqorders.datereceived,
1056 aqorders.quantityreceived,
1058 aqorders.ordernumber
1059 FROM aqorders,aqbasket,aqbooksellers,biblio";
1061 $query .= ",borrowers "
1062 if ( C4::Context->preference("IndependantBranches") );
1065 WHERE aqorders.basketno=aqbasket.basketno
1066 AND aqbasket.booksellerid=aqbooksellers.id
1067 AND biblio.biblionumber=aqorders.biblionumber ";
1069 $query .= " AND aqbasket.authorisedby=borrowers.borrowernumber"
1070 if ( C4::Context->preference("IndependantBranches") );
1072 $query .= " AND biblio.title LIKE " . $dbh->quote( "%" . $title . "%" )
1076 " AND biblio.author LIKE " . $dbh->quote( "%" . $author . "%" )
1079 $query .= " AND name LIKE " . $dbh->quote( "%" . $name . "%" ) if $name;
1081 $query .= " AND creationdate >" . $dbh->quote($from_placed_on)
1084 $query .= " AND creationdate<" . $dbh->quote($to_placed_on)
1087 if ( C4::Context->preference("IndependantBranches") ) {
1088 my $userenv = C4::Context->userenv;
1089 if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
1091 " AND (borrowers.branchcode = '"
1092 . $userenv->{branch}
1093 . "' OR borrowers.branchcode ='')";
1096 $query .= " ORDER BY booksellerid";
1097 my $sth = $dbh->prepare($query);
1100 while ( my $line = $sth->fetchrow_hashref ) {
1101 $line->{count} = $cnt++;
1102 $line->{toggle} = 1 if $cnt % 2;
1103 push @order_loop, $line;
1104 $line->{creationdate} = format_date( $line->{creationdate} );
1105 $line->{datereceived} = format_date( $line->{datereceived} );
1106 $total_qty += $line->{'quantity'};
1107 $total_qtyreceived += $line->{'quantityreceived'};
1108 $total_price += $line->{'quantity'} * $line->{'ecost'};
1111 return \@order_loop, $total_qty, $total_price, $total_qtyreceived;
1114 END { } # module clean-up code here (global destructor)
1124 Koha Developement team <info@koha.org>