fixup damage from quantity addition
[freeside.git] / conf / invoice_latex
index ece0897..693d66e 100644 (file)
@@ -19,7 +19,7 @@
 \r
 \documentclass[letterpaper]{article}\r
 \r
-\usepackage{fancyhdr,lastpage,ifthen,longtable,afterpage}\r
+\usepackage{fancyhdr,lastpage,ifthen,longtable,afterpage,caption,multirow,bigstrut}\r
 \usepackage{graphicx}                  % required for logo graphic\r
 \r
 \addtolength{\voffset}{-0.0cm}         % top margin to top of header\r
 \setlength{\oddsidemargin}{-0.9cm}     % odd page left margin\r
 \setlength{\evensidemargin}{-0.9cm}    % even page left margin\r
 \r
+\LTchunksize=40\r
+\r
 \renewcommand{\headrulewidth}{0pt}\r
 \renewcommand{\footrulewidth}{1pt}\r
 \r
+\renewcommand{\footrule}{\r
+[@--\r
+  $coupon ? '\ifthenelse{\equal{\thepage}{1}}' : '';\r
+--@]\r
+  {\r
+  }\r
+  {\r
+    \vbox to 0pt{\rule{\headwidth}{\footrulewidth}\vss}\r
+  }\r
+}\r
+\r
+\newcommand{\extracouponspace}{4.8cm}\r
+\r
 % Adjust the inset of the mailing address\r
 \newcommand{\addressinset}[1][]{\hspace{1.0cm}}\r
 \r
@@ -45,7 +60,7 @@
 \newcommand{\returninset}[1][]{\hspace{-0.25cm}}\r
 \r
 % New command for address lines i.e. skip them if blank\r
