Bug 8127: Fix filters use in 'Most-circulated items report'

Filters are broken for many reasons. Previous patch contains some
(little) tidying.
There are 3 parts in this patch:
1 - The column name is incorrectly named in the dropdown for "branch",
  it is added in this patch
2 - There is a definition for 'Day' and 'Month', but not for 'Week', it
is also added in this patch
3 - Dbh variables are passed in the string definition AND in the call. I
removed them from the string definition since it violates the coding
guidelines.

Test plan:

1. On an fresh ktd db, run the script provided here (https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=8127#c3)  to fill the database with checkins/checkouts:

Visit http://your_koha:8081/cgi-bin/koha/reports/cat_issues_top.pl
2. Run a baseline test with following params:
Checkout date from 01/01/2020
Checkout date to: tomorrow
Library: Any library
Fill nothing else

Notice it is works

3. Test with some limits (Library, Week, and any other), notice you encounter errors on Library and Week, and that any other is empty, without error.

4. Apply patch
5. Rerun 2-3 and notice you now have results. Check with each possible limit, limiting to 5. Test once with 10 as a limit.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Baptiste Wojtkowski 2026-05-20 14:48:00 +00:00 committed by Lucas Gass
parent 0f40b53044
commit 2b78fd1de0
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 12 additions and 7 deletions

View File

@ -178,7 +178,7 @@
><label for="criteria">By: </label
><select name="Criteria" id="criteria">
<option value="" selected="selected">None</option>
<option value="branch">Library</option>
<option value="branchcode">Library</option>
<option value="categorycode">Categorycode</option>
<option value="itemtype">Itemtype</option>
<option value="Day">Day</option>

View File

@ -218,7 +218,6 @@ sub calculate {
$colfilter[0] = @$filters[10] if ( $column =~ /issuedate/ );
$colfilter[0] = @$filters[11] if ( $column =~ /issuedate/ );
# loop cols.
if ( $column eq "Day" ) {
@ -226,6 +225,12 @@ sub calculate {
$column = "old_issues.issuedate";
$colfield .= "dayname($column)";
$colorder .= "weekday($column)";
} elsif ( $column eq "Week" ) {
#Display by Week
$column = "old_issues.issuedate";
$colfield .= "week($column)";
$colorder .= "week($column)";
} elsif ( $column eq "Month" ) {
#Display by Month
@ -252,15 +257,15 @@ sub calculate {
WHERE 1";
if ( ( $column =~ /issuedate/ ) or ( $column =~ /returndate/ ) ) {
if ( $colfilter[1] and ( $colfilter[0] ) ) {
$strsth2 .= " and $column between '$colfilter[0]' and '$colfilter[1]' ";
$strsth2 .= " and $column between ? and ? ";
} elsif ( $colfilter[1] ) {
$strsth2 .= " and $column < '$colfilter[1]' ";
$strsth2 .= " and $column < ? ";
} elsif ( $colfilter[0] ) {
$strsth2 .= " and $column > '$colfilter[0]' ";
$strsth2 .= " and $column > ? ";
}
} elsif ( $colfilter[0] ) {
$colfilter[0] =~ s/\*/%/g;
$strsth2 .= " and $column LIKE '$colfilter[0]' ";
$strsth2 .= " and $column LIKE ? ";
}
$strsth2 .= " group by $colfield";
$strsth2 .= " order by $colorder";
@ -354,7 +359,7 @@ sub calculate {
$dbcalc->execute;
my %indice;
while ( my @data = $dbcalc->fetchrow ) {
my ( $row, $rank, $id, $callnum, $ccode, $loc, $col ) = @data;
my ( $row, $rank, $id, $col ) = @data;
$col = "zzEMPTY" if ( !defined($col) );
$indice{$col} = 1 if ( not( $indice{$col} ) );
$table[ $indice{$col} ]->{$col}->{'name'} = $row;