invoice template and config localization, #12367
[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,fslongtable,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 \r
27 \addtolength{\voffset}{-0.0cm}          % top margin to top of header\r
28 \addtolength{\hoffset}{-0.6cm}          % left margin on page\r
29 \addtolength{\topmargin}{[@-- defined($topmargin) ? $topmargin : '-1.25cm' --@]}\r
30 \setlength{\headheight}{2.0cm}          % height of header\r
31 \setlength{\headsep}{[@-- defined($headsep) ? $headsep : '1.0cm' --@]}\r
32 \setlength{\footskip}{1.0cm}            % bottom of footer from bottom of text\r
33 \r
34 %\addtolength{\textwidth}{2.1in}        % width of text\r
35 \setlength{\textwidth}{19.5cm}\r
36 \setlength{\textheight}{[@-- defined($textheight) ? $textheight : '19.5cm' --@]}\r
37 \setlength{\oddsidemargin}{-0.9cm}      % odd page left margin\r
38 \setlength{\evensidemargin}{-0.9cm}     % even page left margin\r
39 \r
40 \LTchunksize=40\r
41 \r
42 \renewcommand{\headrulewidth}{0pt}\r
43 \renewcommand{\footrulewidth}{1pt}\r
44 \r
45 \renewcommand{\footrule}{\r
46 [@--\r
47   $coupon ? '\ifthenelse{\equal{\thepage}{1}}' : '';\r
48 --@]\r
49   {\r
50   }\r
51   {\r
52     \vbox to 0pt{\rule{\headwidth}{\footrulewidth}\vss}\r
53   }\r
54 }\r
55 \r
56 \newcommand{\extracouponspace}{[@-- defined($extracouponspace) ? $extracouponspace : '3.6cm' --@]}\r
57 \r
58 % Adjust the inset of the mailing address\r
59 \newcommand{\addressinset}[1][]{\hspace{1.0cm}}\r
60 \r
61 % Adjust the inset of the return address and logo\r
62 \newcommand{\returninset}[1][]{\hspace{-0.25cm}}\r
63 \r
64 % New command for address lines i.e. skip them if blank\r
65 \newcommand{\addressline}[1]{\ifthenelse{\equal{#1}{}}{}{#1\\}}\r
66 \r
67 % Inserts dollar symbol\r
68 \newcommand{\dollar}[1][]{\symbol{36}}\r
69 \r
70 % Remove plain style header/footer\r
71 \fancypagestyle{plain}{\r
72   \fancyhead{}\r
73 }\r
74 \fancyhf{}\r
75 \r
76 % Define fancy header/footer for first and subsequent pages\r
77 \fancyfoot[C]{\r
78   \ifthenelse{\equal{\thepage}{1}}\r
79   { % First page\r
80 [@--\r
81   if ($coupon) {\r
82     $OUT .= '\vspace{-\extracouponspace}';\r
83     $OUT .= '\rule[0.5em]{\textwidth}{\footrulewidth}\\\\';\r
84     $OUT .= $coupon;\r
85     $OUT .= '\vspace{'. $couponfootsep. '}' if defined($couponfootsep);\r
86   }\r
87   '';\r
88 --@] [@-- $smallerfooter ? '\scriptsize{' : '\small{' --@]\r
89 [@-- $footer --@]\r
90     }[@-- $coupon ? '\vspace{\extracouponspace}' : '' --@]\r
91   }\r
92   { % ... pages\r
93     [@-- $smallerfooter ? '\scriptsize{' : '\small{' --@]\r
94 [@-- $smallfooter --@]\r
95     }\r
96   }\r
97 }\r
98 \r
99 \fancyfoot[R]{\r
100   \ifthenelse{\equal{\thepage}{1}}\r
101   { % First page\r
102   }\r
103   { % ... pages\r
104     \small{\thepage\ of \pageref{LastPage}}\r
105   }\r
106 }\r
107 \r
108 \fancyhead[L]{\r
109   \ifthenelse{\equal{\thepage}{1}}\r
110   { % First page\r
111     \returninset\r
112     \makebox{\r
113       \begin{tabular}{ll}\r
114         \includegraphics{[@-- $logo_file --@]} & [@-- $verticalreturnaddress ? '\\\\' : '' --@]\r
115         \begin{minipage}[b]{5.5cm}\r
116 [@-- $returnaddress --@]\r
117         \end{minipage}\\\r
118       \end{tabular}\r
119     }\r
120   }\r
121   { % ... pages\r
122     %\includegraphics{[@-- $logo_file --@]}     % Uncomment if you want the logo on all pages.\r
123   }\r
124 }\r
125 \r
126 \fancyhead[R]{\r
127   \ifthenelse{\equal{\thepage}{1}}\r
128   { % First page\r
129     \begin{tabular}{ccc}\r
130     [@-- join(' & ', emt('Invoice date'), emt('Invoice #'), emt('Customer #') ) --@]\\\r
131     \vspace{0.2cm}\r
132     \textbf{[@-- $date --@]} & \textbf{[@-- $invnum --@]} & \textbf{[@-- $custnum --@]} \\\hline\r
133     \rule{0pt}{5ex} &~~ \huge{\textsc{[@-- emt($notice_name) --@]}} & \\\r
134     \vspace{-0.2cm}\r
135      & & \\\hline\r
136     \end{tabular}\r
137   }\r
138   { % ... pages\r
139     \small{\r
140       \begin{tabular}{lll}\r
141       [@-- join(' & ', emt('Invoice date'), emt('Invoice #'), emt('Customer #') ) --@]\\\r
142       \textbf{[@-- $date --@]} & \textbf{[@-- $invnum --@]} & \textbf{[@-- $custnum --@]}\\\r
143       \end{tabular}\r
144     }\r
145   }\r
146 }\r
147 \r
148 \pagestyle{fancy}\r
149 \r
150 \r
151 %% Font options are:\r
152 %%      bch     Bitsream Charter\r
153 %%      put     Utopia\r
154 %%      phv     Adobe Helvetica\r
155 %%      pnc     New Century Schoolbook\r
156 %%      ptm     Times\r
157 %%      pcr     Courier\r
158 \r
159 \renewcommand{\familydefault}{phv}\r
160 \r
161 \r
162 % Commands for freeside table header...\r
163 \r
164 \newcommand{\FSdescriptionlength} { [@-- $unitprices ? '8.2cm' : '12.8cm' --@] }\r
165 \newcommand{\FSdescriptioncolumncount} { [@-- $unitprices ? '4' : '6' --@] }\r
166 \newcommand{\FSunitcolumns}{ [@-- \r
167   $unitprices \r
168   ? '\makebox[2.5cm][l]{\textbf{~~'.emt('Unit Price').'}}&\makebox[1.4cm]{\textbf{~'.emt('Quantity').'}}&' \r
169   : '' --@] }\r
170 \r
171 \newcommand{\FShead}{\r
172   \hline\r
173   \rule{0pt}{2.5ex}\r
174   \makebox[1.4cm]{\textbf{Ref}} &\r
175   \multicolumn{\FSdescriptioncolumncount}{l}{\makebox[\FSdescriptionlength][l]{\textbf{[@-- emt('Description') --@]}}}&\r
176   \FSunitcolumns\r
177   \makebox[1.6cm][r]{\textbf{[@-- emt('Amount') --@]}} \\\r
178   \hline\r
179 }\r
180 \r
181 % ...description...\r
182 \newcommand{\FSdesc}[5]{\r
183   \multicolumn{1}{c}{\rule{0pt}{2.5ex}\textbf{#1}} &\r
184   \multicolumn{[@-- $unitprices ? '4' : '6' --@]}{l}{\textbf{#2}} &\r
185 [@-- $unitprices ? '  \multicolumn{1}{l}{\textbf{#3}} &'."\n".\r
186                    '  \multicolumn{1}{r}{\textbf{#4}} &'."\n"\r
187                  : ''\r
188 --@]\r
189   \multicolumn{1}{r}{\textbf{\dollar #5}}\\\r
190 }\r
191 % ...extended description...\r
192 \newcommand{\FSextdesc}[1]{\r
193   \multicolumn{1}{l}{\rule{0pt}{1.0ex}} &\r
194 %%  \multicolumn{2}{l}{\small{~-~#1}}\\\r
195 #1\\\r
196 }\r
197 % ...and total line items.\r
198 \newcommand{\FStotaldesc}[2]{\r
199   & \multicolumn{6}{l}{#1} & #2\\\r
200 }\r
201 \r
202 \r
203 \begin{document}\r
204 %       Headers and footers defined for the first page\r
205 \addressinset \rule{0.5cm}{0cm} \r
206 \makebox{\r
207 \begin{minipage}[t]{7.0cm}\r
208 \vspace{[@-- defined($addresssep) ? $addresssep : '0.25cm' --@]}\r
209 \textbf{[@-- $payname --@]}\\\r
210 \addressline{[@-- $company --@]}\r
211 \addressline{[@-- $address1 --@]}\r
212 \addressline{[@-- $address2 --@]}\r
213 \addressline{[@-- $city --@], [@-- $state --@]~~[@-- $zip --@]}\r
214 \addressline{[@-- $country --@]}\r
215 \end{minipage}}\r
216 \hfill\r
217 \makebox{\r
218 \begin{minipage}[t]{6.4cm}\r
219 [@--\r
220   if ($ship_enable) {\r
221     $OUT .= '\textbf{' . emt('Service Address') . '}\\\\';\r
222     $OUT .= "\\addressline{$ship_company}";\r
223     $OUT .= "\\addressline{$ship_address1}";\r
224     $OUT .= "\\addressline{$ship_address2}";\r
225     $OUT .= "\\addressline{$ship_city, $ship_state~~$ship_zip}";\r
226     $OUT .= "\\addressline{$ship_country}";\r
227     $OUT .= '~\\\\';\r
228   }else{\r
229     $OUT .= '';\r
230   }\r
231 --@]\r
232 \begin{flushright}\r
233 [@-- $terms ? emt('Terms') .": $terms" : '' --@]\\\r
234 [@-- $po_line --@]\\\r
235 \end{flushright}\r
236 \end{minipage}}\r
237 \vspace{1.5cm}\r
238 %\r
239 [@-- $summary --@]\r
240 %\r
241 \section*{}\r
242 [@--\r
243   foreach my $section ( grep { !$summary || $_->{description} ne $finance_section } @sections ) {\r
244     if ($section->{'pretotal'} && !$summary) {\r
245       $OUT .= '\begin{flushright}';\r
246       $OUT .= '\large\textsc{'. $section->{'pretotal'}. '}\\\\';\r
247       $OUT .= '\\end{flushright}';\r
248     }\r
249     $OUT .= '\pagebreak' if $section->{'post_total'};\r
250     unless ($section->{'summarized'} ) {\r
251       $OUT .= '\captionsetup{singlelinecheck=false,justification=raggedright,font={Large,sc,bf}}';\r
252       $OUT .= '\ifthenelse{\equal{\thepage}{1}}{\setlength{\LTextracouponspace}{\extracouponspace}}{\setlength{\LTextracouponspace}{0pt}}'\r
253         if $coupon;\r
254       $OUT .= '\begin{longtable}{cllllllr}';\r
255       $OUT .= '\caption*{ ';\r
256       $OUT .= ($section->{'description'}) ? $section->{'description'}: emt('Charges');\r
257       $OUT .= '}\\\\';\r
258       if ($section->{header_generator}) {\r
259         $OUT .= &{$section->{header_generator}}();\r
260       } else {\r
261         $OUT .= '\FShead';\r
262       }\r
263       $OUT .= '\endfirsthead';\r
264       $OUT .= '\multicolumn{7}{r}{\rule{0pt}{2.5ex}'.emt('Continued from previous page').'}\\\\';\r
265       if ($section->{header_generator}) {\r
266         $OUT .= &{$section->{header_generator}}();\r
267       } else {\r
268         $OUT .= '\FShead';\r
269       }\r
270       $OUT .= '\endhead';\r
271       $OUT .= '\multicolumn{7}{r}{\rule{0pt}{2.5ex}'.emt('Continued on next page...').'}\\\\';\r
272       $OUT .= '\endfoot';\r
273       $OUT .= '\hline';\r
274 \r
275       if (scalar(@sections) > 1) {\r
276         if ($section->{total_generator}) {\r
277           $OUT .= &{$section->{total_generator}}($section);\r
278         } else {\r
279           $OUT .= '\FStotaldesc{' . $section->{'description'} . ' Total}' .\r
280                   '{' . $section->{'subtotal'} . '}' . "\n";\r
281         }\r
282       }\r
283 \r
284       #if ($section == $sections[$#sections]) {\r
285         foreach my $line (grep {$_->{section}->{description} eq $section->{description}} @total_items) {\r
286           if ($section->{total_line_generator}) {\r
287             $OUT .= &{$section->{total_line_generator}}($line);\r
288           } else {\r
289             $OUT .= '\FStotaldesc{' . $line->{'total_item'} . '}' .\r
290                     '{' . $line->{'total_amount'} . '}' . "\n";\r
291           }\r
292         }\r
293       #}\r
294 \r
295       $OUT .= '\hline';\r
296       $OUT .= '\endlastfoot';\r
297 \r
298       my $lastref = 0;\r
299       foreach my $line (\r
300         grep { ( scalar( @sections ) > 1 \r
301                ? $section->{'description'} eq $_->{'section'}->{'description'}\r
302                : 1\r
303              ) }\r
304         @detail_items )\r
305       {\r
306         my $ext_description = $line->{'ext_description'};\r
307   \r
308         # Don't break-up small packages.\r
309         my $rowbreak = @$ext_description < 5 ? '*' : '';\r
310   \r
311         $OUT .= "\\hline\n" if ($line->{'ref'} && $line->{'ref'} ne $lastref);\r
312         if ($section->{description_generator}) {\r
313           $OUT .= &{$section->{description_generator}}($line);\r
314         } else {\r
315           $OUT .= '\FSdesc'.\r
316                   '{' . ( $line->{'ref'} ne $lastref ? $line->{'ref'} : '' ) . '}'.\r
317                   '{' . $line->{'description'} . '}' .\r
318                   '{' . ( $unitprices ? $line->{'unit_amount'} : '' ) . '}'.\r
319                   '{' . ( $unitprices ? $line->{'quantity'} : ''  ) . '}' .\r
320                   '{' . $line->{'amount'} . "}${rowbreak}\n";\r
321         }\r
322         $lastref = $line->{'ref'};\r
323 \r
324         foreach my $ext_desc (@$ext_description) {\r
325           if ($section->{extended_description_generator}) {\r
326             $OUT .= &{$section->{extended_description_generator}}($ext_desc);\r
327           } else {\r
328             if ( $ext_desc !~ /[^\\]&/ ) {\r
329               $ext_desc = substr($ext_desc, 0, 80) . '...'\r
330                 if (length($ext_desc) > 80);\r
331               $ext_desc = '\multicolumn{6}{l}{\small{~~~'. $ext_desc. '}}';\r
332             }else{\r
333               $ext_desc = "~~~$ext_desc";\r
334             }\r
335             $OUT .= '\FSextdesc{' . $ext_desc . '}' . "${rowbreak}\n";\r
336           }\r
337         }\r
338 \r
339       }\r
340 \r
341       $OUT .= '\end{longtable}';\r
342     }\r
343     if ($section->{'posttotal'}) {\r
344       $OUT .= '\begin{flushright}';\r
345       $OUT .= '\normalfont\large\bfseries\textsc{'. $section->{'posttotal'}. '}\\\\';\r
346       $OUT .= '\\end{flushright}';\r
347     }\r
348   }\r
349 \r
350 --@]\r
351 \vfill\r
352 \begin{minipage}[t]{\textwidth}\r
353   [@-- length($summary)\r
354          ? ''\r
355         : ( $smallernotes\r
356               ? '\scriptsize{ '.$notes.' }'\r
357               : $notes\r
358           )\r
359   --@]\r
360   [@-- $coupon ? '\ifthenelse{\equal{\thepage}{1}}{\rule{0pt}{\extracouponspace}}{}' : '' --@]\r
361 \end{minipage}\r
362 \end{document}\r