@@ -29,7 +29,7 @@ use File::HomeDir;
29
29
use Config::General;
30
30
use Time::ParseDate;
31
31
32
- use Barefoot;
32
+ use Barefoot( DEBUG => 1) ;
33
33
use Barefoot::range;
34
34
use Barefoot::format;
35
35
use Barefoot::exception;
@@ -406,54 +406,88 @@ if ($command eq 'TOTAL') # total timers by client
406
406
exit ;
407
407
}
408
408
409
+ # setup variables, needed regardless of type of total required
409
410
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 );
410
414
my $min_time = rc_param(TOTAL => ' mintime' ) || 0;
411
415
my %ignore_timers = map { $_ => 1 } rc_list(TOTAL => ' ignore' );
412
416
413
417
foreach ($mod -> values ($timers ))
414
418
{
415
419
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 ;
416
423
417
424
my $client = $_ -> {' client' } || ' ???' ;
418
425
my $proj = $_ -> {' project' } || ' ???' ;
426
+ my $tracking = $_ -> {' tracking' } || ' ???' ;
427
+ debuggit(3 => " TOTALling timer" , $_ -> {' name' }, " got client/proj/tracking" , $client , $proj , $tracking );
419
428
420
429
my $hrs = rounded_time($client , $_ -> {' time' });
421
430
$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
+ }
424
440
}
425
441
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' });
428
443
debuggit(2 => " found" , scalar (@$logs ), " logs in the DB to total" );
429
444
foreach (@$logs )
430
445
{
431
446
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
+ }
434
456
}
435
457
436
- my (%clients , %projects );
458
+ my (%clients , %subcats );
437
459
foreach my $client (keys %$totals )
438
460
{
439
461
$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 }})
441
463
{
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
+ }
444
475
}
445
476
}
446
477
447
478
foreach my $client (sort keys %$totals )
448
479
{
449
480
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
+ }
453
486
454
- foreach my $proj (sort keys %{$totals -> {$client }})
487
+ foreach my $thing (sort keys %{$totals -> {$client }})
455
488
{
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 };
457
491
}
458
492
}
459
493
@@ -777,7 +811,8 @@ sub usage
777
811
" -T: tracking code to use (no default)\n " ,
778
812
" clientcode, projcode, and phasecode must be a valid 3-character code (will be forced to uppercase)\n " ,
779
813
" 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 " ,
781
816
" timername for other functions defaults to the running timer, if any\n " ,
782
817
" newtimername is ignored for all but -r and -i\n " ,
783
818
);
0 commit comments