Skip to content

Commit cb014d5

Browse files
author
Buddy Burden
committed
=> can now specify a tracking code with -t switch
=> gives total time for that tracking code, including DB time and unlogged time
1 parent c11bded commit cb014d5

File tree

2 files changed

+60
-18
lines changed

2 files changed

+60
-18
lines changed

Barefoot/T3/db_get.pm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ sub get_logs
187187
my $start_date = '{BEGINNING_OF_TIME}';
188188
my $end_date = '{END_OF_TIME}';
189189
my $client_clause = '1 = 1';
190+
my $tracking_clause = '1 = 1';
190191

191192
if ($opts->{'DATE'})
192193
{
@@ -200,22 +201,28 @@ sub get_logs
200201
die("get logs: don't know how to set date for $opts->{'DATE'}");
201202
}
202203
}
204+
debuggit(3 => "get_logs: start date", $start_date, "end date", $end_date);
203205
if ($opts->{'CLIENT'})
204206
{
205207
$client_clause = 'l.client_id = {client}';
206208
}
207-
debuggit(3 => "get_logs: start date", $start_date, "end date", $end_date);
209+
if ($opts->{'TRACKING'})
210+
{
211+
$tracking_clause = 'l.tracking_code = {tracking}';
212+
}
208213

209214
my $data = &t3->load_data(qq{
210215
select l.client_id, l.proj_id, l.log_date, l.hours
211216
from {~timer}.time_log l
212217
where l.emp_id = {emp}
213218
and $client_clause
219+
and $tracking_clause
214220
and l.log_date between {start} and {end}
215221
order by l.log_date
216222
},
217223
emp => $emp_id, start => $start_date, end => $end_date,
218224
client => $opts->{'CLIENT'},
225+
tracking => $opts->{'TRACKING'},
219226
);
220227
die("get logs query failed:", &t3->last_error()) unless $data;
221228

t3/timer/timer

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use File::HomeDir;
2929
use Config::General;
3030
use Time::ParseDate;
3131

32-
use Barefoot;
32+
use Barefoot(DEBUG => 1);
3333
use Barefoot::range;
3434
use Barefoot::format;
3535
use Barefoot::exception;
@@ -406,54 +406,88 @@ if ($command eq 'TOTAL') # total timers by client
406406
exit;
407407
}
408408

409+
# setup variables, needed regardless of type of total required
409410
my $totals = {};
411+
my $emp_id = get_emp_id($mod->user);
412+
my $tracking_to_total = $ARGV[0]; # 1st arg for this is a tracking code (or nothing)
413+
debuggit(2 => "for TOTAL, tracking is", $tracking_to_total);
410414
my $min_time = rc_param(TOTAL => 'mintime') || 0;
411415
my %ignore_timers = map { $_ => 1 } rc_list(TOTAL => 'ignore');
412416

413417
foreach ($mod->values($timers))
414418
{
415419
next if exists $ignore_timers{$_->{name}};
420+
debuggit(4 => "checking timer", $_->{'name'}, "and found tracking code", $_->{'tracking'},
421+
"when looking for tracking code", $tracking_to_total);
422+
next if $tracking_to_total and $_->{'tracking'} ne $tracking_to_total;
416423

417424
my $client = $_->{'client'} || '???';
418425
my $proj = $_->{'project'} || '???';
426+
my $tracking = $_->{'tracking'} || '???';
427+
debuggit(3 => "TOTALling timer", $_->{'name'}, "got client/proj/tracking", $client, $proj, $tracking);
419428

420429
my $hrs = rounded_time($client, $_->{'time'});
421430
$hrs = $min_time if calc_time($_->{'time'}) > 0 and $hrs < $min_time;
422-
$totals->{$client}->{$proj} += $hrs;
423-
$totals->{$client}->{':TOTAL'} += $hrs;
431+
if ($tracking_to_total) # just total for this tracking code
432+
{
433+
$totals->{$client}->{$tracking} += $hrs;
434+
}
435+
else # total by client/proj for "this week"
436+
{
437+
$totals->{$client}->{$proj} += $hrs;
438+
$totals->{$client}->{':TOTAL'} += $hrs;
439+
}
424440
}
425441

