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);
32 use C4::Bookseller qw(GetBookSellerFromId);
33 use C4::Templates qw(gettemplate);
38 use vars qw($VERSION @ISA @EXPORT);
41 # set the version for version checking
42 $VERSION = 3.07.00.049;
46 &GetBasket &NewBasket &CloseBasket &DelBasket &ModBasket
47 &GetBasketAsCSV &GetBasketGroupAsCSV
48 &GetBasketsByBookseller &GetBasketsByBasketgroup
49 &GetBasketsInfosByBookseller
53 &ModBasketgroup &NewBasketgroup &DelBasketgroup &GetBasketgroup &CloseBasketgroup
54 &GetBasketgroups &ReOpenBasketgroup
56 &NewOrder &DelOrder &ModOrder &GetPendingOrders &GetOrder &GetOrders &GetOrdersByBiblionumber
57 &GetLateOrders &GetOrderFromItemnumber
58 &SearchOrder &GetHistory &GetRecentAcqui
59 &ModReceiveOrder &CancelReceipt
60 &GetCancelledOrders &TransferOrder
61 &GetLastOrderNotReceivedFromSubscriptionid &GetLastOrderReceivedFromSubscriptionid
62 &NewOrderItem &ModItemOrder
64 &GetParcels &GetParcel
65 &GetContracts &GetContract
76 &GetItemnumbersFromOrder
86 sub GetOrderFromItemnumber {
87 my ($itemnumber) = @_;
88 my $dbh = C4::Context->dbh;
91 SELECT * from aqorders LEFT JOIN aqorders_items
92 ON ( aqorders.ordernumber = aqorders_items.ordernumber )
93 WHERE itemnumber = ? |;
95 my $sth = $dbh->prepare($query);
99 $sth->execute($itemnumber);
101 my $order = $sth->fetchrow_hashref;
106 # Returns the itemnumber(s) associated with the ordernumber given in parameter
107 sub GetItemnumbersFromOrder {
108 my ($ordernumber) = @_;
109 my $dbh = C4::Context->dbh;
110 my $query = "SELECT itemnumber FROM aqorders_items WHERE ordernumber=?";
111 my $sth = $dbh->prepare($query);
112 $sth->execute($ordernumber);
115 while (my $order = $sth->fetchrow_hashref) {
116 push @tab, $order->{'itemnumber'};
130 C4::Acquisition - Koha functions for dealing with orders and acquisitions
138 The functions in this module deal with acquisitions, managing book
139 orders, basket and parcels.
143 =head2 FUNCTIONS ABOUT BASKETS
147 $aqbasket = &GetBasket($basketnumber);
149 get all basket informations in aqbasket for a given basket
151 B<returns:> informations for a given basket returned as a hashref.
157 my $dbh = C4::Context->dbh;
160 concat( b.firstname,' ',b.surname) AS authorisedbyname,
161 b.branchcode AS branch
163 LEFT JOIN borrowers b ON aqbasket.authorisedby=b.borrowernumber
166 my $sth=$dbh->prepare($query);
167 $sth->execute($basketno);
168 my $basket = $sth->fetchrow_hashref;
172 #------------------------------------------------------------#
176 $basket = &NewBasket( $booksellerid, $authorizedby, $basketname,
177 $basketnote, $basketbooksellernote, $basketcontractnumber, $deliveryplace, $billingplace );
179 Create a new basket in aqbasket table
183 =item C<$booksellerid> is a foreign key in the aqbasket table
185 =item C<$authorizedby> is the username of who created the basket
189 The other parameters are optional, see ModBasketHeader for more info on them.
194 my ( $booksellerid, $authorisedby, $basketname, $basketnote,
195 $basketbooksellernote, $basketcontractnumber, $deliveryplace,
196 $billingplace ) = @_;
197 my $dbh = C4::Context->dbh;
199 'INSERT INTO aqbasket (creationdate,booksellerid,authorisedby) '
200 . 'VALUES (now(),?,?)';
201 $dbh->do( $query, {}, $booksellerid, $authorisedby );
203 my $basket = $dbh->{mysql_insertid};
204 $basketname ||= q{}; # default to empty strings
206 $basketbooksellernote ||= q{};
207 ModBasketHeader( $basket, $basketname, $basketnote, $basketbooksellernote,
208 $basketcontractnumber, $booksellerid, $deliveryplace, $billingplace );
212 #------------------------------------------------------------#
216 &CloseBasket($basketno);
218 close a basket (becomes unmodifiable,except for recieves)
224 my $dbh = C4::Context->dbh;
230 my $sth = $dbh->prepare($query);
231 $sth->execute($basketno);
234 #------------------------------------------------------------#
236 =head3 GetBasketAsCSV
238 &GetBasketAsCSV($basketno);
240 Export a basket as CSV
242 $cgi parameter is needed for column name translation
247 my ($basketno, $cgi) = @_;
248 my $basket = GetBasket($basketno);
249 my @orders = GetOrders($basketno);
250 my $contract = GetContract($basket->{'contractnumber'});
252 my $template = C4::Templates::gettemplate("acqui/csv/basket.tmpl", "intranet", $cgi);
255 foreach my $order (@orders) {
256 my $bd = GetBiblioData( $order->{'biblionumber'} );
258 contractname => $contract->{'contractname'},
259 ordernumber => $order->{'ordernumber'},
260 entrydate => $order->{'entrydate'},
261 isbn => $order->{'isbn'},
262 author => $bd->{'author'},
263 title => $bd->{'title'},
264 publicationyear => $bd->{'publicationyear'},
265 publishercode => $bd->{'publishercode'},
266 collectiontitle => $bd->{'collectiontitle'},
267 notes => $order->{'notes'},
268 quantity => $order->{'quantity'},
269 rrp => $order->{'rrp'},
270 deliveryplace => C4::Branch::GetBranchName( $basket->{'deliveryplace'} ),
271 billingplace => C4::Branch::GetBranchName( $basket->{'billingplace'} ),
274 contractname author title publishercode collectiontitle notes
275 deliveryplace billingplace
277 # Double the quotes to not be interpreted as a field end
278 $row->{$_} =~ s/"/""/g if $row->{$_};
284 if(defined $a->{publishercode} and defined $b->{publishercode}) {
285 $a->{publishercode} cmp $b->{publishercode};
289 $template->param(rows => \@rows);
291 return $template->output;
295 =head3 GetBasketGroupAsCSV
299 &GetBasketGroupAsCSV($basketgroupid);
301 Export a basket group as CSV
303 $cgi parameter is needed for column name translation
309 sub GetBasketGroupAsCSV {
310 my ($basketgroupid, $cgi) = @_;
311 my $baskets = GetBasketsByBasketgroup($basketgroupid);
313 my $template = C4::Templates::gettemplate('acqui/csv/basketgroup.tmpl', 'intranet', $cgi);
316 for my $basket (@$baskets) {
317 my @orders = GetOrders( $$basket{basketno} );
318 my $contract = GetContract( $$basket{contractnumber} );
319 my $bookseller = GetBookSellerFromId( $$basket{booksellerid} );
320 my $basketgroup = GetBasketgroup( $$basket{basketgroupid} );
322 foreach my $order (@orders) {
323 my $bd = GetBiblioData( $order->{'biblionumber'} );
325 clientnumber => $bookseller->{accountnumber},
326 basketname => $basket->{basketname},
327 ordernumber => $order->{ordernumber},
328 author => $bd->{author},
329 title => $bd->{title},
330 publishercode => $bd->{publishercode},
331 publicationyear => $bd->{publicationyear},
332 collectiontitle => $bd->{collectiontitle},
333 isbn => $order->{isbn},
334 quantity => $order->{quantity},
335 rrp => $order->{rrp},
336 discount => $bookseller->{discount},
337 ecost => $order->{ecost},
338 notes => $order->{notes},
339 entrydate => $order->{entrydate},
340 booksellername => $bookseller->{name},
341 bookselleraddress => $bookseller->{address1},
342 booksellerpostal => $bookseller->{postal},
343 contractnumber => $contract->{contractnumber},
344 contractname => $contract->{contractname},
345 basketgroupdeliveryplace => C4::Branch::GetBranchName( $basketgroup->{deliveryplace} ),
346 basketgroupbillingplace => C4::Branch::GetBranchName( $basketgroup->{billingplace} ),
347 basketdeliveryplace => C4::Branch::GetBranchName( $basket->{deliveryplace} ),
348 basketbillingplace => C4::Branch::GetBranchName( $basket->{billingplace} ),
351 basketname author title publishercode collectiontitle notes
352 booksellername bookselleraddress booksellerpostal contractname
353 basketgroupdeliveryplace basketgroupbillingplace
354 basketdeliveryplace basketbillingplace
356 # Double the quotes to not be interpreted as a field end
357 $row->{$_} =~ s/"/""/g if $row->{$_};
362 $template->param(rows => \@rows);
364 return $template->output;
368 =head3 CloseBasketgroup
370 &CloseBasketgroup($basketgroupno);
376 sub CloseBasketgroup {
377 my ($basketgroupno) = @_;
378 my $dbh = C4::Context->dbh;
379 my $sth = $dbh->prepare("
380 UPDATE aqbasketgroups
384 $sth->execute($basketgroupno);
387 #------------------------------------------------------------#
389 =head3 ReOpenBaskergroup($basketgroupno)
391 &ReOpenBaskergroup($basketgroupno);
397 sub ReOpenBasketgroup {
398 my ($basketgroupno) = @_;
399 my $dbh = C4::Context->dbh;
400 my $sth = $dbh->prepare("
401 UPDATE aqbasketgroups
405 $sth->execute($basketgroupno);
408 #------------------------------------------------------------#
413 &DelBasket($basketno);
415 Deletes the basket that has basketno field $basketno in the aqbasket table.
419 =item C<$basketno> is the primary key of the basket in the aqbasket table.
426 my ( $basketno ) = @_;
427 my $query = "DELETE FROM aqbasket WHERE basketno=?";
428 my $dbh = C4::Context->dbh;
429 my $sth = $dbh->prepare($query);
430 $sth->execute($basketno);
434 #------------------------------------------------------------#
438 &ModBasket($basketinfo);
440 Modifies a basket, using a hashref $basketinfo for the relevant information, only $basketinfo->{'basketno'} is required.
444 =item C<$basketno> is the primary key of the basket in the aqbasket table.
451 my $basketinfo = shift;
452 my $query = "UPDATE aqbasket SET ";
454 foreach my $key (keys %$basketinfo){
455 if ($key ne 'basketno'){
456 $query .= "$key=?, ";
457 push(@params, $basketinfo->{$key} || undef );
460 # get rid of the "," at the end of $query
461 if (substr($query, length($query)-2) eq ', '){
466 $query .= "WHERE basketno=?";
467 push(@params, $basketinfo->{'basketno'});
468 my $dbh = C4::Context->dbh;
469 my $sth = $dbh->prepare($query);
470 $sth->execute(@params);
474 #------------------------------------------------------------#
476 =head3 ModBasketHeader
478 &ModBasketHeader($basketno, $basketname, $note, $booksellernote, $contractnumber, $booksellerid);
480 Modifies a basket's header.
484 =item C<$basketno> is the "basketno" field in the "aqbasket" table;
486 =item C<$basketname> is the "basketname" field in the "aqbasket" table;
488 =item C<$note> is the "note" field in the "aqbasket" table;
490 =item C<$booksellernote> is the "booksellernote" field in the "aqbasket" table;
492 =item C<$contractnumber> is the "contractnumber" (foreign) key in the "aqbasket" table.
494 =item C<$booksellerid> is the id (foreign) key in the "aqbooksellers" table for the vendor.
496 =item C<$deliveryplace> is the "deliveryplace" field in the aqbasket table.
498 =item C<$billingplace> is the "billingplace" field in the aqbasket table.
504 sub ModBasketHeader {
505 my ($basketno, $basketname, $note, $booksellernote, $contractnumber, $booksellerid, $deliveryplace, $billingplace) = @_;
508 SET basketname=?, note=?, booksellernote=?, booksellerid=?, deliveryplace=?, billingplace=?
512 my $dbh = C4::Context->dbh;
513 my $sth = $dbh->prepare($query);
514 $sth->execute($basketname, $note, $booksellernote, $booksellerid, $deliveryplace, $billingplace, $basketno);
516 if ( $contractnumber ) {
517 my $query2 ="UPDATE aqbasket SET contractnumber=? WHERE basketno=?";
518 my $sth2 = $dbh->prepare($query2);
519 $sth2->execute($contractnumber,$basketno);
525 #------------------------------------------------------------#
527 =head3 GetBasketsByBookseller
529 @results = &GetBasketsByBookseller($booksellerid, $extra);
531 Returns a list of hashes of all the baskets that belong to bookseller 'booksellerid'.
535 =item C<$booksellerid> is the 'id' field of the bookseller in the aqbooksellers table
537 =item C<$extra> is the extra sql parameters, can be
539 $extra->{groupby}: group baskets by column
540 ex. $extra->{groupby} = aqbasket.basketgroupid
541 $extra->{orderby}: order baskets by column
542 $extra->{limit}: limit number of results (can be helpful for pagination)
548 sub GetBasketsByBookseller {
549 my ($booksellerid, $extra) = @_;
550 my $query = "SELECT * FROM aqbasket WHERE booksellerid=?";
552 if ($extra->{groupby}) {
553 $query .= " GROUP by $extra->{groupby}";
555 if ($extra->{orderby}){
556 $query .= " ORDER by $extra->{orderby}";
558 if ($extra->{limit}){
559 $query .= " LIMIT $extra->{limit}";
562 my $dbh = C4::Context->dbh;
563 my $sth = $dbh->prepare($query);
564 $sth->execute($booksellerid);
565 my $results = $sth->fetchall_arrayref({});
570 =head3 GetBasketsInfosByBookseller
572 my $baskets = GetBasketsInfosByBookseller($supplierid, $allbaskets);
574 The optional second parameter allbaskets is a boolean allowing you to
575 select all baskets from the supplier; by default only active baskets (open or
576 closed but still something to receive) are returned.
578 Returns in a arrayref of hashref all about booksellers baskets, plus:
579 total_biblios: Number of distinct biblios in basket
580 total_items: Number of items in basket
581 expected_items: Number of non-received items in basket
585 sub GetBasketsInfosByBookseller {
586 my ($supplierid, $allbaskets) = @_;
588 return unless $supplierid;
590 my $dbh = C4::Context->dbh;
593 SUM(aqorders.quantity) AS total_items,
594 COUNT(DISTINCT aqorders.biblionumber) AS total_biblios,
596 IF(aqorders.datereceived IS NULL
597 AND aqorders.datecancellationprinted IS NULL
602 LEFT JOIN aqorders ON aqorders.basketno = aqbasket.basketno
603 WHERE booksellerid = ?};
605 $query.=" AND (closedate IS NULL OR (aqorders.quantity > aqorders.quantityreceived AND datecancellationprinted IS NULL))";
607 $query.=" GROUP BY aqbasket.basketno";
609 my $sth = $dbh->prepare($query);
610 $sth->execute($supplierid);
611 return $sth->fetchall_arrayref({});
615 #------------------------------------------------------------#
617 =head3 GetBasketsByBasketgroup
619 $baskets = &GetBasketsByBasketgroup($basketgroupid);
621 Returns a reference to all baskets that belong to basketgroup $basketgroupid.
625 sub GetBasketsByBasketgroup {
626 my $basketgroupid = shift;
628 SELECT *, aqbasket.booksellerid as booksellerid
630 LEFT JOIN aqcontract USING(contractnumber) WHERE basketgroupid=?
632 my $dbh = C4::Context->dbh;
633 my $sth = $dbh->prepare($query);
634 $sth->execute($basketgroupid);
635 my $results = $sth->fetchall_arrayref({});
640 #------------------------------------------------------------#
642 =head3 NewBasketgroup
644 $basketgroupid = NewBasketgroup(\%hashref);
646 Adds a basketgroup to the aqbasketgroups table, and add the initial baskets to it.
648 $hashref->{'booksellerid'} is the 'id' field of the bookseller in the aqbooksellers table,
650 $hashref->{'name'} is the 'name' field of the basketgroup in the aqbasketgroups table,
652 $hashref->{'basketlist'} is a list reference of the 'id's of the baskets that belong to this group,
654 $hashref->{'billingplace'} is the 'billingplace' field of the basketgroup in the aqbasketgroups table,
656 $hashref->{'deliveryplace'} is the 'deliveryplace' field of the basketgroup in the aqbasketgroups table,
658 $hashref->{'freedeliveryplace'} is the 'freedeliveryplace' field of the basketgroup in the aqbasketgroups table,
660 $hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table,
662 $hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise.
667 my $basketgroupinfo = shift;
668 die "booksellerid is required to create a basketgroup" unless $basketgroupinfo->{'booksellerid'};
669 my $query = "INSERT INTO aqbasketgroups (";
671 foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment closed)) {
672 if ( defined $basketgroupinfo->{$field} ) {
673 $query .= "$field, ";
674 push(@params, $basketgroupinfo->{$field});
677 $query .= "booksellerid) VALUES (";
682 push(@params, $basketgroupinfo->{'booksellerid'});
683 my $dbh = C4::Context->dbh;
684 my $sth = $dbh->prepare($query);
685 $sth->execute(@params);
686 my $basketgroupid = $dbh->{'mysql_insertid'};
687 if( $basketgroupinfo->{'basketlist'} ) {
688 foreach my $basketno (@{$basketgroupinfo->{'basketlist'}}) {
689 my $query2 = "UPDATE aqbasket SET basketgroupid=? WHERE basketno=?";
690 my $sth2 = $dbh->prepare($query2);
691 $sth2->execute($basketgroupid, $basketno);
694 return $basketgroupid;
697 #------------------------------------------------------------#
699 =head3 ModBasketgroup
701 ModBasketgroup(\%hashref);
703 Modifies a basketgroup in the aqbasketgroups table, and add the baskets to it.
705 $hashref->{'id'} is the 'id' field of the basketgroup in the aqbasketgroup table, this parameter is mandatory,
707 $hashref->{'name'} is the 'name' field of the basketgroup in the aqbasketgroups table,
709 $hashref->{'basketlist'} is a list reference of the 'id's of the baskets that belong to this group,
711 $hashref->{'billingplace'} is the 'billingplace' field of the basketgroup in the aqbasketgroups table,
713 $hashref->{'deliveryplace'} is the 'deliveryplace' field of the basketgroup in the aqbasketgroups table,
715 $hashref->{'freedeliveryplace'} is the 'freedeliveryplace' field of the basketgroup in the aqbasketgroups table,
717 $hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table,
719 $hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise.
724 my $basketgroupinfo = shift;
725 die "basketgroup id is required to edit a basketgroup" unless $basketgroupinfo->{'id'};
726 my $dbh = C4::Context->dbh;
727 my $query = "UPDATE aqbasketgroups SET ";
729 foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment closed)) {
730 if ( defined $basketgroupinfo->{$field} ) {
731 $query .= "$field=?, ";
732 push(@params, $basketgroupinfo->{$field});
737 $query .= " WHERE id=?";
738 push(@params, $basketgroupinfo->{'id'});
739 my $sth = $dbh->prepare($query);
740 $sth->execute(@params);
742 $sth = $dbh->prepare('UPDATE aqbasket SET basketgroupid = NULL WHERE basketgroupid = ?');
743 $sth->execute($basketgroupinfo->{'id'});
745 if($basketgroupinfo->{'basketlist'} && @{$basketgroupinfo->{'basketlist'}}){
746 $sth = $dbh->prepare("UPDATE aqbasket SET basketgroupid=? WHERE basketno=?");
747 foreach my $basketno (@{$basketgroupinfo->{'basketlist'}}) {
748 $sth->execute($basketgroupinfo->{'id'}, $basketno);
755 #------------------------------------------------------------#
757 =head3 DelBasketgroup
759 DelBasketgroup($basketgroupid);
761 Deletes a basketgroup in the aqbasketgroups table, and removes the reference to it from the baskets,
765 =item C<$basketgroupid> is the 'id' field of the basket in the aqbasketgroup table
772 my $basketgroupid = shift;
773 die "basketgroup id is required to edit a basketgroup" unless $basketgroupid;
774 my $query = "DELETE FROM aqbasketgroups WHERE id=?";
775 my $dbh = C4::Context->dbh;
776 my $sth = $dbh->prepare($query);
777 $sth->execute($basketgroupid);
781 #------------------------------------------------------------#
784 =head2 FUNCTIONS ABOUT ORDERS
786 =head3 GetBasketgroup
788 $basketgroup = &GetBasketgroup($basketgroupid);
790 Returns a reference to the hash containing all infermation about the basketgroup.
795 my $basketgroupid = shift;
796 die "basketgroup id is required to edit a basketgroup" unless $basketgroupid;
797 my $query = "SELECT * FROM aqbasketgroups WHERE id=?";
798 my $dbh = C4::Context->dbh;
799 my $sth = $dbh->prepare($query);
800 $sth->execute($basketgroupid);
801 my $result = $sth->fetchrow_hashref;
806 #------------------------------------------------------------#
808 =head3 GetBasketgroups
810 $basketgroups = &GetBasketgroups($booksellerid);
812 Returns a reference to the array of all the basketgroups of bookseller $booksellerid.
816 sub GetBasketgroups {
817 my $booksellerid = shift;
818 die 'bookseller id is required to edit a basketgroup' unless $booksellerid;
819 my $query = 'SELECT * FROM aqbasketgroups WHERE booksellerid=? ORDER BY id DESC';
820 my $dbh = C4::Context->dbh;
821 my $sth = $dbh->prepare($query);
822 $sth->execute($booksellerid);
823 return $sth->fetchall_arrayref({});
826 #------------------------------------------------------------#
828 =head2 FUNCTIONS ABOUT ORDERS
832 #------------------------------------------------------------#
834 =head3 GetPendingOrders
836 $orders = &GetPendingOrders($supplierid,$grouped,$owner,$basketno,$ordernumber,$search,$ean);
838 Finds pending orders from the bookseller with the given ID. Ignores
839 completed and cancelled orders.
841 C<$booksellerid> contains the bookseller identifier
842 C<$owner> contains 0 or 1. 0 means any owner. 1 means only the list of orders entered by the user itself.
843 C<$grouped> is a boolean that, if set to 1 will group all order lines of the same basket
844 in a single result line
845 C<$orders> is a reference-to-array; each element is a reference-to-hash.
847 Used also by the filter in parcel.pl
854 These give the value of the corresponding field in the aqorders table
855 of the Koha database.
857 Results are ordered from most to least recent.
861 sub GetPendingOrders {
862 my ($supplierid,$grouped,$owner,$basketno,$ordernumber,$search,$ean) = @_;
863 my $dbh = C4::Context->dbh;
865 SELECT ".($grouped?"count(*),":"")."aqbasket.basketno,
866 surname,firstname,biblio.*,biblioitems.isbn,
867 aqbasket.closedate, aqbasket.creationdate, aqbasket.basketname,
870 LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno
871 LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
872 LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber
873 LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber
874 WHERE (quantity > quantityreceived OR quantityreceived is NULL)
875 AND datecancellationprinted IS NULL";
877 my $userenv = C4::Context->userenv;
878 if ( C4::Context->preference("IndependentBranches") ) {
879 if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
880 $strsth .= " AND (borrowers.branchcode = ?
881 or borrowers.branchcode = '')";
882 push @query_params, $userenv->{branch};
886 $strsth .= " AND aqbasket.booksellerid = ?";
887 push @query_params, $supplierid;
890 $strsth .= " AND (aqorders.ordernumber=?)";
891 push @query_params, $ordernumber;
894 $strsth .= " AND (biblio.title like ? OR biblio.author LIKE ? OR biblioitems.isbn like ?)";
895 push @query_params, ("%$search%","%$search%","%$search%");
898 $strsth .= " AND biblioitems.ean = ?";
899 push @query_params, $ean;
902 $strsth .= " AND aqbasket.basketno=? ";
903 push @query_params, $basketno;
906 $strsth .= " AND aqbasket.authorisedby=? ";
907 push @query_params, $userenv->{'number'};
909 $strsth .= " group by aqbasket.basketno" if $grouped;
910 $strsth .= " order by aqbasket.basketno";
911 my $sth = $dbh->prepare($strsth);
912 $sth->execute( @query_params );
913 my $results = $sth->fetchall_arrayref({});
918 #------------------------------------------------------------#
922 @orders = &GetOrders($basketnumber, $orderby);
924 Looks up the pending (non-cancelled) orders with the given basket
925 number. If C<$booksellerID> is non-empty, only orders from that seller
929 C<&basket> returns a two-element array. C<@orders> is an array of
930 references-to-hash, whose keys are the fields from the aqorders,
931 biblio, and biblioitems tables in the Koha database.
936 my ( $basketno, $orderby ) = @_;
937 my $dbh = C4::Context->dbh;
939 SELECT biblio.*,biblioitems.*,
943 aqorders_transfers.ordernumber_from AS transferred_from,
944 aqorders_transfers.timestamp AS transferred_from_timestamp
946 LEFT JOIN aqbudgets ON aqbudgets.budget_id = aqorders.budget_id
947 LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber
948 LEFT JOIN biblioitems ON biblioitems.biblionumber =biblio.biblionumber
949 LEFT JOIN aqorders_transfers ON aqorders_transfers.ordernumber_to = aqorders.ordernumber
951 AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
954 $orderby = "biblioitems.publishercode,biblio.title" unless $orderby;
955 $query .= " ORDER BY $orderby";
956 my $sth = $dbh->prepare($query);
957 $sth->execute($basketno);
958 my $results = $sth->fetchall_arrayref({});
963 #------------------------------------------------------------#
964 =head3 GetOrdersByBiblionumber
966 @orders = &GetOrdersByBiblionumber($biblionumber);
968 Looks up the orders with linked to a specific $biblionumber, including
969 cancelled orders and received orders.
972 C<@orders> is an array of references-to-hash, whose keys are the
973 fields from the aqorders, biblio, and biblioitems tables in the Koha database.
977 sub GetOrdersByBiblionumber {
978 my $biblionumber = shift;
979 return unless $biblionumber;
980 my $dbh = C4::Context->dbh;
982 SELECT biblio.*,biblioitems.*,
986 LEFT JOIN aqbudgets ON aqbudgets.budget_id = aqorders.budget_id
987 LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber
988 LEFT JOIN biblioitems ON biblioitems.biblionumber =biblio.biblionumber
989 WHERE aqorders.biblionumber=?
991 my $sth = $dbh->prepare($query);
992 $sth->execute($biblionumber);
993 my $results = $sth->fetchall_arrayref({});
998 #------------------------------------------------------------#
1002 $order = &GetOrder($ordernumber);
1004 Looks up an order by order number.
1006 Returns a reference-to-hash describing the order. The keys of
1007 C<$order> are fields from the biblio, biblioitems, aqorders tables of the Koha database.
1012 my ($ordernumber) = @_;
1013 my $dbh = C4::Context->dbh;
1015 SELECT biblioitems.*, biblio.*, aqorders.*
1017 LEFT JOIN biblio on biblio.biblionumber=aqorders.biblionumber
1018 LEFT JOIN biblioitems on biblioitems.biblionumber=aqorders.biblionumber
1019 WHERE aqorders.ordernumber=?
1022 my $sth= $dbh->prepare($query);
1023 $sth->execute($ordernumber);
1024 my $data = $sth->fetchrow_hashref;
1029 =head3 GetLastOrderNotReceivedFromSubscriptionid
1031 $order = &GetLastOrderNotReceivedFromSubscriptionid($subscriptionid);
1033 Returns a reference-to-hash describing the last order not received for a subscription.
1037 sub GetLastOrderNotReceivedFromSubscriptionid {
1038 my ( $subscriptionid ) = @_;
1039 my $dbh = C4::Context->dbh;
1041 SELECT * FROM aqorders
1042 LEFT JOIN subscription
1043 ON ( aqorders.subscriptionid = subscription.subscriptionid )
1044 WHERE aqorders.subscriptionid = ?
1045 AND aqorders.datereceived IS NULL
1048 my $sth = $dbh->prepare( $query );
1049 $sth->execute( $subscriptionid );
1050 my $order = $sth->fetchrow_hashref;
1054 =head3 GetLastOrderReceivedFromSubscriptionid
1056 $order = &GetLastOrderReceivedFromSubscriptionid($subscriptionid);
1058 Returns a reference-to-hash describing the last order received for a subscription.
1062 sub GetLastOrderReceivedFromSubscriptionid {
1063 my ( $subscriptionid ) = @_;
1064 my $dbh = C4::Context->dbh;
1066 SELECT * FROM aqorders
1067 LEFT JOIN subscription
1068 ON ( aqorders.subscriptionid = subscription.subscriptionid )
1069 WHERE aqorders.subscriptionid = ?
1070 AND aqorders.datereceived =
1072 SELECT MAX( aqorders.datereceived )
1074 LEFT JOIN subscription
1075 ON ( aqorders.subscriptionid = subscription.subscriptionid )
1076 WHERE aqorders.subscriptionid = ?
1077 AND aqorders.datereceived IS NOT NULL
1079 ORDER BY ordernumber DESC
1082 my $sth = $dbh->prepare( $query );
1083 $sth->execute( $subscriptionid, $subscriptionid );
1084 my $order = $sth->fetchrow_hashref;
1090 #------------------------------------------------------------#
1094 &NewOrder(\%hashref);
1096 Adds a new order to the database. Any argument that isn't described
1097 below is the new value of the field with the same name in the aqorders
1098 table of the Koha database.
1102 =item $hashref->{'basketno'} is the basketno foreign key in aqorders, it is mandatory
1104 =item $hashref->{'ordernumber'} is a "minimum order number."
1106 =item $hashref->{'budgetdate'} is effectively ignored.
1107 If it's undef (anything false) or the string 'now', the current day is used.
1108 Else, the upcoming July 1st is used.
1110 =item $hashref->{'subscription'} may be either "yes", or anything else for "no".
1112 =item $hashref->{'uncertainprice'} may be 0 for "the price is known" or 1 for "the price is uncertain"
1114 =item defaults entrydate to Now
1116 The following keys are used: "biblionumber", "title", "basketno", "quantity", "notes", "rrp", "ecost", "gstrate", "unitprice", "subscription", "sort1", "sort2", "booksellerinvoicenumber", "listprice", "budgetdate", "purchaseordernumber", "branchcode", "booksellerinvoicenumber", "budget_id".
1123 my $orderinfo = shift;
1124 #### ------------------------------
1125 my $dbh = C4::Context->dbh;
1129 # if these parameters are missing, we can't continue
1130 for my $key (qw/basketno quantity biblionumber budget_id/) {
1131 croak "Mandatory parameter $key missing" unless $orderinfo->{$key};
1134 if ( defined $orderinfo->{subscription} && $orderinfo->{'subscription'} eq 'yes' ) {
1135 $orderinfo->{'subscription'} = 1;
1137 $orderinfo->{'subscription'} = 0;
1139 $orderinfo->{'entrydate'} ||= C4::Dates->new()->output("iso");
1140 if (!$orderinfo->{quantityreceived}) {
1141 $orderinfo->{quantityreceived} = 0;
1144 my $ordernumber=InsertInTable("aqorders",$orderinfo);
1145 if (not $orderinfo->{parent_ordernumber}) {
1146 my $sth = $dbh->prepare("
1148 SET parent_ordernumber = ordernumber
1149 WHERE ordernumber = ?
1151 $sth->execute($ordernumber);
1153 return ( $orderinfo->{'basketno'}, $ordernumber );
1158 #------------------------------------------------------------#
1167 my ($itemnumber, $ordernumber) = @_;
1168 my $dbh = C4::Context->dbh;
1170 INSERT INTO aqorders_items
1171 (itemnumber, ordernumber)
1174 my $sth = $dbh->prepare($query);
1175 $sth->execute( $itemnumber, $ordernumber);
1178 #------------------------------------------------------------#
1182 &ModOrder(\%hashref);
1184 Modifies an existing order. Updates the order with order number
1185 $hashref->{'ordernumber'} and biblionumber $hashref->{'biblionumber'}. All
1186 other keys of the hash update the fields with the same name in the aqorders
1187 table of the Koha database.
1192 my $orderinfo = shift;
1194 die "Ordernumber is required" if $orderinfo->{'ordernumber'} eq '' ;
1195 die "Biblionumber is required" if $orderinfo->{'biblionumber'} eq '';
1197 my $dbh = C4::Context->dbh;
1200 # update uncertainprice to an integer, just in case (under FF, checked boxes have the value "ON" by default)
1201 $orderinfo->{uncertainprice}=1 if $orderinfo->{uncertainprice};
1203 # delete($orderinfo->{'branchcode'});
1204 # the hash contains a lot of entries not in aqorders, so get the columns ...
1205 my $sth = $dbh->prepare("SELECT * FROM aqorders LIMIT 1;");
1207 my $colnames = $sth->{NAME};
1208 #FIXME Be careful. If aqorders would have columns with diacritics,
1209 #you should need to decode what you get back from NAME.
1210 #See report 10110 and guided_reports.pl
1211 my $query = "UPDATE aqorders SET ";
1213 foreach my $orderinfokey (grep(!/ordernumber/, keys %$orderinfo)){
1214 # ... and skip hash entries that are not in the aqorders table
1215 # FIXME : probably not the best way to do it (would be better to have a correct hash)
1216 next unless grep(/^$orderinfokey$/, @$colnames);
1217 $query .= "$orderinfokey=?, ";
1218 push(@params, $orderinfo->{$orderinfokey});
1221 $query .= "timestamp=NOW() WHERE ordernumber=?";
1222 # push(@params, $specorderinfo{'ordernumber'});
1223 push(@params, $orderinfo->{'ordernumber'} );
1224 $sth = $dbh->prepare($query);
1225 $sth->execute(@params);
1229 #------------------------------------------------------------#
1233 ModItemOrder($itemnumber, $ordernumber);
1235 Modifies the ordernumber of an item in aqorders_items.
1240 my ($itemnumber, $ordernumber) = @_;
1242 return unless ($itemnumber and $ordernumber);
1244 my $dbh = C4::Context->dbh;
1246 UPDATE aqorders_items
1248 WHERE itemnumber = ?
1250 my $sth = $dbh->prepare($query);
1251 return $sth->execute($ordernumber, $itemnumber);
1254 #------------------------------------------------------------#
1256 =head3 GetCancelledOrders
1258 my @orders = GetCancelledOrders($basketno, $orderby);
1260 Returns cancelled orders for a basket
1264 sub GetCancelledOrders {
1265 my ( $basketno, $orderby ) = @_;
1267 return () unless $basketno;
1269 my $dbh = C4::Context->dbh;
1276 aqorders_transfers.ordernumber_to AS transferred_to,
1277 aqorders_transfers.timestamp AS transferred_to_timestamp
1279 LEFT JOIN aqbudgets ON aqbudgets.budget_id = aqorders.budget_id
1280 LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber
1281 LEFT JOIN biblioitems ON biblioitems.biblionumber = biblio.biblionumber
1282 LEFT JOIN aqorders_transfers ON aqorders_transfers.ordernumber_from = aqorders.ordernumber
1284 AND (datecancellationprinted IS NOT NULL
1285 AND datecancellationprinted <> '0000-00-00')
1288 $orderby = "aqorders.datecancellationprinted desc, aqorders.timestamp desc"
1290 $query .= " ORDER BY $orderby";
1291 my $sth = $dbh->prepare($query);
1292 $sth->execute($basketno);
1293 my $results = $sth->fetchall_arrayref( {} );
1299 #------------------------------------------------------------#
1301 =head3 ModReceiveOrder
1303 &ModReceiveOrder($biblionumber, $ordernumber, $quantityreceived, $user,
1304 $cost, $ecost, $invoiceid, rrp, budget_id, datereceived, \@received_itemnumbers);
1306 Updates an order, to reflect the fact that it was received, at least
1307 in part. All arguments not mentioned below update the fields with the
1308 same name in the aqorders table of the Koha database.
1310 If a partial order is received, splits the order into two.
1312 Updates the order with bibilionumber C<$biblionumber> and ordernumber
1318 sub ModReceiveOrder {
1320 $biblionumber, $ordernumber, $quantrec, $user, $cost, $ecost,
1321 $invoiceid, $rrp, $budget_id, $datereceived, $received_items
1325 my $dbh = C4::Context->dbh;
1326 $datereceived = C4::Dates->output('iso') unless $datereceived;
1327 my $suggestionid = GetSuggestionFromBiblionumber( $biblionumber );
1328 if ($suggestionid) {
1329 ModSuggestion( {suggestionid=>$suggestionid,
1330 STATUS=>'AVAILABLE',
1331 biblionumber=> $biblionumber}
1335 my $sth=$dbh->prepare("
1336 SELECT * FROM aqorders
1337 WHERE biblionumber=? AND aqorders.ordernumber=?");
1339 $sth->execute($biblionumber,$ordernumber);
1340 my $order = $sth->fetchrow_hashref();
1343 my $new_ordernumber = $ordernumber;
1344 if ( $order->{quantity} > $quantrec ) {
1345 # Split order line in two parts: the first is the original order line
1346 # without received items (the quantity is decreased),
1347 # the second part is a new order line with quantity=quantityrec
1348 # (entirely received)
1349 $sth=$dbh->prepare("
1352 WHERE ordernumber = ?
1355 $sth->execute($order->{quantity} - $quantrec, $ordernumber);
1359 delete $order->{'ordernumber'};
1360 $order->{'quantity'} = $quantrec;
1361 $order->{'quantityreceived'} = $quantrec;
1362 $order->{'datereceived'} = $datereceived;
1363 $order->{'invoiceid'} = $invoiceid;
1364 $order->{'unitprice'} = $cost;
1365 $order->{'rrp'} = $rrp;
1366 $order->{ecost} = $ecost;
1367 $order->{'orderstatus'} = 3; # totally received
1369 ( $basketno, $new_ordernumber ) = NewOrder($order);
1371 if ($received_items) {
1372 foreach my $itemnumber (@$received_items) {
1373 ModItemOrder($itemnumber, $new_ordernumber);
1377 $sth=$dbh->prepare("update aqorders
1378 set quantityreceived=?,datereceived=?,invoiceid=?,
1379 unitprice=?,rrp=?,ecost=?
1380 where biblionumber=? and ordernumber=?");
1381 $sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$ecost,$biblionumber,$ordernumber);
1384 return ($datereceived, $new_ordernumber);
1387 =head3 CancelReceipt
1389 my $parent_ordernumber = CancelReceipt($ordernumber);
1391 Cancel an order line receipt and update the parent order line, as if no
1393 If items are created at receipt (AcqCreateItem = receiving) then delete
1399 my $ordernumber = shift;
1401 return unless $ordernumber;
1403 my $dbh = C4::Context->dbh;
1405 SELECT datereceived, parent_ordernumber, quantity
1407 WHERE ordernumber = ?
1409 my $sth = $dbh->prepare($query);
1410 $sth->execute($ordernumber);
1411 my $order = $sth->fetchrow_hashref;
1413 warn "CancelReceipt: order $ordernumber does not exist";
1416 unless($order->{'datereceived'}) {
1417 warn "CancelReceipt: order $ordernumber is not received";
1421 my $parent_ordernumber = $order->{'parent_ordernumber'};
1423 if($parent_ordernumber == $ordernumber || not $parent_ordernumber) {
1424 # The order line has no parent, just mark it as not received
1427 SET quantityreceived = ?,
1430 WHERE ordernumber = ?
1432 $sth = $dbh->prepare($query);
1433 $sth->execute(0, undef, undef, $ordernumber);
1435 # The order line has a parent, increase parent quantity and delete
1438 SELECT quantity, datereceived
1440 WHERE ordernumber = ?
1442 $sth = $dbh->prepare($query);
1443 $sth->execute($parent_ordernumber);
1444 my $parent_order = $sth->fetchrow_hashref;
1445 unless($parent_order) {
1446 warn "Parent order $parent_ordernumber does not exist.";
1449 if($parent_order->{'datereceived'}) {
1450 warn "CancelReceipt: parent order is received.".
1451 " Can't cancel receipt.";
1457 WHERE ordernumber = ?
1459 $sth = $dbh->prepare($query);
1460 my $rv = $sth->execute(
1461 $order->{'quantity'} + $parent_order->{'quantity'},
1465 warn "Cannot update parent order line, so do not cancel".
1469 if(C4::Context->preference('AcqCreateItem') eq 'receiving') {
1470 # Remove items that were created at receipt
1472 DELETE FROM items, aqorders_items
1473 USING items, aqorders_items
1474 WHERE items.itemnumber = ? AND aqorders_items.itemnumber = ?
1476 $sth = $dbh->prepare($query);
1477 my @itemnumbers = GetItemnumbersFromOrder($ordernumber);
1478 foreach my $itemnumber (@itemnumbers) {
1479 $sth->execute($itemnumber, $itemnumber);
1483 my @itemnumbers = GetItemnumbersFromOrder($ordernumber);
1484 foreach my $itemnumber (@itemnumbers) {
1485 ModItemOrder($itemnumber, $parent_ordernumber);
1490 DELETE FROM aqorders
1491 WHERE ordernumber = ?
1493 $sth = $dbh->prepare($query);
1494 $sth->execute($ordernumber);
1498 return $parent_ordernumber;
1501 #------------------------------------------------------------#
1505 @results = &SearchOrder($search, $biblionumber, $complete);
1507 Searches for orders.
1509 C<$search> may take one of several forms: if it is an ISBN,
1510 C<&ordersearch> returns orders with that ISBN. If C<$search> is an
1511 order number, C<&ordersearch> returns orders with that order number
1512 and biblionumber C<$biblionumber>. Otherwise, C<$search> is considered
1513 to be a space-separated list of search terms; in this case, all of the
1514 terms must appear in the title (matching the beginning of title
1517 If C<$complete> is C<yes>, the results will include only completed
1518 orders. In any case, C<&ordersearch> ignores cancelled orders.
1520 C<&ordersearch> returns an array.
1521 C<@results> is an array of references-to-hash with the following keys:
1527 =item C<seriestitle>
1538 #### -------- SearchOrder-------------------------------
1539 my ( $ordernumber, $search, $ean, $supplierid, $basket ) = @_;
1541 my $dbh = C4::Context->dbh;
1546 LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber
1547 LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber
1548 LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno
1549 WHERE (datecancellationprinted is NULL)";
1552 $query .= " AND (aqorders.ordernumber=?)";
1553 push @args, $ordernumber;
1556 $query .= " AND (biblio.title like ? OR biblio.author LIKE ? OR biblioitems.isbn like ?)";
1557 push @args, ("%$search%","%$search%","%$search%");
1560 $query .= " AND biblioitems.ean = ?";
1564 $query .= "AND aqbasket.booksellerid = ?";
1565 push @args, $supplierid;
1568 $query .= "AND aqorders.basketno = ?";
1569 push @args, $basket;
1572 my $sth = $dbh->prepare($query);
1573 $sth->execute(@args);
1574 my $results = $sth->fetchall_arrayref({});
1579 #------------------------------------------------------------#
1583 &DelOrder($biblionumber, $ordernumber);
1585 Cancel the order with the given order and biblio numbers. It does not
1586 delete any entries in the aqorders table, it merely marks them as
1592 my ( $bibnum, $ordernumber ) = @_;
1593 my $dbh = C4::Context->dbh;
1596 SET datecancellationprinted=now()
1597 WHERE biblionumber=? AND ordernumber=?
1599 my $sth = $dbh->prepare($query);
1600 $sth->execute( $bibnum, $ordernumber );
1602 my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1603 foreach my $itemnumber (@itemnumbers){
1604 C4::Items::DelItem( $dbh, $bibnum, $itemnumber );
1609 =head3 TransferOrder
1611 my $newordernumber = TransferOrder($ordernumber, $basketno);
1613 Transfer an order line to a basket.
1614 Mark $ordernumber as cancelled with an internal note 'Cancelled and transfered
1615 to BOOKSELLER on DATE' and create new order with internal note
1616 'Transfered from BOOKSELLER on DATE'.
1617 Move all attached items to the new order.
1618 Received orders cannot be transfered.
1619 Return the ordernumber of created order.
1624 my ($ordernumber, $basketno) = @_;
1626 return unless ($ordernumber and $basketno);
1628 my $order = GetOrder( $ordernumber );
1629 return if $order->{datereceived};
1630 my $basket = GetBasket($basketno);
1631 return unless $basket;
1633 my $dbh = C4::Context->dbh;
1634 my ($query, $sth, $rv);
1638 SET datecancellationprinted = CAST(NOW() AS date)
1639 WHERE ordernumber = ?
1641 $sth = $dbh->prepare($query);
1642 $rv = $sth->execute($ordernumber);
1644 delete $order->{'ordernumber'};
1645 $order->{'basketno'} = $basketno;
1647 (undef, $newordernumber) = NewOrder($order);
1650 UPDATE aqorders_items
1652 WHERE ordernumber = ?
1654 $sth = $dbh->prepare($query);
1655 $sth->execute($newordernumber, $ordernumber);
1658 INSERT INTO aqorders_transfers (ordernumber_from, ordernumber_to)
1661 $sth = $dbh->prepare($query);
1662 $sth->execute($ordernumber, $newordernumber);
1664 return $newordernumber;
1667 =head2 FUNCTIONS ABOUT PARCELS
1671 #------------------------------------------------------------#
1675 @results = &GetParcel($booksellerid, $code, $date);
1677 Looks up all of the received items from the supplier with the given
1678 bookseller ID at the given date, for the given code (bookseller Invoice number). Ignores cancelled and completed orders.
1680 C<@results> is an array of references-to-hash. The keys of each element are fields from
1681 the aqorders, biblio, and biblioitems tables of the Koha database.
1683 C<@results> is sorted alphabetically by book title.
1688 #gets all orders from a certain supplier, orders them alphabetically
1689 my ( $supplierid, $code, $datereceived ) = @_;
1690 my $dbh = C4::Context->dbh;
1693 if $code; # add % if we search on a given code (otherwise, let him empty)
1695 SELECT authorisedby,
1700 aqorders.biblionumber,
1701 aqorders.ordernumber,
1702 aqorders.parent_ordernumber,
1704 aqorders.quantityreceived,
1712 LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno
1713 LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
1714 LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber
1715 LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid
1717 aqbasket.booksellerid = ?
1718 AND aqinvoices.invoicenumber LIKE ?
1719 AND aqorders.datereceived = ? ";
1721 my @query_params = ( $supplierid, $code, $datereceived );
1722 if ( C4::Context->preference("IndependentBranches") ) {
1723 my $userenv = C4::Context->userenv;
1724 if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
1725 $strsth .= " and (borrowers.branchcode = ?
1726 or borrowers.branchcode = '')";
1727 push @query_params, $userenv->{branch};
1730 $strsth .= " ORDER BY aqbasket.basketno";
1731 # ## parcelinformation : $strsth
1732 my $sth = $dbh->prepare($strsth);
1733 $sth->execute( @query_params );
1734 while ( my $data = $sth->fetchrow_hashref ) {
1735 push( @results, $data );
1737 # ## countparcelbiblio: scalar(@results)
1743 #------------------------------------------------------------#
1747 $results = &GetParcels($bookseller, $order, $code, $datefrom, $dateto);
1749 get a lists of parcels.
1756 is the bookseller this function has to get parcels.
1759 To know on what criteria the results list has to be ordered.
1762 is the booksellerinvoicenumber.
1764 =item $datefrom & $dateto
1765 to know on what date this function has to filter its search.
1770 a pointer on a hash list containing parcel informations as such :
1776 =item Last operation
1778 =item Number of biblio
1780 =item Number of items
1787 my ($bookseller,$order, $code, $datefrom, $dateto) = @_;
1788 my $dbh = C4::Context->dbh;
1789 my @query_params = ();
1791 SELECT aqinvoices.invoicenumber,
1792 datereceived,purchaseordernumber,
1793 count(DISTINCT biblionumber) AS biblio,
1794 sum(quantity) AS itemsexpected,
1795 sum(quantityreceived) AS itemsreceived
1796 FROM aqorders LEFT JOIN aqbasket ON aqbasket.basketno = aqorders.basketno
1797 LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid
1798 WHERE aqbasket.booksellerid = ? and datereceived IS NOT NULL
1800 push @query_params, $bookseller;
1802 if ( defined $code ) {
1803 $strsth .= ' and aqinvoices.invoicenumber like ? ';
1804 # add a % to the end of the code to allow stemming.
1805 push @query_params, "$code%";
1808 if ( defined $datefrom ) {
1809 $strsth .= ' and datereceived >= ? ';
1810 push @query_params, $datefrom;
1813 if ( defined $dateto ) {
1814 $strsth .= 'and datereceived <= ? ';
1815 push @query_params, $dateto;
1818 $strsth .= "group by aqinvoices.invoicenumber,datereceived ";
1820 # can't use a placeholder to place this column name.
1821 # but, we could probably be checking to make sure it is a column that will be fetched.
1822 $strsth .= "order by $order " if ($order);
1824 my $sth = $dbh->prepare($strsth);
1826 $sth->execute( @query_params );
1827 my $results = $sth->fetchall_arrayref({});
1832 #------------------------------------------------------------#
1834 =head3 GetLateOrders
1836 @results = &GetLateOrders;
1838 Searches for bookseller with late orders.
1841 the table of supplier with late issues. This table is full of hashref.
1847 my $supplierid = shift;
1849 my $estimateddeliverydatefrom = shift;
1850 my $estimateddeliverydateto = shift;
1852 my $dbh = C4::Context->dbh;
1854 #BEWARE, order of parenthesis and LEFT JOIN is important for speed
1855 my $dbdriver = C4::Context->config("db_scheme") || "mysql";
1857 my @query_params = ();
1859 SELECT aqbasket.basketno,
1860 aqorders.ordernumber,
1861 DATE(aqbasket.closedate) AS orderdate,
1862 aqorders.rrp AS unitpricesupplier,
1863 aqorders.ecost AS unitpricelib,
1864 aqorders.claims_count AS claims_count,
1865 aqorders.claimed_date AS claimed_date,
1866 aqbudgets.budget_name AS budget,
1867 borrowers.branchcode AS branch,
1868 aqbooksellers.name AS supplier,
1869 aqbooksellers.id AS supplierid,
1870 biblio.author, biblio.title,
1871 biblioitems.publishercode AS publisher,
1872 biblioitems.publicationyear,
1873 ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) AS estimateddeliverydate,
1877 aqorders LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber
1878 LEFT JOIN biblioitems ON biblioitems.biblionumber = biblio.biblionumber
1879 LEFT JOIN aqbudgets ON aqorders.budget_id = aqbudgets.budget_id,
1880 aqbasket LEFT JOIN borrowers ON aqbasket.authorisedby = borrowers.borrowernumber
1881 LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
1882 WHERE aqorders.basketno = aqbasket.basketno
1883 AND ( datereceived = ''
1884 OR datereceived IS NULL
1885 OR aqorders.quantityreceived < aqorders.quantity
1887 AND aqbasket.closedate IS NOT NULL
1888 AND (aqorders.datecancellationprinted IS NULL OR aqorders.datecancellationprinted='0000-00-00')
1891 if ($dbdriver eq "mysql") {
1893 aqorders.quantity - COALESCE(aqorders.quantityreceived,0) AS quantity,
1894 (aqorders.quantity - COALESCE(aqorders.quantityreceived,0)) * aqorders.rrp AS subtotal,
1895 DATEDIFF(CAST(now() AS date),closedate) AS latesince
1897 if ( defined $delay ) {
1898 $from .= " AND (closedate <= DATE_SUB(CAST(now() AS date),INTERVAL ? DAY)) " ;
1899 push @query_params, $delay;
1902 HAVING quantity <> 0
1903 AND unitpricesupplier <> 0
1904 AND unitpricelib <> 0
1907 # FIXME: account for IFNULL as above
1909 aqorders.quantity AS quantity,
1910 aqorders.quantity * aqorders.rrp AS subtotal,
1911 (CAST(now() AS date) - closedate) AS latesince
1913 if ( defined $delay ) {
1914 $from .= " AND (closedate <= (CAST(now() AS date) -(INTERVAL ? DAY)) ";
1915 push @query_params, $delay;
1918 if (defined $supplierid) {
1919 $from .= ' AND aqbasket.booksellerid = ? ';
1920 push @query_params, $supplierid;
1922 if (defined $branch) {
1923 $from .= ' AND borrowers.branchcode LIKE ? ';
1924 push @query_params, $branch;
1927 if ( defined $estimateddeliverydatefrom or defined $estimateddeliverydateto ) {
1928 $from .= ' AND aqbooksellers.deliverytime IS NOT NULL ';
1930 if ( defined $estimateddeliverydatefrom ) {
1931 $from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) >= ?';
1932 push @query_params, $estimateddeliverydatefrom;
1934 if ( defined $estimateddeliverydateto ) {
1935 $from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) <= ?';
1936 push @query_params, $estimateddeliverydateto;
1938 if ( defined $estimateddeliverydatefrom and not defined $estimateddeliverydateto ) {
1939 $from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) <= CAST(now() AS date)';
1941 if (C4::Context->preference("IndependentBranches")
1942 && C4::Context->userenv
1943 && C4::Context->userenv->{flags} != 1 ) {
1944 $from .= ' AND borrowers.branchcode LIKE ? ';
1945 push @query_params, C4::Context->userenv->{branch};
1947 my $query = "$select $from $having\nORDER BY latesince, basketno, borrowers.branchcode, supplier";
1948 $debug and print STDERR "GetLateOrders query: $query\nGetLateOrders args: " . join(" ",@query_params);
1949 my $sth = $dbh->prepare($query);
1950 $sth->execute(@query_params);
1952 while (my $data = $sth->fetchrow_hashref) {
1953 $data->{orderdate} = format_date($data->{orderdate});
1954 $data->{claimed_date} = format_date($data->{claimed_date});
1955 push @results, $data;
1960 #------------------------------------------------------------#
1964 (\@order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( %params );
1966 Retreives some acquisition history information
1974 basket - search both basket name and number
1975 booksellerinvoicenumber
1978 $order_loop is a list of hashrefs that each look like this:
1980 'author' => 'Twain, Mark',
1982 'biblionumber' => '215',
1984 'creationdate' => 'MM/DD/YYYY',
1985 'datereceived' => undef,
1988 'invoicenumber' => undef,
1990 'ordernumber' => '1',
1992 'quantityreceived' => undef,
1993 'title' => 'The Adventures of Huckleberry Finn'
1995 $total_qty is the sum of all of the quantities in $order_loop
1996 $total_price is the cost of each in $order_loop times the quantity
1997 $total_qtyreceived is the sum of all of the quantityreceived entries in $order_loop
2002 # don't run the query if there are no parameters (list would be too long for sure !)
2003 croak "No search params" unless @_;
2005 my $title = $params{title};
2006 my $author = $params{author};
2007 my $isbn = $params{isbn};
2008 my $ean = $params{ean};
2009 my $name = $params{name};
2010 my $from_placed_on = $params{from_placed_on};
2011 my $to_placed_on = $params{to_placed_on};
2012 my $basket = $params{basket};
2013 my $booksellerinvoicenumber = $params{booksellerinvoicenumber};
2014 my $basketgroupname = $params{basketgroupname};
2017 my $total_qtyreceived = 0;
2018 my $total_price = 0;
2020 my $dbh = C4::Context->dbh;
2028 aqbasket.basketname,
2029 aqbasket.basketgroupid,
2030 aqbasketgroups.name as groupname,
2032 aqbasket.creationdate,
2033 aqorders.datereceived,
2035 aqorders.quantityreceived,
2037 aqorders.ordernumber,
2039 aqinvoices.invoicenumber,
2040 aqbooksellers.id as id,
2041 aqorders.biblionumber
2043 LEFT JOIN aqbasket ON aqorders.basketno=aqbasket.basketno
2044 LEFT JOIN aqbasketgroups ON aqbasket.basketgroupid=aqbasketgroups.id
2045 LEFT JOIN aqbooksellers ON aqbasket.booksellerid=aqbooksellers.id
2046 LEFT JOIN biblioitems ON biblioitems.biblionumber=aqorders.biblionumber
2047 LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber
2048 LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid";
2050 $query .= " LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber"
2051 if ( C4::Context->preference("IndependentBranches") );
2053 $query .= " WHERE (datecancellationprinted is NULL or datecancellationprinted='0000-00-00') ";
2055 my @query_params = ();
2058 $query .= " AND biblio.title LIKE ? ";
2059 $title =~ s/\s+/%/g;
2060 push @query_params, "%$title%";
2064 $query .= " AND biblio.author LIKE ? ";
2065 push @query_params, "%$author%";
2069 $query .= " AND biblioitems.isbn LIKE ? ";
2070 push @query_params, "%$isbn%";
2072 if ( defined $ean and $ean ) {
2073 $query .= " AND biblioitems.ean = ? ";
2074 push @query_params, "$ean";
2077 $query .= " AND aqbooksellers.name LIKE ? ";
2078 push @query_params, "%$name%";
2081 if ( $from_placed_on ) {
2082 $query .= " AND creationdate >= ? ";
2083 push @query_params, $from_placed_on;
2086 if ( $to_placed_on ) {
2087 $query .= " AND creationdate <= ? ";
2088 push @query_params, $to_placed_on;
2092 if ($basket =~ m/^\d+$/) {
2093 $query .= " AND aqorders.basketno = ? ";
2094 push @query_params, $basket;
2096 $query .= " AND aqbasket.basketname LIKE ? ";
2097 push @query_params, "%$basket%";
2101 if ($booksellerinvoicenumber) {
2102 $query .= " AND aqinvoices.invoicenumber LIKE ? ";
2103 push @query_params, "%$booksellerinvoicenumber%";
2106 if ($basketgroupname) {
2107 $query .= " AND aqbasketgroups.name LIKE ? ";
2108 push @query_params, "%$basketgroupname%";
2111 if ( C4::Context->preference("IndependentBranches") ) {
2112 my $userenv = C4::Context->userenv;
2113 if ( $userenv && ($userenv->{flags} || 0) != 1 ) {
2114 $query .= " AND (borrowers.branchcode = ? OR borrowers.branchcode ='' ) ";
2115 push @query_params, $userenv->{branch};
2118 $query .= " ORDER BY id";
2119 my $sth = $dbh->prepare($query);
2120 $sth->execute( @query_params );
2122 while ( my $line = $sth->fetchrow_hashref ) {
2123 $line->{count} = $cnt++;
2124 $line->{toggle} = 1 if $cnt % 2;
2125 push @order_loop, $line;
2126 $total_qty += $line->{'quantity'};
2127 $total_qtyreceived += $line->{'quantityreceived'};
2128 $total_price += $line->{'quantity'} * $line->{'ecost'};
2130 return \@order_loop, $total_qty, $total_price, $total_qtyreceived;
2133 =head2 GetRecentAcqui
2135 $results = GetRecentAcqui($days);
2137 C<$results> is a ref to a table which containts hashref
2141 sub GetRecentAcqui {
2143 my $dbh = C4::Context->dbh;
2147 ORDER BY timestamp DESC
2150 my $sth = $dbh->prepare($query);
2152 my $results = $sth->fetchall_arrayref({});
2158 $contractlist = &GetContracts($booksellerid, $activeonly);
2160 Looks up the contracts that belong to a bookseller
2162 Returns a list of contracts
2166 =item C<$booksellerid> is the "id" field in the "aqbooksellers" table.
2168 =item C<$activeonly> if exists get only contracts that are still active.
2175 my ( $booksellerid, $activeonly ) = @_;
2176 my $dbh = C4::Context->dbh;
2178 if (! $activeonly) {
2182 WHERE booksellerid=?
2187 WHERE booksellerid=?
2188 AND contractenddate >= CURDATE( )";
2190 my $sth = $dbh->prepare($query);
2191 $sth->execute( $booksellerid );
2193 while (my $data = $sth->fetchrow_hashref ) {
2194 push(@results, $data);
2200 #------------------------------------------------------------#
2204 $contract = &GetContract($contractID);
2206 Looks up the contract that has PRIMKEY (contractnumber) value $contractID
2213 my ( $contractno ) = @_;
2214 my $dbh = C4::Context->dbh;
2218 WHERE contractnumber=?
2221 my $sth = $dbh->prepare($query);
2222 $sth->execute( $contractno );
2223 my $result = $sth->fetchrow_hashref;
2231 &AddClaim($ordernumber);
2233 Add a claim for an order
2239 my ($ordernumber) = @_;
2240 my $dbh = C4::Context->dbh;
2243 claims_count = claims_count + 1,
2244 claimed_date = CURDATE()
2245 WHERE ordernumber = ?
2247 my $sth = $dbh->prepare($query);
2248 $sth->execute($ordernumber);
2253 my @invoices = GetInvoices(
2254 invoicenumber => $invoicenumber,
2255 suppliername => $suppliername,
2256 shipmentdatefrom => $shipmentdatefrom, # ISO format
2257 shipmentdateto => $shipmentdateto, # ISO format
2258 billingdatefrom => $billingdatefrom, # ISO format
2259 billingdateto => $billingdateto, # ISO format
2260 isbneanissn => $isbn_or_ean_or_issn,
2263 publisher => $publisher,
2264 publicationyear => $publicationyear,
2265 branchcode => $branchcode,
2266 order_by => $order_by
2269 Return a list of invoices that match all given criteria.
2271 $order_by is "column_name (asc|desc)", where column_name is any of
2272 'invoicenumber', 'booksellerid', 'shipmentdate', 'billingdate', 'closedate',
2273 'shipmentcost', 'shipmentcost_budgetid'.
2275 asc is the default if omitted
2282 my @columns = qw(invoicenumber booksellerid shipmentdate billingdate
2283 closedate shipmentcost shipmentcost_budgetid);
2285 my $dbh = C4::Context->dbh;
2287 SELECT aqinvoices.*, aqbooksellers.name AS suppliername,
2290 aqorders.datereceived IS NOT NULL,
2291 aqorders.biblionumber,
2294 ) AS receivedbiblios,
2295 SUM(aqorders.quantityreceived) AS receiveditems
2297 LEFT JOIN aqbooksellers ON aqbooksellers.id = aqinvoices.booksellerid
2298 LEFT JOIN aqorders ON aqorders.invoiceid = aqinvoices.invoiceid
2299 LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber
2300 LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
2301 LEFT JOIN subscription ON biblio.biblionumber = subscription.biblionumber
2306 if($args{supplierid}) {
2307 push @bind_strs, " aqinvoices.booksellerid = ? ";
2308 push @bind_args, $args{supplierid};
2310 if($args{invoicenumber}) {
2311 push @bind_strs, " aqinvoices.invoicenumber LIKE ? ";
2312 push @bind_args, "%$args{invoicenumber}%";
2314 if($args{suppliername}) {
2315 push @bind_strs, " aqbooksellers.name LIKE ? ";
2316 push @bind_args, "%$args{suppliername}%";
2318 if($args{shipmentdatefrom}) {
2319 push @bind_strs, " aqinvoices.shipementdate >= ? ";
2320 push @bind_args, $args{shipmentdatefrom};
2322 if($args{shipmentdateto}) {
2323 push @bind_strs, " aqinvoices.shipementdate <= ? ";
2324 push @bind_args, $args{shipmentdateto};
2326 if($args{billingdatefrom}) {
2327 push @bind_strs, " aqinvoices.billingdate >= ? ";
2328 push @bind_args, $args{billingdatefrom};
2330 if($args{billingdateto}) {
2331 push @bind_strs, " aqinvoices.billingdate <= ? ";
2332 push @bind_args, $args{billingdateto};
2334 if($args{isbneanissn}) {
2335 push @bind_strs, " (biblioitems.isbn LIKE ? OR biblioitems.ean LIKE ? OR biblioitems.issn LIKE ? ) ";
2336 push @bind_args, $args{isbneanissn}, $args{isbneanissn}, $args{isbneanissn};
2339 push @bind_strs, " biblio.title LIKE ? ";
2340 push @bind_args, $args{title};
2343 push @bind_strs, " biblio.author LIKE ? ";
2344 push @bind_args, $args{author};
2346 if($args{publisher}) {
2347 push @bind_strs, " biblioitems.publishercode LIKE ? ";
2348 push @bind_args, $args{publisher};
2350 if($args{publicationyear}) {
2351 push @bind_strs, " biblioitems.publicationyear = ? ";
2352 push @bind_args, $args{publicationyear};
2354 if($args{branchcode}) {
2355 push @bind_strs, " aqorders.branchcode = ? ";
2356 push @bind_args, $args{branchcode};
2359 $query .= " WHERE " . join(" AND ", @bind_strs) if @bind_strs;
2360 $query .= " GROUP BY aqinvoices.invoiceid ";
2362 if($args{order_by}) {
2363 my ($column, $direction) = split / /, $args{order_by};
2364 if(grep /^$column$/, @columns) {
2365 $direction ||= 'ASC';
2366 $query .= " ORDER BY $column $direction";
2370 my $sth = $dbh->prepare($query);
2371 $sth->execute(@bind_args);
2373 my $results = $sth->fetchall_arrayref({});
2379 my $invoice = GetInvoice($invoiceid);
2381 Get informations about invoice with given $invoiceid
2383 Return a hash filled with aqinvoices.* fields
2388 my ($invoiceid) = @_;
2391 return unless $invoiceid;
2393 my $dbh = C4::Context->dbh;
2399 my $sth = $dbh->prepare($query);
2400 $sth->execute($invoiceid);
2402 $invoice = $sth->fetchrow_hashref;
2406 =head3 GetInvoiceDetails
2408 my $invoice = GetInvoiceDetails($invoiceid)
2410 Return informations about an invoice + the list of related order lines
2412 Orders informations are in $invoice->{orders} (array ref)
2416 sub GetInvoiceDetails {
2417 my ($invoiceid) = @_;
2419 if ( !defined $invoiceid ) {
2420 carp 'GetInvoiceDetails called without an invoiceid';
2424 my $dbh = C4::Context->dbh;
2426 SELECT aqinvoices.*, aqbooksellers.name AS suppliername
2428 LEFT JOIN aqbooksellers ON aqinvoices.booksellerid = aqbooksellers.id
2431 my $sth = $dbh->prepare($query);
2432 $sth->execute($invoiceid);
2434 my $invoice = $sth->fetchrow_hashref;
2437 SELECT aqorders.*, biblio.*
2439 LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber
2442 $sth = $dbh->prepare($query);
2443 $sth->execute($invoiceid);
2444 $invoice->{orders} = $sth->fetchall_arrayref({});
2445 $invoice->{orders} ||= []; # force an empty arrayref if fetchall_arrayref fails
2452 my $invoiceid = AddInvoice(
2453 invoicenumber => $invoicenumber,
2454 booksellerid => $booksellerid,
2455 shipmentdate => $shipmentdate,
2456 billingdate => $billingdate,
2457 closedate => $closedate,
2458 shipmentcost => $shipmentcost,
2459 shipmentcost_budgetid => $shipmentcost_budgetid
2462 Create a new invoice and return its id or undef if it fails.
2469 return unless(%invoice and $invoice{invoicenumber});
2471 my @columns = qw(invoicenumber booksellerid shipmentdate billingdate
2472 closedate shipmentcost shipmentcost_budgetid);
2476 foreach my $key (keys %invoice) {
2477 if(0 < grep(/^$key$/, @columns)) {
2478 push @set_strs, "$key = ?";
2479 push @set_args, ($invoice{$key} || undef);
2485 my $dbh = C4::Context->dbh;
2486 my $query = "INSERT INTO aqinvoices SET ";
2487 $query .= join (",", @set_strs);
2488 my $sth = $dbh->prepare($query);
2489 $rv = $sth->execute(@set_args);
2491 $rv = $dbh->last_insert_id(undef, undef, 'aqinvoices', undef);
2500 invoiceid => $invoiceid, # Mandatory
2501 invoicenumber => $invoicenumber,
2502 booksellerid => $booksellerid,
2503 shipmentdate => $shipmentdate,
2504 billingdate => $billingdate,
2505 closedate => $closedate,
2506 shipmentcost => $shipmentcost,
2507 shipmentcost_budgetid => $shipmentcost_budgetid
2510 Modify an invoice, invoiceid is mandatory.
2512 Return undef if it fails.
2519 return unless(%invoice and $invoice{invoiceid});
2521 my @columns = qw(invoicenumber booksellerid shipmentdate billingdate
2522 closedate shipmentcost shipmentcost_budgetid);
2526 foreach my $key (keys %invoice) {
2527 if(0 < grep(/^$key$/, @columns)) {
2528 push @set_strs, "$key = ?";
2529 push @set_args, ($invoice{$key} || undef);
2533 my $dbh = C4::Context->dbh;
2534 my $query = "UPDATE aqinvoices SET ";
2535 $query .= join(",", @set_strs);
2536 $query .= " WHERE invoiceid = ?";
2538 my $sth = $dbh->prepare($query);
2539 $sth->execute(@set_args, $invoice{invoiceid});
2544 CloseInvoice($invoiceid);
2548 Equivalent to ModInvoice(invoiceid => $invoiceid, closedate => undef);
2553 my ($invoiceid) = @_;
2555 return unless $invoiceid;
2557 my $dbh = C4::Context->dbh;
2560 SET closedate = CAST(NOW() AS DATE)
2563 my $sth = $dbh->prepare($query);
2564 $sth->execute($invoiceid);
2567 =head3 ReopenInvoice
2569 ReopenInvoice($invoiceid);
2573 Equivalent to ModInvoice(invoiceid => $invoiceid, closedate => C4::Dates->new()->output('iso'))
2578 my ($invoiceid) = @_;
2580 return unless $invoiceid;
2582 my $dbh = C4::Context->dbh;
2585 SET closedate = NULL
2588 my $sth = $dbh->prepare($query);
2589 $sth->execute($invoiceid);
2594 DelInvoice($invoiceid);
2596 Delete an invoice if there are no items attached to it.
2601 my ($invoiceid) = @_;
2603 return unless $invoiceid;
2605 my $dbh = C4::Context->dbh;
2611 my $sth = $dbh->prepare($query);
2612 $sth->execute($invoiceid);
2613 my $res = $sth->fetchrow_arrayref;
2614 if ( $res && $res->[0] == 0 ) {
2616 DELETE FROM aqinvoices
2619 my $sth = $dbh->prepare($query);
2620 return ( $sth->execute($invoiceid) > 0 );
2630 Koha Development Team <http://koha-community.org/>