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