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
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 ModReceiveOrder
534 &ModReceiveOrder($biblionumber, $ordernumber, $quantityreceived, $user,
535 $unitprice, $booksellerinvoicenumber, $biblioitemnumber,
536 $freight, $bookfund, $rrp);
538 Updates an order, to reflect the fact that it was received, at least
539 in part. All arguments not mentioned below update the fields with the
540 same name in the aqorders table of the Koha database.
542 Updates the order with bibilionumber C<$biblionumber> and ordernumber
545 Also updates the book fund ID in the aqorderbreakdown table.
552 sub ModReceiveOrder {
554 $biblio, $ordnum, $quantrec, $user, $cost,
555 $invoiceno, $freight, $rrp, $bookfund
558 my $dbh = C4::Context->dbh;
561 SET quantityreceived=?,datereceived=now(),booksellerinvoicenumber=?,
562 unitprice=?,freight=?,rrp=?
563 WHERE biblionumber=? AND ordernumber=?
565 my $sth = $dbh->prepare($query);
566 my $suggestionid = GetSuggestionFromBiblionumber( $dbh, $biblio );
568 ModStatus( $suggestionid, 'AVAILABLE', '', $biblio );
570 $sth->execute( $quantrec, $invoiceno, $cost, $freight, $rrp, $biblio,
574 # Allows libraries to change their bookfund during receiving orders
575 # allows them to adjust budgets
576 if ( C4::Context->preferene("LooseBudgets") ) {
578 UPDATE aqorderbreakdown
582 my $sth = $dbh->prepare($query);
583 $sth->execute( $bookfund, $ordnum );
588 #------------------------------------------------------------#
592 @results = &SearchOrder($search, $biblionumber, $complete);
596 C<$search> may take one of several forms: if it is an ISBN,
597 C<&ordersearch> returns orders with that ISBN. If C<$search> is an
598 order number, C<&ordersearch> returns orders with that order number
599 and biblionumber C<$biblionumber>. Otherwise, C<$search> is considered
600 to be a space-separated list of search terms; in this case, all of the
601 terms must appear in the title (matching the beginning of title
604 If C<$complete> is C<yes>, the results will include only completed
605 orders. In any case, C<&ordersearch> ignores cancelled orders.
607 C<&ordersearch> returns an array.
608 C<@results> is an array of references-to-hash with the following keys:
625 my ( $search, $id, $biblio, $catview ) = @_;
626 my $dbh = C4::Context->dbh;
627 my @data = split( ' ', $search );
630 @searchterms = ($id);
632 map { push( @searchterms, "$_%", "% $_%" ) } @data;
633 push( @searchterms, $search, $search, $biblio );
637 "SELECT *,biblio.title FROM aqorders,biblioitems,biblio,aqbasket
638 WHERE aqorders.biblioitemnumber = biblioitems.biblioitemnumber AND
639 aqorders.basketno = aqbasket.basketno
640 AND aqbasket.booksellerid = ?
641 AND biblio.biblionumber=aqorders.biblionumber
642 AND ((datecancellationprinted is NULL)
643 OR (datecancellationprinted = '0000-00-00'))
647 map { "(biblio.title like ? or biblio.title like ?)" } @data )
649 . ") OR biblioitems.isbn=? OR (aqorders.ordernumber=? AND aqorders.biblionumber=?)) ";
654 " SELECT *,biblio.title
655 FROM aqorders,biblioitems,biblio,aqbasket
656 WHERE aqorders.biblioitemnumber = biblioitems.biblioitemnumber
657 AND aqorders.basketno = aqbasket.basketno
658 AND biblio.biblionumber=aqorders.biblionumber
659 AND ((datecancellationprinted is NULL)
660 OR (datecancellationprinted = '0000-00-00'))
661 AND (aqorders.quantityreceived < aqorders.quantity OR aqorders.quantityreceived is NULL)
665 map { "(biblio.title like ? OR biblio.title like ?)" } @data )
667 . ") or biblioitems.isbn=? OR (aqorders.ordernumber=? AND aqorders.biblionumber=?)) ";
669 $query .= " GROUP BY aqorders.ordernumber";
670 my $sth = $dbh->prepare($query);
671 $sth->execute(@searchterms);
678 my $sth2 = $dbh->prepare($query2);
681 FROM aqorderbreakdown
684 my $sth3 = $dbh->prepare($query3);
686 while ( my $data = $sth->fetchrow_hashref ) {
687 $sth2->execute( $data->{'biblionumber'} );
688 my $data2 = $sth2->fetchrow_hashref;
689 $data->{'author'} = $data2->{'author'};
690 $data->{'seriestitle'} = $data2->{'seriestitle'};
691 $sth3->execute( $data->{'ordernumber'} );
692 my $data3 = $sth3->fetchrow_hashref;
693 $data->{'branchcode'} = $data3->{'branchcode'};
694 $data->{'bookfundid'} = $data3->{'bookfundid'};
695 push( @results, $data );
703 #------------------------------------------------------------#
709 &DelOrder($biblionumber, $ordernumber);
711 Cancel the order with the given order and biblio numbers. It does not
712 delete any entries in the aqorders table, it merely marks them as
720 my ( $bibnum, $ordnum ) = @_;
721 my $dbh = C4::Context->dbh;
724 SET datecancellationprinted=now()
725 WHERE biblionumber=? AND ordernumber=?
727 my $sth = $dbh->prepare($query);
728 $sth->execute( $bibnum, $ordnum );
737 =head2 FUNCTIONS ABOUT PARCELS
743 #------------------------------------------------------------#
749 @results = &GetParcel($booksellerid, $code, $date);
751 Looks up all of the received items from the supplier with the given
752 bookseller ID at the given date, for the given code (bookseller Invoice number). Ignores cancelled and completed orders.
754 C<@results> is an array of references-to-hash. The keys of each element are fields from
755 the aqorders, biblio, and biblioitems tables of the Koha database.
757 C<@results> is sorted alphabetically by book title.
765 #gets all orders from a certain supplier, orders them alphabetically
766 my ( $supplierid, $code, $datereceived ) = @_;
767 my $dbh = C4::Context->dbh;
770 if $code; # add % if we search on a given code (otherwise, let him empty)
777 aqorders.biblionumber,
779 aqorders.ordernumber,
781 aqorders.quantityreceived,
786 FROM aqorders,aqbasket
787 LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
788 WHERE aqbasket.basketno=aqorders.basketno
789 AND aqbasket.booksellerid=?
790 AND aqorders.booksellerinvoicenumber LIKE \"$code\"
791 AND aqorders.datereceived= \'$datereceived\'";
793 if ( C4::Context->preference("IndependantBranches") ) {
794 my $userenv = C4::Context->userenv;
795 if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
797 " and (borrowers.branchcode = '"
799 . "' or borrowers.branchcode ='')";
802 $strsth .= " order by aqbasket.basketno";
803 ### parcelinformation : $strsth
804 my $sth = $dbh->prepare($strsth);
805 $sth->execute($supplierid);
806 while ( my $data = $sth->fetchrow_hashref ) {
807 push( @results, $data );
809 ### countparcelbiblio: $count
815 #------------------------------------------------------------#
821 $results = &GetParcels($bookseller, $order, $code, $datefrom, $dateto);
822 get a lists of parcels.
827 is the bookseller this function has to get parcels.
830 To know on what criteria the results list has to be ordered.
833 is the booksellerinvoicenumber.
835 =item $datefrom & $dateto
836 to know on what date this function has to filter its search.
839 a pointer on a hash list containing parcel informations as such :
845 =item Number of biblio
847 =item Number of items
854 my ($bookseller,$order, $code, $datefrom, $dateto) = @_;
855 my $dbh = C4::Context->dbh;
857 SELECT aqorders.booksellerinvoicenumber,
859 count(DISTINCT biblionumber) AS biblio,
860 sum(quantity) AS itemsexpected,
861 sum(quantityreceived) AS itemsreceived
862 FROM aqorders, aqbasket
863 WHERE aqbasket.basketno = aqorders.basketno
864 AND aqbasket.booksellerid = $bookseller and datereceived IS NOT NULL
867 $strsth .= "and aqorders.booksellerinvoicenumber like \"$code%\" " if ($code);
869 $strsth .= "and datereceived >=" . $dbh->quote($datefrom) . " " if ($datefrom);
871 $strsth .= "and datereceived <=" . $dbh->quote($dateto) . " " if ($dateto);
873 $strsth .= "group by aqorders.booksellerinvoicenumber,datereceived ";
874 $strsth .= "order by $order " if ($order);
875 my $sth = $dbh->prepare($strsth);
880 while ( my $data2 = $sth->fetchrow_hashref ) {
881 push @results, $data2;
888 #------------------------------------------------------------#
894 @results = &GetLateOrders;
896 Searches for bookseller with late orders.
899 the table of supplier with late issues. This table is full of hashref.
907 my $supplierid = shift;
910 my $dbh = C4::Context->dbh;
912 #BEWARE, order of parenthesis and LEFT JOIN is important for speed
914 my $dbdriver = C4::Context->config("db_scheme") || "mysql";
917 if ( $dbdriver eq "mysql" ) {
919 SELECT aqbasket.basketno,
920 DATE(aqbasket.closedate) AS orderdate,
921 aqorders.quantity - IFNULL(aqorders.quantityreceived,0) AS quantity,
922 aqorders.rrp AS unitpricesupplier,
923 aqorders.ecost AS unitpricelib,
924 (aqorders.quantity - IFNULL(aqorders.quantityreceived,0)) * aqorders.rrp AS subtotal,
925 aqbookfund.bookfundname AS budget,
926 borrowers.branchcode AS branch,
927 aqbooksellers.name AS supplier,
930 biblioitems.publishercode AS publisher,
931 biblioitems.publicationyear,
932 DATEDIFF(CURDATE( ),closedate) AS latesince
934 (aqorders LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber)
935 LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber)
936 LEFT JOIN aqorderbreakdown ON aqorders.ordernumber = aqorderbreakdown.ordernumber)
937 LEFT JOIN aqbookfund ON aqorderbreakdown.bookfundid = aqbookfund.bookfundid),
938 (aqbasket LEFT JOIN borrowers ON aqbasket.authorisedby = borrowers.borrowernumber)
939 LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
940 WHERE aqorders.basketno = aqbasket.basketno
941 AND (closedate < DATE_SUB(CURDATE( ),INTERVAL $delay DAY))
942 AND ((datereceived = '' OR datereceived is null)
943 OR (aqorders.quantityreceived < aqorders.quantity) )
945 $strsth .= " AND aqbasket.booksellerid = $supplierid " if ($supplierid);
946 $strsth .= " AND borrowers.branchcode like \'" . $branch . "\'"
949 " AND borrowers.branchcode like \'"
950 . C4::Context->userenv->{branch} . "\'"
951 if ( C4::Context->preference("IndependantBranches")
952 && C4::Context->userenv
953 && C4::Context->userenv->{flags} != 1 );
954 $strsth .=" HAVING quantity<>0
955 AND unitpricesupplier<>0
957 ORDER BY latesince,basketno,borrowers.branchcode, supplier
962 SELECT aqbasket.basketno,
963 DATE(aqbasket.closedate) AS orderdate,
964 aqorders.quantity, aqorders.rrp AS unitpricesupplier,
965 aqorders.ecost as unitpricelib,
966 aqorders.quantity * aqorders.rrp AS subtotal
967 aqbookfund.bookfundname AS budget,
968 borrowers.branchcode AS branch,
969 aqbooksellers.name AS supplier,
972 biblioitems.publishercode AS publisher,
973 biblioitems.publicationyear,
974 (CURDATE - closedate) AS latesince
976 (aqorders LEFT JOIN biblio on biblio.biblionumber = aqorders.biblionumber)
977 LEFT JOIN biblioitems on biblioitems.biblionumber=biblio.biblionumber)
978 LEFT JOIN aqorderbreakdown on aqorders.ordernumber = aqorderbreakdown.ordernumber)
979 LEFT JOIN aqbookfund ON aqorderbreakdown.bookfundid = aqbookfund.bookfundid),
980 (aqbasket LEFT JOIN borrowers on aqbasket.authorisedby = borrowers.borrowernumber) LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
981 WHERE aqorders.basketno = aqbasket.basketno
982 AND (closedate < (CURDATE -(INTERVAL $delay DAY))
983 AND ((datereceived = '' OR datereceived is null)
984 OR (aqorders.quantityreceived < aqorders.quantity) ) ";
985 $strsth .= " AND aqbasket.booksellerid = $supplierid " if ($supplierid);
987 $strsth .= " AND borrowers.branchcode like \'" . $branch . "\'" if ($branch);
988 $strsth .=" AND borrowers.branchcode like \'". C4::Context->userenv->{branch} . "\'"
989 if (C4::Context->preference("IndependantBranches") && C4::Context->userenv->{flags} != 1 );
990 $strsth .=" ORDER BY latesince,basketno,borrowers.branchcode, supplier";
992 my $sth = $dbh->prepare($strsth);
996 while ( my $data = $sth->fetchrow_hashref ) {
997 $data->{hilighted} = $hilighted if ( $hilighted > 0 );
998 $data->{orderdate} = format_date( $data->{orderdate} );
999 push @results, $data;
1000 $hilighted = -$hilighted;
1006 #------------------------------------------------------------#
1012 (\@order_loop, $total_qty, $total_price, $total_qtyreceived)=&GetHistory( $title, $author, $name, $from_placed_on, $to_placed_on )
1014 this function get the search history.
1021 my ( $title, $author, $name, $from_placed_on, $to_placed_on ) = @_;
1024 my $total_qtyreceived = 0;
1025 my $total_price = 0;
1027 # don't run the query if there are no parameters (list would be too long for sure !)
1028 if ( $title || $author || $name || $from_placed_on || $to_placed_on ) {
1029 my $dbh = C4::Context->dbh;
1035 name,aqbasket.creationdate,
1036 aqorders.datereceived,
1038 aqorders.quantityreceived,
1040 aqorders.ordernumber
1041 FROM aqorders,aqbasket,aqbooksellers,biblio";
1043 $query .= ",borrowers "
1044 if ( C4::Context->preference("IndependantBranches") );
1047 WHERE aqorders.basketno=aqbasket.basketno
1048 AND aqbasket.booksellerid=aqbooksellers.id
1049 AND biblio.biblionumber=aqorders.biblionumber ";
1051 $query .= " AND aqbasket.authorisedby=borrowers.borrowernumber"
1052 if ( C4::Context->preference("IndependantBranches") );
1054 $query .= " AND biblio.title LIKE " . $dbh->quote( "%" . $title . "%" )
1058 " AND biblio.author LIKE " . $dbh->quote( "%" . $author . "%" )
1061 $query .= " AND name LIKE " . $dbh->quote( "%" . $name . "%" ) if $name;
1063 $query .= " AND creationdate >" . $dbh->quote($from_placed_on)
1066 $query .= " AND creationdate<" . $dbh->quote($to_placed_on)
1069 if ( C4::Context->preference("IndependantBranches") ) {
1070 my $userenv = C4::Context->userenv;
1071 if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
1073 " AND (borrowers.branchcode = '"
1074 . $userenv->{branch}
1075 . "' OR borrowers.branchcode ='')";
1078 $query .= " ORDER BY booksellerid";
1079 my $sth = $dbh->prepare($query);
1082 while ( my $line = $sth->fetchrow_hashref ) {
1083 $line->{count} = $cnt++;
1084 $line->{toggle} = 1 if $cnt % 2;
1085 push @order_loop, $line;
1086 $line->{creationdate} = format_date( $line->{creationdate} );
1087 $line->{datereceived} = format_date( $line->{datereceived} );
1088 $total_qty += $line->{'quantity'};
1089 $total_qtyreceived += $line->{'quantityreceived'};
1090 $total_price += $line->{'quantity'} * $line->{'ecost'};
1093 return \@order_loop, $total_qty, $total_price, $total_qtyreceived;
1096 END { } # module clean-up code here (global destructor)
1106 Koha Developement team <info@koha.org>