fixup damage from quantity addition
[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,longtable,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}{4.8cm}\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 --@] \small{\r
86 [@-- $footer --@]\r
87     }[@-- $coupon ? '\vspace{\extracouponspace}' : '' --@]\r
88   }\r
89   { % ... pages\r
90     \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{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 description...\r
160 \newcommand{\FSdesc}[5]{\r
161   \multicolumn{1}{c}{\rule{0pt}{2.5ex}\textbf{#1}} &\r
162   \multicolumn{4}{l}{\textbf{#2}} &\r
163   \multicolumn{1}{l}{\textbf{#3}} &\r
164   \multicolumn{1}{r}{\textbf{#4}} &\r
165   \multicolumn{1}{r}{\textbf{\dollar #5}}\\\r
166 }\r
167 % ...extended description...\r
168 \newcommand{\FSextdesc}[1]{\r
169   \multicolumn{1}{l}{\rule{0pt}{1.0ex}} &\r
170 %%  \multicolumn{2}{l}{\small{~-~#1}}\\\r
171 #1\\\r
172 }\r
173 % ...and total line items.\r
174 \newcommand{\FStotaldesc}[2]{\r
175   & \multicolumn{6}{l}{#1} & #2\\\r
176 }\r
177 \r
178 \r
179 \begin{document}\r
180 %\r
181 %%      Headers and footers defined for the first page\r
182 %\r
183 %%      The LH Heading comprising logo\r
184 %%      UNCOMMENT the following FOUR lines and change the path if necssary to provide a logo\r
185 %\r
186 %%      The Heading comprising isue date, customer ref & INVOICE name\r
187 %\r
188 %%      Header & footer changes for subsequent pages\r
189 %\r
190 %\r
191 %\r
192 [@-- $coupon ? '\enlargethispage{-\extracouponspace}' : '' --@]\r
193 \addressinset \rule{0.5cm}{0cm} \r
194 \makebox{\r
195 \begin{minipage}[t]{5.0cm}\r
196 \vspace{0.25cm}\r
197 \textbf{[@-- $payname --@]}\\\r
198 \addressline{[@-- $company --@]}\r
199 \addressline{[@-- $address1 --@]}\r
200 \addressline{[@-- $address2 --@]}\r
201 \addressline{[@-- $city --@], [@-- $state --@]~~[@-- $zip --@]}\r
202 \addressline{[@-- $country --@]}\r
203 \end{minipage}}\r
204 \hfill\r
205 \makebox{\r
206 \begin{minipage}[t]{6.4cm}\r
207 \begin{flushright}\r
208 [@--\r
209   if ($ship_enable) {\r
210     $OUT .= '\textbf{Service Address}\\\\';\r
211     $OUT .= "\\addressline{$ship_company}";\r
212     $OUT .= "\\addressline{$ship_address1}";\r
213     $OUT .= "\\addressline{$ship_address2}";\r
214     $OUT .= "\\addressline{$ship_city, $ship_state~~$ship_zip}";\r
215     $OUT .= "\\addressline{$ship_country}";\r
216     $OUT .= '~\\\\';\r
217     $OUT .= "\\textbf{ID:}~~$agent_custid\\\\" if $agent_custid;\r
218     $OUT .= "\\textbf{Fax:}~~$ship_fax\\\\" if $ship_fax;\r
219     $OUT .= '~\\\\' if ($ship_fax or $agent_custid);\r
220   }else{\r
221     $OUT .= '';\r
222   }\r
223 --@]\r
224 Terms: [@-- $terms --@]\\\r
225 [@-- $po_line --@]\\\r
226 \end{flushright}\r
227 \end{minipage}}\r
228 \vspace{1.5cm}\r
229 %\r
230 \section*{}\r
231 [@--\r
232   foreach my $section ( @sections ) {\r
233     if ($section->{'pretotal'}) {\r
234       $OUT .= '\begin{flushright}';\r
235       $OUT .= '\large\textsc{'. $section->{'pretotal'}. '}\\\\';\r
236       $OUT .= '\\end{flushright}';\r
237     }\r
238     $OUT .= '\captionsetup{singlelinecheck=false,justification=raggedright,font={Large,sc,bf}}';\r
239     $OUT .= '\begin{longtable}{cllllllr}';\r
240     $OUT .= '\caption*{ ';\r
241     $OUT .= ($section->{'description'}) ? $section->{'description'}: 'Charges';\r
242     $OUT .= '}\\\\';\r
243     $OUT .= '\hline';\r
244     $OUT .= '\rule{0pt}{2.5ex}';\r
245     $OUT .= '\makebox[1.4cm]{\textbf{Ref}} & ';\r
246     $OUT .= '\makebox[2.0cm][l]{\textbf{Description}}& ';\r
247     $OUT .= '\makebox[2.0cm][l]{}& ';\r
248     $OUT .= '\makebox[2.0cm][l]{}& ';\r
249     $OUT .= '\makebox[2.0cm][l]{}& ';\r
250     $OUT .= '\makebox[2.0cm][l]{\textbf{'. ($unitprices ? '~~Unit Price' : ''). '}}&';\r
251     $OUT .= '\makebox[2.0cm]{\textbf{'. ($unitprices ? '~Quantity' : ''). '}}&';\r
252     $OUT .= '\makebox[2.0cm][r]{\textbf{Amount}} \\\\';\r
253     $OUT .= '\hline';\r
254     $OUT .= '\endfirsthead';\r
255     $OUT .= '\multicolumn{7}{r}{\rule{0pt}{2.5ex}Continued from previous page}\\\\';\r
256     $OUT .= '\hline';\r
257     $OUT .= '\rule{0pt}{2.5ex}';\r
258     $OUT .= '\makebox[1.4cm]{\textbf{Ref}} & ';\r
259     $OUT .= '\makebox[2.0cm][l]{\textbf{Description}}& ';\r
260     $OUT .= '\makebox[2.0cm][l]{}& ';\r
261     $OUT .= '\makebox[2.0cm][l]{}& ';\r
262     $OUT .= '\makebox[2.0cm][l]{}& ';\r
263     $OUT .= '\makebox[2.0cm][l]{\textbf{'. ($unitprices ? '~~Unit Price' : ''). '}}&';\r
264     $OUT .= '\makebox[2.0cm]{\textbf{'. ($unitprices ? '~Quantity' : ''). '}}&';\r
265     $OUT .= '\makebox[2.0cm][r]{\textbf{Amount}} \\\\';\r
266     $OUT .= '\hline';\r
267     $OUT .= '\endhead';\r
268     $OUT .= '\multicolumn{7}{r}{\rule{0pt}{2.5ex}Continued on next page...}\\\\';\r
269     $OUT .= '\endfoot';\r
270     $OUT .= '\hline';\r
271 \r
272     if (scalar(@sections) > 1) {\r
273       $OUT .= '\FStotaldesc{' . $section->{'description'} . ' Total}' .\r
274               '{' . $section->{'subtotal'} . '}' . "\n";\r
275     }\r
276 \r
277     #if ($section == $sections[$#sections]) {\r
278       foreach my $line (grep {$_->{section}->{description} eq $section->{description}} @total_items) {\r
279         $OUT .= '\FStotaldesc{' . $line->{'total_item'} . '}' .\r
280                 '{' . $line->{'total_amount'} . '}' . "\n";\r
281       }\r
282     #}\r
283 \r
284     $OUT .= '\hline';\r
285     $OUT .= '\endlastfoot';\r
286 \r
287     foreach my $line (\r
288       grep { ( scalar( @sections ) > 1 \r
289              ? $section->{'description'} eq $_->{'section'}->{'description'}\r
290              : 1\r
291            ) }\r
292       @detail_items )\r
293     {\r
294       my $ext_description = $line->{'ext_description'};\r
295   \r
296       # Don't break-up small packages.\r
297       my $rowbreak = @$ext_description < 5 ? '*' : '';\r
298   \r
299       $OUT .= "\\hline\n";\r
300       $OUT .= '\FSdesc{' . $line->{'ref'} . '}{' . $line->{'description'} . '}' .\r
301               '{' . ( $unitprices ? $line->{'unit_amount'} : '' ) . '}'.\r
302               '{' . ( $unitprices ? $line->{'quantity'} : ''  ) . '}' .\r
303               '{' . $line->{'amount'} . "}${rowbreak}\n";\r
304 \r
305       foreach my $ext_desc (@$ext_description) {\r
306         if ( $ext_desc !~ /[^\\]&/ ) {\r
307           $ext_desc = substr($ext_desc, 0, 80) . '...'\r
308             if (length($ext_desc) > 80);\r
309           $ext_desc = '\multicolumn{6}{l}{\small{~~~'. $ext_desc. '}}';\r
310         }else{\r
311           $ext_desc = "~~~$ext_desc";\r
312         }\r
313         $OUT .= '\FSextdesc{' . $ext_desc . '}' . "${rowbreak}\n";\r
314       }\r
315 \r
316     }\r
317 \r
318     $OUT .= '\end{longtable}';\r
319 \r
320     if ($section->{'posttotal'}) {\r
321       $OUT .= '\begin{flushright}';\r
322       $OUT .= '\normalfont\large\bfseries\textsc{'. $section->{'posttotal'}. '}\\\\';\r
323       $OUT .= '\\end{flushright}';\r
324     }\r
325   }\r
326 \r
327 --@]\r
328 \vfill\r
329 [@-- $notes --@]\r
330 \end{document}\r