X-Git-Url: https://git.donarmstrong.com/?p=bin.git;a=blobdiff_plain;f=latexize_invoice;h=e40789afd5362719a355592216e7cc37771924ee;hp=1418b46e9c2b1e9762c517dbf80856fe5e5d16e0;hb=3d5241a316e3ff729b19b878b0841558120f75e9;hpb=57454875143747f5425969ceda59fc900eef62dd diff --git a/latexize_invoice b/latexize_invoice index 1418b46..e40789a 100755 --- a/latexize_invoice +++ b/latexize_invoice @@ -10,16 +10,40 @@ # \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*\[[^\]]+\]/) { + if (/^\s*\*\s*([^-]+)\s+-.+\[([^\]]+)\]\s*\[[^\]]+\]/) { if (defined $time) { - print format_events($time,@events); + print format_events(date => $date, + time => $time, + total => \$total, + events => \@events); } @events = (); - $time = $1; + $date = $1; + $time = $2; } if (/^\s+\-\s*(.+)/) { my $event = $1; @@ -28,13 +52,43 @@ while (<>){ } } if (defined $time) { - print format_events($time,@events); + print format_events(date => $date, + time => $time, + total => \$total, + events => \@events); } sub format_events{ - my ($time,@events) = @_; - my $output = ' \Fee{\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