Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix math error by egreg (@eg9) #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 44 additions & 40 deletions invoice.cls
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
%%% modified by egreg
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright (c) 2011 Trey Hunner %
% %
Expand Down Expand Up @@ -29,14 +30,17 @@
\usepackage[letterpaper,hmargin=0.79in,vmargin=0.79in]{geometry}
\usepackage[parfill]{parskip} % Do not indent paragraphs
\usepackage{fp} % Fixed-point arithmetic
\usepackage{calc} % Counters for totaling hours and cost
\usepackage{longtable}

\pagestyle{empty} % No page numbers
\linespread{1.5}

\setlength{\doublerulesep}{\arrayrulewidth} % Double rules look like one thick one

% variables for total cost and subcost, total hours and subhours
\def\totalcost{0}\def\subcost{0}
\def\totalhours{0}\def\subhours{0}

% Command for setting a default hourly rate
\newcommand{\hourlyrate}[1]{\def \@hourlyrate {#1}}
\hourlyrate{1}
Expand All @@ -45,68 +49,68 @@
\\
}

% Counters for totaling up hours and dollars
\newcounter{hours} \newcounter{subhours} \newcounter{cost} \newcounter{subcost}
\setcounter{hours}{0} \setcounter{subhours}{0} \setcounter{cost}{0} \setcounter{subcost}{0}

% Formats inputed number with 2 digits after the decimal place
\newcommand*{\formatNumber}[1]{\FPround{\cost}{#1}{2}\cost} %
\newcommand*{\formatNumber}[1]{\FPround{\temp}{#1}{2}\temp} %

% Returns the total of counter
\newcommand*{\total}[1]{\FPdiv{\t}{\arabic{#1}}{1000}\formatNumber{\t}}
\newcommand*{\total}[1]{\formatNumber{#1}}

% Create an invoice table
\newenvironment{invoiceTable}{
\newenvironment{invoiceTable}{%
% Create a new row from title, unit quantity, unit rate, and unit name
\newcommand*{\unitrow}[4]{%
\addtocounter{cost}{1000 * \real{##2} * \real{##3}}%
\addtocounter{subcost}{1000 * \real{##2} * \real{##3}}%
##1 & \formatNumber{##2} ##4 & \$\formatNumber{##3} & \$\FPmul{\cost}{##2}{##3}\formatNumber{\cost}%
\FPmul{\tempa}{##2}{##3}%
\FPadd{\tempb}{\totalcost}{\tempa}%
\global\let\totalcost\tempb
\FPadd{\tempb}{\subcost}{\tempa}%
\global\let\subcost\tempb
##1 & \formatNumber{##2} ##4 & \$\formatNumber{##3} & \$\FPmul{\temp}{##2}{##3}\formatNumber{\temp}%
\\
}
}%
% Create a new row from title and expense amount
\newcommand*{\feerow}[2]{%
\addtocounter{cost}{1000 * \real{##2}}%
\addtocounter{subcost}{1000 * \real{##2}}%
##1 & & \$\formatNumber{##2} & \$\FPmul{\cost}{##2}{1}\formatNumber{\cost}%
\FPadd{\tempa}{\totalcost}{##2}%
\global\let\totalcost\tempa
\FPadd{\tempa}{\subcost}{##2}%
\global\let\subcost\tempa
##1 & & \$\formatNumber{##2} & \$\formatNumber{##2}%
\\
}

\newcommand{\subtotalNoStar}{
{\bf Subtotal} & {\bf \total{subhours} hours} & & {\bf \$\total{subcost}}
\setcounter{subcost}{0}
\setcounter{subhours}{0}
}%
\newcommand{\subtotalNoStar}{%
\textbf{Subtotal} & \textbf{\total{\subhours} hours} & & \textbf{\$\total{\subcost}}%
\gdef\subcost{0}%
\gdef\subhours{0}%
\\*[1.5ex]
}
\newcommand{\subtotalStar}{
{\bf Subtotal} & & & {\bf \$\total{subcost}}
\setcounter{subcost}{0}
}%
\newcommand{\subtotalStar}{%
\textbf{Subtotal} & & & \textbf{\$\total{\subcost}}
\gdef\subcost{0}%
\\*[1.5ex]
}
\newcommand{\subtotal}{
}%
\newcommand{\subtotal}{%
\hline
\@ifstar
\subtotalStar%
\subtotalNoStar%
}


\subtotalStar
\subtotalNoStar
}%
% Create a new row from date and hours worked (use stored fee type and hourly rate)
\newcommand*{\hourrow}[2]{%
\addtocounter{hours}{1000 * \real{##2}}%
\addtocounter{subhours}{1000 * \real{##2}}%
\FPadd{\tempa}{\totalhours}{##2}%
\global\let\totalhours\tempa
\FPadd{\tempa}{\subhours}{##2}%
\global\let\subhours\tempa
\unitrow{##1}{##2}{\@hourlyrate}{hours}%
}
\renewcommand{\tabcolsep}{0.8ex}
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
}%
\setlength{\tabcolsep}{0.8ex}%
\setlength\LTleft{0pt}%
\setlength\LTright{0pt}%
\begin{longtable}{@{\extracolsep{\fill}\hspace{\tabcolsep}} l r r r }
\hline
{\bf Description of Services} & \multicolumn{1}{c}{\bf Quantity} & \multicolumn{1}{c}{\bf Unit Price} & \multicolumn{1}{c}{\bf Amount} \\*
\bfseries Description of Services & \multicolumn{1}{c}{\bfseries Quantity} & \multicolumn{1}{c}{\bfseries Unit Price} & \multicolumn{1}{c}{\bfseries Amount} \\*
\hline\hline
\endhead
}{
\hline\hline\hline
{\bf Balance Due} & & & {\bf \$\total{cost}} \\
\bfseries Balance Due & & & \bfseries \$\total{\totalcost} \\
\end{longtable}
}