5 include('elements/monthly.html',
7 'title' => 'Page title',
9 'labels' => \@labels, # or \%labels (keys are items)
12 'colors' => \@colors, # or \%colors,
15 'graph_labels' => \@graph_labels, # or \%graph_labels,
18 'params' => \@params, # opt,
19 'links' => \@links, # or \%link, #opt
20 'link_fromparam' => 'param_from', #defaults to 'begin'
21 'link_toparam' => 'param_to', #defaults to 'end'
23 #optional, pulled from CGI params if not specified
24 'start_month' => $smonth,
25 'start_year' => $syear,
26 'end_month' => $emonth,
30 'agentnum' => $agentnum,
32 'graph_type' => 'LinesPoints',
35 'sprintf' => '%u', #sprintf format, overrides default %.2f
40 % if ( $cgi->param('_type') =~ /^(csv)$/ ) {
42 % #http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes
43 % http_header('Content-Type' => 'text/plain' );
45 % my $csv = new Text::CSV_XS { 'always_quote' => 1,
46 % 'eol' => "\n", #"\015\012", #"\012"
49 % $csv->combine(map { my $m=$_; $m =~ s/^(\d+)\//$mon[$1-1] /; $m; }
50 % ('', @{$data->{label}}, $opt{'nototal'} ? () : 'Total')
55 % my @bottom_total = ();
56 % foreach ( @{ $data->{'items'} } ) {
61 % shift( @{ $data->{'item_labels'} } ),
62 % map { $total += $_; $bottom_total[$col++] += $_; sprintf($sprintf, $_); }
63 % ( @{ shift( @{$data->{data}} ) } ),
64 % ( $opt{'nototal'} ? () : sprintf($sprintf, $total) ),
66 % unless ( $opt{'nototal'} ) {
67 % $bottom_total[$col++] += $total;
74 % if ( $opt{'bottom_total'} ) {
77 % map { sprintf($sprintf, $_) } @bottom_total,
84 % } elsif ( $cgi->param('_type') =~ /(\.xls)$/ ) {
86 % #http_header('Content-Type' => 'application/excel' ); #eww
87 % http_header('Content-Type' => 'application/vnd.ms-excel' );
88 % #http_header('Content-Type' => 'application/msexcel' ); #alas
91 % my $XLS = new IO::Scalar \$output;
92 % my $workbook = Spreadsheet::WriteExcel->new($XLS)
93 % or die "Error opening .xls file: $!";
95 % my $worksheet = $workbook->add_worksheet(substr($opt{'title'},0,31));
99 % foreach ('', @{$data->{label}}, ($opt{'nototal'} ? () : 'Total') ) {
101 % $header =~ s/^(\d+)\//$mon[$1-1] /;
102 % $worksheet->write($r, $c++, $header)
105 % my @bottom_total = ();
106 % foreach ( @{ $data->{'items'} } ) {
110 % $worksheet->write( $r, $c++, shift( @{ $data->{'item_labels'} } ) );
111 % foreach ( @{ shift( @{$data->{data}} ) } ) {
113 % $bottom_total[$c] += $_;
114 % $worksheet->write($r, $c++, sprintf($sprintf, $_) );
116 % unless ( $opt{'nototal'} ) {
117 % $bottom_total[$c] += $total;
118 % $worksheet->write($r, $c++, sprintf($sprintf, $total) );
123 % if ( $opt{'bottom_total'} ) {
125 % $worksheet->write($r, $c++, 'Total');
126 % $worksheet->write($r, $c++, sprintf($sprintf, $_)) foreach @bottom_total;
129 % $workbook->close();# or die "Error creating .xls file: $!";
131 % http_header('Content-Length' => length($output) );
134 % } elsif ( $cgi->param('_type') =~ /^(png)$/ ) {
136 % #my $chart = Chart::LinesPoints->new(1024,480);
137 % #my $chart = Chart::LinesPoints->new(768,480);
139 % my $graph_type = 'LinesPoints';
140 % if ( $opt{'graph_type'} =~ /^(LinesPoints|Mountain)$/ ) {
143 % my $class = "Chart::$graph_type";
145 % my $chart = $class->new(976,384);
150 % 'legend' => 'bottom',
152 % map { my $color = $_;
154 % [ map hex($_), unpack 'a2a2a2', $color ]
156 % #@{ $opt{'colors'} }
157 % @{ $data->{'colors'} }
159 % #'grey_background' => [ 211, 211, 211 ],
160 % 'grey_background' => 'white',
161 % 'background' => [ 0xe8, 0xe8, 0xe8 ], #grey
163 % #'grey_background' => 'false',
164 % 'legend_labels' => $data->{'item_labels'},
169 % #my @data = map { $data->{$_} } ( 'label', @items );
170 % my @data = @{ $data->{data} };
171 % unshift @data, $data->{'label'};
173 % http_header('Content-Type' => 'image/png' );
175 % $chart->_set_colors();
177 <% $chart->scalar_png(\@data) %>
181 <% include('/elements/header.html', $opt{'title'} ) %>
182 % $cgi->param('_type', 'png');
184 <IMG SRC="<% $cgi->self_url %>" WIDTH="976" HEIGHT="384">
187 % unless ( $opt{'disable_download'} ) {
188 % $cgi->param('_type', "monthly.xls" );
189 Download full results<BR>
190 as <A HREF="<% $cgi->self_url %>">Excel spreadsheet</A><BR>
191 % $cgi->param('_type', 'csv');
192 as <A HREF="<% $cgi->self_url %>">CSV file</A></P>
193 % $cgi->param('_type', "html" );
197 <% include('/elements/table.html', 'e8e8e8') %>
203 % foreach my $column ( @{$data->{label}} ) {
204 % #$column =~ s/^(\d+)\//$mon[$1-1]<BR>/e;
205 % $column =~ s/^(\d+)\//$mon[$1-1]<BR>/;
206 <TH><% $column %></TH>
209 % unless ( $opt{'nototal'} ) {
215 % my @bottom_total = ();
216 % foreach my $row ( @{ $data->{'items'} } ) {
218 % #my $color = shift( @{ $opt{'colors'} } );
219 % my $color = shift( @{ $data->{'colors'} } );
220 % my $link = shift( @{ $data->{'links'} } );
221 % my ( $begin, $end ) = ( $fromparam, $toparam );
222 % if ( ref($link) ) {
224 % $link = $ref->{link};
225 % $begin = $ref->{fromparam};
226 % $end = $ref->{toparam};
228 % $link = $link ? qq(<A HREF="$link) : '';
229 % my $label = shift( @{ $data->{'item_labels'} } );
234 <FONT COLOR="#<% $color %>"><% $label %></FONT>
237 % #my $link = exists($opt{'links'}{$row})
238 % # ? qq(<A HREF="$opt{'links'}{$row})
240 % my @speriod = @{$data->{speriod}};
241 % my @eperiod = @{$data->{eperiod}};
245 % foreach my $column ( @{ shift( @{$data->{data}} ) } ) {
247 <TD ALIGN="right" BGCOLOR="#ffffff">
248 <% $link ? $link. "$begin=". shift(@speriod). ";$end=". shift(@eperiod). '">' : '' %><FONT COLOR="#<% $color %>"><% $money_char %><% sprintf($sprintf,, $column) %></FONT><% $link ? '</A>' : '' %>
252 % $bottom_total[$col++] += $column;
256 % unless ( $opt{'nototal'} ) {
257 <TD ALIGN="right" BGCOLOR="#f5f6be">
258 <% $link ? $link. "$begin=". ${$data->{speriod}}[0]. ";$end=". ${$data->{eperiod}}[-1]. '">' : '' %><FONT COLOR="#<% $color %>"><% $money_char %><% sprintf($sprintf, $total) %></FONT><% $link ? '</A>' : '' %>
260 % $bottom_total[$col++] += $total;
267 % if ( $opt{'bottom_total'} ) {
268 % my @speriod = ( @{$data->{speriod}}, ${$data->{speriod}}[0] );
269 % my @eperiod = ( @{$data->{eperiod}}, ${$data->{eperiod}}[-1] );
274 % foreach my $total ( @bottom_total ) {
276 <TD ALIGN="right" BGCOLOR="#f5f6be">
277 <% $opt{'bottom_link'}
278 ? '<A HREF="'. $opt{'bottom_link'}.
279 "$fromparam=". shift(@speriod).
280 ";$toparam=". shift(@eperiod). '">'
282 %>$<% sprintf($sprintf, $total) %><% $opt{'bottom_link'} ? '</A>' : '' %>
294 <% include('/elements/footer.html') %>
303 my $sprintf = $opt{'sprintf'} || '%.2f';
304 my $fromparam = $opt{'link_fromparam'} || 'begin';
305 my $toparam = $opt{'link_toparam'} || 'end';
307 my $conf = new FS::Conf;
308 my $money_char = $opt{'disable_money'} ? '' : $conf->config('money_char');
310 my @items = @{ $opt{'items'} };
312 foreach my $other (qw( labels graph_labels colors links )) {
313 #foreach my $other (qw( labels graph_labels colors )) {
314 if ( ref($opt{$other}) eq 'HASH' ) {
315 $opt{$other} = [ map $opt{$other}{$_}, @items ];
319 my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
322 $opt{'start_month'} ||= $cgi->param('start_month'); # || $curmon+1;
323 $opt{'start_year'} ||= $cgi->param('start_year'); # || 1899+$curyear;
326 $opt{'end_month'} ||= $cgi->param('end_month'); # || $curmon+1;
327 $opt{'end_year'} ||= $cgi->param('end_year'); # || 1900+$curyear;
329 my $report = new FS::Report::Table::Monthly (
331 #'items' => $opt{'items'},
333 'params' => $opt{'params'},
334 'item_labels' => ( $cgi->param('_type') =~ /^(png)$/
335 ? $opt{'graph_labels'}
338 'colors' => $opt{'colors'},
339 'links' => $opt{'links'},
341 'start_month' => $opt{'start_month'},
342 'start_year' => $opt{'start_year'},
343 'end_month' => $opt{'end_month'},
344 'end_year' => $opt{'end_year'},
346 'agentnum' => $opt{'agentnum'},
347 'remove_empty' => $opt{'remove_empty'},
349 my $data = $report->data;