-\newcommand{\addressline}[1]{\ifthenelse{\equal{#1}{}}{}{#1\newline}}\r
+\newcommand{\addressline}[1]{\ifthenelse{\equal{#1}{}}{}{#1\\}}\r
 \r
 % Inserts dollar symbol\r
 \newcommand{\dollar}[1][]{\symbol{36}}\r
 \fancyfoot[C]{\r
   \ifthenelse{\equal{\thepage}{1}}\r
   { % First page\r
-    \small{\r
+[@--\r
+  if ($coupon) {\r
+    $OUT .= '\vspace{-\extracouponspace}';\r
+    $OUT .= '\rule[0.5em]{\textwidth}{\footrulewidth}\\\\';\r
+    $OUT .= $coupon;\r
+  }\r
+  '';\r
+--@] \small{\r
 [@-- $footer --@]\r
-    }\r
+    }[@-- $coupon ? '\vspace{\extracouponspace}' : '' --@]\r
   }\r
   { % ... pages\r
     \small{\r
 \r
 \r
 % Commands for freeside description...\r
-\newcommand{\FSdesc}[3]{\r
+\newcommand{\FSdesc}[5]{\r
   \multicolumn{1}{c}{\rule{0pt}{2.5ex}\textbf{#1}} &\r
-  \multicolumn{6}{l}{\textbf{#2}} &\r
-  \multicolumn{1}{r}{\textbf{\dollar #3}}\\\r
+  \multicolumn{4}{l}{\textbf{#2}} &\r
+  \multicolumn{1}{l}{\textbf{#3}} &\r
+  \multicolumn{1}{r}{\textbf{#4}} &\r
+  \multicolumn{1}{r}{\textbf{\dollar #5}}\\\r
 }\r
 % ...extended description...\r
 \newcommand{\FSextdesc}[1]{\r
   \multicolumn{1}{l}{\rule{0pt}{1.0ex}} &\r
 %%  \multicolumn{2}{l}{\small{~-~#1}}\\\r
-  ~-~#1\\\r
+#1\\\r
 }\r
 % ...and total line items.\r
 \newcommand{\FStotaldesc}[2]{\r
 %\r
 %\r
 %\r
-\begin{tabular}{ll}\r
-\addressinset \rule{0cm}{0cm} &\r
+[@-- $coupon ? '\enlargethispage{-\extracouponspace}' : '' --@]\r
+\addressinset \rule{0.5cm}{0cm} \r
 \makebox{\r
 \begin{minipage}[t]{5.0cm}\r
 \vspace{0.25cm}\r
 \addressline{[@-- $city --@], [@-- $state --@]~~[@-- $zip --@]}\r
 \addressline{[@-- $country --@]}\r
 \end{minipage}}\r
-\end{tabular}\r
 \hfill\r
 \makebox{\r
 \begin{minipage}[t]{6.4cm}\r
 \begin{flushright}\r
+[@--\r
+  if ($ship_enable) {\r
+    $OUT .= '\textbf{Service Address}\\\\';\r
+    $OUT .= "\\addressline{$ship_company}";\r
+    $OUT .= "\\addressline{$ship_address1}";\r
+    $OUT .= "\\addressline{$ship_address2}";\r
+    $OUT .= "\\addressline{$ship_city, $ship_state~~$ship_zip}";\r
+    $OUT .= "\\addressline{$ship_country}";\r
+    $OUT .= '~\\\\';\r
+    $OUT .= "\\textbf{ID:}~~$agent_custid\\\\" if $agent_custid;\r
+    $OUT .= "\\textbf{Fax:}~~$ship_fax\\\\" if $ship_fax;\r
+    $OUT .= '~\\\\' if ($ship_fax or $agent_custid);\r
+  }else{\r
+    $OUT .= '';\r
+  }\r
+--@]\r
 Terms: [@-- $terms --@]\\\r
 [@-- $po_line --@]\\\r
 \end{flushright}\r
 \end{minipage}}\r
 \vspace{1.5cm}\r
 %\r
+\section*{}\r
 [@--\r
   foreach my $section ( @sections ) {\r
-    $OUT .= '\section*{\textsc{';\r
-    $OUT .= ($section->{'description'}) ? $section->{'description'} : 'Charges';\r
-    $OUT .= '}}\begin{longtable}{cllllllr}';\r
+    if ($section->{'pretotal'}) {\r
+      $OUT .= '\begin{flushright}';\r
+      $OUT .= '\large\textsc{'. $section->{'pretotal'}. '}\\\\';\r
+      $OUT .= '\\end{flushright}';\r
+    }\r
+    $OUT .= '\captionsetup{singlelinecheck=false,justification=raggedright,font={Large,sc,bf}}';\r
+    $OUT .= '\begin{longtable}{cllllllr}';\r
+    $OUT .= '\caption*{ ';\r
+    $OUT .= ($section->{'description'}) ? $section->{'description'}: 'Charges';\r
+    $OUT .= '}\\\\';\r
     $OUT .= '\hline';\r
     $OUT .= '\rule{0pt}{2.5ex}';\r
     $OUT .= '\makebox[1.4cm]{\textbf{Ref}} & ';\r
-    $OUT .= '\multicolumn{6}{l}{\makebox[12.8cm][l]{\textbf{Description}}} & ';\r
-    $OUT .= '\makebox[2.5cm][r]{\textbf{Amount}} \\\\';\r
+    $OUT .= '\makebox[2.0cm][l]{\textbf{Description}}& ';\r
+    $OUT .= '\makebox[2.0cm][l]{}& ';\r
+    $OUT .= '\makebox[2.0cm][l]{}& ';\r
+    $OUT .= '\makebox[2.0cm][l]{}& ';\r
+    $OUT .= '\makebox[2.0cm][l]{\textbf{'. ($unitprices ? '~~Unit Price' : ''). '}}&';\r
+    $OUT .= '\makebox[2.0cm]{\textbf{'. ($unitprices ? '~Quantity' : ''). '}}&';\r
+    $OUT .= '\makebox[2.0cm][r]{\textbf{Amount}} \\\\';\r
     $OUT .= '\hline';\r
     $OUT .= '\endfirsthead';\r
     $OUT .= '\multicolumn{7}{r}{\rule{0pt}{2.5ex}Continued from previous page}\\\\';\r
     $OUT .= '\hline';\r
     $OUT .= '\rule{0pt}{2.5ex}';\r
     $OUT .= '\makebox[1.4cm]{\textbf{Ref}} & ';\r
-    $OUT .= '\multicolumn{6}{l}{\makebox[12.8cm][l]{\textbf{Description}}} & ';\r
-    $OUT .= '\makebox[2.5cm][r]{\textbf{Amount}} \\\\';\r
+    $OUT .= '\makebox[2.0cm][l]{\textbf{Description}}& ';\r
+    $OUT .= '\makebox[2.0cm][l]{}& ';\r
+    $OUT .= '\makebox[2.0cm][l]{}& ';\r
+    $OUT .= '\makebox[2.0cm][l]{}& ';\r
+    $OUT .= '\makebox[2.0cm][l]{\textbf{'. ($unitprices ? '~~Unit Price' : ''). '}}&';\r
+    $OUT .= '\makebox[2.0cm]{\textbf{'. ($unitprices ? '~Quantity' : ''). '}}&';\r
+    $OUT .= '\makebox[2.0cm][r]{\textbf{Amount}} \\\\';\r
     $OUT .= '\hline';\r
     $OUT .= '\endhead';\r
     $OUT .= '\multicolumn{7}{r}{\rule{0pt}{2.5ex}Continued on next page...}\\\\';\r
@@ -217,12 +274,12 @@ Terms: [@-- $terms --@]\\
               '{' . $section->{'subtotal'} . '}' . "\n";\r
     }\r
 \r
-    if ($section == $sections[$#sections]) {\r
-      foreach my $line (@total_items) {\r
+    #if ($section == $sections[$#sections]) {\r
+      foreach my $line (grep {$_->{section}->{description} eq $section->{description}} @total_items) {\r
         $OUT .= '\FStotaldesc{' . $line->{'total_item'} . '}' .\r
                 '{' . $line->{'total_amount'} . '}' . "\n";\r
       }\r
-    }\r
+    #}\r
 \r
     $OUT .= '\hline';\r
     $OUT .= '\endlastfoot';\r
@@ -241,13 +298,17 @@ Terms: [@-- $terms --@]\\
   \r
       $OUT .= "\\hline\n";\r
       $OUT .= '\FSdesc{' . $line->{'ref'} . '}{' . $line->{'description'} . '}' .\r
+              '{' . ( $unitprices ? $line->{'unit_amount'} : '' ) . '}'.\r
+              '{' . ( $unitprices ? $line->{'quantity'} : ''  ) . '}' .\r
               '{' . $line->{'amount'} . "}${rowbreak}\n";\r
 \r
       foreach my $ext_desc (@$ext_description) {\r
         if ( $ext_desc !~ /[^\\]&/ ) {\r
           $ext_desc = substr($ext_desc, 0, 80) . '...'\r
             if (length($ext_desc) > 80);\r
-          $ext_desc = '\small{'. $ext_desc. '}';\r
+          $ext_desc = '\multicolumn{6}{l}{\small{~~~'. $ext_desc. '}}';\r
+        }else{\r
+          $ext_desc = "~~~$ext_desc";\r
         }\r
         $OUT .= '\FSextdesc{' . $ext_desc . '}' . "${rowbreak}\n";\r
       }\r
@@ -256,6 +317,11 @@ Terms: [@-- $terms --@]\\
 \r
     $OUT .= '\end{longtable}';\r
 \r
+    if ($section->{'posttotal'}) {\r
+      $OUT .= '\begin{flushright}';\r
+      $OUT .= '\normalfont\large\bfseries\textsc{'. $section->{'posttotal'}. '}\\\\';\r
+      $OUT .= '\\end{flushright}';\r
+    }\r
   }\r
 \r
 --@]\r