From 5b663bf17415f04e515a387b6afbf50b4ffdf4e7 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 26 Mar 2015 13:22:06 +0100 Subject: [PATCH] Bug 13914: Holds statistics report should add values from reserves and old_reserves MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit And not pick one randomly... To reproduce: 1/ Go on Reports › Holds statistics 2/ Fill the form with: Hold status: All checked (Asked Processing Waiting Satisfied Cancelled) Hold Date From 01/01/2014 To 31/01/2014 Pickup library => empty Holding library => empty Home library => empty Row is "Hold status", Column is "Pickup library". 3/ Submit! 4/ Look at the results 5/ Restart mysql 6/ Ctrl+R to resubmit the form 7/ Look at the results The generated query looks like ( SELECT stuffs FROM reserves ) UNION ( SELECT stuffs FROM old_reserves ) It returns something like: +------+---------------+-------------+ | line | col | calculation | +------+---------------+-------------+ | 1 | BRANCHCODE1 | 1 | < from the reserves table | 1 | BRANCHCODE1 | 11 | < from the old_reserves table | 1 | BRANCHCODE2 | 2 | | 1 | BRANCHCODE2 | 22 | | 2 | BRANCHCODE1 | 4 | | 2 | BRANCHCODE1 | 44 | | 2 | BRANCHCODE2 | 5 | | 2 | BRANCHCODE2 | 55 | +------+---------------+-------------+ The screen will display 1 OR 11 for the BRANCHCODE1 line 1. Since ( line, col ) is not uniq, fetchall_hashref (l.280) was not a good idea here. This patch replaces it with fetchall_arrayref, reconstruct the variables used later and add the values from reserves and old_reserves. Test plan: Confirm that the results are now relevant. --- reports/reserves_stats.pl | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/reports/reserves_stats.pl b/reports/reserves_stats.pl index df8d648..b798862 100755 --- a/reports/reserves_stats.pl +++ b/reports/reserves_stats.pl @@ -275,17 +275,20 @@ sub calculate { @sqlparams=(@sqlparams,@sqlorparams); $dbcalc->execute(@sqlparams,@sqlparams); my ($emptycol,$emptyrow); - my $data = $dbcalc->fetchall_hashref([qw(line col)]); - my %cols_hash; - foreach my $row (keys %$data){ - push @loopline, $row; - foreach my $col (keys %{$$data{$row}}){ - $$data{$row}{totalrow}+=$$data{$row}{$col}{calculation}; - $grantotal+=$$data{$row}{$col}{calculation}; - $cols_hash{$col}=1 ; - } - } my $urlbase="do_it=1&".join("&",map{"filter_$_=$$filters_hashref{$_}"} keys %$filters_hashref); + + my $results = $dbcalc->fetchall_arrayref({}); + my %cols_hash; + my $data; + foreach my $r (@$results){ + my $row = $r->{line}; + $data->{$row}{$r->{col}}{calculation} += $r->{calculation}; + $data->{$row}{totalrow} += $r->{calculation}; + $grantotal += $r->{calculation}; + $cols_hash{$r->{col}}=1 ; + } + @loopline = keys $data; + foreach my $row (sort @loopline) { my @loopcell; #@loopcol ensures the order for columns is common with column titles -- 2.1.0