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