default to 1
[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}{-1.25cm}       % top margin to top of header\r
28 \setlength{\headheight}{2.0cm}          % height of header\r
29 \setlength{\headsep}{1.0cm}             % between header and text\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}{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}{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   }\r
84   '';\r
85 --@] [@-- $smallerfooter ? '\scriptsize{' : '\small{' --@]\r
86 [@-- $footer --@]\r
87     }[@-- $coupon ? '\vspace{\extracouponspace}' : '' --@]\r
88   }\r
89   { % ... pages\r
90     [@-- $smallerfooter ? '\scriptsize{' : '\small{' --@]\r
91 [@-- $smallfooter --@]\r
92     }\r
93   }\r
94 }\r
95 \r
96 \fancyfoot[R]{\r
97   \ifthenelse{\equal{\thepage}{1}}\r
98   { % First page\r
99   }\r
100   { % ... pages\r
101     \small{\thepage\ of \pageref{LastPage}}\r
102   }\r
103 }\r
104 \r
105 \fancyhead[L]{\r
106   \ifthenelse{\equal{\thepage}{1}}\r
107   { % First page\r
108     \returninset\r
109     \makebox{\r
110       \begin{tabular}{ll}\r
111         \includegraphics{[@-- $logo_file --@]} &\r
112         \begin{minipage}[b]{5.5cm}\r
113 [@-- $returnaddress --@]\r
114         \end{minipage}\r
115       \end{tabular}\r
116     }\r
117   }\r
118   { % ... pages\r
119     %\includegraphics{[@-- $logo_file --@]}     % Uncomment if you want the logo on all pages.\r
120   }\r
121 }\r
122 \r
123 \fancyhead[R]{\r
124   \ifthenelse{\equal{\thepage}{1}}\r
125   { % First page\r
126     \begin{tabular}{ccc}\r
127     Invoice date & Invoice \#& Customer\#\\\r
128     \vspace{0.2cm}\r
129     \textbf{[@-- $date --@]} & \textbf{[@-- $invnum --@]} & \textbf{[@-- $custnum --@]} \\\hline\r
130     \rule{0pt}{5ex} &~~ \huge{\textsc{[@-- $notice_name || 'Invoice' --@]}} & \\\r
131     \vspace{-0.2cm}\r
132      & & \\\hline\r
133     \end{tabular}\r
134   }\r
135   { % ... pages\r
136     \small{\r
137       \begin{tabular}{lll}\r
138       Invoice date & Invoice \#& Customer\#\\\r
139       \textbf{[@-- $date --@]} & \textbf{[@-- $invnum --@]} & \textbf{[@-- $custnum --@]}\\\r
140       \end{tabular}\r
141     }\r
142   }\r
143 }\r
144 \r
145 \pagestyle{fancy}\r
146 \r
147 \r
148 %% Font options are:\r
149 %%      bch     Bitsream Charter\r
150 %%      put     Utopia\r
151 %%      phv     Adobe Helvetica\r
152 %%      pnc     New Century Schoolbook\r
153 %%      ptm     Times\r
154 %%      pcr     Courier\r
155 \r
156 \renewcommand{\familydefault}{phv}\r
157 \r
158 \r
159 % Commands for freeside table header...\r
160 \r
161 \newcommand{\FSdescriptionlength} { [@-- $unitprices ? '8.2cm' : '12.8cm' --@] }\r
162 \newcommand{\FSdescriptioncolumncount} { [@-- $unitprices ? '4' : '6' --@] }\r
163 \newcommand{\FSunitcolumns}{ [@-- $unitprices ? '\makebox[2.5cm][l]{\textbf{~~Unit Price}}&\makebox[1.4cm]{\textbf{~Quantity}}&' : '' --@] }\r
164 \r
165 \newcommand{\FShead}{\r
166   \hline\r
167   \rule{0pt}{2.5ex}\r
168   \makebox[1.4cm]{\textbf{Ref}} &\r
169 %  \makebox[2.9cm][l]{\textbf{Description}}&\r
170 %  \makebox[1.4cm][l]{}&\r
171 %  \makebox[1.4cm][l]{}&\r
172 %  \makebox[2.5cm][l]{}&\r
173   \multicolumn{\FSdescriptioncolumncount}{l}{\makebox[\FSdescriptionlength][l]{\textbf{Description}}}&\r
174   \FSunitcolumns\r
175   \makebox[1.6cm][r]{\textbf{Amount}} \\\r
176   \hline\r
177 }\r
178 \r
179 % ...description...\r
180 \newcommand{\FSdesc}[5]{\r
181   \multicolumn{1}{c}{\rule{0pt}{2.5ex}\textbf{#1}} &\r
182   \multicolumn{4}{l}{\textbf{#2}} &\r
183   \multicolumn{1}{l}{\textbf{#3}} &\r
184   \multicolumn{1}{r}{\textbf{#4}} &\r
185   \multicolumn{1}{r}{\textbf{\dollar #5}}\\\r
186 }\r
187 % ...extended description...\r
188 \newcommand{\FSextdesc}[1]{\r
189   \multicolumn{1}{l}{\rule{0pt}{1.0ex}} &\r
190 %%  \multicolumn{2}{l}{\small{~-~#1}}\\\r
191 #1\\\r
192 }\r
193 % ...and total line items.\r
194 \newcommand{\FStotaldesc}[2]{\r
195   & \multicolumn{6}{l}{#1} & #2\\\r
196 }\r
197 \r
198 \r
199 \begin{document}\r
200 %       Headers and footers defined for the first page\r
201 \addressinset \rule{0.5cm}{0cm} \r
202 \makebox{\r
203 \begin{minipage}[t]{7.0cm}\r
204 \vspace{0.25cm}\r
205 \textbf{[@-- $payname --@]}\\\r
206 \addressline{[@-- $company --@]}\r
207 \addressline{[@-- $address1 --@]}\r
208 \addressline{[@-- $address2 --@]}\r
209 \addressline{[@-- $city --@], [@-- $state --@]~~[@-- $zip --@]}\r
210 \addressline{[@-- $country --@]}\r
211 \end{minipage}}\r
212 \hfill\r
213 \makebox{\r
214 \begin{minipage}[t]{6.4cm}\r
215 [@--\r
216   if ($ship_enable) {\r
217     $OUT .= '\textbf{Service Address}\\\\';\r
218     $OUT .= "\\addressline{$ship_company}";\r
219     $OUT .= "\\addressline{$ship_address1}";\r
220     $OUT .= "\\addressline{$ship_address2}";\r
221     $OUT .= "\\addressline{$ship_city, $ship_state~~$ship_zip}";\r
222     $OUT .= "\\addressline{$ship_country}";\r
223     $OUT .= '~\\\\';\r
224   }else{\r
225     $OUT .= '';\r
226   }\r
227 --@]\r
228 \begin{flushright}\r
229 Terms: [@-- $terms --@]\\\r
230 [@-- $po_line --@]\\\r
231 \end{flushright}\r
232 \end{minipage}}\r
233 \vspace{1.5cm}\r
234 %\r
235 [@-- $summary --@]\r
236 %\r
237 \section*{}\r
238 [@--\r
239   foreach my $section ( grep { !$summary || $_->{description} ne $finance_section } @sections ) {\r
240     if ($section->{'pretotal'} && !$summary) {\r
241       $OUT .= '\begin{flushright}';\r
242       $OUT .= '\large\textsc{'. $section->{'pretotal'}. '}\\\\';\r
243       $OUT .= '\\end{flushright}';\r
244     }\r
245     $OUT .= '\pagebreak' if $section{'post_total'};\r
246     unless ($section->{'summarized'} ) {\r
247       $OUT .= '\captionsetup{singlelinecheck=false,justification=raggedright,font={Large,sc,bf}}';\r
248       $OUT .= '\ifthenelse{\equal{\thepage}{1}}{\setlength{\LTextracouponspace}{\extracouponspace}}{\setlength{\LTextracouponspace}{0pt}}'\r
249         if $coupon;\r
250       $OUT .= '\begin{longtable}{cllllllr}';\r
251       $OUT .= '\caption*{ ';\r
252       $OUT .= ($section->{'description'}) ? $section->{'description'}: 'Charges';\r
253       $OUT .= '}\\\\';\r
254       $OUT .= '\FShead';\r
255       $OUT .= '\endfirsthead';\r
256       $OUT .= '\multicolumn{7}{r}{\rule{0pt}{2.5ex}Continued from previous page}\\\\';\r
257       $OUT .= '\FShead';\r
258       $OUT .= '\endhead';\r
259       $OUT .= '\multicolumn{7}{r}{\rule{0pt}{2.5ex}Continued on next page...}\\\\';\r
260       $OUT .= '\endfoot';\r
261       $OUT .= '\hline';\r
262 \r
263       if (scalar(@sections) > 1) {\r
264         $OUT .= '\FStotaldesc{' . $section->{'description'} . ' Total}' .\r
265                 '{' . $section->{'subtotal'} . '}' . "\n";\r
266       }\r
267 \r
268       #if ($section == $sections[$#sections]) {\r
269         foreach my $line (grep {$_->{section}->{description} eq $section->{description}} @total_items) {\r
270           $OUT .= '\FStotaldesc{' . $line->{'total_item'} . '}' .\r
271                   '{' . $line->{'total_amount'} . '}' . "\n";\r
272         }\r
273       #}\r
274 \r
275       $OUT .= '\hline';\r
276       $OUT .= '\endlastfoot';\r
277 \r
278       my $lastref = 0;\r
279       foreach my $line (\r
280         grep { ( scalar( @sections ) > 1 \r
281                ? $section->{'description'} eq $_->{'section'}->{'description'}\r
282                : 1\r
283              ) }\r
284         @detail_items )\r
285       {\r
286         my $ext_description = $line->{'ext_description'};\r
287   \r
288         # Don't break-up small packages.\r
289         my $rowbreak = @$ext_description < 5 ? '*' : '';\r
290   \r
291         $OUT .= "\\hline\n" if ($line->{'ref'} && $line->{'ref'} ne $lastref);\r
292         $OUT .= '\FSdesc'.\r
293                 '{' . ( $line->{'ref'} ne $lastref ? $line->{'ref'} : '' ) . '}'.\r
294                 '{' . $line->{'description'} . '}' .\r
295                 '{' . ( $unitprices ? $line->{'unit_amount'} : '' ) . '}'.\r
296                 '{' . ( $unitprices ? $line->{'quantity'} : ''  ) . '}' .\r
297                 '{' . $line->{'amount'} . "}${rowbreak}\n";\r
298         $lastref = $line->{'ref'};\r
299 \r
300         foreach my $ext_desc (@$ext_description) {\r
301           if ( $ext_desc !~ /[^\\]&/ ) {\r
302             $ext_desc = substr($ext_desc, 0, 80) . '...'\r
303               if (length($ext_desc) > 80);\r
304             $ext_desc = '\multicolumn{6}{l}{\small{~~~'. $ext_desc. '}}';\r
305           }else{\r
306             $ext_desc = "~~~$ext_desc";\r
307           }\r
308           $OUT .= '\FSextdesc{' . $ext_desc . '}' . "${rowbreak}\n";\r
309         }\r
310 \r
311       }\r
312 \r
313       $OUT .= '\end{longtable}';\r
314     }\r
315     if ($section->{'posttotal'}) {\r
316       $OUT .= '\begin{flushright}';\r
317       $OUT .= '\normalfont\large\bfseries\textsc{'. $section->{'posttotal'}. '}\\\\';\r
318       $OUT .= '\\end{flushright}';\r
319     }\r
320   }\r
321 \r
322 --@]\r
323 \vfill\r
324 \begin{minipage}[t]{\textwidth}\r
325   [@-- length($summary)\r
326          ? ''\r
327         : ( $smallernotes\r
328               ? '\scriptsize{ '.$notes.' }'\r
329               : $notes\r
330           )\r
331   --@]\r
332   [@-- $coupon ? '\ifthenelse{\equal{\thepage}{1}}{\rule{0pt}{\extracouponspace}}{}' : '' --@]\r
333 \end{minipage}\r
334 \end{document}\r