invoice watermarks, #24665
authorMark Wells <mark@freeside.biz>
Mon, 22 Jun 2015 20:26:02 +0000 (13:26 -0700)
committerMark Wells <mark@freeside.biz>
Thu, 25 Jun 2015 20:18:50 +0000 (13:18 -0700)
FS/FS/Conf.pm
FS/FS/Schema.pm
FS/FS/Template_Mixin.pm
FS/FS/invoice_conf.pm
conf/invoice_html
conf/invoice_latex
httemplate/edit/invoice_conf.html

index d211361..ddbdc29 100644 (file)
@@ -679,10 +679,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
 );
@@ -1379,6 +1381,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 <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:2.1:Documentation:Administration#Typeset_.28LaTeX.29_invoice_templates">billing documentation</a> for details.',
@@ -1566,6 +1577,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.',
index bab179f..fc6d301 100644 (file)
@@ -4724,6 +4724,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',
index 44d44e1..0d7c1f1 100644 (file)
@@ -818,35 +818,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',
@@ -860,6 +861,8 @@ sub print_generic {
       die $error;
     }
 
+    # fill in variables
+
     $invoice_data{$include} = $inc_tt->fill_in( HASH => \%invoice_data );
 
     $invoice_data{$include} =~ s/\n+$//
index da448b8..d88c89a 100644 (file)
@@ -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')
   ;
index 06ee775..7cadd7c 100644 (file)
@@ -1,6 +1,18 @@
 <STYLE TYPE="text/css">
-.invoice { font-family: sans-serif; font-size: 10pt }
-.invoice_header { font-size: 10pt }
+.invoice {
+  font-family: sans-serif;
+  font-size: 10pt;
+  display: inline-block;
+  padding: 4pt;
+  border: 1px solid black;
+  background-color: white;
+  min-width: 625px;
+  position: relative;
+}
+.invoice_header {
+  font-size: 10pt;
+  border-spacing: 4pt;
+}
 .invoice_headerright TH { border-top: 2px solid #000000; border-bottom: 2px solid #000000 }
 .invoice_headerright TD { font-size: 10pt; empty-cells: show }
 .invoice_summary TH { border-bottom: 2px solid #000000 }
 .invoice_extdesc TD { font-size: 8pt }
 .invoice_totaldesc TD { font-size: 10pt; empty-cells: show }
 .allcaps { text-transform:uppercase; font-size: 12pt }
+.watermark-box {
+  z-index: 10;
+  position: absolute;
+  text-align: center;
+  padding: 0;
+  filter: alpha(opacity=25);
+  opacity: 0.25;
+  width: 100%;
+  height: 100%;
+  display: table;
+}
+.watermark-content {
+  display: table-cell;
+  vertical-align: middle;
+  font-size: 96pt;
+}
 </STYLE>
 
-<table class="invoice" bgcolor="#ffffff" WIDTH=625 CELLSPACING=8 STYLE="border:1px solid #000000"><tr><td>
+<div class="invoice">
+
+  <DIV CLASS="watermark-box"><DIV CLASS="watermark-content">
+      <%= $watermark %>
+  </DIV></DIV>
 
   <table class="invoice_header" width="100%">
     <tr>
   <hr NOSHADE SIZE=2 COLOR="#000000">
   <p align="center" <%= $smallerfooter ? 'STYLE="font-size:75%;"' : '' %>><%= $footer %>
 
-</td></tr></table>
+</div>
index 40ec703..c7c696b 100644 (file)
 \usepackage{graphicx}                  % required for logo graphic\r
 \usepackage[utf8]{inputenc}             % multilanguage support\r
 \usepackage[T1]{fontenc}\r
+[@-- if ( length($watermark) ) {\r
+  $OUT .= '\r
+\usepackage{background}\r
+\backgroundsetup{\r
+  placement=center,\r
+  opacity=0.25,\r
+  color=black,\r
+  angle=0,\r
+  contents=' . $watermark . '\r
+}';\r
+}\r
+'';\r
+--@]\r
 \r
 \addtolength{\voffset}{-0.0cm}         % top margin to top of header\r
 \addtolength{\hoffset}{-0.6cm}         % left margin on page\r
index 7122653..861114b 100644 (file)
@@ -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
   ) ),
 
 );