From 11ca9a51a76837f1821b2b0e8972c78bf221c6a1 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Mon, 22 Jun 2015 13:14:33 -0700 Subject: [PATCH] invoice watermarks, #24665 --- FS/FS/Conf.pm | 20 ++++++++++++++++++++ FS/FS/Schema.pm | 2 ++ FS/FS/Template_Mixin.pm | 39 ++++++++++++++++++++------------------ FS/FS/invoice_conf.pm | 6 ++++++ conf/invoice_html | 40 +++++++++++++++++++++++++++++++++++---- conf/invoice_latex | 13 +++++++++++++ httemplate/edit/invoice_conf.html | 5 +++++ 7 files changed, 103 insertions(+), 22 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 9255284a3..191a712a8 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -605,10 +605,12 @@ invoice_latexfooter invoice_latexsmallfooter invoice_latexnotes invoice_latexcoupon +invoice_latexwatermark invoice_html invoice_htmlreturnaddress invoice_htmlfooter invoice_htmlnotes +invoice_htmlwatermark logo.png logo.eps ); @@ -1304,6 +1306,15 @@ sub reason_type_options { }, { + 'key' => 'invoicehtmlwatermark', + 'section' => 'invoicing', + 'description' => 'Watermark for HTML invoices. Appears in a semitransparent positioned DIV overlaid on the main invoice container.', + 'type' => 'textarea', + 'per_agent' => 1, + 'per_locale' => 1, + }, + + { 'key' => 'invoice_latex', 'section' => 'invoicing', 'description' => 'Optional LaTeX template for typeset PostScript invoices. See the billing documentation for details.', @@ -1491,6 +1502,15 @@ and customer address. Include units.', }, { + 'key' => 'invoicelatexwatermark', + 'section' => 'invoicing', + 'description' => 'Watermark for LaTeX invoices. See "texdoc background" for information on what this can contain. The content itself should be enclosed in braces, optionally followed by a comma and any formatting options.', + 'type' => 'textarea', + 'per_agent' => 1, + 'per_locale' => 1, + }, + + { 'key' => 'invoice_email_pdf', 'section' => 'invoicing', 'description' => 'Send PDF invoice as an attachment to emailed invoices. By default, includes the HTML invoice as the email body, unless invoice_email_pdf_note is set.', diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 70d7c5afb..0bdc99539 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -6914,6 +6914,8 @@ sub tables_hashref { 'latexsmallfooter', 'text', 'NULL', '', '', '', 'latexreturnaddress', 'text', 'NULL', '', '', '', 'with_latexcoupon', 'char', 'NULL', '1', '', '', + 'htmlwatermark', 'text', 'NULL', '', '', '', + 'latexwatermark', 'text', 'NULL', '', '', '', 'lpr', 'varchar', 'NULL', $char_d, '', '', ], 'primary_key' => 'confnum', diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm index 32e300776..37dcf2a5e 100644 --- a/FS/FS/Template_Mixin.pm +++ b/FS/FS/Template_Mixin.pm @@ -817,35 +817,36 @@ sub print_generic { my @include = ( [ $tc, 'notes' ], [ 'invoice_', 'footer' ], [ 'invoice_', 'smallfooter', ], + [ 'invoice_', 'watermark' ], ); push @include, [ $tc, 'coupon', ] unless $params{'no_coupon'}; foreach my $i (@include) { + # load the configuration for this sub-template + my($base, $include) = @$i; my $inc_file = $conf->key_orbase("$base$format$include", $template); - my @inc_src; - - if ( $conf->exists($inc_file, $agentnum) - && length( $conf->config($inc_file, $agentnum) ) ) { - - @inc_src = $conf->config($inc_file, $agentnum); - - } else { - - $inc_file = $conf->key_orbase("${base}latex$include", $template); - - my $convert_map = $convert_maps{$format}{$include}; - @inc_src = map { s/\[\@--/$delimiters{$format}[0]/g; - s/--\@\]/$delimiters{$format}[1]/g; - $_; - } - &$convert_map( $conf->config($inc_file, $agentnum) ); + my @inc_src = $conf->config($inc_file, $agentnum); + if (!@inc_src) { + my $converter = $convert_maps{$format}{$include}; + if ( $converter ) { + # then attempt to convert LaTeX to the requested format + $inc_file = $conf->key_orbase($base.'latex'.$include, $template); + @inc_src = &$converter( $conf->config($inc_file, $agentnum) ); + foreach (@inc_src) { + # this isn't included in the convert_maps + my ($open, $close) = @{ $delimiters{$format} }; + s/\[\@--/$open/g; + s/--\@\]/$close/g; + } + } + } # else @inc_src is empty and that's fine - } + # make a Text::Template out of it my $inc_tt = new Text::Template ( TYPE => 'ARRAY', @@ -859,6 +860,8 @@ sub print_generic { die $error; } + # fill in variables + $invoice_data{$include} = $inc_tt->fill_in( HASH => \%invoice_data ); $invoice_data{$include} =~ s/\n+$// diff --git a/FS/FS/invoice_conf.pm b/FS/FS/invoice_conf.pm index da448b816..d88c89a7c 100644 --- a/FS/FS/invoice_conf.pm +++ b/FS/FS/invoice_conf.pm @@ -49,6 +49,8 @@ and supports the FS::Conf interface. The following fields are supported: =item htmlreturnaddress - return address (HTML) +=item htmlwatermark - watermark to show in background (HTML) + =item latexnotes - "notes" section (LaTeX) =item latexfooter - footer (LaTeX) @@ -59,6 +61,8 @@ and supports the FS::Conf interface. The following fields are supported: =item latexsmallfooter - footer for pages after the first (LaTeX) +=item latexwatermark - watermark to show in background (LaTeX) + =item with_latexcoupon - 'Y' to print the payment coupon (LaTeX) =item lpr - command to print the invoice (passed on stdin as a PDF) @@ -185,11 +189,13 @@ sub check { || $self->ut_anything('htmlfooter') || $self->ut_anything('htmlsummary') || $self->ut_anything('htmlreturnaddress') + || $self->ut_anything('htmlwatermark') || $self->ut_anything('latexnotes') || $self->ut_anything('latexfooter') || $self->ut_anything('latexsummary') || $self->ut_anything('latexsmallfooter') || $self->ut_anything('latexreturnaddress') + || $self->ut_anything('latexwatermark') # flags || $self->ut_flag('with_latexcoupon') ; diff --git a/conf/invoice_html b/conf/invoice_html index 06ee77588..7cadd7c37 100644 --- a/conf/invoice_html +++ b/conf/invoice_html @@ -1,6 +1,18 @@ -
+
+ +
+ <%= $watermark %> +
@@ -279,4 +311,4 @@

