From bdc133cce25309bc160f37da6232bfdc4dbb0ec0 Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Sun, 12 Sep 2010 06:24:25 +0000 Subject: [PATCH] update make invoice --- make_invoice | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/make_invoice b/make_invoice index eecbcc4..c0d79ba 100755 --- a/make_invoice +++ b/make_invoice @@ -104,6 +104,7 @@ my %options = (log => undef, debug => 0, help => 0, man => 0, + log_only => 0, ); GetOptions(\%options, @@ -111,6 +112,7 @@ GetOptions(\%options, 'time_granularity|time-granularity|g=s', 'time_interval|min-time-interval|T=s', 'hourly_fee|hourly-fee|f=s', + 'log_only|log-only', 'debug|d+','help|h|?','man|m'); pod2usage() if $options{help}; @@ -162,6 +164,7 @@ my @events; while (<$log_fh>) { chomp; + next if /^Total: \d+\.\d{2}$/; if (/^\s*\* /) { if (defined $time) { $tex_log .= format_events(date => $date, @@ -173,27 +176,28 @@ while (<$log_fh>) { $date = undef; $time = undef; } + s/\s*\[[\.\d]+\]\s*\[[\.\d]+\]\s*$//; my $string = $_; my ($d1,$d2) = map {s/^\s*\*\s*//; - ParseDate($_) + UnixDate(ParseDate($_),'%s') } split /\s*-\s*/; if (not defined $first_date) { $first_date = $d1; } $last_date = $d2; - my $delta = DateCalc($d1,$d2); - my $hours = Delta_Format($delta,0,'%ht'); + my $delta = $d2-$d1; + $date = $d1; + $date2 = $d2; + my $hours = $delta / (60*60); if ($hours < $options{time_interval}) { $hours = $options{time_interval} } - if ($options{time_granularity}) { + if ($options{time_granularity} > 0) { $hours = ceil($hours / $options{time_granularity})*$options{time_granularity}; } - $delta = ParseDateDelta($hours * 60 * 60 . ' sec'); - ($date,$date2) = ($d1,$d2); $time = $hours; - $totaldelta = defined($totaldelta)?DateCalc($delta,$totaldelta):$delta; - $calc_log .= qq($string [).Delta_Format($delta,2,q(%ht)).qq(] [).Delta_Format($totaldelta,2,q(%ht)).qq(]\n); + $totaldelta += $delta; + $calc_log .= qq($string [).sprintf('%.2f',$hours).qq(] [).sprintf('%.2f',$totaldelta/(60*60)).qq(]\n); } elsif (/^\s+-\s*(.+)/) { my $event = $1; @@ -205,7 +209,7 @@ while (<$log_fh>) { $calc_log .= $_.qq(\n); } } -$calc_log .= "\nTotal: ".Delta_Format($totaldelta,2,q(%ht)).qq(\n); +$calc_log .= "\nTotal: ".sprintf('%.2f',$totaldelta/(60*60)).qq(\n); if (defined $time) { $tex_log .= format_events(date => $date, date2 => $date2, @@ -237,8 +241,8 @@ my $template; $template = <$template_fh>; } -my $invoice_start = UnixDate($first_date,'%B %e, %Y'); -my $invoice_stop = UnixDate($last_date,'%B %e, %Y'); +my $invoice_start = strftime('%c',localtime($first_date)); +my $invoice_stop = strftime('%c',localtime($last_date)); my $tt = Text::Template->new(TYPE=>'string', SOURCE => $template, @@ -254,7 +258,12 @@ if (not defined $tex_invoice) { die $Text::Template::ERROR; } -my $invoice_date = UnixDate($last_date,'%m_%d_%Y'); +if ($options{log_only}) { + print $calc_log; + exit 0; +} + +my $invoice_date = strftime('%Y_%m_%d',localtime($last_date)); my $invoice_dir = "invoice_$invoice_date"; if (not -d $invoice_dir) { @@ -321,8 +330,8 @@ sub format_events{ ${$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". + my $output = '\hline'."\n".' \mbox{'.strftime('%A, %B %e, %H:%M',localtime($param{date})). + ' to '.strftime('%H:%M %Z',localtime($param{date2}))."}\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}). -- 2.39.2