5 % # 'title' => 'Page title',
6 % # 'items' => \@items,
7 % # 'params' => \@params, # opt,
8 % # 'labels' => \@labels, # or \%labels (keys are items)
9 % # 'graph_labels' => \@graph_labels, # or \%graph_labels,
10 % # 'colors' => \@colors, # or \%colors,
11 % # 'links => \@links, # or \%link, #opt
12 % # 'start_month' => $smonth,
13 % # 'start_year' => $syear,
14 % # 'end_month' => $emonth,
15 % # 'end_year' => $eyear,
16 % # 'agentnum' => $agentnum, #opt
17 % # 'nototal' => 1, #opt,
18 % # 'graph_type' => 'LinesPoints', #opt
19 % # 'remove_empty' => 1, #opt,
20 % # 'bottom_total' => 1, #opt,
23 % my @items = @{ $opt{'items'} };
25 % foreach my $other (qw( labels graph_labels colors links )) {
26 % #foreach my $other (qw( labels graph_labels colors )) {
27 % if ( ref($opt{$other}) eq 'HASH' ) {
28 % $opt{$other} = [ map $opt{$other}{$_}, @items ];
32 % my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
34 % my $report = new FS::Report::Table::Monthly (
36 % #'items' => $opt{'items'},
38 % 'params' => $opt{'params'},
39 % 'item_labels' => ( $cgi->param('_type') =~ /^(png)$/
40 % ? $opt{'graph_labels'}
43 % 'colors' => $opt{'colors'},
44 % 'links' => $opt{'links'},
46 % 'start_month' => $opt{'start_month'},
47 % 'start_year' => $opt{'start_year'},
48 % 'end_month' => $opt{'end_month'},
49 % 'end_year' => $opt{'end_year'},
51 % 'agentnum' => $opt{'agentnum'},
52 % 'remove_empty' => $opt{'remove_empty'},
54 % my $data = $report->data;
56 % if ( $cgi->param('_type') =~ /^(csv)$/ ) {
58 % #http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes
59 % http_header('Content-Type' => 'text/plain' );
61 % my $csv = new Text::CSV_XS { 'always_quote' => 1,
62 % 'eol' => "\n", #"\015\012", #"\012"
65 % $csv->combine(map { my $m=$_; $m =~ s/^(\d+)\//$mon[$1-1] /; $m; }
66 % ('', @{$data->{label}}, $opt{'nototal'} ? () : 'Total')
71 % my @bottom_total = ();
72 % foreach ( @{ $data->{'items'} } ) {
77 % shift( @{ $data->{'item_labels'} } ),
78 % map { $total += $_; $bottom_total[$col++] += $_; sprintf("%.2f", $_); }
79 % ( @{ shift( @{$data->{data}} ) } ),
80 % ( $opt{'nototal'} ? () : sprintf("%.2f", $total) ),
82 % unless ( $opt{'nototal'} ) {
83 % $bottom_total[$col++] += $total;
90 % if ( $opt{'bottom_total'} ) {
93 % map { sprintf("%.2f", $_) } @bottom_total,
100 % } elsif ( $cgi->param('_type') =~ /(\.xls)$/ ) {
102 % #http_header('Content-Type' => 'application/excel' ); #eww
103 % http_header('Content-Type' => 'application/vnd.ms-excel' );
104 % #http_header('Content-Type' => 'application/msexcel' ); #alas
107 % my $XLS = new IO::Scalar \$output;
108 % my $workbook = Spreadsheet::WriteExcel->new($XLS)
109 % or die "Error opening .xls file: $!";
111 % my $worksheet = $workbook->add_worksheet(substr($opt{'title'},0,31));
115 % foreach ('', @{$data->{label}}, ($opt{'nototal'} ? () : 'Total') ) {
117 % $header =~ s/^(\d+)\//$mon[$1-1] /;
118 % $worksheet->write($r, $c++, $header)
121 % my @bottom_total = ();
122 % foreach ( @{ $data->{'items'} } ) {
126 % $worksheet->write( $r, $c++, shift( @{ $data->{'item_labels'} } ) );
127 % foreach ( @{ shift( @{$data->{data}} ) } ) {
129 % $bottom_total[$c] += $_;
130 % $worksheet->write($r, $c++, sprintf("%.2f", $_) );
132 % unless ( $opt{'nototal'} ) {
133 % $bottom_total[$c] += $total;
134 % $worksheet->write($r, $c++, sprintf("%.2f", $total) );
139 % if ( $opt{'bottom_total'} ) {
141 % $worksheet->write($r, $c++, 'Total');
142 % $worksheet->write($r, $c++, sprintf("%.2f", $_)) foreach @bottom_total;
145 % $workbook->close();# or die "Error creating .xls file: $!";
147 % http_header('Content-Length' => length($output) );
150 % } elsif ( $cgi->param('_type') =~ /^(png)$/ ) {
152 % #my $chart = Chart::LinesPoints->new(1024,480);
153 % #my $chart = Chart::LinesPoints->new(768,480);
155 % my $graph_type = 'LinesPoints';
156 % if ( $opt{'graph_type'} =~ /^(LinesPoints|Mountain)$/ ) {
159 % my $class = "Chart::$graph_type";
161 % my $chart = $class->new(976,384);
166 % 'legend' => 'bottom',
168 % map { my $color = $_;
170 % [ map hex($_), unpack 'a2a2a2', $color ]
172 % #@{ $opt{'colors'} }
173 % @{ $data->{'colors'} }
175 % #'grey_background' => [ 211, 211, 211 ],
176 % 'grey_background' => 'white',
177 % 'background' => [ 0xe8, 0xe8, 0xe8 ], #grey
179 % #'grey_background' => 'false',
180 % 'legend_labels' => $data->{'item_labels'},
185 % #my @data = map { $data->{$_} } ( 'label', @items );
186 % my @data = @{ $data->{data} };
187 % unshift @data, $data->{'label'};
189 % http_header('Content-Type' => 'image/png' );
191 % $chart->_set_colors();
194 <% $chart->scalar_png(\@data) %>
199 <% include('/elements/header.html', $opt{'title'} ) %>
200 % $cgi->param('_type', 'png');
202 <IMG SRC="<% $cgi->self_url %>" WIDTH="976" HEIGHT="384">
205 % unless ( $opt{'disable_download'} ) {
206 % $cgi->param('_type', "monthly.xls" );
207 Download full results
208 as <A HREF="<% $cgi->self_url %>">Excel spreadsheet</A>
209 % $cgi->param('_type', 'csv');
210 as <A HREF="<% $cgi->self_url %>">CSV file</A></P>
211 % $cgi->param('_type', "html" );
215 <% include('/elements/table.html', 'e8e8e8') %>
220 % foreach my $column ( @{$data->{label}} ) {
221 % #$column =~ s/^(\d+)\//$mon[$1-1]<BR>/e;
222 % $column =~ s/^(\d+)\//$mon[$1-1]<BR>/;
225 <TH><% $column %></TH>
227 % unless ( $opt{'nototal'} ) {
234 % my @bottom_total = ();
235 % foreach my $row ( @{ $data->{'items'} } ) {
237 % #my $color = shift( @{ $opt{'colors'} } );
238 % my $color = shift( @{ $data->{'colors'} } );
239 % my $link = shift( @{ $data->{'links'} } );
240 % $link = $link ? qq(<A HREF="$link) : '';
246 <TH><FONT COLOR="#<% $color %>"><% shift( @{ $data->{'item_labels'} } ) %></FONT></TH>
247 % #my $link = exists($opt{'links'}{$row})
248 % # ? qq(<A HREF="$opt{'links'}{$row})
250 % my @speriod = @{$data->{speriod}};
251 % my @eperiod = @{$data->{eperiod}};
255 % foreach my $column ( @{ shift( @{$data->{data}} ) } ) { # ( @{$data->{$row}} ) {
259 <TD ALIGN="right" BGCOLOR="#ffffff">
260 <% $link ? $link. 'begin='. shift(@speriod). ';end='. shift(@eperiod). '">' : '' %><FONT COLOR="#<% $color %>">$<% sprintf("%.2f", $column) %></FONT><% $link ? '</A>' : '' %>
264 % $bottom_total[$col++] += $column;
267 % unless ( $opt{'nototal'} ) {
270 <TD ALIGN="right" BGCOLOR="#f5f6be">
271 <% $link ? $link. 'begin='. ${$data->{speriod}}[0]. ';end='. ${$data->{eperiod}}[-1]. '">' : '' %><FONT COLOR="#<% $color %>">$<% sprintf("%.2f", $total) %></FONT><% $link ? '</A>' : '' %>
273 % $bottom_total[$col++] += $total;
279 % if ( $opt{'bottom_total'} ) {
280 % my @speriod = ( @{$data->{speriod}}, ${$data->{speriod}}[0] );
281 % my @eperiod = ( @{$data->{eperiod}}, ${$data->{eperiod}}[-1] );
287 % foreach my $total ( @bottom_total ) {
290 <TD ALIGN="right" BGCOLOR="#f5f6be">
291 <% $opt{'bottom_link'}
292 ? '<A HREF="'. $opt{'bottom_link'}.
293 'begin='. shift(@speriod).
294 ';end='. shift(@eperiod). '">'
296 %>$<% sprintf("%.2f", $total) %><% $opt{'bottom_link'} ? '</A>' : '' %>
308 <% include('/elements/footer.html') %>