- }
- }
-
- # then do a seperate query for commited totals, (pervious single query was
- # returning incorrect comitted results.
-
- my $query = "
- SELECT quantity,datereceived,freight,unitprice,
- listprice,ecost,quantityreceived AS qrev,
- subscription,biblio.title,itemtype,aqorders.biblionumber,
- aqorders.booksellerinvoicenumber,
- quantity-quantityreceived AS tleft,
- aqorders.ordernumber AS ordnum,entrydate,budgetdate,
- booksellerid,aqbasket.basketno
- FROM aqorderbreakdown,
- aqbasket,
- aqorders
- LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber
- WHERE bookfundid=?
- AND aqorders.ordernumber=aqorderbreakdown.ordernumber
- AND aqorders.basketno=aqbasket.basketno
- AND (budgetdate >= ? AND budgetdate < ?)
- AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
- ";
-
- my $sth = $dbh->prepare($query);
- $sth->execute( $id, $start, $end );
-
- my $comtd;
-
- my $total = 0;
- while ( my $data = $sth->fetchrow_hashref ) {
- my $left = $data->{'tleft'};
- if ( !$left || $left eq '' ) {
- $left = $data->{'quantity'};
- }
- if ( $left && $left > 0 ) {
- my $subtotal = $left * $data->{'ecost'};
- $data->{subtotal} = $subtotal;
- $data->{'left'} = $left;
- $comtd += $subtotal;
- }