From 284969e522df66d0876cfac38b361c6bb924788b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 14 Oct 2020 11:58:26 +0100 Subject: [PATCH] Bug 24381: Convert printfeercpt to use GetPreparedLetter This patch updates C4::Letters to allow use of existing koha template includes from notices, then updates the printfeercpt slip print option to use GetPreparedLetter rather than calling getletter directly. As part of this work, we also add credits and debits handling to the _parseletter_sth and _get_tt_params routines in C4::Letters to allow for recognisable variable names in the notice template. --- C4/Letters.pm | 25 +++++++++++++++++++ .../prog/en/modules/members/printfeercpt.tt | 21 +++++++++++----- members/printfeercpt.pl | 21 ++++++++++------ 3 files changed, 54 insertions(+), 13 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 2bae52d346..b4303f4e39 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -31,6 +31,7 @@ use Try::Tiny; use C4::Members; use C4::Log; use C4::SMS; +use C4::Templates; use C4::Debug; use Koha::DateUtils; use Koha::SMS::Providers; @@ -751,8 +752,11 @@ sub _parseletter_sth { # broke things for the rest of us. prepare_cached is a better # way to cache statement handles anyway. my $query = + ($table eq 'accountlines' ) ? "SELECT * FROM $table WHERE accountlines_id = ?" : ($table eq 'biblio' ) ? "SELECT * FROM $table WHERE biblionumber = ?" : ($table eq 'biblioitems' ) ? "SELECT * FROM $table WHERE biblionumber = ?" : + ($table eq 'credits' ) ? "SELECT * FROM accountlines WHERE accountlines_id = ?" : + ($table eq 'debits' ) ? "SELECT * FROM accountlines WHERE accountlines_id = ?" : ($table eq 'items' ) ? "SELECT * FROM $table WHERE itemnumber = ?" : ($table eq 'issues' ) ? "SELECT * FROM $table WHERE itemnumber = ?" : ($table eq 'old_issues' ) ? "SELECT * FROM $table WHERE itemnumber = ? ORDER BY timestamp DESC LIMIT 1" : @@ -1487,6 +1491,14 @@ sub _process_tt { my $loops = $params->{loops}; my $substitute = $params->{substitute} || {}; + my $htdocs = C4::Context->config('intrahtdocs'); + my ($theme, $lang, $activethemes)= C4::Templates::themelanguage( $htdocs, 'about.tt', 'intranet'); + my @includes; + foreach (@$activethemes) { + push @includes, "$htdocs/$_/$lang/includes"; + push @includes, "$htdocs/$_/en/includes" unless $lang eq 'en'; + } + my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE}; my $template = Template->new( { @@ -1495,6 +1507,7 @@ sub _process_tt { PLUGIN_BASE => 'Koha::Template::Plugin', COMPILE_EXT => $use_template_cache ? '.ttc' : '', COMPILE_DIR => $use_template_cache ? C4::Context->config('template_cache_dir') : '', + INCLUDE_PATH => \@includes, FILTERS => {}, ENCODING => 'UTF-8', } @@ -1548,6 +1561,18 @@ sub _get_tt_params { plural => 'branches', pk => 'branchcode', }, + credits => { + module => 'Koha::Account::Lines', + singular => 'credit', + plural => 'credits', + pk => 'accountlines_id', + }, + debits => { + module => 'Koha::Account::Lines', + singular => 'debit', + plural => 'debits', + pk => 'accountlines_id', + }, items => { module => 'Koha::Items', singular => 'item', diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/printfeercpt.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/printfeercpt.tt index c1de78be6b..6227f8f7b6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/printfeercpt.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/printfeercpt.tt @@ -1,16 +1,15 @@ [% USE raw %] [% USE Asset %] [% USE Koha %] -[% USE KohaDates %] -[% USE Branches %] -[% USE Price %] [% SET footerjs = 1 %] -[% PROCESS 'accounts.inc' %] - [% INCLUDE 'doc-head-open.inc' %] Print receipt for [% patron.cardnumber | html %] [% INCLUDE 'doc-head-close.inc' %] + + + + [% Asset.css("css/printreceiptinvoice.css") | $raw %] [% INCLUDE 'blocking_errors.inc' %] @@ -18,7 +17,17 @@
- [% letter.content | $raw | evaltt %] + [% IF slip %] + [% IF plain %] +
+      [% slip | html %]
+    
+ [% ELSE %] + [% slip | $raw %] + [% END %] + [% ELSE %] + No print template found + [% END %]
[% MACRO jsinclude BLOCK %] diff --git a/members/printfeercpt.pl b/members/printfeercpt.pl index 0dd60f3de2..b414532282 100755 --- a/members/printfeercpt.pl +++ b/members/printfeercpt.pl @@ -55,15 +55,22 @@ output_and_exit_if_error( } ); -my $letter = C4::Letters::getletter( 'circulation', 'ACCOUNT_CREDIT', - C4::Context::mybranch, 'print', $patron->lang ); +my $letter = C4::Letters::GetPreparedLetter( + module => 'circulation', + letter_code => 'ACCOUNT_CREDIT', + branchcode => C4::Context::mybranch, + message_transport_type => 'print', + lang => $patron->lang, + tables => { 'credits' => $credit_id }, + substitute => { + tendered => scalar $input->param('tendered'), + change => scalar $input->param('change') + } +); $template->param( - letter => $letter, - credit => $credit, - - tendered => scalar $input->param('tendered'), - change => scalar $input->param('change') + slip => $letter->{content}, + plain => !$letter->{is_html} ); output_html_with_http_headers $input, $cookie, $template->output; -- 2.20.1