\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{invoice}[2010/06/02 RIG imitiation of common invoice format]

% \LoadClassWithOptions{letter}%
% Can use the above line as a replacement for the following three if
% get LaTeX2e version postdating 1995/12/01, but the letterhead stuff
% in this file is designed only to work for letterpaper or legalpaper.
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{letter}}%
\ProcessOptions\relax
\LoadClass[]{letter}%

\usepackage{fp}

\def\name#1{\def\namecontents{#1}}
\def\namecontents{}
\def\addr#1{\def\addrcontents{#1}}
\def\addrcontents{}

\def\emptycontents{%
\def\datecontents{}%
\def\invoicenumcontents{}%
\def\billtocontents{}%
\def\shiptocontents{}%
\def\ponumcontents{}%
\def\termscontents{}%
\def\repcontents{}%
\def\shipcontents{}%
\def\viacontents{}%
\def\fobcontents{}%
\def\projectcontents{}%
}
\emptycontents

\def\date#1{\def\datecontents{#1}}
\def\invoicenum#1{\def\invoicenumcontents{#1}}
\def\billto#1{\def\billtocontents{#1}}
\def\shipto#1{\def\shiptocontents{#1}}
\def\ponum#1{\def\ponumcontents{#1}}
\def\terms#1{\def\termscontents{#1}}
\def\rep#1{\def\repcontents{#1}}
\def\ship#1{\def\shipcontents{#1}}
\def\via#1{\def\viacontents{#1}}
\def\fob#1{\def\fobcontents{#1}}
\def\project#1{\def\projectcontents{#1}}

\newcommand{\addrbox}[2]{\begin{tabular}{|p{3in}|} \hline
 \hspace*{1em} #1 \\ \hline
 \parbox[b]{2.8in}{#2} \rule[-7ex]{0pt}{21ex} \\ \hline
 \end{tabular}}

\FPset\total0
 \global\edef\totalout{\FPprint\total}

\newcommand{\lineitem}[4]{\rcol{#1} & #2 & #3 & \rcol{#4} &
 \rcol{\FPmul\amount{#1}{#4}\FPround\amount\amount2\FPprint\amount\FPadd\total\totalout\amount\FPround\total\total2\global\edef\totalout{\FPprint\total}}
 \\}
\newcommand{\vertspace}[1]{&&&&\rule{0pt}{#1}\\}

\newcommand{\ccol}[1]{\multicolumn{1}{|c|}{#1}}
\newcommand{\lcol}[1]{\multicolumn{1}{|l|}{#1}}
\newcommand{\rcol}[1]{\multicolumn{1}{|r|}{#1}}

\def\invoice{%
 {\large \parbox{4in}{\namecontents \\[2ex] \addrcontents}}
 \vspace*{-15ex}
 \begin{flushright}
 {\bf\Huge Invoice} \\[3ex]
 \begin{tabular}{|c|c|} \hline
 Date & Invoice \# \\ \hline
 \datecontents & \invoicenumcontents \\ \hline
 \end{tabular}
 \end{flushright}
 \addrbox{Bill To}{\billtocontents}
 \hfill
 \addrbox{Ship To}{\shiptocontents}\\[2ex]
 \noindent
 \begin{tabular}{|p{.8in}|p{1.1in}|p{.4in}|p{.7in}|p{.6in}|p{1in}|p{1.56in}|} \hline
 \ccol{P.O. Number} & \ccol{Terms} & \ccol{Rep} & \ccol{Ship} & \ccol{Via} & \ccol{F.O.B.} & \ccol{Project} \\ \hline
 &&&&&& \\
 \ccol{\ponumcontents} & \ccol{\termscontents} & \ccol{\repcontents} & \ccol{\shipcontents} & \ccol{\viacontents} & \ccol{\fobcontents} & \projectcontents \\
 &&&&&& \\ \hline
 \end{tabular}
 \par
 \noindent
 \begin{tabular}{|p{.9in}|p{1in}|p{2.75in}|p{1in}|p{1in}|} \hline
 \ccol{Quantity} & \ccol{Item Code} & \ccol{Description} & \ccol{Price Each} & \ccol{Amount} \\ \hline
 &&&& \\
 }

\def\endinvoice{&&&&\\\hline
 &&&\multicolumn{2}{c|}{}\\
 &&&\multicolumn{2}{|c|}{{\LARGE\bf Total}\hfill \$\totalout}\\
 &&&\multicolumn{2}{c|}{}\\\hline\end{tabular}}
