# \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;
}
}
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