426-
my $emp_id = get_emp_id($mod->user);
427-
my $logs = get_logs($emp_id, { DATE => 'THIS_WEEK' });
442+
my $logs = get_logs($emp_id, $tracking_to_total ? { TRACKING => $tracking_to_total } : { DATE => 'THIS_WEEK' });
428443
debuggit(2 => "found", scalar(@$logs), "logs in the DB to total");
429444
foreach (@$logs)
430445
{
431446
my $hrs = $_->{'hours'};
432-
$totals->{$_->{'client_id'}}->{$_->{'proj_id'}} += $hrs;
433-
$totals->{$_->{'client_id'}}->{':TOTAL'} += $hrs;
447+
if ($tracking_to_total)
448+
{
449+
$totals->{$_->{'client_id'}}->{$tracking_to_total} += $hrs;
450+
}
451+
else
452+
{
453+
$totals->{$_->{'client_id'}}->{$_->{'proj_id'}} += $hrs;
454+
$totals->{$_->{'client_id'}}->{':TOTAL'} += $hrs;
455+
}
434456
}
435457

436-
my (%clients, %projects);
458+
my (%clients, %subcats);
437459
foreach my $client (keys %$totals)
438460
{
439461
$clients{$client} = eval { one_datum("select name from {~timer}.client where client_id = '$client'") } || '???';
440-
foreach my $proj (keys %{$totals->{$client}})
462+
foreach my $thing (keys %{$totals->{$client}})
441463
{
442-
my $proj_query = "select name from {~timer}.project where client_id = '$client' and proj_id = '$proj'";
443-
$projects{$client}->{$proj} = eval { one_datum($proj_query) } || '???';
464+
if ($tracking_to_total)
465+
{
466+
my $query = 'select name from {@client_tracking} '
467+
. "where client_id = '$client' and tracking_code = '$thing'";
468+
$subcats{$client}->{$thing} = eval { one_datum($query) } || '???';
469+
}
470+
else
471+
{
472+
my $query = 'select name from {@project} ' . "where client_id = '$client' and proj_id = '$thing'";
473+
$subcats{$client}->{$thing} = eval { one_datum($query) } || '???';
474+
}
444475
}
445476
}
446477

447478
foreach my $client (sort keys %$totals)
448479
{
449480
my $total_hrs = delete $totals->{$client}->{':TOTAL'};
450-
next unless $total_hrs;
451-
print "-" x length(Totals_Header), "\n";
452-
writeln(Totals_Header, $client, $clients{$client}, $total_hrs);
481+
if ($total_hrs)
482+
{
483+
print "-" x length(Totals_Header), "\n";
484+
writeln(Totals_Header, $client, $clients{$client}, $total_hrs);
485+
}
453486

454-
foreach my $proj (sort keys %{$totals->{$client}})
487+
foreach my $thing (sort keys %{$totals->{$client}})
455488
{
456-
writeln(Totals, $proj, $projects{$client}->{$proj}, $totals->{$client}->{$proj}) if $totals->{$client}->{$proj};
489+
writeln(Totals, $thing, $subcats{$client}->{$thing}, $totals->{$client}->{$thing})
490+
if $totals->{$client}->{$thing};
457491
}
458492
}
459493

@@ -777,7 +811,8 @@ sub usage
777811
" -T: tracking code to use (no default)\n",
778812
" clientcode, projcode, and phasecode must be a valid 3-character code (will be forced to uppercase)\n",
779813
" trackingcode is freeform and will not be case adjusted\n",
780-
" timername is ignored for -p, -e, -l, -L, and -t\n",
814+
" timername is ignored for -p, -e, -l, and -L\n",
815+
" timername is treated as a tracking code to total up (total for all time) for -t\n",
781816
" timername for other functions defaults to the running timer, if any\n",
782817
" newtimername is ignored for all but -r and -i\n",
783818
);

0 commit comments

Comments
 (0)