><%= $footer %> -

+
diff --git a/conf/invoice_latex b/conf/invoice_latex index 40ec70313..c7c696b5d 100644 --- a/conf/invoice_latex +++ b/conf/invoice_latex @@ -23,6 +23,19 @@ \usepackage{graphicx} % required for logo graphic \usepackage[utf8]{inputenc} % multilanguage support \usepackage[T1]{fontenc} +[@-- if ( length($watermark) ) { + $OUT .= ' +\usepackage{background} +\backgroundsetup{ + placement=center, + opacity=0.25, + color=black, + angle=0, + contents=' . $watermark . ' +}'; +} +''; +--@] \addtolength{\voffset}{-0.0cm} % top margin to top of header \addtolength{\hoffset}{-0.6cm} % left margin on page diff --git a/httemplate/edit/invoice_conf.html b/httemplate/edit/invoice_conf.html index 7122653f2..861114b1c 100644 --- a/httemplate/edit/invoice_conf.html +++ b/httemplate/edit/invoice_conf.html @@ -49,6 +49,7 @@ my @fields = ( 'Footer', 'Summary header', 'Return address', + 'Watermark', 'Small footer', 'Enable coupon', ), @@ -59,6 +60,7 @@ my @fields = ( { field => 'latexfooter', %textarea }, { field => 'latexsummary', %textarea }, { field => 'latexreturnaddress', %textarea }, + { field => 'latexwatermark', %textarea }, { field => 'latexsmallfooter', %textarea }, { field => 'with_latexcoupon', type => 'checkbox', value => 'Y' }, @@ -68,6 +70,7 @@ my @fields = ( { field => 'htmlfooter', %textarea }, { field => 'htmlsummary', %textarea }, { field => 'htmlreturnaddress', %textarea }, + { field => 'htmlwatermark', %textarea }, # logo { type => 'columnend' }, @@ -87,12 +90,14 @@ my %labels = ( latexfooter latexsummary latexreturnaddress + latexwatermark with_latexcoupon latexsmallfooter htmlnotes htmlfooter htmlsummary htmlreturnaddress + htmlwatermark ) ), ); -- 2.11.0