File Coverage

blib/lib/App/TimeClock/Daily/HtmlPrinter.pm
Criterion Covered Total %
statement 27 27 100.0
branch 1 2 50.0
condition n/a
subroutine 6 6 100.0
pod 3 3 100.0
total 37 38 97.3


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

$title

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

");

89 3         14 $self->_print(sprintf("TOTAL = %.2f
", $work_year_to_date));
90 3         9 $self->_print(sprintf("PERIOD = %d days
", $day_count));
91 3 50       16 $self->_print(sprintf("AVG. DAY = %.2f
", $day_count > 0 ? $work_year_to_date / $day_count : 0));
92 3         7 $self->_print("

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