X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=acqui%2Fspent.pl;h=c3c4693afb385fdd359b2d960b7812fa89551e63;hb=5d6c092921919526ade501facb1220f8a108a08f;hp=954fdf63c5542cea4ca5d59d63a3a88dd408d613;hpb=235a9dfb7d259b67f0c4167b56c7a0b04275046d;p=koha_fer diff --git a/acqui/spent.pl b/acqui/spent.pl index 954fdf63c5..c3c4693afb 100755 --- a/acqui/spent.pl +++ b/acqui/spent.pl @@ -25,14 +25,13 @@ =head1 DESCRIPTION -this script is designed to show the spent amount in budges +this script is designed to show the spent amount in budgets =cut use C4::Context; use C4::Auth; use C4::Output; -use C4::Dates; use strict; use warnings; use CGI; @@ -61,20 +60,23 @@ SELECT aqbasket.booksellerid, itype, title, - aqorders.booksellerinvoicenumber, + aqorders.invoiceid, + aqinvoices.invoicenumber, quantityreceived, unitprice, - freight, datereceived, aqorders.biblionumber FROM (aqorders, aqbasket) -LEFT JOIN items ON - items.biblioitemnumber=aqorders.biblioitemnumber LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber +LEFT JOIN items ON + biblio.biblionumber = items.biblionumber LEFT JOIN aqorders_items ON - aqorders.ordernumber=aqorders_items.ordernumber + items.itemnumber = aqorders_items.itemnumber +LEFT JOIN aqinvoices ON + aqorders.invoiceid = aqinvoices.invoiceid WHERE + aqorders.ordernumber=aqorders_items.ordernumber AND aqorders.basketno=aqbasket.basketno AND budget_id=? AND (datecancellationprinted IS NULL OR @@ -86,27 +88,48 @@ $sth->execute($bookfund); if ( $sth->err ) { die "An error occurred fetching records: " . $sth->errstr; } -my $total = 0; +my $subtotal = 0; my $toggle; my @spent; while ( my $data = $sth->fetchrow_hashref ) { my $recv = $data->{'quantityreceived'}; if ( $recv > 0 ) { - my $subtotal = $recv * ( $data->{'unitprice'} + $data->{'freight'} ); - $data->{'subtotal'} = sprintf( "%.2f", $subtotal ); - $data->{'freight'} = sprintf( "%.2f", $data->{'freight'} ); + my $rowtotal = $recv * $data->{'unitprice'}; + $data->{'rowtotal'} = sprintf( "%.2f", $rowtotal ); $data->{'unitprice'} = sprintf( "%.2f", $data->{'unitprice'} ); - $total += $subtotal; + $subtotal += $rowtotal; push @spent, $data; } } -$total = sprintf( "%.2f", $total ); -$template->{VARS}->{'fund'} = $bookfund; -$template->{VARS}->{'spent'} = \@spent; -$template->{VARS}->{'total'} = $total; -$template->{VARS}->{'fund_code'} = $fund_code; +my $total = $subtotal; +$query = qq{ + SELECT invoicenumber, shipmentcost + FROM aqinvoices + WHERE shipmentcost_budgetid = ? +}; +$sth = $dbh->prepare($query); +$sth->execute($bookfund); +my @shipmentcosts; +while (my $data = $sth->fetchrow_hashref) { + push @shipmentcosts, { + shipmentcost => sprintf("%.2f", $data->{shipmentcost}), + invoicenumber => $data->{invoicenumber} + }; + $total += $data->{shipmentcost}; +} $sth->finish; +$total = sprintf( "%.2f", $total ); + +$template->param( + fund => $bookfund, + spent => \@spent, + subtotal => $subtotal, + shipmentcosts => \@shipmentcosts, + total => $total, + fund_code => $fund_code +); + output_html_with_http_headers $input, $cookie, $template->output;