fix double "$", #37122
[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.25cm' --@]}\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 : '3.6cm' --@]}\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{'. $couponfootsep. '}' if defined($couponfootsep);\r
99   }\r
100   '';\r
101 --@] [@-- $smallerfooter ? '\scriptsize{' : '\small{' --@]\r
102 [@-- $footer --@]\r
103     }[@-- $coupon ? '\vspace{\extracouponspace}' : '' --@]\r
104   }\r
105   { % ... pages\r
106     [@-- $smallerfooter ? '\scriptsize{' : '\small{' --@]\r
107 [@-- $smallfooter --@]\r
108     }\r
109   }\r
110 }\r
111 \r
112 \fancyfoot[R]{\r
113   \ifthenelse{\equal{\thepage}{1}}\r
114   { % First page\r
115   }\r
116   { % ... pages\r
117     \small{\thepage\ of \pageref{LastPage}}\r
118   }\r
119 }\r
120 \r
121 \fancyhead[L]{\r
122   \ifthenelse{\equal{\thepage}{1}}\r
123   { % First page\r
124     \returninset\r
125     \makebox{\r
126       \begin{tabular}{ll}\r
127         \includegraphics{[@-- $logo_file --@]} & [@-- $verticalreturnaddress ? '\\\\' : '' --@]\r
128         \begin{minipage}[b]{5.5cm}\r
129 [@-- $returnaddress --@]\r
130         \end{minipage}\\\r
131       \end{tabular}\r
132     }\r
133   }\r
134   { % ... pages\r
135     %\includegraphics{[@-- $logo_file --@]}     % Uncomment if you want the logo on all pages.\r
136   }\r
137 }\r
138 \r
139 \fancyhead[R]{\r
140   \ifthenelse{\equal{\thepage}{1}}\r
141   { % First page\r
142     \begin{tabular}{ccc}\r
143     [@-- join(' & ', ( $no_date   ? '' : emt('Invoice date') ),\r
144                      ( $no_number ? '' : emt('Invoice #')    ),\r
145                      emt('Customer #')\r
146              )\r
147     --@]\\\r
148     \vspace{0.2cm}\r
149     \textbf{[@-- $date --@]} & \textbf{[@-- $invnum --@]} & \textbf{[@-- $custnum --@]} \\\hline\r
150     \rule{0pt}{5ex} &~~ \huge{\textsc{[@-- emt($notice_name) --@]}} & \\\r
151     \vspace{-0.2cm}\r
152      & & \\\hline\r
153     \end{tabular}\r
154   }\r
155   { % ... pages\r
156     \small{\r
157       \begin{tabular}{lll}\r
158       [@-- join(' & ', emt('Invoice date'), emt('Invoice #'), emt('Customer #') ) --@]\\\r
159       \textbf{[@-- $date --@]} & \textbf{[@-- $invnum --@]} & \textbf{[@-- $custnum --@]}\\\r
160       \end{tabular}\r
161     }\r
162   }\r
163 }\r
164 \r
165 \pagestyle{fancy}\r
166 \r
167 \r
168 %% Font options are:\r
169 %%      bch     Bitsream Charter\r
170 %%      put     Utopia\r
171 %%      phv     Adobe Helvetica\r
172 %%      pnc     New Century Schoolbook\r
173 %%      ptm     Times\r
174 %%      pcr     Courier\r
175 \r
176 \renewcommand{\familydefault}{phv}\r
177 \r
178 \r
179 % Commands for freeside table header...\r
180 \r
181 \newcommand{\FSdescriptionlength} { [@-- $unitprices ? '8.2cm' : '12.8cm' --@] }\r
182 \newcommand{\FSdescriptioncolumncount} { [@-- $unitprices ? '4' : '6' --@] }\r
183 \newcommand{\FSunitcolumns}{ [@-- \r
184   $unitprices\r
185   ? '\makebox[2.5cm][r]{\textbf{~~' . emt('Unit Price') . '}} &' .\r
186     '\makebox[1.4cm]{\textbf{~' . emt('Quantity') . '}} & ' \r
187   : '' --@] }\r
188 \r
189 \newcommand{\FShead}{\r
190   \hline\r
191   \rule{0pt}{2.5ex}\r
192   \makebox[1.4cm]{} &\r
193   \multicolumn{\FSdescriptioncolumncount}{l}{\makebox[\FSdescriptionlength][l]{\textbf{[@-- emt('Description') --@]}}}&\r
194   \FSunitcolumns\r
195   \makebox[1.6cm][r]{\textbf{[@-- emt('Amount') --@]}} \\\r
196   \hline\r
197 }\r
198 \r
199 \newcommand{\FSusagehead}{\r
200   \hline\r
201   \rule{0pt}{2.5ex}\r
202   \makebox[1.4cm]{} &\r
203   \multicolumn{4}{l}{\r
204     \makebox[\FSdescriptionlength][l]{\textbf{[@-- emt('Description') --@]}}\r
205   } &\r
206   \textbf{~~[@-- emt('Calls') --@]} &\r
207   \textbf{~~[@-- emt('Duration') --@]} &\r
208   \textbf{~~[@-- emt('Amount') --@]} \\\r
209   \hline\r
210 }\r
211 \r
212 }% ...description...\r
213 \newcommand{\FSdesc}[5]{\r
214   \multicolumn{1}{c}{\rule{0pt}{2.5ex}\textbf{#1}} &\r
215   \multicolumn{[@-- $unitprices ? '4' : '6' --@]}{l}{\textbf{#2}} &\r
216 [@-- $unitprices ? '  \multicolumn{1}{r}{\textbf{#3}} &'."\n".\r
217                    '  \multicolumn{1}{r}{\textbf{#4}} &'."\n"\r
218                  : ''\r
219 --@]\r
220   \multicolumn{1}{r}{\textbf{#5}}\\\r
221 }\r
222 % ...extended description...\r
223 \newcommand{\FSextdesc}[1]{\r
224   \multicolumn{1}{l}{\rule{0pt}{1.0ex}} &\r
225 %%  \multicolumn{2}{l}{\small{~-~#1}}\\\r
226 #1\\\r
227 }\r
228 % ...and total line items.\r
229 \newcommand{\FStotaldesc}[2]{\r
230   & \multicolumn{6}{l}{#1} & #2\\\r
231 }\r
232 \r
233 % ...usage class summary\r
234 \newcommand{\FSusagedesc}[4]{\r
235   \multicolumn{1}{c}{\rule{0pt}{2.5ex}} &\r
236   \multicolumn{4}{l}{\textbf{#1}} &\r
237   \multicolumn{1}{r}{\textbf{#2}} &\r
238   \multicolumn{1}{r}{\textbf{#3}} &\r
239   \multicolumn{1}{r}{\textbf{#4}}\r
240   \\\r
241 }\r
242 \r
243 \begin{document}\r
244 %       Headers and footers defined for the first page\r
245 \addressinset \rule{0.5cm}{0cm} \r
246 \makebox{\r
247 \begin{minipage}[t]{7.0cm}\r
248 \vspace{[@-- defined($addresssep) ? $addresssep : '0.25cm' --@]}\r
249 \textbf{[@-- $payname --@]}\\\r
250 \addressline{[@-- $company --@]}\r
251 \addressline{[@-- $address1 --@]}\r
252 \addressline{[@-- $address2 --@]}\r
253 \addressline{[@-- $city --@], [@-- $state --@]~~[@-- $zip --@]}\r
254 \addressline{[@-- $country --@]}\r
255 \end{minipage}}\r
256 \hfill\r
257 \makebox{\r
258 \begin{minipage}[t]{6.4cm}\r
259 [@--\r
260   if ($ship_enable) {\r
261     $OUT .= '\textbf{' . emt('Service Address') . '}\\\\';\r
262     $OUT .= "\\addressline{$ship_company}";\r
263     $OUT .= "\\addressline{$ship_address1}";\r
264     $OUT .= "\\addressline{$ship_address2}";\r
265     $OUT .= "\\addressline{$ship_city, $ship_state~~$ship_zip}";\r
266     $OUT .= "\\addressline{$ship_country}";\r
267     $OUT .= '~\\\\';\r
268   }else{\r
269     $OUT .= '';\r
270   }\r
271 --@]\r
272 \begin{flushright}\r
273 [@-- $terms ? emt('Terms') .": $terms" : '' --@]\\\r
274 [@-- $po_line --@]\\\r
275 \end{flushright}\r
276 \end{minipage}}\r
277 \vspace{1.5cm}\r
278 %\r
279 [@-- $summary --@]\r
280 %\r
281 \section*{}\r
282 [@--\r
283   foreach my $section ( grep { !$summary || $_->{description} ne $finance_section } @sections ) {\r
284     if ($section->{'pretotal'} && !$summary) {\r
285       $OUT .= '\begin{flushright}';\r
286       $OUT .= '\large\textsc{'. $section->{'pretotal'}. '}\\\\';\r
287       $OUT .= '\\end{flushright}';\r
288     }\r
289     $OUT .= '\pagebreak' if $section->{'post_total'};\r
290     unless ($section->{'summarized'} ) {\r
291       $OUT .= '\captionsetup{singlelinecheck=false,justification=raggedright,font={Large,sc,bf}}';\r
292       $OUT .= '\ifthenelse{\equal{\thepage}{1}}{\setlength{\LTextracouponspace}{\extracouponspace}}{\setlength{\LTextracouponspace}{0pt}}'\r
293         if $coupon;\r
294       $OUT .= '\begin{longtable}{cllllllr}';\r
295       $OUT .= '\caption*{ ';\r
296       if ($section->{'location'}) {\r
297         $OUT .= $section->{'location'}{'label_prefix'}. ': '\r
298           if length($section->{'location'}{'label_prefix'});\r
299         $OUT .= $section->{'location'}{'address1'};\r
300         $OUT .= ', ' . $section->{'location'}{'address2'}\r
301           if length($section->{'location'}{'address2'});\r
302         $OUT .= ', ' .\r
303                 $section->{'location'}{'city'} . ', ' .\r
304                 $section->{'location'}{'state'} . '~' .\r
305                 $section->{'location'}{'zip'};\r
306       } elsif ( $section->{'description'} ) {\r
307         $OUT .= ($section->{'description'});\r
308       } else {\r
309         $OUT .= emt('Charges');\r
310       }\r
311       $OUT .= '}\\\\';\r
312       if ($section->{header_generator}) {\r
313         $OUT .= &{$section->{header_generator}}();\r
314       } elsif ( $section->{usage_section} ) {\r
315         $OUT .= '\FSusagehead';\r
316       } else {\r
317         $OUT .= '\FShead';\r
318       }\r
319       $OUT .= '\endfirsthead';\r
320       $OUT .= '\multicolumn{7}{r}{\rule{0pt}{2.5ex}'.emt('Continued from previous page').'}\\\\';\r
321       if ($section->{header_generator}) {\r
322         $OUT .= &{$section->{header_generator}}();\r
323       } elsif ( $section->{usage_section} ) {\r
324         $OUT .= '\FSusagehead';\r
325       } else {\r
326         $OUT .= '\FShead';\r
327       }\r
328       $OUT .= '\endhead';\r
329       $OUT .= '\multicolumn{7}{r}{\rule{0pt}{2.5ex}'.emt('Continued on next page...').'}\\\\';\r
330       $OUT .= '\endfoot';\r
331       $OUT .= '\hline';\r
332 \r
333       if (scalar(@sections) > 1 and !$section->{no_subtotal}) {\r
334         if ($section->{total_generator}) {\r
335           $OUT .= &{$section->{total_generator}}($section);\r
336         } else {\r
337           $OUT .= '\FStotaldesc{' . $section->{'description'} . ' Total}' .\r
338                   '{' . $section->{'subtotal'} . '}' . "\n";\r
339         }\r
340       }\r
341 \r
342       #if ($section == $sections[$#sections]) {\r
343         foreach my $line (grep {$_->{section}->{description} eq $section->{description}} @total_items) {\r
344           if ($section->{total_line_generator}) {\r
345             $OUT .= &{$section->{total_line_generator}}($line);\r
346           } else {\r
347             $OUT .= '\FStotaldesc{' . $line->{'total_item'} . '}' .\r
348                     '{' . $line->{'total_amount'} . '}' . "\n";\r
349           }\r
350         }\r
351       #}\r
352 \r
353       $OUT .= '\hline';\r
354       $OUT .= '\endlastfoot';\r
355 \r
356       my $lastref = 0;\r
357       foreach my $line (\r
358         grep { ( scalar( @sections ) > 1 \r
359                ? $section->{'description'} eq $_->{'section'}->{'description'}\r
360                : 1\r
361              ) }\r
362         @detail_items )\r
363       {\r
364         my $ext_description = $line->{'ext_description'};\r
365   \r
366         # Don't break-up small packages.\r
367         my $rowbreak = @$ext_description < 5 ? '*' : '';\r
368   \r
369         $OUT .= "\\hline\n" if (($line->{'ref'} || 0) ne $lastref);\r
370         if ($section->{description_generator}) {\r
371           $OUT .= &{$section->{description_generator}}($line);\r
372         } elsif ($section->{usage_section}) {\r
373           my $minutes = sprintf('%d', $line->{'duration'} / 60);\r
374           my $seconds = $line->{'duration'} % 60;\r
375           $OUT .= '\FSusagedesc\r
376             {' . $line->{'description'} . '}\r
377             {' . $line->{'quantity'} . '}\r
378             {' . $minutes . 'm ' . $seconds . 's' . '}\r
379             {' . $line->{'amount'} . '}';\r
380         } else {\r
381           $OUT .= '\FSdesc'.\r
382                   '{}'.\r
383                   '{' . $line->{'description'} . '}' ;\r
384           if ( $unitprices and length($line->{'unit_amount'}) ) {\r
385             # then show the unit amount and quantity\r
386             $OUT .= \r
387                 '{\\dollar' . $line->{'unit_amount'} . '}'.\r
388                 '{'         . $line->{'quantity'}    . '}';\r
389           } else {\r
390             # leave those columns blank\r
391             $OUT .= '{}{}';\r
392           }\r
393           $OUT .= '{\\dollar' . $line->{'amount'} . "}${rowbreak}\n";\r
394         }\r
395         $lastref = $line->{'ref'} || 0;\r
396 \r
397         foreach my $ext_desc (@$ext_description) {\r
398           if ($section->{extended_description_generator}) {\r
399             $OUT .= &{$section->{extended_description_generator}}($ext_desc);\r
400           } else {\r
401             if ( $ext_desc !~ /[^\\]&/ ) {\r
402               $ext_desc = substr($ext_desc, 0, 80) . '...'\r
403                 if (length($ext_desc) > 80);\r
404               $ext_desc = '\multicolumn{6}{l}{\small{~~~'. $ext_desc. '}}';\r
405             }else{\r
406               $ext_desc = "~~~$ext_desc";\r
407             }\r
408             $OUT .= '\FSextdesc{' . $ext_desc . '}' . "${rowbreak}\n";\r
409           }\r
410         }\r
411 \r
412       }\r
413 \r
414       $OUT .= '\end{longtable}';\r
415     }\r
416     if ($section->{'posttotal'}) {\r
417       $OUT .= '\begin{flushright}';\r
418       $OUT .= '\normalfont\large\bfseries\textsc{'. $section->{'posttotal'}. '}\\\\';\r
419       $OUT .= '\\end{flushright}';\r
420     }\r
421   }\r
422 \r
423 --@]\r
424 \vfill\r
425 \begin{minipage}[t]{\textwidth}\r
426   [@-- length($summary)\r
427          ? ''\r
428         : ( $smallernotes\r
429               ? '\scriptsize{ '.$notes.' }'\r
430               : $notes\r
431           )\r
432   --@]\r
433   [@-- $coupon ? '\ifthenelse{\equal{\thepage}{1}}{\rule{0pt}{\extracouponspace}}{}' : '' --@]\r
434 \end{minipage}\r
435 \end{document}\r