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