Bug 21033: Remove few warns in acqui/basket.pl
[srvgit] / acqui / spent.pl
index 4d60029..988b8c2 100755 (executable)
@@ -32,9 +32,9 @@ this script is designed to show the spent amount in budgets
 use C4::Context;
 use C4::Auth;
 use C4::Output;
-use strict;
-use warnings;
+use Modern::Perl;
 use CGI qw ( -utf8 );
+use Koha::Acquisition::Invoice::Adjustments;
 
 my $dbh      = C4::Context->dbh;
 my $input    = new CGI;
@@ -54,7 +54,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 
 my $query = <<EOQ;
 SELECT
-    aqorders.basketno, aqorders.ordernumber,
+    aqorders.biblionumber, aqorders.basketno, aqorders.ordernumber,
     quantity-quantityreceived AS tleft,
     ecost, budgetdate, entrydate,
     aqbasket.booksellerid,
@@ -64,8 +64,7 @@ SELECT
     aqinvoices.invoicenumber,
     quantityreceived,
     unitprice,
-    datereceived,
-    aqorders.biblionumber
+    datereceived
 FROM (aqorders, aqbasket)
 LEFT JOIN biblio ON
     biblio.biblionumber=aqorders.biblionumber
@@ -89,7 +88,6 @@ if ( $sth->err ) {
     die "An error occurred fetching records: " . $sth->errstr;
 }
 my $subtotal = 0;
-my $toggle;
 my @spent;
 while ( my $data = $sth->fetchrow_hashref ) {
     my $recv = $data->{'quantityreceived'};
@@ -121,6 +119,11 @@ while (my $data = $sth->fetchrow_hashref) {
 }
 $sth->finish;
 
+my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $bookfund, closedate => { '!=' => undef } }, { join => 'invoiceid' } );
+while ( my $adj = $adjustments->next ){
+    $total += $adj->adjustment;
+}
+
 $total = sprintf( "%.2f", $total );
 
 $template->param(
@@ -128,6 +131,7 @@ $template->param(
     spent => \@spent,
     subtotal => $subtotal,
     shipmentcosts => \@shipmentcosts,
+    adjustments => $adjustments,
     total => $total,
     fund_code => $fund_code
 );