X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=acqui%2Fspent.pl;h=b4436e901833a0f4c3a86b75f480b22b009c4ce2;hb=459b082f3512d22856429183840a90117970b59e;hp=954fdf63c5542cea4ca5d59d63a3a88dd408d613;hpb=c9d0c168679d6b225e305b45331e1e86ee4939d1;p=koha.git diff --git a/acqui/spent.pl b/acqui/spent.pl index 954fdf63c5..b4436e9018 100755 --- a/acqui/spent.pl +++ b/acqui/spent.pl @@ -25,17 +25,16 @@ =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; +use CGI qw ( -utf8 ); my $dbh = C4::Context->dbh; my $input = new 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;