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 &GetSingleOrder
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 concat(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;
298 my $dbh = C4::Context->dbh;
299 my $sth=$dbh->prepare("Select * from biblio,aqorders left join aqorderbreakdown
300 on aqorders.ordernumber=aqorderbreakdown.ordernumber
301 where aqorders.ordernumber=?
302 and biblio.biblionumber=aqorders.biblionumber");
303 $sth->execute($ordnum);
304 my $data=$sth->fetchrow_hashref;
309 #------------------------------------------------------------#
311 =head3 GetOrderNumber
315 $ordernumber = &GetOrderNumber($biblioitemnumber, $biblionumber);
317 Looks up the ordernumber with the given biblionumber
319 Returns the number of this order.
321 =item C<$ordernumber> is the order number.
327 my ( $biblionumber ) = @_;
328 my $dbh = C4::Context->dbh;
335 my $sth = $dbh->prepare($query);
336 $sth->execute( $biblionumber );
338 return $sth->fetchrow;
341 #------------------------------------------------------------#
347 $order = &GetOrder($ordernumber);
349 Looks up an order by order number.
351 Returns a reference-to-hash describing the order. The keys of
352 C<$order> are fields from the biblio, , aqorders, and
353 aqorderbreakdown tables of the Koha database.
361 my $dbh = C4::Context->dbh;
365 LEFT JOIN aqorderbreakdown ON aqorders.ordernumber=aqorderbreakdown.ordernumber
366 WHERE aqorders.ordernumber=?
367 AND biblio.biblionumber=aqorders.biblionumber
370 my $sth= $dbh->prepare($query);
371 $sth->execute($ordnum);
372 my $data = $sth->fetchrow_hashref;
377 #------------------------------------------------------------#
383 &NewOrder($basket, $biblionumber, $title, $quantity, $listprice,
384 $booksellerid, $who, $notes, $bookfund, $biblioitemnumber, $rrp,
385 $ecost, $gst, $budget, $unitprice, $subscription,
386 $booksellerinvoicenumber);
388 Adds a new order to the database. Any argument that isn't described
389 below is the new value of the field with the same name in the aqorders
390 table of the Koha database.
392 C<$ordnum> is a "minimum order number." After adding the new entry to
393 the aqorders table, C<&neworder> finds the first entry in aqorders
394 with order number greater than or equal to C<$ordnum>, and adds an
395 entry to the aqorderbreakdown table, with the order number just found,
396 and the book fund ID of the newly-added order.
398 C<$budget> is effectively ignored.
400 C<$subscription> may be either "yes", or anything else for "no".
408 $basketno, $biblionumber, $title, $quantity,
409 $listprice, $booksellerid, $authorisedby, $notes,
410 $bookfund, $rrp, $ecost,
411 $gst, $budget, $cost, $sub,
412 $invoice, $sort1, $sort2
416 my $year = localtime->year() + 1900;
417 my $month = localtime->mon() + 1; # months starts at 0, add 1
419 if ( !$budget || $budget eq 'now' ) {
423 # if month is july or more, budget start is 1 jul, next year.
424 elsif ( $month >= '7' ) {
425 ++$year; # add 1 to year , coz its next year
426 $budget = "'$year-07-01'";
430 # START OF NEW BUDGET, 1ST OF JULY, THIS YEAR
431 $budget = "'$year-07-01'";
434 if ( $sub eq 'yes' ) {
441 # if $basket empty, it's also a new basket, create it
443 $basketno = NewBasket( $booksellerid, $authorisedby );
446 my $dbh = C4::Context->dbh;
449 ( biblionumber,title,basketno,quantity,listprice,notes,
450 rrp,ecost,gst,unitprice,subscription,sort1,sort2,budgetdate,entrydate)
451 VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,$budget,now() )
453 my $sth = $dbh->prepare($query);
456 $biblionumber, $title, $basketno, $quantity, $listprice,
457 $notes, $rrp, $ecost, $gst,
458 $cost, $sub, $sort1, $sort2
462 #get ordnum MYSQL dependant, but $dbh->last_insert_id returns null
463 my $ordnum = $dbh->{'mysql_insertid'};
465 INSERT INTO aqorderbreakdown (ordernumber,bookfundid)
468 $sth = $dbh->prepare($query);
469 $sth->execute( $ordnum, $bookfund );
471 return ( $basketno, $ordnum );
474 #------------------------------------------------------------#
480 &ModOrder($title, $ordernumber, $quantity, $listprice,
481 $biblionumber, $basketno, $supplier, $who, $notes,
482 $bookfundid, $bibitemnum, $rrp, $ecost, $gst, $budget,
483 $unitprice, $booksellerinvoicenumber);
485 Modifies an existing order. Updates the order with order number
486 C<$ordernumber> and biblionumber C<$biblionumber>. All other arguments
487 update the fields with the same name in the aqorders table of the Koha
490 Entries with order number C<$ordernumber> in the aqorderbreakdown
491 table are also updated to the new book fund ID.
499 $title, $ordnum, $quantity, $listprice, $biblionumber,
500 $basketno, $supplier, $who, $notes, $bookfund,
501 $rrp, $ecost, $gst, $budget,
502 $cost, $invoice, $sort1, $sort2
505 my $dbh = C4::Context->dbh;
509 quantity=?,listprice=?,basketno=?,
510 rrp=?,ecost=?,unitprice=?,booksellerinvoicenumber=?,
511 notes=?,sort1=?, sort2=?
512 WHERE ordernumber=? AND biblionumber=?
514 my $sth = $dbh->prepare($query);
516 $title, $quantity, $listprice, $basketno, $rrp,
517 $ecost, $cost, $invoice, $notes, $sort1,
518 $sort2, $ordnum, $biblionumber
522 UPDATE aqorderbreakdown
526 $sth = $dbh->prepare($query);
528 unless ( $sth->execute( $bookfund, $ordnum ) )
529 { # zero rows affected [Bug 734]
531 INSERT INTO aqorderbreakdown
532 (ordernumber,bookfundid)
535 $sth = $dbh->prepare($query);
536 $sth->execute( $ordnum, $bookfund );
541 #------------------------------------------------------------#
543 =head3 ModOrderBiblioNumber
547 &ModOrderBiblioNumber($biblioitemnumber,$ordnum, $biblionumber);
549 Modifies the biblioitemnumber for an existing order.
550 Updates the order with order number C<$ordernum> and biblionumber C<$biblionumber>.
557 #------------------------------------------------------------#
559 =head3 ModReceiveOrder
563 &ModReceiveOrder($biblionumber, $ordernumber, $quantityreceived, $user,
564 $unitprice, $booksellerinvoicenumber, $biblioitemnumber,
565 $freight, $bookfund, $rrp);
567 Updates an order, to reflect the fact that it was received, at least
568 in part. All arguments not mentioned below update the fields with the
569 same name in the aqorders table of the Koha database.
571 Updates the order with bibilionumber C<$biblionumber> and ordernumber
574 Also updates the book fund ID in the aqorderbreakdown table.
581 sub ModReceiveOrder {
583 $biblionumber, $ordnum, $quantrec, $user, $cost,
584 $invoiceno, $freight, $rrp, $bookfund
587 my $dbh = C4::Context->dbh;
590 SET quantityreceived=?,datereceived=now(),booksellerinvoicenumber=?,
591 unitprice=?,freight=?,rrp=?
592 WHERE biblionumber=? AND ordernumber=?
594 my $sth = $dbh->prepare($query);
595 my $suggestionid = GetSuggestionFromBiblionumber( $dbh, $biblionumber );
597 ModStatus( $suggestionid, 'AVAILABLE', '', $biblionumber );
599 $sth->execute( $quantrec, $invoiceno, $cost, $freight, $rrp, $biblionumber,
603 # Allows libraries to change their bookfund during receiving orders
604 # allows them to adjust budgets
605 if ( C4::Context->preferene("LooseBudgets") ) {
607 UPDATE aqorderbreakdown
611 my $sth = $dbh->prepare($query);
612 $sth->execute( $bookfund, $ordnum );
617 #------------------------------------------------------------#
621 @results = &SearchOrder($search, $biblionumber, $complete);
625 C<$search> may take one of several forms: if it is an ISBN,
626 C<&ordersearch> returns orders with that ISBN. If C<$search> is an
627 order number, C<&ordersearch> returns orders with that order number
628 and biblionumber C<$biblionumber>. Otherwise, C<$search> is considered
629 to be a space-separated list of search terms; in this case, all of the
630 terms must appear in the title (matching the beginning of title
633 If C<$complete> is C<yes>, the results will include only completed
634 orders. In any case, C<&ordersearch> ignores cancelled orders.
636 C<&ordersearch> returns an array.
637 C<@results> is an array of references-to-hash with the following keys:
654 ### Requires fixing for KOHA 3 API for performance. Currently just fiixed so it works
655 ## Very CPU expensive searches seems to be repeated!!
656 ## This search can be directed to ZEBRA for title,isbn etc. ordernumber ,booksellerid to acquiorders
657 my ( $search, $id, $biblio, $catview ) = @_;
658 my $dbh = C4::Context->dbh;
659 my @data = split( ' ', $search );
662 @searchterms = ($id);
664 map { push( @searchterms, "$_%", "% $_%" ) } @data;
665 push( @searchterms, $search, $search, $biblio );
669 "SELECT *,biblio.title FROM aqorders,biblio,aqbasket
670 WHERE biblio.biblionumber=aqorders.biblionumber AND
671 aqorders.basketno = aqbasket.basketno
672 AND aqbasket.booksellerid = ?
674 AND ((datecancellationprinted is NULL)
675 OR (datecancellationprinted = '0000-00-00'))
679 map { "(biblio.title like ? or biblio.title like ?)" } @data )
681 . ") OR biblio.isbn=? OR (aqorders.ordernumber=? AND aqorders.biblionumber=?)) ";
686 " SELECT *,biblio.title
687 FROM aqorders,biblio,aqbasket
688 WHERE aqorders.biblionumber = biblio.biblionumber
689 AND aqorders.basketno = aqbasket.basketno
691 AND ((datecancellationprinted is NULL)
692 OR (datecancellationprinted = '0000-00-00'))
693 AND (aqorders.quantityreceived < aqorders.quantity OR aqorders.quantityreceived is NULL)
697 map { "(biblio.title like ? OR biblio.title like ?)" } @data )
699 . ") or biblio.isbn=? OR (aqorders.ordernumber=? AND aqorders.biblionumber=?)) ";
701 $query .= " GROUP BY aqorders.ordernumber";
702 my $sth = $dbh->prepare($query);
703 $sth->execute(@searchterms);
710 FROM aqorderbreakdown
713 my $sth3 = $dbh->prepare($query3);
715 while ( my $data = $sth->fetchrow_hashref ) {
716 ## Retrieving a whole marc record just to extract seriestitle is very poor performance
717 ## Rewrite these searches
718 my $record=XMLgetbibliohash($dbh,$data->{'biblionumber'});
719 my $seriestitle=XML_readline_onerecord($record,"seriestitle","biblios");
721 # $data->{'author'} = $data->{'author'};
722 $data->{'seriestitle'} = $seriestitle;
723 $sth3->execute( $data->{'ordernumber'} );
724 my $data3 = $sth3->fetchrow_hashref;
725 $data->{'branchcode'} = $data3->{'branchcode'};
726 $data->{'bookfundid'} = $data3->{'bookfundid'};
727 push( @results, $data );
735 #------------------------------------------------------------#
741 &DelOrder($biblionumber, $ordernumber);
743 Cancel the order with the given order and biblio numbers. It does not
744 delete any entries in the aqorders table, it merely marks them as
752 my ( $biblionumber, $ordnum ) = @_;
753 my $dbh = C4::Context->dbh;
756 SET datecancellationprinted=now()
757 WHERE biblionumber=? AND ordernumber=?
759 my $sth = $dbh->prepare($query);
760 $sth->execute( $biblionumber, $ordnum );
769 =head2 FUNCTIONS ABOUT PARCELS
775 #------------------------------------------------------------#
781 @results = &GetParcel($booksellerid, $code, $date);
783 Looks up all of the received items from the supplier with the given
784 bookseller ID at the given date, for the given code (bookseller Invoice number). Ignores cancelled and completed orders.
786 C<@results> is an array of references-to-hash. The keys of each element are fields from
787 the aqorders, biblio tables of the Koha database.
789 C<@results> is sorted alphabetically by book title.
797 #gets all orders from a certain supplier, orders them alphabetically
798 my ( $supplierid, $code, $datereceived ) = @_;
799 my $dbh = C4::Context->dbh;
802 if $code; # add % if we search on a given code (otherwise, let him empty)
809 aqorders.biblionumber,
811 aqorders.ordernumber,
813 aqorders.quantityreceived,
818 FROM aqorders,aqbasket
819 LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
820 WHERE aqbasket.basketno=aqorders.basketno
821 AND aqbasket.booksellerid=?
822 AND aqorders.booksellerinvoicenumber LIKE \"$code\"
823 AND aqorders.datereceived= \'$datereceived\'";
825 if ( C4::Context->preference("IndependantBranches") ) {
826 my $userenv = C4::Context->userenv;
827 if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
829 " and (borrowers.branchcode = '"
831 . "' or borrowers.branchcode ='')";
834 $strsth .= " order by aqbasket.basketno";
835 ### parcelinformation : $strsth
836 my $sth = $dbh->prepare($strsth);
837 $sth->execute($supplierid);
838 while ( my $data = $sth->fetchrow_hashref ) {
839 push( @results, $data );
841 ### countparcelbiblio: $count
847 #------------------------------------------------------------#
853 $results = &GetParcels($bookseller, $order, $code, $datefrom, $dateto);
854 get a lists of parcels.
859 is the bookseller this function has to get parcels.
862 To know on what criteria the results list has to be ordered.
865 is the booksellerinvoicenumber.
867 =item $datefrom & $dateto
868 to know on what date this function has to filter its search.
871 a pointer on a hash list containing parcel informations as such :
877 =item Number of biblio
879 =item Number of items
886 my ($bookseller,$order, $code, $datefrom, $dateto) = @_;
887 my $dbh = C4::Context->dbh;
889 SELECT aqorders.booksellerinvoicenumber,
891 count(DISTINCT biblionumber) AS biblio,
892 sum(quantity) AS itemsexpected,
893 sum(quantityreceived) AS itemsreceived
894 FROM aqorders, aqbasket
895 WHERE aqbasket.basketno = aqorders.basketno
896 AND aqbasket.booksellerid = $bookseller and datereceived IS NOT NULL
899 $strsth .= "and aqorders.booksellerinvoicenumber like \"$code%\" " if ($code);
901 $strsth .= "and datereceived >=" . $dbh->quote($datefrom) . " " if ($datefrom);
903 $strsth .= "and datereceived <=" . $dbh->quote($dateto) . " " if ($dateto);
905 $strsth .= "group by aqorders.booksellerinvoicenumber,datereceived ";
906 $strsth .= "order by $order " if ($order);
907 my $sth = $dbh->prepare($strsth);
912 while ( my $data2 = $sth->fetchrow_hashref ) {
913 push @results, $data2;
920 #------------------------------------------------------------#
926 @results = &GetLateOrders;
928 Searches for bookseller with late orders.
931 the table of supplier with late issues. This table is full of hashref.
938 ## requirse fixing for KOHA 3 API. Currently does not return publisher
940 my $supplierid = shift;
943 my $dbh = C4::Context->dbh;
945 #BEWARE, order of parenthesis and LEFT JOIN is important for speed
947 my $dbdriver = C4::Context->config("db_scheme") || "mysql";
950 if ( $dbdriver eq "mysql" ) {
952 SELECT aqbasket.basketno,
953 DATE(aqbasket.closedate) AS orderdate,
954 aqorders.quantity - IFNULL(aqorders.quantityreceived,0) AS quantity,
955 aqorders.rrp AS unitpricesupplier,
956 aqorders.ecost AS unitpricelib,
957 (aqorders.quantity - IFNULL(aqorders.quantityreceived,0)) * aqorders.rrp AS subtotal,
958 aqbookfund.bookfundname AS budget,
959 borrowers.branchcode AS branch,
960 aqbooksellers.name AS supplier,
964 DATEDIFF(CURDATE( ),closedate) AS latesince
966 (aqorders LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber)
968 LEFT JOIN aqorderbreakdown ON aqorders.ordernumber = aqorderbreakdown.ordernumber)
969 LEFT JOIN aqbookfund ON aqorderbreakdown.bookfundid = aqbookfund.bookfundid),
970 (aqbasket LEFT JOIN borrowers ON aqbasket.authorisedby = borrowers.borrowernumber)
971 LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
972 WHERE aqorders.basketno = aqbasket.basketno
973 AND (closedate < DATE_SUB(CURDATE( ),INTERVAL $delay DAY))
974 AND ((datereceived = '' OR datereceived is null)
975 OR (aqorders.quantityreceived < aqorders.quantity) )
977 $strsth .= " AND aqbasket.booksellerid = $supplierid " if ($supplierid);
978 $strsth .= " AND borrowers.branchcode like \'" . $branch . "\'"
981 " AND borrowers.branchcode like \'"
982 . C4::Context->userenv->{branch} . "\'"
983 if ( C4::Context->preference("IndependantBranches")
984 && C4::Context->userenv
985 && C4::Context->userenv->{flags} != 1 );
986 $strsth .=" HAVING quantity<>0
987 AND unitpricesupplier<>0
989 ORDER BY latesince,basketno,borrowers.branchcode, supplier
994 SELECT aqbasket.basketno,
995 DATE(aqbasket.closedate) AS orderdate,
996 aqorders.quantity, aqorders.rrp AS unitpricesupplier,
997 aqorders.ecost as unitpricelib,
998 aqorders.quantity * aqorders.rrp AS subtotal
999 aqbookfund.bookfundname AS budget,
1000 borrowers.branchcode AS branch,
1001 aqbooksellers.name AS supplier,
1005 (CURDATE - closedate) AS latesince
1007 (aqorders LEFT JOIN biblio on biblio.biblionumber = aqorders.biblionumber)
1009 LEFT JOIN aqorderbreakdown on aqorders.ordernumber = aqorderbreakdown.ordernumber)
1010 LEFT JOIN aqbookfund ON aqorderbreakdown.bookfundid = aqbookfund.bookfundid),
1011 (aqbasket LEFT JOIN borrowers on aqbasket.authorisedby = borrowers.borrowernumber) LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
1012 WHERE aqorders.basketno = aqbasket.basketno
1013 AND (closedate < (CURDATE -(INTERVAL $delay DAY))
1014 AND ((datereceived = '' OR datereceived is null)
1015 OR (aqorders.quantityreceived < aqorders.quantity) ) ";
1016 $strsth .= " AND aqbasket.booksellerid = $supplierid " if ($supplierid);
1018 $strsth .= " AND borrowers.branchcode like \'" . $branch . "\'" if ($branch);
1019 $strsth .=" AND borrowers.branchcode like \'". C4::Context->userenv->{branch} . "\'"
1020 if (C4::Context->preference("IndependantBranches") && C4::Context->userenv->{flags} != 1 );
1021 $strsth .=" ORDER BY latesince,basketno,borrowers.branchcode, supplier";
1023 my $sth = $dbh->prepare($strsth);
1027 while ( my $data = $sth->fetchrow_hashref ) {
1028 $data->{hilighted} = $hilighted if ( $hilighted > 0 );
1029 $data->{orderdate} = format_date( $data->{orderdate} );
1030 push @results, $data;
1031 $hilighted = -$hilighted;
1037 #------------------------------------------------------------#
1043 (\@order_loop, $total_qty, $total_price, $total_qtyreceived)=&GetHistory( $title, $author, $name, $from_placed_on, $to_placed_on )
1045 this function get the search history.
1052 my ( $title, $author, $name, $from_placed_on, $to_placed_on ) = @_;
1055 my $total_qtyreceived = 0;
1056 my $total_price = 0;
1058 # don't run the query if there are no parameters (list would be too long for sure !)
1059 if ( $title || $author || $name || $from_placed_on || $to_placed_on ) {
1060 my $dbh = C4::Context->dbh;
1066 name,aqbasket.creationdate,
1067 aqorders.datereceived,
1069 aqorders.quantityreceived,
1071 aqorders.ordernumber
1072 FROM aqorders,aqbasket,aqbooksellers,biblio";
1074 $query .= ",borrowers "
1075 if ( C4::Context->preference("IndependantBranches") );
1078 WHERE aqorders.basketno=aqbasket.basketno
1079 AND aqbasket.booksellerid=aqbooksellers.id
1080 AND biblio.biblionumber=aqorders.biblionumber ";
1082 $query .= " AND aqbasket.authorisedby=borrowers.borrowernumber"
1083 if ( C4::Context->preference("IndependantBranches") );
1085 $query .= " AND biblio.title LIKE " . $dbh->quote( "%" . $title . "%" )
1089 " AND biblio.author LIKE " . $dbh->quote( "%" . $author . "%" )
1092 $query .= " AND name LIKE " . $dbh->quote( "%" . $name . "%" ) if $name;
1094 $query .= " AND creationdate >" . $dbh->quote($from_placed_on)
1097 $query .= " AND creationdate<" . $dbh->quote($to_placed_on)
1100 if ( C4::Context->preference("IndependantBranches") ) {
1101 my $userenv = C4::Context->userenv;
1102 if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
1104 " AND (borrowers.branchcode = '"
1105 . $userenv->{branch}
1106 . "' OR borrowers.branchcode ='')";
1109 $query .= " ORDER BY booksellerid";
1110 my $sth = $dbh->prepare($query);
1113 while ( my $line = $sth->fetchrow_hashref ) {
1114 $line->{count} = $cnt++;
1115 $line->{toggle} = 1 if $cnt % 2;
1116 push @order_loop, $line;
1117 $line->{creationdate} = format_date( $line->{creationdate} );
1118 $line->{datereceived} = format_date( $line->{datereceived} );
1119 $total_qty += $line->{'quantity'};
1120 $total_qtyreceived += $line->{'quantityreceived'};
1121 $total_price += $line->{'quantity'} * $line->{'ecost'};
1124 return \@order_loop, $total_qty, $total_price, $total_qtyreceived;
1127 END { } # module clean-up code here (global destructor)
1137 Koha Developement team <info@koha.org>