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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 use C4::Dates qw(format_date format_date_in_iso);
31 use C4::SQLHelper qw(InsertInTable);
36 use vars qw($VERSION @ISA @EXPORT);
39 # set the version for version checking
40 $VERSION = 3.08.01.002;
44 &GetBasket &NewBasket &CloseBasket &DelBasket &ModBasket
46 &GetBasketsByBookseller &GetBasketsByBasketgroup
47 &GetBasketsInfosByBookseller
51 &ModBasketgroup &NewBasketgroup &DelBasketgroup &GetBasketgroup &CloseBasketgroup
52 &GetBasketgroups &ReOpenBasketgroup
54 &NewOrder &DelOrder &ModOrder &GetPendingOrders &GetOrder &GetOrders
55 &GetOrderNumber &GetLateOrders &GetOrderFromItemnumber
56 &SearchOrder &GetHistory &GetRecentAcqui
57 &ModReceiveOrder &ModOrderBiblioitemNumber
60 &NewOrderItem &ModOrderItem
62 &GetParcels &GetParcel
63 &GetContracts &GetContract
65 &GetItemnumbersFromOrder
75 sub GetOrderFromItemnumber {
76 my ($itemnumber) = @_;
77 my $dbh = C4::Context->dbh;
80 SELECT * from aqorders LEFT JOIN aqorders_items
81 ON ( aqorders.ordernumber = aqorders_items.ordernumber )
82 WHERE itemnumber = ? |;
84 my $sth = $dbh->prepare($query);
88 $sth->execute($itemnumber);
90 my $order = $sth->fetchrow_hashref;
95 # Returns the itemnumber(s) associated with the ordernumber given in parameter
96 sub GetItemnumbersFromOrder {
97 my ($ordernumber) = @_;
98 my $dbh = C4::Context->dbh;
99 my $query = "SELECT itemnumber FROM aqorders_items WHERE ordernumber=?";
100 my $sth = $dbh->prepare($query);
101 $sth->execute($ordernumber);
104 while (my $order = $sth->fetchrow_hashref) {
105 push @tab, $order->{'itemnumber'};
119 C4::Acquisition - Koha functions for dealing with orders and acquisitions
127 The functions in this module deal with acquisitions, managing book
128 orders, basket and parcels.
132 =head2 FUNCTIONS ABOUT BASKETS
136 $aqbasket = &GetBasket($basketnumber);
138 get all basket informations in aqbasket for a given basket
140 B<returns:> informations for a given basket returned as a hashref.
146 my $dbh = C4::Context->dbh;
149 concat( b.firstname,' ',b.surname) AS authorisedbyname,
150 b.branchcode AS branch
152 LEFT JOIN borrowers b ON aqbasket.authorisedby=b.borrowernumber
155 my $sth=$dbh->prepare($query);
156 $sth->execute($basketno);
157 my $basket = $sth->fetchrow_hashref;
161 #------------------------------------------------------------#
165 $basket = &NewBasket( $booksellerid, $authorizedby, $basketname,
166 $basketnote, $basketbooksellernote, $basketcontractnumber );
168 Create a new basket in aqbasket table
172 =item C<$booksellerid> is a foreign key in the aqbasket table
174 =item C<$authorizedby> is the username of who created the basket
178 The other parameters are optional, see ModBasketHeader for more info on them.
182 # FIXME : this function seems to be unused.
185 my ( $booksellerid, $authorisedby, $basketname, $basketnote, $basketbooksellernote, $basketcontractnumber ) = @_;
186 my $dbh = C4::Context->dbh;
189 (creationdate,booksellerid,authorisedby)
190 VALUES (now(),'$booksellerid','$authorisedby')
194 #find & return basketno MYSQL dependant, but $dbh->last_insert_id always returns null :-(
195 my $basket = $dbh->{'mysql_insertid'};
196 ModBasketHeader($basket, $basketname || '', $basketnote || '', $basketbooksellernote || '', $basketcontractnumber || undef, $booksellerid);
200 #------------------------------------------------------------#
204 &CloseBasket($basketno);
206 close a basket (becomes unmodifiable,except for recieves)
212 my $dbh = C4::Context->dbh;
218 my $sth = $dbh->prepare($query);
219 $sth->execute($basketno);
222 #------------------------------------------------------------#
224 =head3 GetBasketAsCSV
226 &GetBasketAsCSV($basketno);
228 Export a basket as CSV
234 my $basket = GetBasket($basketno);
235 my @orders = GetOrders($basketno);
236 my $contract = GetContract($basket->{'contractnumber'});
237 my $csv = Text::CSV->new();
240 # TODO: Translate headers
241 my @headers = qw(contractname ordernumber entrydate isbn author title publishercode collectiontitle notes quantity rrp);
243 $csv->combine(@headers);
244 $output = $csv->string() . "\n";
247 foreach my $order (@orders) {
249 # newlines are not valid characters for Text::CSV combine()
250 $order->{'notes'} =~ s/[\r\n]+//g;
252 $contract->{'contractname'},
253 $order->{'ordernumber'},
254 $order->{'entrydate'},
258 $order->{'publishercode'},
259 $order->{'collectiontitle'},
261 $order->{'quantity'},
264 push (@rows, \@cols);
267 foreach my $row (@rows) {
268 $csv->combine(@$row);
269 $output .= $csv->string() . "\n";
278 =head3 CloseBasketgroup
280 &CloseBasketgroup($basketgroupno);
286 sub CloseBasketgroup {
287 my ($basketgroupno) = @_;
288 my $dbh = C4::Context->dbh;
289 my $sth = $dbh->prepare("
290 UPDATE aqbasketgroups
294 $sth->execute($basketgroupno);
297 #------------------------------------------------------------#
299 =head3 ReOpenBaskergroup($basketgroupno)
301 &ReOpenBaskergroup($basketgroupno);
307 sub ReOpenBasketgroup {
308 my ($basketgroupno) = @_;
309 my $dbh = C4::Context->dbh;
310 my $sth = $dbh->prepare("
311 UPDATE aqbasketgroups
315 $sth->execute($basketgroupno);
318 #------------------------------------------------------------#
323 &DelBasket($basketno);
325 Deletes the basket that has basketno field $basketno in the aqbasket table.
329 =item C<$basketno> is the primary key of the basket in the aqbasket table.
336 my ( $basketno ) = @_;
337 my $query = "DELETE FROM aqbasket WHERE basketno=?";
338 my $dbh = C4::Context->dbh;
339 my $sth = $dbh->prepare($query);
340 $sth->execute($basketno);
344 #------------------------------------------------------------#
348 &ModBasket($basketinfo);
350 Modifies a basket, using a hashref $basketinfo for the relevant information, only $basketinfo->{'basketno'} is required.
354 =item C<$basketno> is the primary key of the basket in the aqbasket table.
361 my $basketinfo = shift;
362 my $query = "UPDATE aqbasket SET ";
364 foreach my $key (keys %$basketinfo){
365 if ($key ne 'basketno'){
366 $query .= "$key=?, ";
367 push(@params, $basketinfo->{$key} || undef );
370 # get rid of the "," at the end of $query
371 if (substr($query, length($query)-2) eq ', '){
376 $query .= "WHERE basketno=?";
377 push(@params, $basketinfo->{'basketno'});
378 my $dbh = C4::Context->dbh;
379 my $sth = $dbh->prepare($query);
380 $sth->execute(@params);
384 #------------------------------------------------------------#
386 =head3 ModBasketHeader
388 &ModBasketHeader($basketno, $basketname, $note, $booksellernote, $contractnumber);
390 Modifies a basket's header.
394 =item C<$basketno> is the "basketno" field in the "aqbasket" table;
396 =item C<$basketname> is the "basketname" field in the "aqbasket" table;
398 =item C<$note> is the "note" field in the "aqbasket" table;
400 =item C<$booksellernote> is the "booksellernote" field in the "aqbasket" table;
402 =item C<$contractnumber> is the "contractnumber" (foreign) key in the "aqbasket" table.
408 sub ModBasketHeader {
409 my ($basketno, $basketname, $note, $booksellernote, $contractnumber) = @_;
410 my $query = "UPDATE aqbasket SET basketname=?, note=?, booksellernote=? WHERE basketno=?";
411 my $dbh = C4::Context->dbh;
412 my $sth = $dbh->prepare($query);
413 $sth->execute($basketname,$note,$booksellernote,$basketno);
414 if ( $contractnumber ) {
415 my $query2 ="UPDATE aqbasket SET contractnumber=? WHERE basketno=?";
416 my $sth2 = $dbh->prepare($query2);
417 $sth2->execute($contractnumber,$basketno);
423 #------------------------------------------------------------#
425 =head3 GetBasketsByBookseller
427 @results = &GetBasketsByBookseller($booksellerid, $extra);
429 Returns a list of hashes of all the baskets that belong to bookseller 'booksellerid'.
433 =item C<$booksellerid> is the 'id' field of the bookseller in the aqbooksellers table
435 =item C<$extra> is the extra sql parameters, can be
437 $extra->{groupby}: group baskets by column
438 ex. $extra->{groupby} = aqbasket.basketgroupid
439 $extra->{orderby}: order baskets by column
440 $extra->{limit}: limit number of results (can be helpful for pagination)
446 sub GetBasketsByBookseller {
447 my ($booksellerid, $extra) = @_;
448 my $query = "SELECT * FROM aqbasket WHERE booksellerid=?";
450 if ($extra->{groupby}) {
451 $query .= " GROUP by $extra->{groupby}";
453 if ($extra->{orderby}){
454 $query .= " ORDER by $extra->{orderby}";
456 if ($extra->{limit}){
457 $query .= " LIMIT $extra->{limit}";
460 my $dbh = C4::Context->dbh;
461 my $sth = $dbh->prepare($query);
462 $sth->execute($booksellerid);
463 my $results = $sth->fetchall_arrayref({});
468 =head3 GetBasketsInfosByBookseller
470 my $baskets = GetBasketsInfosByBookseller($supplierid);
472 Returns in a arrayref of hashref all about booksellers baskets, plus:
473 total_biblios: Number of distinct biblios in basket
474 total_items: Number of items in basket
475 expected_items: Number of non-received items in basket
479 sub GetBasketsInfosByBookseller {
480 my ($supplierid) = @_;
482 return unless $supplierid;
484 my $dbh = C4::Context->dbh;
487 SUM(aqorders.quantity) AS total_items,
488 COUNT(DISTINCT aqorders.biblionumber) AS total_biblios,
490 IF(aqorders.datereceived IS NULL
491 AND aqorders.datecancellationprinted IS NULL
496 LEFT JOIN aqorders ON aqorders.basketno = aqbasket.basketno
497 WHERE booksellerid = ?
498 GROUP BY aqbasket.basketno
500 my $sth = $dbh->prepare($query);
501 $sth->execute($supplierid);
502 return $sth->fetchall_arrayref({});
506 #------------------------------------------------------------#
508 =head3 GetBasketsByBasketgroup
510 $baskets = &GetBasketsByBasketgroup($basketgroupid);
512 Returns a reference to all baskets that belong to basketgroup $basketgroupid.
516 sub GetBasketsByBasketgroup {
517 my $basketgroupid = shift;
518 my $query = "SELECT * FROM aqbasket
519 LEFT JOIN aqcontract USING(contractnumber) WHERE basketgroupid=?";
520 my $dbh = C4::Context->dbh;
521 my $sth = $dbh->prepare($query);
522 $sth->execute($basketgroupid);
523 my $results = $sth->fetchall_arrayref({});
528 #------------------------------------------------------------#
530 =head3 NewBasketgroup
532 $basketgroupid = NewBasketgroup(\%hashref);
534 Adds a basketgroup to the aqbasketgroups table, and add the initial baskets to it.
536 $hashref->{'booksellerid'} is the 'id' field of the bookseller in the aqbooksellers table,
538 $hashref->{'name'} is the 'name' field of the basketgroup in the aqbasketgroups table,
540 $hashref->{'basketlist'} is a list reference of the 'id's of the baskets that belong to this group,
542 $hashref->{'deliveryplace'} is the 'deliveryplace' field of the basketgroup in the aqbasketgroups table,
544 $hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table,
546 $hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise.
551 my $basketgroupinfo = shift;
552 die "booksellerid is required to create a basketgroup" unless $basketgroupinfo->{'booksellerid'};
553 my $query = "INSERT INTO aqbasketgroups (";
555 foreach my $field ('name', 'deliveryplace', 'deliverycomment', 'closed') {
556 if ( $basketgroupinfo->{$field} ) {
557 $query .= "$field, ";
558 push(@params, $basketgroupinfo->{$field});
561 $query .= "booksellerid) VALUES (";
566 push(@params, $basketgroupinfo->{'booksellerid'});
567 my $dbh = C4::Context->dbh;
568 my $sth = $dbh->prepare($query);
569 $sth->execute(@params);
570 my $basketgroupid = $dbh->{'mysql_insertid'};
571 if( $basketgroupinfo->{'basketlist'} ) {
572 foreach my $basketno (@{$basketgroupinfo->{'basketlist'}}) {
573 my $query2 = "UPDATE aqbasket SET basketgroupid=? WHERE basketno=?";
574 my $sth2 = $dbh->prepare($query2);
575 $sth2->execute($basketgroupid, $basketno);
578 return $basketgroupid;
581 #------------------------------------------------------------#
583 =head3 ModBasketgroup
585 ModBasketgroup(\%hashref);
587 Modifies a basketgroup in the aqbasketgroups table, and add the baskets to it.
589 $hashref->{'id'} is the 'id' field of the basketgroup in the aqbasketgroup table, this parameter is mandatory,
591 $hashref->{'name'} is the 'name' field of the basketgroup in the aqbasketgroups table,
593 $hashref->{'basketlist'} is a list reference of the 'id's of the baskets that belong to this group,
595 $hashref->{'billingplace'} is the 'billingplace' field of the basketgroup in the aqbasketgroups table,
597 $hashref->{'deliveryplace'} is the 'deliveryplace' field of the basketgroup in the aqbasketgroups table,
599 $hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table,
601 $hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise.
606 my $basketgroupinfo = shift;
607 die "basketgroup id is required to edit a basketgroup" unless $basketgroupinfo->{'id'};
608 my $dbh = C4::Context->dbh;
609 my $query = "UPDATE aqbasketgroups SET ";
611 foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment closed)) {
612 if ( defined $basketgroupinfo->{$field} ) {
613 $query .= "$field=?, ";
614 push(@params, $basketgroupinfo->{$field});
619 $query .= " WHERE id=?";
620 push(@params, $basketgroupinfo->{'id'});
621 my $sth = $dbh->prepare($query);
622 $sth->execute(@params);
624 $sth = $dbh->prepare('UPDATE aqbasket SET basketgroupid = NULL WHERE basketgroupid = ?');
625 $sth->execute($basketgroupinfo->{'id'});
627 if($basketgroupinfo->{'basketlist'} && @{$basketgroupinfo->{'basketlist'}}){
628 $sth = $dbh->prepare("UPDATE aqbasket SET basketgroupid=? WHERE basketno=?");
629 foreach my $basketno (@{$basketgroupinfo->{'basketlist'}}) {
630 $sth->execute($basketgroupinfo->{'id'}, $basketno);
637 #------------------------------------------------------------#
639 =head3 DelBasketgroup
641 DelBasketgroup($basketgroupid);
643 Deletes a basketgroup in the aqbasketgroups table, and removes the reference to it from the baskets,
647 =item C<$basketgroupid> is the 'id' field of the basket in the aqbasketgroup table
654 my $basketgroupid = shift;
655 die "basketgroup id is required to edit a basketgroup" unless $basketgroupid;
656 my $query = "DELETE FROM aqbasketgroups WHERE id=?";
657 my $dbh = C4::Context->dbh;
658 my $sth = $dbh->prepare($query);
659 $sth->execute($basketgroupid);
663 #------------------------------------------------------------#
666 =head2 FUNCTIONS ABOUT ORDERS
668 =head3 GetBasketgroup
670 $basketgroup = &GetBasketgroup($basketgroupid);
672 Returns a reference to the hash containing all infermation about the basketgroup.
677 my $basketgroupid = shift;
678 die "basketgroup id is required to edit a basketgroup" unless $basketgroupid;
679 my $query = "SELECT * FROM aqbasketgroups WHERE id=?";
680 my $dbh = C4::Context->dbh;
681 my $sth = $dbh->prepare($query);
682 $sth->execute($basketgroupid);
683 my $result = $sth->fetchrow_hashref;
688 #------------------------------------------------------------#
690 =head3 GetBasketgroups
692 $basketgroups = &GetBasketgroups($booksellerid);
694 Returns a reference to the array of all the basketgroups of bookseller $booksellerid.
698 sub GetBasketgroups {
699 my $booksellerid = shift;
700 die "bookseller id is required to edit a basketgroup" unless $booksellerid;
701 my $query = "SELECT * FROM aqbasketgroups WHERE booksellerid=? ORDER BY `id` DESC";
702 my $dbh = C4::Context->dbh;
703 my $sth = $dbh->prepare($query);
704 $sth->execute($booksellerid);
705 my $results = $sth->fetchall_arrayref({});
710 #------------------------------------------------------------#
712 =head2 FUNCTIONS ABOUT ORDERS
716 #------------------------------------------------------------#
718 =head3 GetPendingOrders
720 $orders = &GetPendingOrders($booksellerid, $grouped, $owner);
722 Finds pending orders from the bookseller with the given ID. Ignores
723 completed and cancelled orders.
725 C<$booksellerid> contains the bookseller identifier
726 C<$grouped> contains 0 or 1. 0 means returns the list, 1 means return the total
727 C<$owner> contains 0 or 1. 0 means any owner. 1 means only the list of orders entered by the user itself.
729 C<$orders> is a reference-to-array; each element is a
730 reference-to-hash with the following fields:
731 C<$grouped> is a boolean that, if set to 1 will group all order lines of the same basket
732 in a single result line
736 =item C<authorizedby>
744 These give the value of the corresponding field in the aqorders table
745 of the Koha database.
747 Results are ordered from most to least recent.
751 sub GetPendingOrders {
752 my ($supplierid,$grouped,$owner,$basketno) = @_;
753 my $dbh = C4::Context->dbh;
755 SELECT ".($grouped?"count(*),":"")."aqbasket.basketno,
756 surname,firstname,biblio.*,biblioitems.isbn,
757 aqbasket.closedate, aqbasket.creationdate, aqbasket.basketname,
760 LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno
761 LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
762 LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber
763 LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber
765 AND (quantity > quantityreceived OR quantityreceived is NULL)
766 AND datecancellationprinted IS NULL";
767 my @query_params = ( $supplierid );
768 my $userenv = C4::Context->userenv;
769 if ( C4::Context->preference("IndependantBranches") ) {
770 if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
771 $strsth .= " and (borrowers.branchcode = ?
772 or borrowers.branchcode = '')";
773 push @query_params, $userenv->{branch};
777 $strsth .= " AND aqbasket.authorisedby=? ";
778 push @query_params, $userenv->{'number'};
781 $strsth .= " AND aqbasket.basketno=? ";
782 push @query_params, $basketno;
784 $strsth .= " group by aqbasket.basketno" if $grouped;
785 $strsth .= " order by aqbasket.basketno";
787 my $sth = $dbh->prepare($strsth);
788 $sth->execute( @query_params );
789 my $results = $sth->fetchall_arrayref({});
794 #------------------------------------------------------------#
798 @orders = &GetOrders($basketnumber, $orderby);
800 Looks up the pending (non-cancelled) orders with the given basket
801 number. If C<$booksellerID> is non-empty, only orders from that seller
805 C<&basket> returns a two-element array. C<@orders> is an array of
806 references-to-hash, whose keys are the fields from the aqorders,
807 biblio, and biblioitems tables in the Koha database.
812 my ( $basketno, $orderby ) = @_;
813 my $dbh = C4::Context->dbh;
815 SELECT biblio.*,biblioitems.*,
820 LEFT JOIN aqbudgets ON aqbudgets.budget_id = aqorders.budget_id
821 LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber
822 LEFT JOIN biblioitems ON biblioitems.biblionumber =biblio.biblionumber
824 AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
827 $orderby = "biblioitems.publishercode,biblio.title" unless $orderby;
828 $query .= " ORDER BY $orderby";
829 my $sth = $dbh->prepare($query);
830 $sth->execute($basketno);
831 my $results = $sth->fetchall_arrayref({});
836 #------------------------------------------------------------#
838 =head3 GetOrderNumber
840 $ordernumber = &GetOrderNumber($biblioitemnumber, $biblionumber);
842 Looks up the ordernumber with the given biblionumber and biblioitemnumber.
844 Returns the number of this order.
848 =item C<$ordernumber> is the order number.
855 my ( $biblionumber,$biblioitemnumber ) = @_;
856 my $dbh = C4::Context->dbh;
861 AND biblioitemnumber=?
863 my $sth = $dbh->prepare($query);
864 $sth->execute( $biblionumber, $biblioitemnumber );
866 return $sth->fetchrow;
869 #------------------------------------------------------------#
873 $order = &GetOrder($ordernumber);
875 Looks up an order by order number.
877 Returns a reference-to-hash describing the order. The keys of
878 C<$order> are fields from the biblio, biblioitems, aqorders tables of the Koha database.
883 my ($ordernumber) = @_;
884 my $dbh = C4::Context->dbh;
886 SELECT biblioitems.*, biblio.*, aqorders.*
888 LEFT JOIN biblio on biblio.biblionumber=aqorders.biblionumber
889 LEFT JOIN biblioitems on biblioitems.biblionumber=aqorders.biblionumber
890 WHERE aqorders.ordernumber=?
893 my $sth= $dbh->prepare($query);
894 $sth->execute($ordernumber);
895 my $data = $sth->fetchrow_hashref;
900 #------------------------------------------------------------#
904 &NewOrder(\%hashref);
906 Adds a new order to the database. Any argument that isn't described
907 below is the new value of the field with the same name in the aqorders
908 table of the Koha database.
912 =item $hashref->{'basketno'} is the basketno foreign key in aqorders, it is mandatory
914 =item $hashref->{'ordernumber'} is a "minimum order number."
916 =item $hashref->{'budgetdate'} is effectively ignored.
917 If it's undef (anything false) or the string 'now', the current day is used.
918 Else, the upcoming July 1st is used.
920 =item $hashref->{'subscription'} may be either "yes", or anything else for "no".
922 =item $hashref->{'uncertainprice'} may be 0 for "the price is known" or 1 for "the price is uncertain"
924 =item defaults entrydate to Now
926 The following keys are used: "biblionumber", "title", "basketno", "quantity", "notes", "biblioitemnumber", "rrp", "ecost", "gst", "unitprice", "subscription", "sort1", "sort2", "booksellerinvoicenumber", "listprice", "budgetdate", "purchaseordernumber", "branchcode", "booksellerinvoicenumber", "bookfundid".
933 my $orderinfo = shift;
934 #### ------------------------------
935 my $dbh = C4::Context->dbh;
939 # if these parameters are missing, we can't continue
940 for my $key (qw/basketno quantity biblionumber budget_id/) {
941 croak "Mandatory parameter $key missing" unless $orderinfo->{$key};
944 if ( defined $orderinfo->{subscription} && $orderinfo->{'subscription'} eq 'yes' ) {
945 $orderinfo->{'subscription'} = 1;
947 $orderinfo->{'subscription'} = 0;
949 $orderinfo->{'entrydate'} ||= C4::Dates->new()->output("iso");
950 if (!$orderinfo->{quantityreceived}) {
951 $orderinfo->{quantityreceived} = 0;
954 my $ordernumber=InsertInTable("aqorders",$orderinfo);
955 return ( $orderinfo->{'basketno'}, $ordernumber );
960 #------------------------------------------------------------#
969 my ($itemnumber, $ordernumber) = @_;
970 my $dbh = C4::Context->dbh;
972 INSERT INTO aqorders_items
973 (itemnumber, ordernumber)
976 my $sth = $dbh->prepare($query);
977 $sth->execute( $itemnumber, $ordernumber);
980 #------------------------------------------------------------#
984 &ModOrder(\%hashref);
986 Modifies an existing order. Updates the order with order number
987 $hashref->{'ordernumber'} and biblionumber $hashref->{'biblionumber'}. All
988 other keys of the hash update the fields with the same name in the aqorders
989 table of the Koha database.
994 my $orderinfo = shift;
996 die "Ordernumber is required" if $orderinfo->{'ordernumber'} eq '' ;
997 die "Biblionumber is required" if $orderinfo->{'biblionumber'} eq '';
999 my $dbh = C4::Context->dbh;
1002 # update uncertainprice to an integer, just in case (under FF, checked boxes have the value "ON" by default)
1003 $orderinfo->{uncertainprice}=1 if $orderinfo->{uncertainprice};
1005 # delete($orderinfo->{'branchcode'});
1006 # the hash contains a lot of entries not in aqorders, so get the columns ...
1007 my $sth = $dbh->prepare("SELECT * FROM aqorders LIMIT 1;");
1009 my $colnames = $sth->{NAME};
1010 my $query = "UPDATE aqorders SET ";
1012 foreach my $orderinfokey (grep(!/ordernumber/, keys %$orderinfo)){
1013 # ... and skip hash entries that are not in the aqorders table
1014 # FIXME : probably not the best way to do it (would be better to have a correct hash)
1015 next unless grep(/^$orderinfokey$/, @$colnames);
1016 $query .= "$orderinfokey=?, ";
1017 push(@params, $orderinfo->{$orderinfokey});
1020 $query .= "timestamp=NOW() WHERE ordernumber=?";
1021 # push(@params, $specorderinfo{'ordernumber'});
1022 push(@params, $orderinfo->{'ordernumber'} );
1023 $sth = $dbh->prepare($query);
1024 $sth->execute(@params);
1028 #------------------------------------------------------------#
1032 &ModOrderItem(\%hashref);
1034 Modifies the itemnumber in the aqorders_items table. The input hash needs three entities:
1038 =item - itemnumber: the old itemnumber
1039 =item - ordernumber: the order this item is attached to
1040 =item - newitemnumber: the new itemnumber we want to attach the line to
1047 my $orderiteminfo = shift;
1048 if (! $orderiteminfo->{'ordernumber'} || ! $orderiteminfo->{'itemnumber'} || ! $orderiteminfo->{'newitemnumber'}){
1049 die "Ordernumber, itemnumber and newitemnumber is required";
1052 my $dbh = C4::Context->dbh;
1054 my $query = "UPDATE aqorders_items set itemnumber=? where itemnumber=? and ordernumber=?";
1055 my @params = ($orderiteminfo->{'newitemnumber'}, $orderiteminfo->{'itemnumber'}, $orderiteminfo->{'ordernumber'});
1056 my $sth = $dbh->prepare($query);
1057 $sth->execute(@params);
1061 #------------------------------------------------------------#
1064 =head3 ModOrderBibliotemNumber
1066 &ModOrderBiblioitemNumber($biblioitemnumber,$ordernumber, $biblionumber);
1068 Modifies the biblioitemnumber for an existing order.
1069 Updates the order with order number C<$ordernum> and biblionumber C<$biblionumber>.
1073 #FIXME: is this used at all?
1074 sub ModOrderBiblioitemNumber {
1075 my ($biblioitemnumber,$ordernumber, $biblionumber) = @_;
1076 my $dbh = C4::Context->dbh;
1079 SET biblioitemnumber = ?
1080 WHERE ordernumber = ?
1081 AND biblionumber = ?";
1082 my $sth = $dbh->prepare($query);
1083 $sth->execute( $biblioitemnumber, $ordernumber, $biblionumber );
1086 =head3 GetCancelledOrders
1088 my @orders = GetCancelledOrders($basketno, $orderby);
1090 Returns cancelled orders for a basket
1094 sub GetCancelledOrders {
1095 my ( $basketno, $orderby ) = @_;
1097 return () unless $basketno;
1099 my $dbh = C4::Context->dbh;
1101 SELECT biblio.*, biblioitems.*, aqorders.*, aqbudgets.*
1103 LEFT JOIN aqbudgets ON aqbudgets.budget_id = aqorders.budget_id
1104 LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber
1105 LEFT JOIN biblioitems ON biblioitems.biblionumber = biblio.biblionumber
1107 AND (datecancellationprinted IS NOT NULL
1108 AND datecancellationprinted <> '0000-00-00')
1111 $orderby = "aqorders.datecancellationprinted desc, aqorders.timestamp desc"
1113 $query .= " ORDER BY $orderby";
1114 my $sth = $dbh->prepare($query);
1115 $sth->execute($basketno);
1116 my $results = $sth->fetchall_arrayref( {} );
1122 #------------------------------------------------------------#
1124 =head3 ModReceiveOrder
1126 &ModReceiveOrder($biblionumber, $ordernumber, $quantityreceived, $user,
1127 $unitprice, $booksellerinvoicenumber, $biblioitemnumber,
1128 $freight, $bookfund, $rrp);
1130 Updates an order, to reflect the fact that it was received, at least
1131 in part. All arguments not mentioned below update the fields with the
1132 same name in the aqorders table of the Koha database.
1134 If a partial order is received, splits the order into two. The received
1135 portion must have a booksellerinvoicenumber.
1137 Updates the order with bibilionumber C<$biblionumber> and ordernumber
1143 sub ModReceiveOrder {
1145 $biblionumber, $ordernumber, $quantrec, $user, $cost,
1146 $invoiceno, $freight, $rrp, $budget_id, $datereceived
1149 my $dbh = C4::Context->dbh;
1150 $datereceived = C4::Dates->output('iso') unless $datereceived;
1151 my $suggestionid = GetSuggestionFromBiblionumber( $biblionumber );
1152 if ($suggestionid) {
1153 ModSuggestion( {suggestionid=>$suggestionid,
1154 STATUS=>'AVAILABLE',
1155 biblionumber=> $biblionumber}
1159 my $sth=$dbh->prepare("
1160 SELECT * FROM aqorders
1161 WHERE biblionumber=? AND aqorders.ordernumber=?");
1163 $sth->execute($biblionumber,$ordernumber);
1164 my $order = $sth->fetchrow_hashref();
1167 if ( $order->{quantity} > $quantrec ) {
1168 $sth=$dbh->prepare("
1170 SET quantityreceived=?
1172 , booksellerinvoicenumber=?
1177 WHERE biblionumber=? AND ordernumber=?");
1179 $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$quantrec,$biblionumber,$ordernumber);
1182 # create a new order for the remaining items, and set its bookfund.
1183 foreach my $orderkey ( "linenumber", "allocation" ) {
1184 delete($order->{'$orderkey'});
1186 $order->{'quantity'} -= $quantrec;
1187 $order->{'quantityreceived'} = 0;
1188 my $newOrder = NewOrder($order);
1190 $sth=$dbh->prepare("update aqorders
1191 set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?,
1192 unitprice=?,freight=?,rrp=?
1193 where biblionumber=? and ordernumber=?");
1194 $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblionumber,$ordernumber);
1197 return $datereceived;
1199 #------------------------------------------------------------#
1203 @results = &SearchOrder($search, $biblionumber, $complete);
1205 Searches for orders.
1207 C<$search> may take one of several forms: if it is an ISBN,
1208 C<&ordersearch> returns orders with that ISBN. If C<$search> is an
1209 order number, C<&ordersearch> returns orders with that order number
1210 and biblionumber C<$biblionumber>. Otherwise, C<$search> is considered
1211 to be a space-separated list of search terms; in this case, all of the
1212 terms must appear in the title (matching the beginning of title
1215 If C<$complete> is C<yes>, the results will include only completed
1216 orders. In any case, C<&ordersearch> ignores cancelled orders.
1218 C<&ordersearch> returns an array.
1219 C<@results> is an array of references-to-hash with the following keys:
1225 =item C<seriestitle>
1236 #### -------- SearchOrder-------------------------------
1237 my ($ordernumber, $search, $supplierid, $basket) = @_;
1239 my $dbh = C4::Context->dbh;
1244 LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber
1245 LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber
1246 LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno
1247 WHERE (datecancellationprinted is NULL)";
1250 $query .= " AND (aqorders.ordernumber=?)";
1251 push @args, $ordernumber;
1254 $query .= " AND (biblio.title like ? OR biblio.author LIKE ? OR biblioitems.isbn like ?)";
1255 push @args, ("%$search%","%$search%","%$search%");
1258 $query .= "AND aqbasket.booksellerid = ?";
1259 push @args, $supplierid;
1262 $query .= "AND aqorders.basketno = ?";
1263 push @args, $basket;
1266 my $sth = $dbh->prepare($query);
1267 $sth->execute(@args);
1268 my $results = $sth->fetchall_arrayref({});
1273 #------------------------------------------------------------#
1277 &DelOrder($biblionumber, $ordernumber);
1279 Cancel the order with the given order and biblio numbers. It does not
1280 delete any entries in the aqorders table, it merely marks them as
1286 my ( $bibnum, $ordernumber ) = @_;
1287 my $dbh = C4::Context->dbh;
1290 SET datecancellationprinted=now()
1291 WHERE biblionumber=? AND ordernumber=?
1293 my $sth = $dbh->prepare($query);
1294 $sth->execute( $bibnum, $ordernumber );
1296 my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1297 foreach my $itemnumber (@itemnumbers){
1298 C4::Items::DelItem( $dbh, $bibnum, $itemnumber );
1303 =head2 FUNCTIONS ABOUT PARCELS
1307 #------------------------------------------------------------#
1311 @results = &GetParcel($booksellerid, $code, $date);
1313 Looks up all of the received items from the supplier with the given
1314 bookseller ID at the given date, for the given code (bookseller Invoice number). Ignores cancelled and completed orders.
1316 C<@results> is an array of references-to-hash. The keys of each element are fields from
1317 the aqorders, biblio, and biblioitems tables of the Koha database.
1319 C<@results> is sorted alphabetically by book title.
1324 #gets all orders from a certain supplier, orders them alphabetically
1325 my ( $supplierid, $code, $datereceived ) = @_;
1326 my $dbh = C4::Context->dbh;
1329 if $code; # add % if we search on a given code (otherwise, let him empty)
1331 SELECT authorisedby,
1336 aqorders.biblionumber,
1337 aqorders.ordernumber,
1339 aqorders.quantityreceived,
1346 LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno
1347 LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
1348 LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber
1350 aqbasket.booksellerid = ?
1351 AND aqorders.booksellerinvoicenumber LIKE ?
1352 AND aqorders.datereceived = ? ";
1354 my @query_params = ( $supplierid, $code, $datereceived );
1355 if ( C4::Context->preference("IndependantBranches") ) {
1356 my $userenv = C4::Context->userenv;
1357 if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
1358 $strsth .= " and (borrowers.branchcode = ?
1359 or borrowers.branchcode = '')";
1360 push @query_params, $userenv->{branch};
1363 $strsth .= " ORDER BY aqbasket.basketno";
1364 # ## parcelinformation : $strsth
1365 my $sth = $dbh->prepare($strsth);
1366 $sth->execute( @query_params );
1367 while ( my $data = $sth->fetchrow_hashref ) {
1368 push( @results, $data );
1370 # ## countparcelbiblio: scalar(@results)
1376 #------------------------------------------------------------#
1380 $results = &GetParcels($bookseller, $order, $code, $datefrom, $dateto);
1382 get a lists of parcels.
1389 is the bookseller this function has to get parcels.
1392 To know on what criteria the results list has to be ordered.
1395 is the booksellerinvoicenumber.
1397 =item $datefrom & $dateto
1398 to know on what date this function has to filter its search.
1403 a pointer on a hash list containing parcel informations as such :
1409 =item Last operation
1411 =item Number of biblio
1413 =item Number of items
1420 my ($bookseller,$order, $code, $datefrom, $dateto) = @_;
1421 my $dbh = C4::Context->dbh;
1422 my @query_params = ();
1424 SELECT aqorders.booksellerinvoicenumber,
1425 datereceived,purchaseordernumber,
1426 count(DISTINCT biblionumber) AS biblio,
1427 sum(quantity) AS itemsexpected,
1428 sum(quantityreceived) AS itemsreceived
1429 FROM aqorders LEFT JOIN aqbasket ON aqbasket.basketno = aqorders.basketno
1430 WHERE aqbasket.booksellerid = ? and datereceived IS NOT NULL
1432 push @query_params, $bookseller;
1434 if ( defined $code ) {
1435 $strsth .= ' and aqorders.booksellerinvoicenumber like ? ';
1436 # add a % to the end of the code to allow stemming.
1437 push @query_params, "$code%";
1440 if ( defined $datefrom ) {
1441 $strsth .= ' and datereceived >= ? ';
1442 push @query_params, $datefrom;
1445 if ( defined $dateto ) {
1446 $strsth .= 'and datereceived <= ? ';
1447 push @query_params, $dateto;
1450 $strsth .= "group by aqorders.booksellerinvoicenumber,datereceived ";
1452 # can't use a placeholder to place this column name.
1453 # but, we could probably be checking to make sure it is a column that will be fetched.
1454 $strsth .= "order by $order " if ($order);
1456 my $sth = $dbh->prepare($strsth);
1458 $sth->execute( @query_params );
1459 my $results = $sth->fetchall_arrayref({});
1464 #------------------------------------------------------------#
1466 =head3 GetLateOrders
1468 @results = &GetLateOrders;
1470 Searches for bookseller with late orders.
1473 the table of supplier with late issues. This table is full of hashref.
1479 my $supplierid = shift;
1481 my $estimateddeliverydatefrom = shift;
1482 my $estimateddeliverydateto = shift;
1484 my $dbh = C4::Context->dbh;
1486 #BEWARE, order of parenthesis and LEFT JOIN is important for speed
1487 my $dbdriver = C4::Context->config("db_scheme") || "mysql";
1489 my @query_params = ();
1491 SELECT aqbasket.basketno,
1492 aqorders.ordernumber,
1493 DATE(aqbasket.closedate) AS orderdate,
1494 aqorders.rrp AS unitpricesupplier,
1495 aqorders.ecost AS unitpricelib,
1496 aqorders.claims_count AS claims_count,
1497 aqorders.claimed_date AS claimed_date,
1498 aqbudgets.budget_name AS budget,
1499 borrowers.branchcode AS branch,
1500 aqbooksellers.name AS supplier,
1501 aqbooksellers.id AS supplierid,
1502 biblio.author, biblio.title,
1503 biblioitems.publishercode AS publisher,
1504 biblioitems.publicationyear,
1505 ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) AS estimateddeliverydate,
1509 aqorders LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber
1510 LEFT JOIN biblioitems ON biblioitems.biblionumber = biblio.biblionumber
1511 LEFT JOIN aqbudgets ON aqorders.budget_id = aqbudgets.budget_id,
1512 aqbasket LEFT JOIN borrowers ON aqbasket.authorisedby = borrowers.borrowernumber
1513 LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
1514 WHERE aqorders.basketno = aqbasket.basketno
1515 AND ( datereceived = ''
1516 OR datereceived IS NULL
1517 OR aqorders.quantityreceived < aqorders.quantity
1519 AND aqbasket.closedate IS NOT NULL
1520 AND (aqorders.datecancellationprinted IS NULL OR aqorders.datecancellationprinted='0000-00-00')
1523 if ($dbdriver eq "mysql") {
1525 aqorders.quantity - IFNULL(aqorders.quantityreceived,0) AS quantity,
1526 (aqorders.quantity - IFNULL(aqorders.quantityreceived,0)) * aqorders.rrp AS subtotal,
1527 DATEDIFF(CAST(now() AS date),closedate) AS latesince
1529 if ( defined $delay ) {
1530 $from .= " AND (closedate <= DATE_SUB(CAST(now() AS date),INTERVAL ? DAY)) " ;
1531 push @query_params, $delay;
1534 HAVING quantity <> 0
1535 AND unitpricesupplier <> 0
1536 AND unitpricelib <> 0
1539 # FIXME: account for IFNULL as above
1541 aqorders.quantity AS quantity,
1542 aqorders.quantity * aqorders.rrp AS subtotal,
1543 (CAST(now() AS date) - closedate) AS latesince
1545 if ( defined $delay ) {
1546 $from .= " AND (closedate <= (CAST(now() AS date) -(INTERVAL ? DAY)) ";
1547 push @query_params, $delay;
1550 if (defined $supplierid) {
1551 $from .= ' AND aqbasket.booksellerid = ? ';
1552 push @query_params, $supplierid;
1554 if (defined $branch) {
1555 $from .= ' AND borrowers.branchcode LIKE ? ';
1556 push @query_params, $branch;
1558 if ( defined $estimateddeliverydatefrom ) {
1560 AND aqbooksellers.deliverytime IS NOT NULL
1561 AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) >= ?';
1562 push @query_params, $estimateddeliverydatefrom;
1564 if ( defined $estimateddeliverydatefrom and defined $estimateddeliverydateto ) {
1565 $from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) <= ?';
1566 push @query_params, $estimateddeliverydateto;
1567 } elsif ( defined $estimateddeliverydatefrom ) {
1568 $from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) <= CAST(now() AS date)';
1570 if (C4::Context->preference("IndependantBranches")
1571 && C4::Context->userenv
1572 && C4::Context->userenv->{flags} != 1 ) {
1573 $from .= ' AND borrowers.branchcode LIKE ? ';
1574 push @query_params, C4::Context->userenv->{branch};
1576 my $query = "$select $from $having\nORDER BY latesince, basketno, borrowers.branchcode, supplier";
1577 $debug and print STDERR "GetLateOrders query: $query\nGetLateOrders args: " . join(" ",@query_params);
1578 my $sth = $dbh->prepare($query);
1579 $sth->execute(@query_params);
1581 while (my $data = $sth->fetchrow_hashref) {
1582 $data->{orderdate} = format_date($data->{orderdate});
1583 $data->{claimed_date} = format_date($data->{claimed_date});
1584 push @results, $data;
1589 #------------------------------------------------------------#
1593 (\@order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( %params );
1595 Retreives some acquisition history information
1603 basket - search both basket name and number
1604 booksellerinvoicenumber
1607 $order_loop is a list of hashrefs that each look like this:
1609 'author' => 'Twain, Mark',
1611 'biblionumber' => '215',
1613 'creationdate' => 'MM/DD/YYYY',
1614 'datereceived' => undef,
1617 'invoicenumber' => undef,
1619 'ordernumber' => '1',
1621 'quantityreceived' => undef,
1622 'title' => 'The Adventures of Huckleberry Finn'
1624 $total_qty is the sum of all of the quantities in $order_loop
1625 $total_price is the cost of each in $order_loop times the quantity
1626 $total_qtyreceived is the sum of all of the quantityreceived entries in $order_loop
1631 # don't run the query if there are no parameters (list would be too long for sure !)
1632 croak "No search params" unless @_;
1634 my $title = $params{title};
1635 my $author = $params{author};
1636 my $isbn = $params{isbn};
1637 my $name = $params{name};
1638 my $from_placed_on = $params{from_placed_on};
1639 my $to_placed_on = $params{to_placed_on};
1640 my $basket = $params{basket};
1641 my $booksellerinvoicenumber = $params{booksellerinvoicenumber};
1645 my $total_qtyreceived = 0;
1646 my $total_price = 0;
1648 my $dbh = C4::Context->dbh;
1655 aqbasket.basketname,
1656 aqbasket.basketgroupid,
1657 aqbasketgroups.name as groupname,
1659 aqbasket.creationdate,
1660 aqorders.datereceived,
1662 aqorders.quantityreceived,
1664 aqorders.ordernumber,
1665 aqorders.booksellerinvoicenumber as invoicenumber,
1666 aqbooksellers.id as id,
1667 aqorders.biblionumber
1669 LEFT JOIN aqbasket ON aqorders.basketno=aqbasket.basketno
1670 LEFT JOIN aqbasketgroups ON aqbasket.basketgroupid=aqbasketgroups.id
1671 LEFT JOIN aqbooksellers ON aqbasket.booksellerid=aqbooksellers.id
1672 LEFT JOIN biblioitems ON biblioitems.biblionumber=aqorders.biblionumber
1673 LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber";
1675 $query .= " LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber"
1676 if ( C4::Context->preference("IndependantBranches") );
1678 $query .= " WHERE (datecancellationprinted is NULL or datecancellationprinted='0000-00-00') ";
1680 my @query_params = ();
1683 $query .= " AND biblio.title LIKE ? ";
1684 $title =~ s/\s+/%/g;
1685 push @query_params, "%$title%";
1689 $query .= " AND biblio.author LIKE ? ";
1690 push @query_params, "%$author%";
1694 $query .= " AND biblioitems.isbn LIKE ? ";
1695 push @query_params, "%$isbn%";
1699 $query .= " AND aqbooksellers.name LIKE ? ";
1700 push @query_params, "%$name%";
1703 if ( $from_placed_on ) {
1704 $query .= " AND creationdate >= ? ";
1705 push @query_params, $from_placed_on;
1708 if ( $to_placed_on ) {
1709 $query .= " AND creationdate <= ? ";
1710 push @query_params, $to_placed_on;
1714 if ($basket =~ m/^\d+$/) {
1715 $query .= " AND aqorders.basketno = ? ";
1716 push @query_params, $basket;
1718 $query .= " AND aqbasket.basketname LIKE ? ";
1719 push @query_params, "%$basket%";
1723 if ($booksellerinvoicenumber) {
1724 $query .= " AND (aqorders.booksellerinvoicenumber LIKE ? OR aqbasket.booksellerinvoicenumber LIKE ?)";
1725 push @query_params, "%$booksellerinvoicenumber%", "%$booksellerinvoicenumber%";
1728 if ( C4::Context->preference("IndependantBranches") ) {
1729 my $userenv = C4::Context->userenv;
1730 if ( $userenv && ($userenv->{flags} || 0) != 1 ) {
1731 $query .= " AND (borrowers.branchcode = ? OR borrowers.branchcode ='' ) ";
1732 push @query_params, $userenv->{branch};
1735 $query .= " ORDER BY id";
1736 my $sth = $dbh->prepare($query);
1737 $sth->execute( @query_params );
1739 while ( my $line = $sth->fetchrow_hashref ) {
1740 $line->{count} = $cnt++;
1741 $line->{toggle} = 1 if $cnt % 2;
1742 push @order_loop, $line;
1743 $total_qty += $line->{'quantity'};
1744 $total_qtyreceived += $line->{'quantityreceived'};
1745 $total_price += $line->{'quantity'} * $line->{'ecost'};
1747 return \@order_loop, $total_qty, $total_price, $total_qtyreceived;
1750 =head2 GetRecentAcqui
1752 $results = GetRecentAcqui($days);
1754 C<$results> is a ref to a table which containts hashref
1758 sub GetRecentAcqui {
1760 my $dbh = C4::Context->dbh;
1764 ORDER BY timestamp DESC
1767 my $sth = $dbh->prepare($query);
1769 my $results = $sth->fetchall_arrayref({});
1775 $contractlist = &GetContracts($booksellerid, $activeonly);
1777 Looks up the contracts that belong to a bookseller
1779 Returns a list of contracts
1783 =item C<$booksellerid> is the "id" field in the "aqbooksellers" table.
1785 =item C<$activeonly> if exists get only contracts that are still active.
1792 my ( $booksellerid, $activeonly ) = @_;
1793 my $dbh = C4::Context->dbh;
1795 if (! $activeonly) {
1799 WHERE booksellerid=?
1804 WHERE booksellerid=?
1805 AND contractenddate >= CURDATE( )";
1807 my $sth = $dbh->prepare($query);
1808 $sth->execute( $booksellerid );
1810 while (my $data = $sth->fetchrow_hashref ) {
1811 push(@results, $data);
1817 #------------------------------------------------------------#
1821 $contract = &GetContract($contractID);
1823 Looks up the contract that has PRIMKEY (contractnumber) value $contractID
1830 my ( $contractno ) = @_;
1831 my $dbh = C4::Context->dbh;
1835 WHERE contractnumber=?
1838 my $sth = $dbh->prepare($query);
1839 $sth->execute( $contractno );
1840 my $result = $sth->fetchrow_hashref;
1848 &AddClaim($ordernumber);
1850 Add a claim for an order
1856 my ($ordernumber) = @_;
1857 my $dbh = C4::Context->dbh;
1860 claims_count = claims_count + 1,
1861 claimed_date = CURDATE()
1862 WHERE ordernumber = ?
1864 my $sth = $dbh->prepare($query);
1865 $sth->execute($ordernumber);
1874 Koha Development Team <http://koha-community.org/>