Bug 38621: Use GetPreparedLetter for report templates
Previously, report templates were rendered using process_tt directly.
This made the available variables inconsistent with other notices and
slips. This patch switches to rendering report templates through the
same function as other notices. To match the arguments to this system,
this patch also makes the report system reference templates by their
code rather than ID.
Test plan:
1. Under Tools > Notices and Slips, create a new notice in the Reports
module. Choose a code and a name, and under Email assign a subject
and the following body:
[% today %]
[% FOREACH d IN data %]
[% d.title %]
[% END %]
2. Under Reports, create a new report from SQL with a name and the
following query:
SELECT * FROM biblio LIMIT 1
3. Create another report from SQL with a different name and the
following query, specifying a runtime parameter:
SELECT * FROM biblio WHERE 'a'=<<Param>> LIMIT 1
4. On the first report, select "Run with template" and choose the
template created earlier.
5. Verify that the report runs successfully, and the output does not
include the current date.
6. On the second report, select "Run with template" and choose the
template created earlier. Choose "a" as the runtime parameter value
when asked.
7. Verify that the report runs successfully, and the output does not
include the current date.
8. Apply patch.
9. On the first report, select "Run with template" and choose the
template created earlier.
10. Verify that the report runs successfully, and the output now
includes the current date along with the fetched data.
11. Under the Download dropdown, select "Rendered template (...)".
12. Verify the downloaded file matches the report output.
13. On the second report, select "Run with template" and choose the
template created earlier. Choose "a" as the runtime parameter value
when asked.
14. Verify that the report runs successfully, and the output now
includes the current date along with the fetched data.
15. Under the Download dropdown, select "Rendered template (...)".
16. Verify the downloaded file matches the report output.
Sponsored-by: Open Fifth
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
parent
d77897c203
commit
cbbfa8c8d2
|
|
@ -71,7 +71,7 @@
|
|||
<ul class="dropdown-menu">
|
||||
[% FOREACH tmpl IN templates %]
|
||||
<li>
|
||||
<a class="dropdown-item" id="runreport_[% tmpl.id | html %]" href="/cgi-bin/koha/reports/guided_reports.pl?id=[% id | html %]&op=run&template=[% tmpl.id | html %][% PROCESS params %]">
|
||||
<a class="dropdown-item" id="runreport_[% tmpl.id | html %]" href="/cgi-bin/koha/reports/guided_reports.pl?id=[% id | html %]&op=run&template_code=[% tmpl.code | html %][% PROCESS params %]">
|
||||
[% tmpl.name | html %]
|
||||
</a>
|
||||
</li>
|
||||
|
|
@ -145,7 +145,7 @@
|
|||
><a
|
||||
class="dropdown-item"
|
||||
id="template"
|
||||
href="/cgi-bin/koha/reports/guided_reports.pl?op=export&format=template&id=[% id | html %]&template=[% template_id | html %]&reportname=[% name |uri %][% PROCESS params %]"
|
||||
href="/cgi-bin/koha/reports/guided_reports.pl?op=export&format=template&id=[% id | html %]&template_code=[% template_code | html %]&reportname=[% name |uri %][% PROCESS params %]"
|
||||
>Rendered template ([% processed_notice_title | html %])</a
|
||||
></li
|
||||
>
|
||||
|
|
|
|||
|
|
@ -975,8 +975,8 @@
|
|||
<!-- /.rows -->
|
||||
<fieldset class="action">
|
||||
<input type="hidden" name="op" value="run" />
|
||||
[% IF ( template_id ) %]
|
||||
<input type="hidden" name="template" value="[% template_id | html %]" />
|
||||
[% IF ( template_code ) %]
|
||||
<input type="hidden" name="template_code" value="[% template_code | html %]" />
|
||||
[% END %]
|
||||
[% INCLUDE 'throttled-button.inc' element_type='button' classes='btn btn-primary' label=t('Run the report') %]
|
||||
</fieldset>
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ use Koha::Notice::Templates;
|
|||
use Koha::TemplateUtils qw( process_tt );
|
||||
use C4::ClassSource qw( GetClassSources );
|
||||
use C4::Scrubber;
|
||||
use C4::Letters qw( GetPreparedLetter );
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -748,24 +749,16 @@ if ( !$op ) {
|
|||
print $_ while <$ods_fh>;
|
||||
unlink $ods_filepath;
|
||||
} elsif ( $format eq 'template' ) {
|
||||
my $template_id = $input->param('template');
|
||||
my $notice_template = Koha::Notice::Templates->find($template_id);
|
||||
my $data = $sth->fetchall_arrayref( {} );
|
||||
$content = process_tt(
|
||||
$notice_template->content,
|
||||
{
|
||||
data => $data,
|
||||
report_id => $report_id,
|
||||
for_download => 1,
|
||||
}
|
||||
);
|
||||
$reportfilename = process_tt(
|
||||
$notice_template->title,
|
||||
{
|
||||
data => $data,
|
||||
report_id => $report_id,
|
||||
}
|
||||
my $template_code = $input->param('template_code');
|
||||
my $data = $sth->fetchall_arrayref( {} );
|
||||
|
||||
my $rendered = GetPreparedLetter(
|
||||
module => 'report',
|
||||
letter_code => $template_code,
|
||||
objects => { data => $data, report_id => $report_id, for_download => 1 }
|
||||
);
|
||||
$content = $rendered->{content};
|
||||
$reportfilename = $rendered->{title};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -832,7 +825,7 @@ if ( $op eq 'run' ) {
|
|||
my $report_id = $input->param('id');
|
||||
my @sql_params = $input->multi_param('sql_params');
|
||||
my @param_names = $input->multi_param('param_name');
|
||||
my $template_id = $input->param('template');
|
||||
my $template_code = $input->param('template_code');
|
||||
my $want_full_chart = $input->param('want_full_chart') || 0;
|
||||
|
||||
# offset algorithm
|
||||
|
|
@ -1018,7 +1011,7 @@ if ( $op eq 'run' ) {
|
|||
'auth_val_errors' => \@authval_errors,
|
||||
'enter_params' => 1,
|
||||
'id' => $report_id,
|
||||
'template_id' => $template_id,
|
||||
'template_code' => $template_code,
|
||||
);
|
||||
} else {
|
||||
my ( $sql, $header_types );
|
||||
|
|
@ -1085,18 +1078,20 @@ if ( $op eq 'run' ) {
|
|||
$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);
|
||||
if ($template_code) {
|
||||
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 } );
|
||||
my $title_rendered =
|
||||
process_tt( $notice_template->title, { data => $data, report_id => $report_id } );
|
||||
|
||||
my $rendered = GetPreparedLetter(
|
||||
module => 'report',
|
||||
letter_code => $template_code,
|
||||
objects => { data => $data, report_id => $report_id }
|
||||
);
|
||||
|
||||
$template->param(
|
||||
template_id => $template_id,
|
||||
processed_notice => $notice_rendered,
|
||||
processed_notice_title => $title_rendered,
|
||||
template_code => $template_code,
|
||||
processed_notice => $rendered->{content},
|
||||
processed_notice_title => $rendered->{title},
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue