X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FAcquisition.pm;h=e406d81618ec00bfcfa7a2699c9fb43b9804150d;hb=da0337b374c5824c0f9edcb3e8545c812644ff63;hp=4a9eae6c2d65abed8035d97d9194bf20b1a0eae7;hpb=45a7d554eaae67d42e02cb126336d78716b88c89;p=koha.git diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 4a9eae6c2d..e406d81618 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -53,12 +53,12 @@ BEGIN { &ModBasketgroup &NewBasketgroup &DelBasketgroup &GetBasketgroup &CloseBasketgroup &GetBasketgroups &ReOpenBasketgroup - &NewOrder &DelOrder &ModOrder &GetPendingOrders &GetOrder &GetOrders - &GetOrderNumber &GetLateOrders &GetOrderFromItemnumber + &NewOrder &DelOrder &ModOrder &GetPendingOrders &GetOrder &GetOrders &GetOrdersByBiblionumber + &GetLateOrders &GetOrderFromItemnumber &SearchOrder &GetHistory &GetRecentAcqui - &ModReceiveOrder &CancelReceipt &ModOrderBiblioitemNumber + &ModReceiveOrder &CancelReceipt &GetCancelledOrders - + &GetLastOrderNotReceivedFromSubscriptionid &GetLastOrderReceivedFromSubscriptionid &NewOrderItem &ModOrderItem &ModItemOrder &GetParcels &GetParcel @@ -568,7 +568,11 @@ sub GetBasketsByBookseller { =head3 GetBasketsInfosByBookseller - my $baskets = GetBasketsInfosByBookseller($supplierid); + my $baskets = GetBasketsInfosByBookseller($supplierid, $allbaskets); + +The optional second parameter allbaskets is a boolean allowing you to +select all baskets from the supplier; by default only active baskets (open or +closed but still something to receive) are returned. Returns in a arrayref of hashref all about booksellers baskets, plus: total_biblios: Number of distinct biblios in basket @@ -578,7 +582,7 @@ Returns in a arrayref of hashref all about booksellers baskets, plus: =cut sub GetBasketsInfosByBookseller { - my ($supplierid) = @_; + my ($supplierid, $allbaskets) = @_; return unless $supplierid; @@ -595,9 +599,12 @@ sub GetBasketsInfosByBookseller { ) AS expected_items FROM aqbasket LEFT JOIN aqorders ON aqorders.basketno = aqbasket.basketno - WHERE booksellerid = ? - GROUP BY aqbasket.basketno - }; + WHERE booksellerid = ?}; + if(!$allbaskets) { + $query.=" AND (closedate IS NULL OR (aqorders.quantity > aqorders.quantityreceived AND datecancellationprinted IS NULL))"; + } + $query.=" GROUP BY aqbasket.basketno"; + my $sth = $dbh->prepare($query); $sth->execute($supplierid); return $sth->fetchall_arrayref({}); @@ -643,8 +650,12 @@ $hashref->{'name'} is the 'name' field of the basketgroup in the aqbasketgroups $hashref->{'basketlist'} is a list reference of the 'id's of the baskets that belong to this group, +$hashref->{'billingplace'} is the 'billingplace' field of the basketgroup in the aqbasketgroups table, + $hashref->{'deliveryplace'} is the 'deliveryplace' field of the basketgroup in the aqbasketgroups table, +$hashref->{'freedeliveryplace'} is the 'freedeliveryplace' field of the basketgroup in the aqbasketgroups table, + $hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table, $hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise. @@ -656,8 +667,8 @@ sub NewBasketgroup { die "booksellerid is required to create a basketgroup" unless $basketgroupinfo->{'booksellerid'}; my $query = "INSERT INTO aqbasketgroups ("; my @params; - foreach my $field ('name', 'deliveryplace', 'deliverycomment', 'closed') { - if ( $basketgroupinfo->{$field} ) { + foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment closed)) { + if ( defined $basketgroupinfo->{$field} ) { $query .= "$field, "; push(@params, $basketgroupinfo->{$field}); } @@ -700,6 +711,8 @@ $hashref->{'billingplace'} is the 'billingplace' field of the basketgroup in the $hashref->{'deliveryplace'} is the 'deliveryplace' field of the basketgroup in the aqbasketgroups table, +$hashref->{'freedeliveryplace'} is the 'freedeliveryplace' field of the basketgroup in the aqbasketgroups table, + $hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table, $hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise. @@ -861,7 +874,7 @@ sub GetPendingOrders { AND datecancellationprinted IS NULL"; my @query_params; my $userenv = C4::Context->userenv; - if ( C4::Context->preference("IndependantBranches") ) { + if ( C4::Context->preference("IndependentBranches") ) { if ( ($userenv) && ( $userenv->{flags} != 1 ) ) { $strsth .= " AND (borrowers.branchcode = ? or borrowers.branchcode = '')"; @@ -944,36 +957,38 @@ sub GetOrders { } #------------------------------------------------------------# +=head3 GetOrdersByBiblionumber -=head3 GetOrderNumber - - $ordernumber = &GetOrderNumber($biblioitemnumber, $biblionumber); - -Looks up the ordernumber with the given biblionumber and biblioitemnumber. - -Returns the number of this order. - -=over + @orders = &GetOrdersByBiblionumber($biblionumber); -=item C<$ordernumber> is the order number. +Looks up the orders with linked to a specific $biblionumber, including +cancelled orders and received orders. -=back +return : +C<@orders> is an array of references-to-hash, whose keys are the +fields from the aqorders, biblio, and biblioitems tables in the Koha database. =cut -sub GetOrderNumber { - my ( $biblionumber,$biblioitemnumber ) = @_; - my $dbh = C4::Context->dbh; - my $query = " - SELECT ordernumber - FROM aqorders - WHERE biblionumber=? - AND biblioitemnumber=? +sub GetOrdersByBiblionumber { + my $biblionumber = shift; + return unless $biblionumber; + my $dbh = C4::Context->dbh; + my $query =" + SELECT biblio.*,biblioitems.*, + aqorders.*, + aqbudgets.* + FROM aqorders + LEFT JOIN aqbudgets ON aqbudgets.budget_id = aqorders.budget_id + LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber + LEFT JOIN biblioitems ON biblioitems.biblionumber =biblio.biblionumber + WHERE aqorders.biblionumber=? "; my $sth = $dbh->prepare($query); - $sth->execute( $biblionumber, $biblioitemnumber ); - - return $sth->fetchrow; + $sth->execute($biblionumber); + my $results = $sth->fetchall_arrayref({}); + $sth->finish; + return @$results; } #------------------------------------------------------------# @@ -1007,6 +1022,67 @@ sub GetOrder { return $data; } +=head3 GetLastOrderNotReceivedFromSubscriptionid + + $order = &GetLastOrderNotReceivedFromSubscriptionid($subscriptionid); + +Returns a reference-to-hash describing the last order not received for a subscription. + +=cut + +sub GetLastOrderNotReceivedFromSubscriptionid { + my ( $subscriptionid ) = @_; + my $dbh = C4::Context->dbh; + my $query = qq| + SELECT * FROM aqorders + LEFT JOIN subscription + ON ( aqorders.subscriptionid = subscription.subscriptionid ) + WHERE aqorders.subscriptionid = ? + AND aqorders.datereceived IS NULL + LIMIT 1 + |; + my $sth = $dbh->prepare( $query ); + $sth->execute( $subscriptionid ); + my $order = $sth->fetchrow_hashref; + return $order; +} + +=head3 GetLastOrderReceivedFromSubscriptionid + + $order = &GetLastOrderReceivedFromSubscriptionid($subscriptionid); + +Returns a reference-to-hash describing the last order received for a subscription. + +=cut + +sub GetLastOrderReceivedFromSubscriptionid { + my ( $subscriptionid ) = @_; + my $dbh = C4::Context->dbh; + my $query = qq| + SELECT * FROM aqorders + LEFT JOIN subscription + ON ( aqorders.subscriptionid = subscription.subscriptionid ) + WHERE aqorders.subscriptionid = ? + AND aqorders.datereceived = + ( + SELECT MAX( aqorders.datereceived ) + FROM aqorders + LEFT JOIN subscription + ON ( aqorders.subscriptionid = subscription.subscriptionid ) + WHERE aqorders.subscriptionid = ? + AND aqorders.datereceived IS NOT NULL + ) + ORDER BY ordernumber DESC + LIMIT 1 + |; + my $sth = $dbh->prepare( $query ); + $sth->execute( $subscriptionid, $subscriptionid ); + my $order = $sth->fetchrow_hashref; + return $order; + +} + + #------------------------------------------------------------# =head3 NewOrder @@ -1033,7 +1109,7 @@ Else, the upcoming July 1st is used. =item defaults entrydate to Now -The following keys are used: "biblionumber", "title", "basketno", "quantity", "notes", "biblioitemnumber", "rrp", "ecost", "gstrate", "unitprice", "subscription", "sort1", "sort2", "booksellerinvoicenumber", "listprice", "budgetdate", "purchaseordernumber", "branchcode", "booksellerinvoicenumber", "budget_id". +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". =back @@ -1125,6 +1201,9 @@ sub ModOrder { my $sth = $dbh->prepare("SELECT * FROM aqorders LIMIT 1;"); $sth->execute; my $colnames = $sth->{NAME}; + #FIXME Be careful. If aqorders would have columns with diacritics, + #you should need to decode what you get back from NAME. + #See report 10110 and guided_reports.pl my $query = "UPDATE aqorders SET "; foreach my $orderinfokey (grep(!/ordernumber/, keys %$orderinfo)){ @@ -1201,29 +1280,6 @@ sub ModItemOrder { #------------------------------------------------------------# - -=head3 ModOrderBibliotemNumber - - &ModOrderBiblioitemNumber($biblioitemnumber,$ordernumber, $biblionumber); - -Modifies the biblioitemnumber for an existing order. -Updates the order with order number C<$ordernum> and biblionumber C<$biblionumber>. - -=cut - -#FIXME: is this used at all? -sub ModOrderBiblioitemNumber { - my ($biblioitemnumber,$ordernumber, $biblionumber) = @_; - my $dbh = C4::Context->dbh; - my $query = " - UPDATE aqorders - SET biblioitemnumber = ? - WHERE ordernumber = ? - AND biblionumber = ?"; - my $sth = $dbh->prepare($query); - $sth->execute( $biblioitemnumber, $ordernumber, $biblionumber ); -} - =head3 GetCancelledOrders my @orders = GetCancelledOrders($basketno, $orderby); @@ -1265,8 +1321,7 @@ sub GetCancelledOrders { =head3 ModReceiveOrder &ModReceiveOrder($biblionumber, $ordernumber, $quantityreceived, $user, - $unitprice, $invoiceid, $biblioitemnumber, - $bookfund, $rrp, \@received_itemnumbers); + $cost, $ecost, $invoiceid, rrp, budget_id, datereceived, \@received_itemnumbers); Updates an order, to reflect the fact that it was received, at least in part. All arguments not mentioned below update the fields with the @@ -1625,7 +1680,7 @@ sub GetParcel { AND aqorders.datereceived = ? "; my @query_params = ( $supplierid, $code, $datereceived ); - if ( C4::Context->preference("IndependantBranches") ) { + if ( C4::Context->preference("IndependentBranches") ) { my $userenv = C4::Context->userenv; if ( ($userenv) && ( $userenv->{flags} != 1 ) ) { $strsth .= " and (borrowers.branchcode = ? @@ -1844,7 +1899,7 @@ sub GetLateOrders { if ( defined $estimateddeliverydatefrom and not defined $estimateddeliverydateto ) { $from .= ' AND ADDDATE(aqbasket.closedate, INTERVAL aqbooksellers.deliverytime DAY) <= CAST(now() AS date)'; } - if (C4::Context->preference("IndependantBranches") + if (C4::Context->preference("IndependentBranches") && C4::Context->userenv && C4::Context->userenv->{flags} != 1 ) { $from .= ' AND borrowers.branchcode LIKE ? '; @@ -1941,6 +1996,7 @@ sub GetHistory { aqorders.quantityreceived, aqorders.ecost, aqorders.ordernumber, + aqorders.invoiceid, aqinvoices.invoicenumber, aqbooksellers.id as id, aqorders.biblionumber @@ -1953,7 +2009,7 @@ sub GetHistory { LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid"; $query .= " LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber" - if ( C4::Context->preference("IndependantBranches") ); + if ( C4::Context->preference("IndependentBranches") ); $query .= " WHERE (datecancellationprinted is NULL or datecancellationprinted='0000-00-00') "; @@ -2013,7 +2069,7 @@ sub GetHistory { push @query_params, "%$basketgroupname%"; } - if ( C4::Context->preference("IndependantBranches") ) { + if ( C4::Context->preference("IndependentBranches") ) { my $userenv = C4::Context->userenv; if ( $userenv && ($userenv->{flags} || 0) != 1 ) { $query .= " AND (borrowers.branchcode = ? OR borrowers.branchcode ='' ) ";