set invoice defaults to support online printing, #33849
[freeside.git] / conf / invoice_latex
1 %% file: Standard Multipage.tex\r
2 %% Purpose: Multipage bill template for e-Bills\r
3 %% \r
4 %% Created by Mark Asplen-Taylor\r
5 %% Asplen Management Ltd\r
6 %% www.asplen.co.uk\r
7 %%\r
8 %% Modified for Freeside by Kristian Hoffman\r
9 %%\r
10 %% Changes\r
11 %%      0.1     4/12/00 Created\r
12 %%      0.2     18/10/01        More fields added\r
13 %%      1.0     16/11/01        RELEASED\r
14 %%      1.2     16/10/02        Invoice number added\r
15 %%      1.3     2/12/02 Logo graphic added\r
16 %%      1.4     7/2/03  Multipage headers/footers added\r
17 %%      n/a     forked for Freeside; checked into CVS\r
18 %%\r
19 \r
20 \documentclass[letterpaper]{article}\r
21 \r
22 \usepackage{fancyhdr,lastpage,ifthen,array,longtable,afterpage,caption,multirow,bigstrut}\r
23 \usepackage{graphicx}                   % required for logo graphic\r
24 \usepackage[utf8]{inputenc}             % multilanguage support\r
25 \usepackage[T1]{fontenc}\r
26 [@-- if ( length($watermark) ) {\r
27   $OUT .= '\r
28 \usepackage{background}\r
29 \backgroundsetup{\r
30   placement=center,\r
31   opacity=0.25,\r
32   color=black,\r
33   angle=0,\r
34   contents=' . $watermark . '\r
35 }';\r
36 }\r
37 '';\r
38 --@]\r
39 \r
40 \addtolength{\voffset}{-0.0cm}          % top margin to top of header\r
41 \addtolength{\hoffset}{-0.6cm}          % left margin on page\r
42 \addtolength{\topmargin}{[@-- defined($topmargin) ? $topmargin : '-1.00cm' --@]}\r
43 \setlength{\headheight}{2.0cm}          % height of header\r
44 \setlength{\headsep}{[@-- defined($headsep) ? $headsep : '1.0cm' --@]}\r
45 \setlength{\footskip}{1.0cm}            % bottom of footer from bottom of text\r
46 \r
47 %\addtolength{\textwidth}{2.1in}        % width of text\r
48 \setlength{\textwidth}{19.5cm}\r
49 \setlength{\textheight}{[@-- defined($textheight) ? $textheight : '19.5cm' --@]}\r
50 \setlength{\oddsidemargin}{-0.9cm}      % odd page left margin\r
51 \setlength{\evensidemargin}{-0.9cm}     % even page left margin\r
52 \r
53 \LTchunksize=40\r
54 \r
55 \renewcommand{\headrulewidth}{0pt}\r
56 \renewcommand{\footrulewidth}{1pt}\r
57 \r
58 \renewcommand{\footrule}{\r
59 [@--\r
60   $coupon ? '\ifthenelse{\equal{\thepage}{1}}' : '';\r
61 --@]\r
62   {\r
63   }\r
64   {\r
65     \vbox to 0pt{\rule{\headwidth}{\footrulewidth}\vss}\r
66   }\r
67 }\r
68 \r
69 \newcommand{\extracouponspace}{[@-- defined($extracouponspace) ? $extracouponspace : '2.7in' --@]}\r
70 \r
71 % Adjust the inset of the mailing address\r
72 \newcommand{\addressinset}[1][]{\hspace{1.0cm}}\r
73 \r
74 % Adjust the inset of the return address and logo\r
75 \newcommand{\returninset}[1][]{\hspace{-0.25cm}}\r
76 \r
77 % New command for address lines i.e. skip them if blank\r
78 \newcommand{\addressline}[1]{\ifthenelse{\equal{#1}{}}{}{#1\\}}\r
79 \r
80 % Inserts dollar symbol\r
81 \newcommand{\dollar}[1][]{\symbol{36}}\r
82 \r
83 % Remove plain style header/footer\r
84 \fancypagestyle{plain}{\r
85   \fancyhead{}\r
86 }\r
87 \fancyhf{}\r
88 \r
89 % Define fancy header/footer for first and subsequent pages\r
90 \fancyfoot[C]{\r
91   \ifthenelse{\equal{\thepage}{1}}\r
92   { % First page\r
93 [@--\r
94   if ($coupon) {\r
95     $OUT .= '\vspace{-\extracouponspace}';\r
96     $OUT .= '\rule[0.5em]{\textwidth}{\footrulewidth}\\\\';\r
97     $OUT .= $coupon;\r
98     $OUT .= '\vspace{'.\r
99       (defined($couponfootsep) ? $couponfootsep : '0.2in') .\r
100       '}';\r
101   }\r
102   '';\r
103 --@] [@-- $smallerfooter ? '\scriptsize{' : '\small{' --@]\r
104 [@-- $footer --@]\r
105     }[@-- $coupon ? '\vspace{\extracouponspace}' : '' --@]\r
106   }\r
107   { % ... pages\r
108     [@-- $smallerfooter ? '\scriptsize{' : '\small{' --@]\r
109 [@-- $smallfooter --@]\r
110     }\r
111   }\r
112 }\r
113 \r
114 \fancyfoot[R]{\r
115   \ifthenelse{\equal{\thepage}{1}}\r
116   { % First page\r
117   }\r
118   { % ... pages\r
119     \small{\thepage\ of \pageref{LastPage}}\r
120   }\r
121 }\r
122 \r
123 \fancyhead[L]{\r
124   \ifthenelse{\equal{\thepage}{1}}\r
125   { % First page\r
126     \returninset\r
127     \makebox{\r
128       \begin{tabular}{ll}\r
129         \begin{minipage}[b]{5.5cm}\r
130 [@-- $returnaddress --@]\r
131         \end{minipage} &\r
132         \includegraphics{[@-- $logo_file --@]}\\\r
133       \end{tabular}\r
134     }\r
135   }\r
136   { % ... pages\r
137     %\includegraphics{[@-- $logo_file --@]}     % Uncomment if you want the logo on all pages.\r
138   }\r
139 }\r
140 \r
141 \fancyhead[R]{\r
142   \ifthenelse{\equal{\thepage}{1}}\r
143   { % First page\r
144     \begin{tabular}{ccc}\r
145     [@-- join(' & ', ( $no_date   ? '' : emt('Invoice date') ),\r
146                      ( $no_number ? '' : emt('Invoice #')    ),\r
147                      emt('Customer #')\r
148              )\r
149     --@]\\\r
150     \vspace{0.2cm}\r
151     \textbf{[@-- $date --@]} & \textbf{[@-- $invnum --@]} & \textbf{[@-- $custnum --@]} \\\hline\r
152     \rule{0pt}{5ex} &~~ \huge{\textsc{[@-- emt($notice_name) --@]}} & \\\r
153     \vspace{-0.2cm}\r
154      & & \\\hline\r
155     \end{tabular}\r
156   }\r
157   { % ... pages\r
158     \small{\r
159       \begin{tabular}{lll}\r
160       [@-- join(' & ', emt('Invoice date'), emt('Invoice #'), emt('Customer #') ) --@]\\\r
161       \textbf{[@-- $date --@]} & \textbf{[@-- $invnum --@]} & \textbf{[@-- $custnum --@]}\\\r
162       \end{tabular}\r
163     }\r
164   }\r
165 }\r
166 \r
167 \pagestyle{fancy}\r
168 \r
169 \r
170 %% Font options are:\r
171 %%      bch     Bitsream Charter\r
172 %%      put     Utopia\r
173 %%      phv     Adobe Helvetica\r
174 %%      pnc     New Century Schoolbook\r
175 %%      ptm     Times\r
176 %%      pcr     Courier\r
177 \r
178 \renewcommand{\familydefault}{phv}\r
179 \r
180 \r
181 % Commands for freeside table header...\r
182 \r
183 \newcommand{\FSdescriptionlength} { [@-- $unitprices ? '8.2cm' : '12.8cm' --@] }\r
184 \newcommand{\FSdescriptioncolumncount} { [@-- $unitprices ? '4' : '6' --@] }\r
185 \newcommand{\FSunitcolumns}{ [@-- \r
186   $unitprices\r
187   ? '\makebox[2.5cm][r]{\textbf{~~' . emt('Unit Price') . '}} &' .\r
188     '\makebox[1.4cm]{\textbf{~' . emt('Quantity') . '}} & ' \r
189   : '' --@] }\r
190 \r
191 \newcommand{\FShead}{\r
192   \hline\r
193   \rule{0pt}{2.5ex}\r
194   \makebox[1.4cm]{} &\r
195   \multicolumn{\FSdescriptioncolumncount}{l}{\makebox[\FSdescriptionlength][l]{\textbf{[@-- emt('Description') --@]}}}&\r
196   \FSunitcolumns\r
197   \makebox[1.6cm][r]{\textbf{[@-- emt('Amount') --@]}} \\\r
198   \hline\r
199 }\r
200 \r
201 \newcommand{\FSusagehead}{\r
202   \hline\r
203   \rule{0pt}{2.5ex}\r
204   \makebox[1.4cm]{} &\r
205   \multicolumn{4}{l}{\r
206     \makebox[\FSdescriptionlength][l]{\textbf{[@-- emt('Description') --@]}}\r
207   } &\r
208   \textbf{~~[@-- emt('Calls') --@]} &\r
209   \textbf{~~[@-- emt('Duration') --@]} &\r
210   \textbf{~~[@-- emt('Amount') --@]} \\\r
211   \hline\r
212 }\r
213 \r
214 % ...description...\r
215 \newcommand{\FSdesc}[5]{\r
216   \multicolumn{1}{c}{\rule{0pt}{2.5ex}\textbf{#1}} &\r
217   \multicolumn{[@-- $unitprices ? '4' : '6' --@]}{l}{\textbf{#2}} &\r
218 [@-- $unitprices ? '  \multicolumn{1}{r}{\textbf{#3}} &'."\n".\r
219                    '  \multicolumn{1}{r}{\textbf{#4}} &'."\n"\r
220                  : ''\r
221 --@]\r
222   \multicolumn{1}{r}{\textbf{#5}}\\\r
223 }\r
224 % ...extended description...\r
225 \newcommand{\FSextdesc}[1]{\r
226   \multicolumn{1}{l}{\rule{0pt}{1.0ex}} &\r
227 %%  \multicolumn{2}{l}{\small{~-~#1}}\\\r
228 #1\\\r
229 }\r
230 % ...and total line items.\r
231 \newcommand{\FStotaldesc}[2]{\r
232   & \multicolumn{6}{l}{#1} & #2\\\r
233 }\r
234 \r
235 % ...usage class summary\r
236 \newcommand{\FSusagedesc}[4]{\r
237   \multicolumn{1}{c}{\rule{0pt}{2.5ex}} &\r
238   \multicolumn{4}{l}{\textbf{#1}} &\r
239   \multicolumn{1}{r}{\textbf{#2}} &\r
240   \multicolumn{1}{r}{\textbf{#3}} &\r
241   \multicolumn{1}{r}{\textbf{#4}}\r
242   \\\r
243 }\r
244 \r
245 \begin{document}\r
246 %       Headers and footers defined for the first page\r
247 \addressinset \rule{0.5cm}{0cm} \r
248 \makebox{\r
249 \begin{minipage}[t]{7.0cm}\r
250 \vspace{[@-- defined($addresssep) ? $addresssep : '0.25cm' --@]}\r
251 \textbf{[@-- $payname --@]}\\\r
252 \addressline{[@-- $company --@]}\r
253 \addressline{[@-- $address1 --@]}\r
254 \addressline{[@-- $address2 --@]}\r
255 \addressline{[@-- $city --@], [@-- $state --@]~~[@-- $zip --@]}\r
256 \addressline{[@-- $country --@]}\r
257 \end{minipage}}\r
258 \hfill\r
259 \makebox{\r
260 \begin{minipage}[t]{6.4cm}\r
261 [@--\r
262   if ($ship_enable) {\r
263     $OUT .= '\textbf{' . emt('Service Address') . '}\\\\';\r
264     $OUT .= "\\addressline{$ship_company}";\r
265     $OUT .= "\\addressline{$ship_address1}";\r
266     $OUT .= "\\addressline{$ship_address2}";\r
267     $OUT .= "\\addressline{$ship_city, $ship_state~~$ship_zip}";\r
268     $OUT .= "\\addressline{$ship_country}";\r
269     $OUT .= '~\\\\';\r
270   }else{\r
271     $OUT .= '';\r
272   }\r
273 --@]\r
274 \begin{flushright}\r
275 [@-- $terms ? emt('Terms') .": $terms" : '' --@]\\\r
276 [@-- $po_line --@]\\\r
277 \end{flushright}\r
278 \end{minipage}}\r
279 \vspace{1.5cm}\r
280 %\r
281 [@-- $summary --@]\r
282 %\r
283 \section*{}\r
284 [@--\r
285   foreach my $section ( grep { !$summary || $_->{description} ne $finance_section } @sections ) {\r
286     if ($section->{'pretotal'} && !$summary) {\r
287       $OUT .= '\begin{flushright}';\r
288       $OUT .= '\large\textsc{'. $section->{'pretotal'}. '}\\\\';\r
289       $OUT .= '\\end{flushright}';\r
290     }\r
291     $OUT .= '\pagebreak' if $section->{'post_total'};\r
292     unless ($section->{'summarized'} ) {\r
293       $OUT .= '\captionsetup{singlelinecheck=false,justification=raggedright,font={Large,sc,bf}}';\r
294       $OUT .= '\ifthenelse{\equal{\thepage}{1}}{\setlength{\LTextracouponspace}{\extracouponspace}}{\setlength{\LTextracouponspace}{0pt}}'\r
295         if $coupon;\r
296       $OUT .= '\begin{longtable}{cllllllr}';\r
297       $OUT .= '\caption*{ ';\r
298       if ($section->{'location'}) {\r
299         $OUT .= $section->{'location'}{'label_prefix'}. ': '\r
300           if length($section->{'location'}{'label_prefix'});\r
301         $OUT .= $section->{'location'}{'address1'};\r
302         $OUT .= ', ' . $section->{'location'}{'address2'}\r
303           if length($section->{'location'}{'address2'});\r
304         $OUT .= ', ' .\r
305                 $section->{'location'}{'city'} . ', ' .\r
306                 $section->{'location'}{'state'} . '~' .\r
307                 $section->{'location'}{'zip'};\r
308       } elsif ( $section->{'description'} ) {\r
309         $OUT .= ($section->{'description'});\r
310       } else {\r
311         $OUT .= emt('Charges');\r
312       }\r
313       $OUT .= '}\\\\';\r
314       if ($section->{header_generator}) {\r
315         $OUT .= &{$section->{header_generator}}();\r
316       } elsif ( $section->{usage_section} ) {\r
317         $OUT .= '\FSusagehead';\r
318       } else {\r
319         $OUT .= '\FShead';\r
320       }\r
321       $OUT .= '\endfirsthead';\r
322       $OUT .= '\multicolumn{7}{r}{\rule{0pt}{2.5ex}'.emt('Continued from previous page').'}\\\\';\r
323       if ($section->{header_generator}) {\r
324         $OUT .= &{$section->{header_generator}}();\r
325       } elsif ( $section->{usage_section} ) {\r
326         $OUT .= '\FSusagehead';\r
327       } else {\r
328         $OUT .= '\FShead';\r
329       }\r
330       $OUT .= '\endhead';\r
331       $OUT .= '\multicolumn{7}{r}{\rule{0pt}{2.5ex}'.emt('Continued on next page...').'}\\\\';\r
332       $OUT .= '\endfoot';\r
333       $OUT .= '\hline';\r
334 \r
335       if (scalar(@sections) > 1 and !$section->{no_subtotal}) {\r
336         if ($section->{total_generator}) {\r
337           $OUT .= &{$section->{total_generator}}($section);\r
338         } else {\r
339           $OUT .= '\FStotaldesc{' . $section->{'description'} . ' Total}' .\r
340                   '{' . $section->{'subtotal'} . '}' . "\n";\r
341         }\r
342       }\r
343 \r
344       #if ($section == $sections[$#sections]) {\r
345         foreach my $line (grep {$_->{section}->{description} eq $section->{description}} @total_items) {\r
346           if ($section->{total_line_generator}) {\r
347             $OUT .= &{$section->{total_line_generator}}($line);\r
348           } else {\r
349             $OUT .= '\FStotaldesc{' . $line->{'total_item'} . '}' .\r
350                     '{' . $line->{'total_amount'} . '}' . "\n";\r
351           }\r
352         }\r
353       #}\r
354 \r
355       $OUT .= '\hline';\r
356       $OUT .= '\endlastfoot';\r
357 \r
358       my $lastref = 0;\r
359       foreach my $line (\r
360         grep { ( scalar( @sections ) > 1 \r
361                ? $section->{'description'} eq $_->{'section'}->{'description'}\r
362                : 1\r
363              ) }\r
364         @detail_items )\r
365       {\r
366         my $ext_description = $line->{'ext_description'};\r
367   \r
368         # Don't break-up small packages.\r
369         my $rowbreak = @$ext_description < 5 ? '*' : '';\r
370   \r
371         $OUT .= "\\hline\n" if (($line->{'ref'} || 0) ne $lastref);\r
372         if ($section->{description_generator}) {\r
373           $OUT .= &{$section->{description_generator}}($line);\r
374         } elsif ($section->{usage_section}) {\r
375           my $minutes = sprintf('%d', $line->{'duration'} / 60);\r
376           my $seconds = $line->{'duration'} % 60;\r
377           $OUT .= '\FSusagedesc\r
378             {' . $line->{'description'} . '}\r
379             {' . $line->{'quantity'} . '}\r
380             {' . $minutes . 'm ' . $seconds . 's' . '}\r
381             {' . $line->{'amount'} . '}';\r
382         } else {\r
383           $OUT .= '\FSdesc'.\r
384                   '{}'.\r
385                   '{' . $line->{'description'} . '}' ;\r
386           if ( $unitprices and length($line->{'unit_amount'}) ) {\r
387             # then show the unit amount and quantity\r
388             $OUT .= \r
389                 '{\\dollar' . $line->{'unit_amount'} . '}'.\r
390                 '{'         . $line->{'quantity'}    . '}';\r
391           } else {\r
392             # leave those columns blank\r
393             $OUT .= '{}{}';\r
394           }\r
395           $OUT .= '{\\dollar' . $line->{'amount'} . "}${rowbreak}\n";\r
396         }\r
397         $lastref = $line->{'ref'} || 0;\r
398 \r
399         foreach my $ext_desc (@$ext_description) {\r
400           if ($section->{extended_description_generator}) {\r
401             $OUT .= &{$section->{extended_description_generator}}($ext_desc);\r
402           } else {\r
403             if ( $ext_desc !~ /[^\\]&/ ) {\r
404               $ext_desc = substr($ext_desc, 0, 80) . '...'\r
405                 if (length($ext_desc) > 80);\r
406               $ext_desc = '\multicolumn{6}{l}{\small{~~~'. $ext_desc. '}}';\r
407             }else{\r
408               $ext_desc = "~~~$ext_desc";\r
409             }\r
410             $OUT .= '\FSextdesc{' . $ext_desc . '}' . "${rowbreak}\n";\r
411           }\r
412         }\r
413 \r
414       }\r
415 \r
416       $OUT .= '\end{longtable}';\r
417     }\r
418     if ($section->{'posttotal'}) {\r
419       $OUT .= '\begin{flushright}';\r
420       $OUT .= '\normalfont\large\bfseries\textsc{'. $section->{'posttotal'}. '}\\\\';\r
421       $OUT .= '\\end{flushright}';\r
422     }\r
423   }\r
424 \r
425 --@]\r
426 \vfill\r
427 \begin{minipage}[t]{\textwidth}\r
428   [@-- length($summary)\r
429          ? ''\r
430         : ( $smallernotes\r
431               ? '\scriptsize{ '.$notes.' }'\r
432               : $notes\r
433           )\r
434   --@]\r
435   [@-- $coupon ? '\ifthenelse{\equal{\thepage}{1}}{\rule{0pt}{\extracouponspace}}{}' : '' --@]\r
436 \end{minipage}\r
437 \end{document}\r