Bug 23389: Add 'All' option to report dropdowns
authorNick Clemens <nick@bywatersolutions.com>
Tue, 30 Jul 2019 15:20:27 +0000 (15:20 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 7 Oct 2019 13:09:10 +0000 (14:09 +0100)
This patch optionally adds an 'all' option to report dropdowns

Note you will need to use 'LIKE' instead of '=' to allow 'All' to work

To test:
 1 - Write a report:
     SELECT branchname FROM branches WHERE branchcode LIKE <<Branch|branches>>
 2 - Run it
 3 - Select a branch
 4 - You get one branch info
 5 - Note you cannot select all
 6 - Apply patch
 7 - Run report
 8 - No change
 9 - Update report like:
     SELECT branchname FROM branches WHERE branchcode LIKE <<Branch|branches:all>>
10 - Run report
11 - Select 'All'
12 - You get all branches
13 - Select one branch
14 - You get one branch
15 - Test with other authorised categories (itemtypes, YES_NO, etc.)
16 - Confirm it works as expected
17 - Prove -v t/db_dependent/Reports/Guided.t

Signed-off-by: Lisette Scheer <lisetteslatah@gmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

C4/Reports/Guided.pm
koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt
reports/guided_reports.pl
t/db_dependent/Reports/Guided.t

index 6f77f5d..705984d 100644 (file)
@@ -919,6 +919,7 @@ sub GetParametersFromSQL {
 
     for ( my $i = 0; $i < ($#split/2) ; $i++ ) {
         my ($name,$authval) = split(/\|/,$split[$i*2+1]);
+        $authval =~ s/\:all$// if $authval;
         push @sql_parameters, { 'name' => $name, 'authval' => $authval };
     }
 
index de04098..5ae50b6 100644 (file)
@@ -701,6 +701,7 @@ canned reports and writing custom SQL reports.</p>
                 [% ELSE %]
                     <li><label for="sql_params_[% sql_param.labelid | html %]">[% sql_param.entry | html %]:</label>
                         <select name="[%- sql_param.input.name | html -%]" tabindex="1"  size="1" id="[%- sql_param.input.id | html -%]">
+                        [% IF (sql_param.include_all) %]<option value="%">All</option>[% END %]
                         [% FOREACH value IN sql_param.input.values %]
                             <option value="[%- value | html -%]">[%- sql_param.input.labels.$value | html -%]</option>
                         [% END %]
index aad0418..9204c5a 100755 (executable)
@@ -719,11 +719,12 @@ elsif ($phase eq 'Run this report'){
             my @authval_errors;
             my %uniq_params;
             for(my $i=0;$i<($#split/2);$i++) {
-                my ($text,$authorised_value) = split /\|/,$split[$i*2+1];
-                my $sep = $authorised_value ? "|" : "";
-                if( defined $uniq_params{$text.$sep.$authorised_value} ){
+                my ($text,$authorised_value_all) = split /\|/,$split[$i*2+1];
+                my $sep = $authorised_value_all ? "|" : "";
+                if( defined $uniq_params{$text.$sep.$authorised_value_all} ){
                     next;
-                } else { $uniq_params{$text.$sep.$authorised_value} = "$i"; }
+                } else { $uniq_params{$text.$sep.$authorised_value_all} = "$i"; }
+                my ($authorised_value, $all) = split /:/, $authorised_value_all;
                 my $input;
                 my $labelid;
                 if ( not defined $authorised_value ) {
@@ -815,7 +816,7 @@ elsif ($phase eq 'Run this report'){
                     };
                 }
 
-                push @tmpl_parameters, {'entry' => $text, 'input' => $input, 'labelid' => $labelid, 'name' => $text.$sep.$authorised_value };
+                push @tmpl_parameters, {'entry' => $text, 'input' => $input, 'labelid' => $labelid, 'name' => $text.$sep.$authorised_value_all, 'include_all' => $all };
             }
             $template->param('sql'         => $sql,
                             'name'         => $name,
index e0aacfd..5a8b6fa 100644 (file)
@@ -146,13 +146,15 @@ subtest 'GetParametersFromSQL+ValidateSQLParameters' => sub  {
         FROM old_issues
         WHERE YEAR(timestamp) = <<Year|custom_list>> AND
               branchcode = <<Branch|branches>> AND
-              borrowernumber = <<Borrower>>
+              borrowernumber = <<Borrower>> AND
+              itemtype = <<Item type|itemtypes:all>>
     ";
 
     my @test_parameters_with_custom_list = (
         { 'name' => 'Year', 'authval' => 'custom_list' },
         { 'name' => 'Branch', 'authval' => 'branches' },
-        { 'name' => 'Borrower', 'authval' => undef }
+        { 'name' => 'Borrower', 'authval' => undef },
+        { 'name' => 'Item type', 'authval' => 'itemtypes' }
     );
 
     is_deeply( GetParametersFromSQL($test_query_1), \@test_parameters_with_custom_list,