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
23 'no_graph' => \@no_graph, # items to leave off the graph (subtotals)
25 #optional, pulled from CGI params if not specified
26 'start_month' => $smonth,
27 'start_year' => $syear,
28 'end_month' => $emonth,
32 #optional, pulled from CGI params if not specified,
33 #only if 'daily' option is given
38 'agentnum' => $agentnum,
40 'cust_classnum' => \@classnums,
42 'graph_type' => 'LinesPoints',
45 'sprintf' => '%u', #sprintf format, overrides default %.2f
50 <% include('report.html',
51 'items' => $data->{'items'},
52 'data' => $data->{'data'},
53 'row_labels' => $data->{'item_labels'},
54 'graph_labels' => \@graph_labels,
55 'col_labels' => $col_labels,
56 'axis_labels' => $data->{label},
59 'no_graph' => \@no_graph,
60 'bottom_link' => \@bottom_link,
61 'transpose' => $opt{'daily'},
62 map { $_, $opt{$_} } (qw(title
73 $opt{'debug'} ||= $cgi->param('debug');
75 my $conf = new FS::Conf;
76 my $money_char = $opt{'disable_money'} ? '' : $conf->config('money_char');
78 my $fromparam = $opt{'link_fromparam'} || 'begin';
79 my $toparam = $opt{'link_toparam'} || 'end';
81 my @items = @{ $opt{'items'} };
83 foreach my $other (qw( labels graph_labels colors links )) {
84 if ( ref($opt{$other}) eq 'HASH' ) {
85 $opt{$other} = [ map $opt{$other}{$_}, @items ];
89 my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
92 $opt{'start_month'} ||= $cgi->param('start_month'); # || $curmon+1;
93 $opt{'start_year'} ||= $cgi->param('start_year'); # || 1899+$curyear;
96 $opt{'end_month'} ||= $cgi->param('end_month'); # || $curmon+1;
97 $opt{'end_year'} ||= $cgi->param('end_year'); # || 1900+$curyear;
99 $opt{'12mo'} ||= $cgi->param('12mo') ? 1 : 0;
101 $opt{'projection'} ||= $cgi->param('projection') ? 1 : 0;
103 if ( $opt{'daily'} ) { # daily granularity
104 $opt{'start_day'} ||= $cgi->param('start_day');
105 $opt{'end_day'} ||= $cgi->param('end_day');
110 'params' => $opt{'params'},
111 'item_labels' => ( $cgi->param('_type') =~ /^(png)$/
112 ? $opt{'graph_labels'}
115 'colors' => $opt{'colors'},
116 'links' => $opt{'links'},
118 'start_day' => $opt{'start_day'},
119 'start_month' => $opt{'start_month'},
120 'start_year' => $opt{'start_year'},
121 'end_day' => $opt{'end_day'},
122 'end_month' => $opt{'end_month'},
123 'end_year' => $opt{'end_year'},
124 '12mo' => $opt{'12mo'},
125 'projection' => $opt{'projection'},
126 'agentnum' => $opt{'agentnum'},
127 'refnum' => $opt{'refnum'},
128 'cust_classnum'=> $opt{'cust_classnum'},
129 'remove_empty' => $opt{'remove_empty'},
130 'doublemonths' => $opt{'doublemonths'},
131 'normalize' => $opt{'normalize'},
134 warn Dumper({ 'REPORTOPTS' => \%reportopts }) if $opt{'debug'};
137 $report = new FS::Report::Table::Daily(%reportopts) if $opt{'daily'};
138 $report = new FS::Report::Table::Monthly(%reportopts) unless $opt{'daily'};
139 my $data = $report->data;
141 warn Dumper({'DATA' => $data}) if $opt{'debug'};
143 if ( $data->{'error'} ) {
144 die $data->{'error'}; # could be smarter
147 my $col_labels = [ map { my $m = $_; $m =~ s/^(\d+)\//$mon[$1-1] / ; $m }
149 $col_labels = $data->{label} if $opt{'daily'};
154 #if ( $opt{'remove_empty'} ) { # no, always do this
155 # then filter out per-item things for collapsed rows
156 foreach my $i (@{ $data->{'indices'} }) {
157 push @colors, $opt{'colors'}[$i];
158 push @graph_labels, $opt{'graph_labels'}[$i];
159 push @no_graph, $opt{'no_graph'}[$i];
163 foreach my $link (@{ $data->{'links'} }) {
164 my @speriod = @{$data->{'speriod'}};
165 my @eperiod = @{$data->{'eperiod'}};
166 my ($begin, $end) = ($fromparam, $toparam);
170 $begin = $link->{'fromparam'};
171 $end = $link->{'toparam'};
172 @new = ( $link->{'link'} );
175 push @new, "$begin=". shift(@speriod).";$end=".shift(@eperiod);
177 if(! $opt{'nototal'}) {
178 push @new, "$begin=". $data->{'speriod'}[0] . ";$end=". $data->{'eperiod'}[-1];
184 if($opt{'bottom_link'}) {
185 my @speriod = (@{$data->{'speriod'}}, $data->{'speriod'}[0]);
186 my @eperiod = (@{$data->{'eperiod'}}, $data->{'eperiod'}[-1]);
188 push @bottom_link, $opt{'bottom_link'};
190 push @bottom_link, "$fromparam=". shift(@speriod). ";$toparam=". shift(@eperiod);