X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=acqui%2Fspent.pl;h=2d555f9a765a6815924f18d50dbaf39ff92f573e;hb=fa69f553eebbe671760cef93d869e24d4dc243a5;hp=12260c044edd22fb6fd06ad09ae68026d1fcaf0f;hpb=79b0b7648127180d704a7311c058939c8cb76bf0;p=koha.git diff --git a/acqui/spent.pl b/acqui/spent.pl index 12260c044e..2d555f9a76 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; @@ -48,7 +47,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( query => $input, type => "intranet", authnotrequired => 0, - flagsrequired => { acquisition => 1 }, + flagsrequired => { acquisition => '*' }, debug => 1, } ); @@ -61,10 +60,10 @@ SELECT aqbasket.booksellerid, itype, title, - aqorders.booksellerinvoicenumber, + aqorders.invoiceid, + aqinvoices.invoicenumber, quantityreceived, unitprice, - freight, datereceived, aqorders.biblionumber FROM (aqorders, aqbasket) @@ -74,6 +73,8 @@ LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber LEFT JOIN aqorders_items ON aqorders.ordernumber=aqorders_items.ordernumber +LEFT JOIN aqinvoices ON + aqorders.invoiceid = aqinvoices.invoiceid WHERE aqorders.basketno=aqbasket.basketno AND budget_id=? AND @@ -86,27 +87,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;