Bug 36585: Improve 'Patrons with the most checkouts' report

Update the 'Patrons with the most checkouts' report (bor_issues_top.pl)
to:
1. Add the total to the CSV output.
2. Change the screen output to only show the patrons name once, instead
   of for each group by column.
3. Add total check out when output to screen.
4. Change item type group by from biblioitems.itemtype to items.itype.

Note: This does not fix the SQL query so that it can run if the
database is in strict mode.

Test plan:
1. If using koha-testing-docker (KTD), set strict SQL mode for your
   database to 0 (that is, turn it off).
   (Edit <strict_sql_modes>0</strict_sql_modes> in
   /etc/koha/sites/kohadev/koha-conf.xml
   (and then flush_memcached and restart_all))
2. Add some data so that a useful report can be generated:
   . Check out and return some items to different patrons in different
     libraries:
     ==> Minimum end result:
         . two items issued to a patron for one library, 1 item issued
           and returned for the same patron at another library
         . one item issued to another patron from another patron
           category for one of the libraries used previously
3. Generate the report with output to screen with a group by, for
   example: 'By' option set to Category code
4. Observe that the patron name is repeated for each column group.
5. Observe that there is no total column.
6. Generate the report with output to CSV.
7. Observe that the total checkouts is not in the CSV.
8. Apply the patch and restart Koha (restart_all).
9. Generate the CSV report again.
10. Observe that the total checkouts is in the CSV.
11. Generate the report to screen again.
12. Observe that there is a total column and the patron name is only
    shown in one column.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Michael Hafen 2024-04-11 16:33:39 -06:00 committed by Katrin Fischer
parent ada41ec134
commit 212294b7f1
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834
2 changed files with 36 additions and 29 deletions

View file

@ -87,13 +87,14 @@
<table>
<tr>
<th rowspan="2">Rank</th>
<th rowspan="2">Patron</th>
<th rowspan="2">Total</th>
[% FOREACH loopco IN mainloo.loopcol %]
<th colspan="2">[% loopco.coltitle | html %]</th>
<th>[% loopco.coltitle | html %]</th>
[% END %]
</tr>
<tr>
[% FOREACH loopco IN mainloo.loopcol %]
<th>Patron</th>
<th>Checkout count</th>
[% END %]
</tr>
@ -101,13 +102,13 @@
<tr>
[% IF ( loopro.hilighted ) %]<td>[% ELSE %]<td>[% END %]
[% loopro.rowtitle | html %]</td>
[% IF ( loopro.hilighted ) %]<td>[% ELSE %]<td>[% END %]
[% IF ( loopro.reference ) %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% loopro.reference | uri %]">[% END %]
[% IF ( loopro.patron ) %][% loopro.patron | html %][% END %]
[% IF ( loopro.reference ) %]</a>[% END %]
</td>
[% FOREACH loopcel IN loopro.loopcell %]
[% IF ( loopcel.hilighted ) %]<td>[% ELSE %]<td>[% END %]
[% IF ( loopcel.reference ) %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% loopcel.reference | uri %]">[% END %]
[% IF ( loopcel.value ) %][% loopcel.value | html %][% END %]
[% IF ( loopcel.reference ) %]</a>[% END %]
</td>
[% IF ( loopcel.hilighted ) %]<td>[% ELSE %]<td>[% END %]
[% IF ( loopcel.count ) %][% loopcel.count | html %][% END %]
</td>
[% END %]

View file

@ -68,23 +68,25 @@ if ($do_it) {
-filename=>"$basename.csv" );
my $cols = @$results[0]->{loopcol};
my $lines = @$results[0]->{looprow};
# header top-right
# header top-left
print @$results[0]->{line} ."/". @$results[0]->{column} .$sep;
print "Patron".$sep;
print "Total".$sep;
# Other header
print join($sep, map {$_->{coltitle}} @$cols);
print $sep . "Total\n";
print "\n";
# Table
foreach my $line ( @$lines ) {
my $x = $line->{loopcell};
print $line->{rowtitle}.$sep;
print join($sep, map {$_->{value}} @$x);
print $sep,$line->{totalrow};
print '"'.$line->{patron}.'"'.$sep;
print join($sep, map {$_->{count}} @$x);
print "\n";
}
# footer
print "TOTAL";
$cols = @$results[0]->{loopfooter};
print join($sep, map {$_->{totalcol}} @$cols);
print join($sep, map {$_->{total}} @$cols);
print $sep.@$results[0]->{total};
}
exit;
@ -148,7 +150,7 @@ sub calculate {
my $colorder;
if ($column){
$column = "old_issues." .$column if (($column=~/branchcode/) or ($column=~/timestamp/));
$column = "biblioitems.".$column if $column=~/itemtype/;
$column = "items.itype" if $column=~/itemtype/;
$column = "borrowers." .$column if $column=~/categorycode/;
my @colfilter ;
if ($column =~ /timestamp/) {
@ -245,7 +247,7 @@ sub calculate {
'old_issues.returndate >',
'old_issues.returndate <',
'old_issues.branchcode like',
'biblioitems.itemtype like',
'items.itype like',
'borrowers.categorycode like',
);
foreach ((@$filters)[0..9]) {
@ -309,24 +311,28 @@ sub calculate {
foreach my $id (@ranked_ids) {
my @loopcell;
foreach my $key (@cols_in_order) {
if($column){
push @loopcell, {
value => $patrons{$id}->{name},
reference => $id,
count => $patrons{$id}->{allcols}->{$key},
};
}else{
push @loopcell, {
value => $patrons{$id}->{name},
reference => $id,
count => $patrons{$id}->{total},
};
}
if($column){
# Total
push @loopcell, {
count => $patrons{$id}->{total},
};
foreach my $key (@cols_in_order) {
push @loopcell, {
count => $patrons{$id}->{allcols}->{$key},
};
$grantotal += $patrons{$id}->{allcols}->{$key};
}
}else{
push @loopcell, {
count => $patrons{$id}->{total},
};
$grantotal += $patrons{$id}->{total};
}
push @looprow,{ 'rowtitle' => $i++ ,
'loopcell' => \@loopcell,
'hilighted' => ($i%2),
'patron' => $patrons{$id}->{name},
'reference' => $id,
};
# use a limit, if a limit is defined
last if $i > $limit and $limit
@ -336,7 +342,7 @@ sub calculate {
$globalline{loopfilter}=\@loopfilter;
# the core of the table
$globalline{looprow} = \@looprow;
$globalline{loopcol} = [ map {{coltitle=>$_}} @cols_in_order ];
$globalline{loopcol} = [ map {{coltitle=>$_}} @cols_in_order ] if ($column);
# the foot (totals by borrower type)
$globalline{loopfooter} = [];
$globalline{total}= $grantotal; # FIXME: useless