From ed311e319c61231601c0b27cff584c70d1c31396 Mon Sep 17 00:00:00 2001 From: Michael Hafen Date: Thu, 11 Apr 2024 16:33:39 -0600 Subject: [PATCH] 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 0 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 --- .../prog/en/modules/reports/bor_issues_top.tt | 15 +++--- reports/bor_issues_top.pl | 50 +++++++++++-------- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/bor_issues_top.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/bor_issues_top.tt index c867cc5b35..f79f801912 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/bor_issues_top.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/bor_issues_top.tt @@ -86,13 +86,14 @@ + + [% FOREACH loopco IN mainloo.loopcol %] - + [% END %] [% FOREACH loopco IN mainloo.loopcol %] - [% END %] @@ -100,13 +101,13 @@ [% IF ( loopro.hilighted ) %] + [% IF ( loopro.hilighted ) %] [% FOREACH loopcel IN loopro.loopcell %] [% IF ( loopcel.hilighted ) %] - [% IF ( loopcel.hilighted ) %] [% END %] diff --git a/reports/bor_issues_top.pl b/reports/bor_issues_top.pl index 439db23810..617b3c9703 100755 --- a/reports/bor_issues_top.pl +++ b/reports/bor_issues_top.pl @@ -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 -- 2.39.2
RankPatronTotal[% loopco.coltitle | html %][% loopco.coltitle | html %]
Patron Checkout count
[% ELSE %][% END %] [% loopro.rowtitle | html %][% ELSE %][% END %] + [% IF ( loopro.reference ) %][% END %] + [% IF ( loopro.patron ) %][% loopro.patron | html %][% END %] + [% IF ( loopro.reference ) %][% END %] + [% ELSE %][% END %] - [% IF ( loopcel.reference ) %][% END %] - [% IF ( loopcel.value ) %][% loopcel.value | html %][% END %] - [% IF ( loopcel.reference ) %][% END %] - [% ELSE %][% END %] [% IF ( loopcel.count ) %][% loopcel.count | html %][% END %]