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'
22 'daily' => 1, # omit for monthly granularity
24 #optional, pulled from CGI params if not specified
25 'start_month' => $smonth,
26 'start_year' => $syear,
27 'end_month' => $emonth,
31 #optional, pulled from CGI params if not specified,
32 #only if 'daily' option is given
37 'agentnum' => $agentnum,
39 'graph_type' => 'LinesPoints',
42 'sprintf' => '%u', #sprintf format, overrides default %.2f
47 <% include('report.html',
48 'items' => $data->{'items'},
49 'data' => $data->{'data'},
50 'row_labels' => $data->{'item_labels'},
51 'graph_labels' => $opt{'graph_labels'} || $data->{'item_labels'},
52 'col_labels' => $col_labels,
53 'axis_labels' => $data->{label},
54 'colors' => $data->{colors},
56 'bottom_link' => \@bottom_link,
57 map { $_, $opt{$_} } (qw(title
68 my $conf = new FS::Conf;
69 my $money_char = $opt{'disable_money'} ? '' : $conf->config('money_char');
71 my $fromparam = $opt{'link_fromparam'} || 'begin';
72 my $toparam = $opt{'link_toparam'} || 'end';
74 my @items = @{ $opt{'items'} };
76 foreach my $other (qw( labels graph_labels colors links )) {
77 if ( ref($opt{$other}) eq 'HASH' ) {
78 $opt{$other} = [ map $opt{$other}{$_}, @items ];
82 my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
85 $opt{'start_month'} ||= $cgi->param('start_month'); # || $curmon+1;
86 $opt{'start_year'} ||= $cgi->param('start_year'); # || 1899+$curyear;
89 $opt{'end_month'} ||= $cgi->param('end_month'); # || $curmon+1;
90 $opt{'end_year'} ||= $cgi->param('end_year'); # || 1900+$curyear;
92 if ( $opt{'daily'} ) { # daily granularity
93 $opt{'start_day'} ||= $cgi->param('start_day');
94 $opt{'end_day'} ||= $cgi->param('end_day');
99 'params' => $opt{'params'},
100 'item_labels' => ( $cgi->param('_type') =~ /^(png)$/
101 ? $opt{'graph_labels'}
104 'colors' => $opt{'colors'},
105 'links' => $opt{'links'},
107 'start_day' => $opt{'start_day'},
108 'start_month' => $opt{'start_month'},
109 'start_year' => $opt{'start_year'},
110 'end_day' => $opt{'end_day'},
111 'end_month' => $opt{'end_month'},
112 'end_year' => $opt{'end_year'},
113 'agentnum' => $opt{'agentnum'},
114 'remove_empty' => $opt{'remove_empty'},
115 'doublemonths' => $opt{'doublemonths'},
119 $report = new FS::Report::Table::Daily(%reportopts) if $opt{'daily'};
120 $report = new FS::Report::Table::Monthly(%reportopts) unless $opt{'daily'};
121 my $data = $report->data;
123 my $col_labels = [ map { my $m = $_; $m =~ s/^(\d+)\//$mon[$1-1] / ; $m }
125 $col_labels = $data->{label} if $opt{'daily'};
128 foreach my $link (@{ $data->{'links'} }) {
129 my @speriod = @{$data->{'speriod'}};
130 my @eperiod = @{$data->{'eperiod'}};
131 my ($begin, $end) = ($fromparam, $toparam);
135 $begin = $link->{'fromparam'};
136 $end = $link->{'toparam'};
137 @new = ( $link->{'link'} );
140 push @new, "$begin=". shift(@speriod).";$end=".shift(@eperiod);
142 if(! $opt{'nototal'}) {
143 push @new, "$begin=". $data->{'speriod'}[0] . ";$end=". $data->{'eperiod'}[-1];
149 if($opt{'bottom_link'}) {
150 my @speriod = (@{$data->{'speriod'}}, $data->{'speriod'}[0]);
151 my @eperiod = (@{$data->{'eperiod'}}, $data->{'eperiod'}[-1]);
153 push @bottom_link, $opt{'bottom_link'};
155 push @bottom_link, "$fromparam=". shift(@speriod). ";$toparam=". shift(@eperiod);