File Coverage

blib/lib/App/TimeClock/Daily/HtmlPrinter.pm
Criterion Covered Total %
statement 21 21 100.0
branch 1 2 50.0
condition n/a
subroutine 4 4 100.0
pod 3 3 100.0
total 29 30 96.6


line stmt bran cond sub pod time code
1             package App::TimeClock::Daily::HtmlPrinter;
2              
3             our @ISA = qw(App::TimeClock::Daily::PrinterInterface);
4              
5 1     1   385 use POSIX qw(strftime);
  1         1  
  1         4  
6              
7             =head1 NAME
8              
9             App::TimeClock::Daily::HtmlPrinter
10              
11             =head1 DESCRIPTION
12              
13             Implements the L. Will print a
14             (simple) HTML report with embedded (CSS) styling.
15              
16             =head1 METHODS
17              
18             =over
19              
20             =cut
21              
22             =item print_header()
23              
24             Prints a standard HTML header, i.e. DOCTYPE followed by an opening html
25             tag and a head tag. The head will contain a title with todays date and
26             an embedded (css) style. A body tag will open and an h1 header with
27             todays day will be printed. The body and html tags will be closed in the
28             L method.
29              
30             =cut
31             sub print_header {
32 3     3 1 4 my $self = shift;
33 3         40 my $title = "Daily Report " . localtime();
34              
35 3         18 $self->_print(<< "EOD");
36            
37            
38             $title
39            

$title

53             EOD
54              
55             };
56              
57             =item print_day()
58              
59             Prints all activities for a day including a total. Is printed in a
60             standard HTML table.
61              
62             =cut
63             sub print_day {
64 4     4 1 12 my ($self, $date, $start, $end, $work, %projects) = (@_);
65 4         10 my ($year, $mon, $mday) = split(/\//, $date);
66 4         65 my $wday = substr(strftime("%a", 0, 0, 0, $mday, $mon-1, $year-1900),0,3);
67              
68 4         26 $self->_print(sprintf("\n", $wday, $date, $start, $end)); \n", $work)); \n", $k, $projects{$k}));
%3s %s (%s - %s)
69 4         34 $self->_print(sprintf("
Total Daily Hours%5.2f
70              
71 4         13 foreach my $k (sort keys %projects) {
72 10         59 $self->_print(sprintf("
%-60s%5.2f
73             }
74 4         9 $self->_print("
\n");
75             };
76              
77             =item print_footer()
78              
79             Prints the total number of hours worked and the daily average and closes
80             the body and html tags.
81              
82             =cut
83             sub print_footer {
84 3     3 1 7 my ($self, $work_year_to_date, $day_count) = (@_);
85 3         4 $self->_print("

");

86 3         15 $self->_print(sprintf("TOTAL = %.2f
", $work_year_to_date));
87 3         7 $self->_print(sprintf("PERIOD = %d days
", $day_count));
88 3 50       18 $self->_print(sprintf("AVG. DAY = %.2f
", $day_count > 0 ? $work_year_to_date / $day_count : 0));
89 3         6 $self->_print("

\n");
90 3         4 $self->_print("\n");
91             };
92             1;
93              
94             =back
95              
96             =for text
97             =encoding utf-8
98             =end
99              
100             =head1 AUTHOR
101              
102             Søren Lund, C<< >>
103              
104             =head1 SEE ALSO
105              
106             L
107              
108             =head1 COPYRIGHT
109              
110             Copyright (C) 2012-2015 Søren Lund
111              
112             This file is part of App::TimeClock.
113              
114             App::TimeClock is free software: you can redistribute it and/or modify
115             it under the terms of the GNU General Public License as published by
116             the Free Software Foundation, either version 3 of the License, or
117             (at your option) any later version.
118              
119             App::TimeClock is distributed in the hope that it will be useful,
120             but WITHOUT ANY WARRANTY; without even the implied warranty of
121             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
122             GNU General Public License for more details.
123              
124             You should have received a copy of the GNU General Public License
125             along with App::TimeClock. If not, see .