(bug #3348) Budget and funds broken
authorNahuel ANGELINETTI <nahuel.angelinetti@biblibre.com>
Thu, 8 Oct 2009 14:36:20 +0000 (16:36 +0200)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Thu, 8 Oct 2009 15:09:34 +0000 (17:09 +0200)
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
C4/Bookfund.pm
acqui/parcel.pl
acqui/spent.pl

index 35d5253..b3cd99c 100644 (file)
@@ -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 );
index ada1e49..5933858 100644 (file)
@@ -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'};
             }
 
         }
index 3a5cd07..8d60498 100755 (executable)
@@ -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
index 2dd4ddb..aebe98a 100755 (executable)
@@ -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);