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,
40 'graph_type' => 'LinesPoints',
43 'sprintf' => '%u', #sprintf format, overrides default %.2f
48 <% include('report.html',
49 'items' => $data->{'items'},
50 'data' => $data->{'data'},
51 'row_labels' => $data->{'item_labels'},
52 'graph_labels' => $opt{'graph_labels'} || $data->{'item_labels'},
53 'col_labels' => $col_labels,
54 'axis_labels' => $data->{label},
55 'colors' => $data->{colors},
57 'bottom_link' => \@bottom_link,
58 'transpose' => $opt{'daily'},
59 map { $_, $opt{$_} } (qw(title
70 $opt{'debug'} ||= $cgi->param('debug');
72 my $conf = new FS::Conf;
73 my $money_char = $opt{'disable_money'} ? '' : $conf->config('money_char');
75 my $fromparam = $opt{'link_fromparam'} || 'begin';
76 my $toparam = $opt{'link_toparam'} || 'end';
78 my @items = @{ $opt{'items'} };
80 foreach my $other (qw( labels graph_labels colors links )) {
81 if ( ref($opt{$other}) eq 'HASH' ) {
82 $opt{$other} = [ map $opt{$other}{$_}, @items ];
86 my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
89 $opt{'start_month'} ||= $cgi->param('start_month'); # || $curmon+1;
90 $opt{'start_year'} ||= $cgi->param('start_year'); # || 1899+$curyear;
93 $opt{'end_month'} ||= $cgi->param('end_month'); # || $curmon+1;
94 $opt{'end_year'} ||= $cgi->param('end_year'); # || 1900+$curyear;
96 $opt{'projection'} ||= $cgi->param('projection') ? 1 : 0;
98 if ( $opt{'daily'} ) { # daily granularity
99 $opt{'start_day'} ||= $cgi->param('start_day');
100 $opt{'end_day'} ||= $cgi->param('end_day');
105 'params' => $opt{'params'},
106 'item_labels' => ( $cgi->param('_type') =~ /^(png)$/
107 ? $opt{'graph_labels'}
110 'colors' => $opt{'colors'},
111 'links' => $opt{'links'},
113 'start_day' => $opt{'start_day'},
114 'start_month' => $opt{'start_month'},
115 'start_year' => $opt{'start_year'},
116 'end_day' => $opt{'end_day'},
117 'end_month' => $opt{'end_month'},
118 'end_year' => $opt{'end_year'},
119 'projection' => $opt{'projection'},
120 'agentnum' => $opt{'agentnum'},
121 'refnum' => $opt{'refnum'},
122 'remove_empty' => $opt{'remove_empty'},
123 'doublemonths' => $opt{'doublemonths'},
126 warn Dumper({ 'REPORTOPTS' => \%reportopts }) if $opt{'debug'};
129 $report = new FS::Report::Table::Daily(%reportopts) if $opt{'daily'};
130 $report = new FS::Report::Table::Monthly(%reportopts) unless $opt{'daily'};
131 my $data = $report->data;
133 warn Dumper({'DATA' => $data}) if $opt{'debug'};
135 if ( $data->{'error'} ) {
136 die $data->{'error'}; # could be smarter
139 my $col_labels = [ map { my $m = $_; $m =~ s/^(\d+)\//$mon[$1-1] / ; $m }
141 $col_labels = $data->{label} if $opt{'daily'};
143 if ( $opt{'remove_empty'} ) {
144 # need to filter out series labels for collapsed rows
145 $opt{'graph_labels'} = [
146 map { $opt{'graph_labels'}[$_] }
147 @{ $data->{indices} }
152 foreach my $link (@{ $data->{'links'} }) {
153 my @speriod = @{$data->{'speriod'}};
154 my @eperiod = @{$data->{'eperiod'}};
155 my ($begin, $end) = ($fromparam, $toparam);
159 $begin = $link->{'fromparam'};
160 $end = $link->{'toparam'};
161 @new = ( $link->{'link'} );
164 push @new, "$begin=". shift(@speriod).";$end=".shift(@eperiod);
166 if(! $opt{'nototal'}) {
167 push @new, "$begin=". $data->{'speriod'}[0] . ";$end=". $data->{'eperiod'}[-1];
173 if($opt{'bottom_link'}) {
174 my @speriod = (@{$data->{'speriod'}}, $data->{'speriod'}[0]);
175 my @eperiod = (@{$data->{'eperiod'}}, $data->{'eperiod'}[-1]);
177 push @bottom_link, $opt{'bottom_link'};
179 push @bottom_link, "$fromparam=". shift(@speriod). ";$toparam=". shift(@eperiod);