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 %] <div class="panel panel-default"> <div class="panel-heading">[% b.surname %], [% b.firstname %]</div> <div class="panel-body">Expiration: [% b.dateexpiry %]</div> <div class="panel-footer">ID: [% b.borrowernumber %]</div> </div> [% 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 <samalau@gmail.com> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
This commit is contained in:
parent
1d58ebfee3
commit
94cee66ec7
4 changed files with 41 additions and 1 deletions
|
@ -63,6 +63,23 @@
|
|||
<i class="fa fa-play"></i> Run report
|
||||
</a>
|
||||
</div>
|
||||
[% IF templates.count %]
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
|
||||
aria-expanded="false">
|
||||
<i class="fa fa-code"></i> Run with template <span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
[% FOREACH t IN templates %]
|
||||
<li>
|
||||
<a id="runreport" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | html %]&phase=Run%20this%20report&template=[% t.id | html %][% PROCESS params %]">
|
||||
[% t.name | html %]
|
||||
</a>
|
||||
</li>
|
||||
[% END %]
|
||||
</ul>
|
||||
</div>
|
||||
[% END %]
|
||||
<div class="btn-group">
|
||||
<a class="btn btn-default" href="/cgi-bin/koha/tools/scheduler.pl?id=[% id | html %]">
|
||||
<i class="fa-solid fa-clock"></i> Schedule
|
||||
|
|
|
@ -903,7 +903,9 @@
|
|||
</form>
|
||||
[% END # /IF ( enter_params ) %]
|
||||
|
||||
[% IF ( execute ) %]
|
||||
[% IF processed_notice %]
|
||||
[% processed_notice | $raw %]
|
||||
[% ELSIF ( execute ) %]
|
||||
<h1>[% name | html %] <span class="report_heading_id"><span class="report_label">Report ID:</span> <span class="report_number">[% id | html %]</span></span></h1>
|
||||
<div class="page-section">
|
||||
[% IF ( notes ) %]
|
||||
|
|
|
@ -172,6 +172,7 @@
|
|||
<li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&module=serial">Serials (new issue)</a></li>
|
||||
<li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&module=suggestions">Suggestions</a></li>
|
||||
<li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&module=pos">Point of sale</a></li>
|
||||
<li><a href="/cgi-bin/koha/tools/letter.pl?op=add_form&module=report">Report</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div> <!-- /#toolbar -->
|
||||
|
@ -230,6 +231,7 @@
|
|||
[% CASE 'serial' %]<span>Serials (new issue)</span>
|
||||
[% CASE 'suggestions' %]<span>Suggestions</span>
|
||||
[% CASE 'pos' %]<span>Point of sale</span>
|
||||
[% CASE 'report' %]<span>Report</span>
|
||||
[% CASE %]<span>[% lette.module | html %]</span>
|
||||
[% END %]
|
||||
</td>
|
||||
|
@ -411,6 +413,11 @@
|
|||
[% ELSE %]
|
||||
<option value="pos">Point of sale</option>
|
||||
[% END %]
|
||||
[% IF ( module == "report" ) %]
|
||||
<option value="report" selected="selected">Report</option>
|
||||
[% ELSE %]
|
||||
<option value="report">Report</option>
|
||||
[% END %]
|
||||
</select>
|
||||
</li>
|
||||
<li>
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue