From 61f0e97b13d6d5769598a492d7b4c6017a8a5795 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! --- .../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 | 13 +++++++++++++ 4 files changed, 40 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 16c9e3fb28..4edbe0de61 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 %]
Schedule diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt index ecb9480af4..a7ab647398 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt @@ -887,7 +887,9 @@ [% END # /IF ( enter_params ) %] - [% IF ( execute ) %] + [% IF processed_notice %] + [% processed_notice | $raw %] + [% ELSIF ( execute ) %]

[% name | html %] Report ID: [% id | html %]

@@ -215,6 +216,7 @@ [% CASE 'serial' %]Serials (new issue) [% CASE 'suggestions' %]Suggestions [% CASE 'pos' %]Point of sale + [% CASE 'report' %]Report [% CASE %][% lette.module | html %] [% END %] @@ -391,6 +393,11 @@ [% ELSE %] [% END %] + [% IF ( module == "report" ) %] + + [% ELSE %] + + [% END %]
  • diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl index 46792bf88c..66d92ce7f2 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,14 @@ 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.1