Bugzilla – Attachment 119351 Details for
Bug 26734
Convert accounts (monetary) notices to use GetPreparedLetter
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26734: Convert printfeercpt/printinvoice to use GetPreparedLetter
Bug-26734-Convert-printfeercptprintinvoice-to-use-.patch (text/plain), 12.56 KB, created by
Martin Renvoize (ashimema)
on 2021-04-09 08:25:52 UTC
(
hide
)
Description:
Bug 26734: Convert printfeercpt/printinvoice to use GetPreparedLetter
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-04-09 08:25:52 UTC
Size:
12.56 KB
patch
obsolete
>From e78f981dfc4c1fdf4198e0209d3ce415cb270a39 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 14 Oct 2020 11:58:26 +0100 >Subject: [PATCH] Bug 26734: Convert printfeercpt/printinvoice to use > GetPreparedLetter > >This patch updates C4::Letters to allow use of existing koha template >includes from notices, then updates the printfeercpt and printinvoice >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. > >Test plan >1/ Update the ACCOUNT_CREDIT and ACCOUNT_DEBIT notices to use >'accounts.inc' include for account descriptions >1a/ Add `[% PROCESS 'accounts.inc' %]` to the top of the notice >1b/ Replace manual account descriptions with `[% PROCESS >account_type_description account=credit %]` >2/ Print one of each slip and check that descriptions are properly >substituted >3/ Clone the notice to another language >4/ Print the in the other language and note the translated descriptions >are properly substituted. >5/ Signoff > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > C4/Letters.pm | 30 ++++++++++++++++- > C4/Templates.pm | 7 +++- > .../prog/en/modules/members/printfeercpt.tt | 21 ++++++++---- > .../prog/en/modules/members/printinvoice.tt | 22 +++++++++---- > members/printfeercpt.pl | 33 ++++++++++++------- > members/printinvoice.pl | 31 ++++++++++------- > 6 files changed, 108 insertions(+), 36 deletions(-) > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index 28b90fded0..50c62918fb 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; >@@ -627,13 +628,13 @@ sub GetPreparedLetter { > my %params = @_; > > my $letter = $params{letter}; >+ my $lang = $params{lang} || 'default'; > > unless ( $letter ) { > my $module = $params{module} or croak "No module"; > my $letter_code = $params{letter_code} or croak "No letter_code"; > my $branchcode = $params{branchcode} || ''; > my $mtt = $params{message_transport_type} || 'email'; >- my $lang = $params{lang} || 'default'; > > $letter = getletter( $module, $letter_code, $branchcode, $mtt, $lang ); > >@@ -728,6 +729,7 @@ sub GetPreparedLetter { > tables => $tables, > loops => $loops, > substitute => $substitute, >+ lang => $lang > } > ); > >@@ -784,8 +786,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" : >@@ -1524,6 +1529,16 @@ sub _process_tt { > my $tables = $params->{tables}; > my $loops = $params->{loops}; > my $substitute = $params->{substitute} || {}; >+ my $lang = defined($params->{lang}) && $params->{lang} ne 'default' ? $params->{lang} : 'en'; >+ my ($theme, $activethemes); >+ >+ my $htdocs = C4::Context->config('intrahtdocs'); >+ ($theme, $lang, $activethemes)= C4::Templates::activethemes( $htdocs, 'about.tt', 'intranet', $lang); >+ 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( >@@ -1533,6 +1548,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', > } >@@ -1592,6 +1608,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/C4/Templates.pm b/C4/Templates.pm >index bad3275959..2aeedf662e 100644 >--- a/C4/Templates.pm >+++ b/C4/Templates.pm >@@ -268,6 +268,12 @@ sub themelanguage { > # Select a language based on cookie, syspref available languages & browser > my $lang = C4::Languages::getlanguage($query); > >+ return activethemes($htdocs, $tmpl, $interface, $lang); >+} >+ >+sub activethemes { >+ my ($htdocs, $tmpl, $interface, $lang) = @_; >+ > # Get theme > my @themes; > my $theme_syspref = ($interface eq 'intranet') ? 'template' : 'opacthemes'; >@@ -303,7 +309,6 @@ sub themelanguage { > } > } > >- > sub setlanguagecookie { > my ( $query, $language, $uri ) = @_; > >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' %] > <title>Print receipt for [% patron.cardnumber | html %]</title> > [% INCLUDE 'doc-head-close.inc' %] >+ >+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> >+<link rel="shortcut icon" href="[% IF ( IntranetFavicon ) %][% IntranetFavicon | url %][% ELSE %][% interface | html %]/[% theme | html %]/img/favicon.ico[% END %]" type="image/x-icon" /> >+ > [% Asset.css("css/printreceiptinvoice.css") | $raw %] > [% INCLUDE 'blocking_errors.inc' %] > </head> >@@ -18,7 +17,17 @@ > <body id="pat_printfeercpt" class="pat"> > > <div id="receipt"> >- [% letter.content | $raw | evaltt %] >+ [% IF slip %] >+ [% IF plain %] >+ <pre> >+ [% slip | html %] >+ </pre> >+ [% ELSE %] >+ [% slip | $raw %] >+ [% END %] >+ [% ELSE %] >+ No print template found >+ [% END %] > </div> > > [% MACRO jsinclude BLOCK %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/printinvoice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/printinvoice.tt >index 00ee536cea..0362452c25 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/printinvoice.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/printinvoice.tt >@@ -1,23 +1,33 @@ > [% USE raw %] > [% USE Asset %] > [% USE Koha %] >-[% USE Branches %] >-[% USE KohaDates %] >-[% USE Price %] > [% SET footerjs = 1 %] > >-[% PROCESS 'accounts.inc' %] >- > [% INCLUDE 'doc-head-open.inc' %] > <title>Print receipt for [% patron.cardnumber | html %]</title> > [% INCLUDE 'doc-head-close.inc' %] >+ >+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> >+<link rel="shortcut icon" href="[% IF ( IntranetFavicon ) %][% IntranetFavicon | url %][% ELSE %][% interface | html %]/[% theme | html %]/img/favicon.ico[% END %]" type="image/x-icon" /> >+ > [% Asset.css("css/printreceiptinvoice.css") | $raw %] >+[% INCLUDE 'blocking_errors.inc' %] > </head> > > <body id="printinvoice" class="pat"> > > <div id="receipt"> >- [% letter.content | $raw | evaltt %] >+ [% IF slip %] >+ [% IF plain %] >+ <pre> >+ [% slip | html %] >+ </pre> >+ [% ELSE %] >+ [% slip | $raw %] >+ [% END %] >+ [% ELSE %] >+ No print template found >+ [% END %] > </div> > > [% MACRO jsinclude BLOCK %] >diff --git a/members/printfeercpt.pl b/members/printfeercpt.pl >index 0dd60f3de2..2e3dff7b51 100755 >--- a/members/printfeercpt.pl >+++ b/members/printfeercpt.pl >@@ -30,10 +30,10 @@ my $input = CGI->new; > > my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > { >- template_name => "members/printfeercpt.tt", >- query => $input, >- type => "intranet", >- flagsrequired => { >+ template_name => "members/printfeercpt.tt", >+ query => $input, >+ type => "intranet", >+ flagsrequired => { > borrowers => 'edit_borrowers', > updatecharges => 'remaining_permissions' > } >@@ -55,15 +55,26 @@ 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, >+ borrowers => $patron->borrowernumber >+ }, >+ 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}, >+ patron => $patron, > ); > > output_html_with_http_headers $input, $cookie, $template->output; >diff --git a/members/printinvoice.pl b/members/printinvoice.pl >index 4c41461bfa..97b7f58f17 100755 >--- a/members/printinvoice.pl >+++ b/members/printinvoice.pl >@@ -30,10 +30,10 @@ my $input = CGI->new; > > my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > { >- template_name => "members/printinvoice.tt", >- query => $input, >- type => "intranet", >- flagsrequired => { >+ template_name => "members/printinvoice.tt", >+ query => $input, >+ type => "intranet", >+ flagsrequired => { > borrowers => 'edit_borrowers', > updatecharges => 'remaining_permissions' > } >@@ -41,8 +41,8 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > ); > > my $debit_id = $input->param('accountlines_id'); >-my $debit = Koha::Account::Lines->find($debit_id); >-my $patron = $debit->patron; >+my $debit = Koha::Account::Lines->find($debit_id); >+my $patron = $debit->patron; > > my $logged_in_user = Koha::Patrons->find($loggedinuser) or die "Not logged in"; > output_and_exit_if_error( >@@ -55,13 +55,22 @@ output_and_exit_if_error( > } > ); > >-my $letter = C4::Letters::getletter( 'circulation', 'ACCOUNT_DEBIT', >- C4::Context::mybranch, 'print', $patron->lang ); >+my $letter = C4::Letters::GetPreparedLetter( >+ module => 'circulation', >+ letter_code => 'ACCOUNT_DEBIT', >+ branchcode => C4::Context::mybranch, >+ message_transport_type => 'print', >+ lang => $patron->lang, >+ tables => { >+ debits => $debit_id, >+ borrowers => $patron->borrowernumber >+ } >+); > > $template->param( >- letter => $letter, >- debit => $debit >- >+ slip => $letter->{content}, >+ plain => !$letter->{is_html}, >+ patron => $patron, > ); > > output_html_with_http_headers $input, $cookie, $template->output; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 26734
:
111976
|
111977
|
111978
|
112023
|
112024
|
112025
|
112026
|
116257
|
116259
|
116260
|
116261
|
116262
|
116263
|
116272
|
116275
|
116276
|
116277
|
116278
|
116279
|
116644
|
116645
|
116646
|
116647
|
116648
|
116655
|
116656
|
116657
|
116658
|
116659
|
116663
|
116664
|
116665
|
116666
|
116667
|
117261
|
117262
|
117263
|
117264
|
117265
|
118191
|
118192
|
118193
|
118194
|
118195
|
118196
|
118197
|
118200
|
118482
|
118483
|
118484
|
118485
|
118486
|
118487
|
118488
|
118489
|
119350
| 119351 |
119352
|
119353
|
119354
|
119355
|
119356
|
119357
|
119358
|
119642
|
120077
|
121446
|
121449