From: Don Armstrong Date: Sat, 14 Feb 2009 02:30:25 +0000 (+0000) Subject: update make invoice to handle new format X-Git-Url: https://git.donarmstrong.com/?p=bin.git;a=commitdiff_plain;h=8bb2301355a483d2e9c355de96d0321be3242353 update make invoice to handle new format --- diff --git a/make_invoice b/make_invoice index d8cf50f..dc0a2b9 100755 --- a/make_invoice +++ b/make_invoice @@ -21,9 +21,12 @@ make_invoice - makes invoices using latex make_invoice [options] Options: - --log, the log file to use to make the invoice - --template, the template to use to make the invoice - --svn, whether to use subversion or not + --log,-l the log file to use to make the invoice + --template,-t the template to use to make the invoice + --min-time-interval, -m minimum time to bill, default 0 + --time-granularity, -g time granularity, default 0 + --hourly-fee, -f hourly fee, default 50.00 + --svn,-s whether to use subversion or not --debug, -d debugging level (Default 0) --help, -h display this help --man, -m display manual @@ -89,12 +92,14 @@ use POSIX qw(ceil strftime); use Cwd qw(cwd); use Text::Template; +use Params::Validate qw(validate_with :types); + my %options = (log => undef, template => undef, svn => undef, invoice => undef, - time_interval => 0, - time_granularity => 0, + time_interval => 0.00, + time_granularity => 0.00, hourly_fee => '50.00', debug => 0, help => 0, @@ -135,9 +140,19 @@ my $template_fh = IO::File->new($options{template},'r') or my $calc_log = ''; -my $tex_log = ''; +my $tex_log = <<'EOF'; +\setlength\LTleft{0pt plus 1fill minus 1fill}% +\let\LTright\LTleft +\begin{longtable}{|p{9cm}|r|r|r|r|}% +% \caption*{} +\hline + \mbox{Description} & Item Cost & Quantity & Cost & Total \\ +\endhead +EOF my $totaldelta = undef; +my $total = 0; + my $first_date = undef; my $last_date = undef; my $time = undef; @@ -149,7 +164,11 @@ while (<$log_fh>) { chomp; if (/^\s*\* /) { if (defined $time) { - $tex_log .= format_events($date,$date2,$time,@events); + $tex_log .= format_events(date => $date, + date2 => $date2, + time => $time, + total => \$total, + events => \@events); @events = (); $date = undef; $time = undef; @@ -188,13 +207,29 @@ while (<$log_fh>) { } $calc_log .= "\nTotal: ".Delta_Format($totaldelta,2,q(%ht)).qq(\n); if (defined $time) { - $tex_log .= format_events($date,$date2,$time,@events); + $tex_log .= format_events(date => $date, + date2 => $date2, + time => $time, + total => \$total, + events => \@events); @events = (); $date = undef; $date2 = undef; $time = undef; } +$tex_log .= <<'EOF'; +\hline\hline +\multicolumn{4}{|r|}{\textbf{Total}} & \$% +EOF + +$tex_log .= sprintf('%.2f',$total)."%\n"; + +$tex_log .= <<'EOF'; +\\ +\hline +\end{longtable} +EOF my $template; { @@ -262,21 +297,49 @@ if ($options{svn}) { "invoice_${invoice_date}.tex", ) == 0 or die "Unable to add log and invoice to svn"; system('svn','propset','svn:ignore', - "*.aux\n*.log\n*.dvi\n*.ps\n*.pdf\n", + "*.aux\n*.log\n*.dvi\n*.ps\n*.pdf\nauto\n", '.' ) == 0 or die "Unable to set svn:ignore"; } sub format_events{ - my ($date,$date2,$time,@events) = @_; - my $output = ' \Fee{'.strftime('%A, %B %e, %H:%M',localtime(UnixDate($date,'%s'))). - ' to '.strftime('%H:%M %Z',localtime(UnixDate($date2,'%s')))."\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, + }, + date2 => {type => SCALAR, + }, + total => {type => SCALARREF, + }, + events => {type => ARRAYREF, + }, + }, + ); + ${$param{total}} += $param{time} * $options{hourly_fee}; + +# $param{date} =~ s/\s+\d+\:\d+\:\d+\s+[A-Z]{0,3}\s*//; + my $output = '\hline'."\n".' \mbox{'.strftime('%A, %B %e, %H:%M',localtime(UnixDate($param{date},'%s'))). + ' to '.strftime('%H:%M %Z',localtime(UnixDate($param{date2},'%s')))."}\n\n". + ' \begin{itemize*}'."\n"; + $output .= join('',map { s/_/\\_/g; " \\item $_\n";} @{$param{events}}); + $output .= ' \end{itemize*} & \$'.sprintf('%.2f',$options{hourly_fee}).' & '.sprintf('%.2f',$param{time}). + ' & \$'.sprintf('%.2f',$param{time}*$options{hourly_fee}).' & \$'. + sprintf('%.2f',${$param{total}}) . + " \\\\\n"; return $output; } +## sub format_events{ +## my ($date,$date2,$time,@events) = @_; +## my $output = ' \Fee{'.strftime('%A, %B %e, %H:%M',localtime(UnixDate($date,'%s'))). +## ' to '.strftime('%H:%M %Z',localtime(UnixDate($date2,'%s')))."\n". +## ' \begin{itemize*}'."\n"; +## $output .= join('',map {" \\item $_\n"} @events); +## $output .= ' \end{itemize*}}{50.00}{'.$time.'}'."\n"; +## return $output; +## } + __END__