From 94cee66ec7de1ab76f14be70e98afed05f230460 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 27 Jun 2023 12:44:18 -0400 Subject: [PATCH] Bug 34136: Add ability to render a report using a notice template Sometimes it is useful to display the results of a report in a non-table format. We should be able to create notice templates to render reports. Test Plan: 1) Apply this patch 2) Restart all the things! 3) Create a new notice template using the new "Report" option from the "New notice" pulldown. 4) In the "Print" area, paste the following template: [% FOREACH b IN data %]
[% b.surname %], [% b.firstname %]
Expiration: [% b.dateexpiry %]
[% END %] 5) Create a report with the query: SELECT * FROM borrowers 6) Once the report is saved, use the new "Run with template" option to select the template you just created. 7) Note that instead of the results being a paged table, you instead see the results rendered as cards! Signed-off-by: Sam Lau Signed-off-by: Katrin Fischer --- .../prog/en/includes/reports-toolbar.inc | 17 +++++++++++++++++ .../en/modules/reports/guided_reports_start.tt | 4 +++- .../prog/en/modules/tools/letter.tt | 7 +++++++ reports/guided_reports.pl | 14 ++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc index ba5b9d3d92..de76725e8c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc @@ -63,6 +63,23 @@ Run report + [% IF templates.count %] +
+ + +
+ [% END %] @@ -230,6 +231,7 @@ [% CASE 'serial' %]Serials (new issue) [% CASE 'suggestions' %]Suggestions [% CASE 'pos' %]Point of sale + [% CASE 'report' %]Report [% CASE %][% lette.module | html %] [% END %] @@ -411,6 +413,11 @@ [% ELSE %] [% END %] + [% IF ( module == "report" ) %] + + [% ELSE %] + + [% END %]
  • diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl index 46792bf88c..e8c8941d46 100755 --- a/reports/guided_reports.pl +++ b/reports/guided_reports.pl @@ -37,6 +37,8 @@ use Koha::Libraries; use Koha::Patron::Categories; use Koha::SharedContent; use Koha::Util::OpenDocument qw( generate_ods ); +use Koha::Notice::Templates; +use Koha::TemplateUtils qw( process_tt ); use C4::ClassSource qw( GetClassSources ); =head1 NAME @@ -79,6 +81,8 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( my $session_id = $input->cookie('CGISESSID'); my $session = $session_id ? get_session($session_id) : undef; +$template->param( templates => Koha::Notice::Templates->search({ module => 'report' }) ); + my $filter; if ( $input->param("filter_set") or $input->param('clear_filters') ) { $filter = {}; @@ -671,6 +675,7 @@ elsif ($phase eq 'Run this report'){ my $report_id = $input->param('reports'); my @sql_params = $input->multi_param('sql_params'); my @param_names = $input->multi_param('param_name'); + my $template_id = $input->param('template'); my $want_full_chart = $input->param('want_full_chart') || 0; # offset algorithm @@ -872,6 +877,15 @@ elsif ($phase eq 'Run this report'){ $url = join('&sql_params=', $url, map { URI::Escape::uri_escape_utf8($_) } @sql_params); } + if ($template_id) { + my $notice_template = Koha::Notice::Templates->find($template_id); + my ( $sth2, $errors2 ) = execute_query( { sql => $sql, report_id => $report_id } ); + my $data = $sth2->fetchall_arrayref( {} ); + my $notice_rendered = + process_tt( $notice_template->content, { data => $data, report_id => $report_id } ); + $template->param( processed_notice => $notice_rendered ); + } + $template->param( 'results' => \@rows, 'allresults' => \@allrows, -- 2.39.5