From 429e5d401fb4d661330da9d995a0f2f029416d71 Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Thu, 8 Oct 2009 16:36:20 +0200 Subject: [PATCH] (bug #3348) Budget and funds broken This patch, fix the way to detect closed baskets or not. The way to calculate budget and funds and the spent detail. --- C4/Acquisition.pm | 5 +++-- C4/Bookfund.pm | 27 +++++++++++++-------------- acqui/parcel.pl | 2 +- acqui/spent.pl | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 35d525364a..b3cd99c95f 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -206,12 +206,13 @@ sub GetPendingOrders { LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber WHERE booksellerid=? - AND (quantity > quantityreceived OR quantityreceived is NULL) AND datecancellationprinted IS NULL AND (to_days(now())-to_days(closedate) < 180 OR closedate IS NULL) "; if($closed){ - $strsth .= " AND closedate IS NOT NULL "; + $strsth .= " + AND (quantity > quantityreceived OR quantityreceived is NULL) + AND closedate IS NOT NULL "; } ## FIXME Why 180 days ??? my @query_params = ( $supplierid ); diff --git a/C4/Bookfund.pm b/C4/Bookfund.pm index ada1e496f1..59338580a5 100644 --- a/C4/Bookfund.pm +++ b/C4/Bookfund.pm @@ -222,17 +222,18 @@ sub GetBookFundBreakdown { # do a query for spent totals. my $query = " - Select distinct quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived - as qrev,subscription,title,itype as itemtype,aqorders.biblionumber,aqorders.booksellerinvoicenumber, + Select quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived + as qrev,subscription,title,itemtype,aqorders.biblionumber,aqorders.booksellerinvoicenumber, quantity-quantityreceived as tleft, aqorders.ordernumber - as ordnum,entrydate,budgetdate,aqbasket.booksellerid,aqbasket.basketno - from aqorders - inner join aqorderbreakdown on aqorderbreakdown.ordernumber = aqorders.ordernumber - inner join aqbasket on aqbasket.basketno = aqorders.basketno - left join items on items.biblionumber=aqorders.biblionumber - where bookfundid=? - and (datereceived >= ? and datereceived < ?) + as ordnum,entrydate,budgetdate,booksellerid,aqbasket.basketno + from aqorderbreakdown,aqbasket,aqorders + left join biblioitems on biblioitems.biblioitemnumber=aqorders.biblioitemnumber + where bookfundid=? and + aqorders.ordernumber=aqorderbreakdown.ordernumber and + aqorders.basketno=aqbasket.basketno + and ( + (datereceived >= ? and datereceived < ?)) and (datecancellationprinted is NULL or datecancellationprinted='0000-00-00') and (closedate >= ? and closedate < ?) @@ -243,11 +244,9 @@ sub GetBookFundBreakdown { my ($spent) = 0; while ( my $data = $sth->fetchrow_hashref ) { if($data->{datereceived}){ - if ( $data->{'subscription'} == 1 ) { - $spent += $data->{'quantity'} * $data->{'unitprice'}; - } - else { - $spent += ( $data->{'unitprice'} ) * ($data->{'qrev'}?$data->{'qrev'}:0); + my $recv = $data->{'qrev'}; + if ( $recv > 0 ) { + $spent += $recv * $data->{'unitprice'}; } } diff --git a/acqui/parcel.pl b/acqui/parcel.pl index 3a5cd075fc..8d60498854 100755 --- a/acqui/parcel.pl +++ b/acqui/parcel.pl @@ -146,7 +146,7 @@ for (my $i = 0 ; $i < $countlines ; $i++) { $tototal += $total; } -my $pendingorders = GetPendingOrders($supplierid, 0, 1); +my $pendingorders = GetPendingOrders($supplierid, "", 1); my $countpendings = scalar @$pendingorders; # pending orders totals diff --git a/acqui/spent.pl b/acqui/spent.pl index 2dd4ddb3db..aebe98aa43 100755 --- a/acqui/spent.pl +++ b/acqui/spent.pl @@ -45,7 +45,7 @@ my $query = and (datecancellationprinted is NULL or datecancellationprinted='0000-00-00') and (closedate >= ? and closedate < ?) - + ORDER BY datereceived "; my $sth = $dbh->prepare($query); $sth->execute( $bookfund, $start, $end, $start, $end); -- 2.39.5