X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=latexize_invoice;h=e40789afd5362719a355592216e7cc37771924ee;hb=56c8d8b286ae38e170ce915472f9aa86fabf9fee;hp=3ab22f03055957c8c8eb75dace6c75d484c4c3e7;hpb=74c2a33cbd00e0689eac98555891cb28f73ce63c;p=bin.git diff --git a/latexize_invoice b/latexize_invoice index 3ab22f0..e40789a 100755 --- a/latexize_invoice +++ b/latexize_invoice @@ -10,14 +10,36 @@ # \end{itemize*} # }{50.00}{0.94} +use warnings; +use strict; + +use Params::Validate qw(validate_with :types); + my $time = undef; my $date = undef; + +my $hourly_rate = 50.00; + +my $total = 0; + my @events; +print<<'EOF'; +\setlength\LTleft{0pt plus 1fill minus 1fill}% +\let\LTright\LTleft +\begin{longtable}{|p{9cm}|r|r|r|r|}% +% \caption*{} +\hline + Description & Item Cost & Quantity & Cost & Total \\ +EOF + while (<>){ if (/^\s*\*\s*([^-]+)\s+-.+\[([^\]]+)\]\s*\[[^\]]+\]/) { if (defined $time) { - print format_events($date,$time,@events); + print format_events(date => $date, + time => $time, + total => \$total, + events => \@events); } @events = (); $date = $1; @@ -30,15 +52,43 @@ while (<>){ } } if (defined $time) { - print format_events($date,$time,@events); + print format_events(date => $date, + time => $time, + total => \$total, + events => \@events); } sub format_events{ - my ($date,$time,@events) = @_; - $date =~ s/\s+\d+\:\d+\:\d+\s+[A-Z]{0,3}\s*//; - my $output = ' \Fee{'.$date."\n". - ' \begin{itemize*}'."\n"; - $output .= join('',map {" \\item $_\n"} @events); - $output .= ' \end{itemize*}}{50.00}{'.$time.'}'."\n"; + my %param = validate_with(params => \@_, + spec => {time => {type => SCALAR, + }, + date => {type => SCALAR, + }, + total => {type => SCALARREF, + }, + events => {type => ARRAYREF, + }, + }, + ); + ${$param{total}} += $param{time} * $hourly_rate; + + $param{date} =~ s/\s+\d+\:\d+\:\d+\s+[A-Z]{0,3}\s*//; + my $output = '\hline'."\n".' \mbox{'.$param{date}."}\n\n". + ' \begin{itemize*}'."\n"; + $output .= join('',map {" \\item $_\n"} @{$param{events}}); + $output .= ' \end{itemize*} & \$'.sprintf('%.2f',$hourly_rate).' & '.sprintf('%.2f',$param{time}). + ' & \$'.sprintf('%.2f',$param{time}*$hourly_rate).' & \$'. + sprintf('%.2f',${$param{total}}) . + ' \\'."\n"; return $output; } +print<<'EOF'; +\hline\hline +\multicolumn{4}{|r|}{\textbf{Total}} & \$% +EOF +print sprintf('%.2f',$total)."%\n"; +print<<'EOF'; +\\ +\hline +\end{longtable} +EOF