die "I can't find the file: $filename\n"
unless -f $filename;
-print "Processing date range: " . UnixDate($start, '%Y-%m-%d') . " - " . UnixDate($end, '%Y-%m-%d') . "\n";
+print "Processing date range: " . UnixDate($start, '%Y-%m-%d') . " - " . UnixDate($end, '%Y-%m-%d') . "\n\n";
my $parser = iCal::Parser->new(
'start' => UnixDate($start, '%Y%m%d'),
my $events = $cal->{'events'};
my %clients;
+my %days;
+my $total_hours = 0;
use Data::Dumper;
for my $year (keys %{ $events }) {
$hours = 8
if defined $events->{$year}{$month}{$day}{$uid}{'allday'};
+ $dtstart =~ s/T/ /;
+ $desc =~ s/\\//g;
+
+ $total_hours += $hours;
+
+ # Days
+ my ($day) = split(/ /, $dtstart);
+ $days{$day}{lc($summary)}{'work'}{$desc} += $hours;
+ $days{$day}{lc($summary)}{'client'} ||= $summary;
+
+ # Clients
$clients{lc($summary)}{'work'}{$desc}{'hours'} += $hours;
+ $clients{lc($summary)}{'hours'} += $hours;
$clients{lc($summary)}{'client'} ||= $summary;
push @{ $clients{lc($summary)}{'work'}{$desc}{'times'} }, [ $hours, $dtstart ];
#print "event: $summary - $dtstart - $desc\n";
}
}
-for my $client (sort keys %clients) {
- print "$clients{$client}{'client'}:\n";
- for my $desc (sort keys %{ $clients{$client}{'work'} }) {
- print wrap(' ', ' ', $desc) . "\n";
+print_clients_summary();
+print "\n";
+print_clients();
+print "\n";
+print_days();
- for my $time (sort @{ $clients{$client}{'work'}{$desc}{'times'} }) {
- print detail_line($time->[0], $time->[1]);
- }
+print "Total Hours Worked: $total_hours\n\n";
- if (scalar(@{ $clients{$client}{'work'}{$desc}{'times'} }) > 1) {
- print detail_line($clients{$client}{'work'}{$desc}{'hours'}, 'Total');
+exit;
+
+sub detail_line {
+ my $indent = shift;
+ return sprintf((' ' x $indent) . "%2.2f - %s\n", @_);
+}
+
+sub print_clients_summary {
+ $Text::Wrap::columns = 78;
+ for my $client (sort keys %clients) {
+ print detail_line(2, $clients{$client}{'hours'}, $clients{$client}{'client'});
+ }
+}
+
+sub print_clients {
+ $Text::Wrap::columns = 78;
+ for my $client (sort keys %clients) {
+ print "$clients{$client}{'client'}:\n";
+ print detail_line(2, $clients{$client}{'hours'}, 'Client Total');
+ print "\n";
+
+ for my $desc (sort keys %{ $clients{$client}{'work'} }) {
+ print wrap(' ', ' ', $desc) . "\n";
+
+ for my $time (sort { $a->[1] cmp $b->[1] } @{ $clients{$client}{'work'}{$desc}{'times'} }) {
+ print detail_line(4, $time->[0], $time->[1]);
+ }
+
+ if (scalar(@{ $clients{$client}{'work'}{$desc}{'times'} }) > 1) {
+ print detail_line(4, $clients{$client}{'work'}{$desc}{'hours'}, 'Total');
+ }
}
+
+ print "\n";
}
- print "\n";
}
-sub detail_line {
- return sprintf(" %5.2f - %s\n", @_);
+sub print_days {
+ $Text::Wrap::columns = 70;
+ for my $day (sort keys %days) {
+ print "$day:\n";
+
+ for my $client (sort keys %{ $days{$day} }) {
+ for my $desc (sort keys %{ $days{$day}{$client}{'work'} }) {
+ print detail_line(2, $days{$day}{$client}{'work'}{$desc}, wrap('', ' ', "$days{$day}{$client}{'client'} - $desc"));
+ }
+ }
+
+ print "\n";
+ }
}
-
+