X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FBookfund.pm;h=1743a38a5da8bda89be4ba8d40551546d4e042f3;hb=46a76d401ef20f4b23f8b945de11604b4e080ef1;hp=2bb190b583d6392f3b40a229eeaf8534ad884ce7;hpb=8ee881174fbb75e983e9ea09f70b2fcecee396ab;p=koha.git diff --git a/C4/Bookfund.pm b/C4/Bookfund.pm old mode 100755 new mode 100644 index 2bb190b583..1743a38a5d --- a/C4/Bookfund.pm +++ b/C4/Bookfund.pm @@ -17,15 +17,14 @@ package C4::Bookfund; # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, # Suite 330, Boston, MA 02111-1307 USA -# $Id$ use strict; - +# use Smart::Comments; use vars qw($VERSION @ISA @EXPORT); # set the version for version checking -$VERSION = do { my @v = '$Revision$' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); }; +$VERSION = 3.00; =head1 NAME @@ -139,9 +138,9 @@ sub GetBookFunds { if ( $branch ne '' ) { $strsth = " SELECT * - FROM aqbookfund,aqbudget - WHERE aqbookfund.bookfundid=aqbudget.bookfundid - AND startdatenow() AND (aqbookfund.branchcode='' OR aqbookfund.branchcode= ? ) GROUP BY aqbookfund.bookfundid ORDER BY bookfundname"; @@ -149,10 +148,9 @@ sub GetBookFunds { else { $strsth = " SELECT * - FROM aqbookfund, - aqbudget - WHERE aqbookfund.bookfundid=aqbudget.bookfundid - AND startdatenow() GROUP BY aqbookfund.bookfundid ORDER BY bookfundname "; @@ -216,6 +214,7 @@ sub GetBookFundBreakdown { my ( $id, $start, $end ) = @_; my $dbh = C4::Context->dbh; + # if no start/end dates given defaut to everything if ( !$start ) { $start = '0000-00-00'; @@ -224,66 +223,41 @@ sub GetBookFundBreakdown { # do a query for spent totals. my $query = " - SELECT quantity,datereceived,freight,unitprice,listprice,ecost, - quantityreceived,subscription - FROM aqorders - LEFT JOIN aqorderbreakdown ON aqorders.ordernumber=aqorderbreakdown.ordernumber - WHERE bookfundid=? - AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00') - AND ((datereceived >= ? and datereceived < ?) OR (budgetdate >= ? and budgetdate < ?)) + SELECT quantity,datereceived,freight,unitprice,listprice,ecost, + quantityreceived AS qrev,subscription,title,aqorders.biblionumber, + aqorders.booksellerinvoicenumber,quantity-quantityreceived as tleft, + aqorders.ordernumber as ordnum,entrydate,budgetdate,aqbasket.booksellerid, + aqbasket.basketno + FROM aqorders + LEFT JOIN aqorderbreakdown USING (ordernumber) + LEFT JOIN aqbasket USING (basketno) + LEFT JOIN aqbudget USING (bookfundid) + WHERE bookfundid=? + AND (datecancellationprinted IS NULL OR datecancellationprinted = '0000-00-00') + AND closedate BETWEEN startdate AND enddate + AND creationdate > startdate + ORDER BY datereceived "; my $sth = $dbh->prepare($query); - $sth->execute( $id, $start, $end, $start, $end ); + $sth->execute( $id); - my $spent = 0; + my ($spent, $comtd) = (0, 0); while ( my $data = $sth->fetchrow_hashref ) { - if ( $data->{'subscription'} == 1 ) { - $spent += $data->{'quantity'} * $data->{'unitprice'}; - } - else { - - my $leftover = $data->{'quantity'} - ($data->{'quantityreceived'}?$data->{'quantityreceived'}:0); - $spent += ( $data->{'unitprice'} ) * ($data->{'quantityreceived'}?$data->{'quantityreceived'}:0); - + + my $recv = $data->{'qrev'}; + my $left = $data->{'tleft'}; + my $ecost = $data->{'ecost'}; + + + if($data->{datereceived}){ + if ( $recv > 0 ) { + $spent += $recv * $data->{'unitprice'}; + } } - } - - # then do a seperate query for commited totals, (pervious single query was - # returning incorrect comitted results. + $left = $data->{quantity} if(not $recv); - $query = " - 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 - FROM aqorders - LEFT JOIN biblioitems ON biblioitems.biblioitemnumber=aqorders.biblioitemnumber - LEFT JOIN aqorderbreakdown ON aqorders.ordernumber=aqorderbreakdown.ordernumber - WHERE bookfundid=? - AND (budgetdate >= ? AND budgetdate < ?) - AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00') - "; - - $sth = $dbh->prepare($query); -# warn "$start $end"; - $sth->execute( $id, $start, $end ); - - my $comtd=0; + $comtd += $left * $ecost; - 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; - } -# use Data::Dumper; warn Dumper($data); } $sth->finish; @@ -317,33 +291,39 @@ sub NewBookFund{ =head3 ModBookFund -&ModBookFund($bookfundname,$branchcode,$bookfundid); -this function update the bookfundname and the branchcode on aqbookfund table -on database. +&ModBookFund($bookfundname,$bookfundid,$current_branch, $branchcode) + +This function updates the bookfundname and the branchcode in the aqbookfund table. =cut +# FIXME: use placeholders, ->prepare(), ->execute() + sub ModBookFund { - my ($bookfundname,$bookfundid,$branchcode) = @_; + my ($bookfundname,$bookfundid,$current_branch, $branchcode) = @_; + my $dbh = C4::Context->dbh; - my $query = " - UPDATE aqbookfund - SET bookfundname = ? - WHERE bookfundid = ? - AND branchcode= ? - "; - warn "name : $bookfundname"; - my $sth=$dbh->prepare($query); - $sth->execute($bookfundname,$bookfundid,"$branchcode"); -# budgets depending on a bookfund must have the same branchcode -# if the bookfund branchcode is set - if (defined $branchcode) { - $query = " - UPDATE aqbudget - SET branchcode = ? - "; - $sth=$dbh->prepare($query); - $sth->execute($branchcode); + + my $retval = $dbh->do(" + UPDATE aqbookfund + SET bookfundname = '$bookfundname', + branchcode = '$branchcode' + WHERE bookfundid = '$bookfundid' + AND branchcode = '$current_branch' + "); + + ### $retval + + # budgets depending on a bookfund must have the same branchcode + + # if the bookfund branchcode is set, and previous update is successfull, then update aqbudget.branchcode too. + if (defined $branchcode && $retval > 0) { + my $query = "UPDATE aqbudget + SET branchcode = ? + WHERE bookfundid = ? "; + + my $sth=$dbh->prepare($query); + $sth->execute($branchcode, $bookfundid) ; } } @@ -447,7 +427,7 @@ sub Countbookfund { AND branchcode = ? "; my $sth = $dbh->prepare($query); - $sth->execute($bookfundid,$branchcode); + $sth->execute($bookfundid,"$branchcode"); return $sth->fetchrow; }