From c1fa2b017e4f7d79e47e4e2257f17cf8a3d0c84b Mon Sep 17 00:00:00 2001
From: mark
Date: Tue, 10 Jan 2012 18:38:44 +0000
Subject: projected sales report, #15393
---
httemplate/graph/cust_bill_pkg.cgi | 41 +++++++++++++++++++++++++-----
httemplate/graph/elements/monthly.html | 25 ++++++++++++++++++
httemplate/graph/elements/report.html | 24 ++++++++++++-----
httemplate/graph/report_cust_bill_pkg.html | 24 ++++++++++++++---
4 files changed, 97 insertions(+), 17 deletions(-)
(limited to 'httemplate/graph')
diff --git a/httemplate/graph/cust_bill_pkg.cgi b/httemplate/graph/cust_bill_pkg.cgi
index 03e29b901..af4d045fe 100644
--- a/httemplate/graph/cust_bill_pkg.cgi
+++ b/httemplate/graph/cust_bill_pkg.cgi
@@ -22,9 +22,19 @@ die "access denied"
my $link = "${p}search/cust_bill_pkg.cgi?nottax=1";
my $bottom_link = "$link;";
+my $use_usage = $cgi->param('use_usage') || 0;
+my $use_setup = $cgi->param('use_setup') || 0;
my $use_override = $cgi->param('use_override') ? 1 : 0;
-my $use_usage = $cgi->param('use_usage') ? 1 : 0;
my $average_per_cust_pkg = $cgi->param('average_per_cust_pkg') ? 1 : 0;
+my $distribute = $cgi->param('distribute') ? 1 : 0;
+
+my %charge_labels = (
+ 'SR' => 'setup + recurring',
+ 'RU' => 'recurring',
+ 'S' => 'setup',
+ 'R' => 'recurring',
+ 'U' => 'usage',
+);
#XXX or virtual
my( $agentnum, $sel_agent, $all_agent ) = ('', '', '');
@@ -94,6 +104,21 @@ my @labels = ();
my @colors = ();
my @links = ();
+my @components = ( 'SRU' );
+# split/omit components as appropriate
+if ( $use_setup == 1 ) {
+ @components = ( 'S', 'RU' );
+}
+elsif ( $use_setup == 2 ) {
+ @components = ( 'RU' );
+}
+if ( $use_usage == 1 ) {
+ $components[-1] =~ s/U//; push @components, 'U';
+}
+elsif ( $use_usage == 2 ) {
+ $components[-1] =~ s/U//;
+}
+
foreach my $agent ( $all_agent || $sel_agent || qsearch('agent', { 'disabled' => '' } ) ) {
my $col_scheme = Color::Scheme->new
@@ -108,7 +133,7 @@ foreach my $agent ( $all_agent || $sel_agent || qsearch('agent', { 'disabled' =>
my $n = 0;
foreach my $pkg_class ( @pkg_class ) {
- foreach my $component ( $use_usage ? ('recurring', 'usage') : ('') ) {
+ foreach my $component ( @components ) {
push @items, 'cust_bill_pkg';
@@ -118,20 +143,22 @@ foreach my $agent ( $all_agent || $sel_agent || qsearch('agent', { 'disabled' =>
? ( ref($pkg_class) ? $pkg_class->classname : $pkg_class )
: ''
).
- " $component";
+ ' '.$charge_labels{$component};
my $row_classnum = ref($pkg_class) ? $pkg_class->classnum : 0;
my $row_agentnum = $all_agent || $agent->agentnum;
push @params, [ ($all_class ? () : ('classnum' => $row_classnum) ),
($all_agent ? () : ('agentnum' => $row_agentnum) ),
'use_override' => $use_override,
- 'use_usage' => $component,
+ 'charges' => $component,
'average_per_cust_pkg' => $average_per_cust_pkg,
+ 'distribute' => $distribute,
];
push @links, "$link;".($all_agent ? '' : "agentnum=$row_agentnum;").
($all_class ? '' : "classnum=$row_classnum;").
- "use_override=$use_override;use_usage=$component;";
+ "distribute=$distribute;".
+ "use_override=$use_override;charges=$component;";
@recur_colors = ($col_scheme->colors)[0,4,8,1,5,9]
unless @recur_colors;
@@ -147,5 +174,7 @@ foreach my $agent ( $all_agent || $sel_agent || qsearch('agent', { 'disabled' =>
}
#use Data::Dumper;
-
+if ( $cgi->param('debug') == 1 ) {
+ $FS::Report::Table::DEBUG = 1;
+}
%init>
diff --git a/httemplate/graph/elements/monthly.html b/httemplate/graph/elements/monthly.html
index a451ea8ff..275e5e6ff 100644
--- a/httemplate/graph/elements/monthly.html
+++ b/httemplate/graph/elements/monthly.html
@@ -64,6 +64,7 @@ Example:
<%init>
my(%opt) = @_;
+$opt{'debug'} ||= $cgi->param('debug');
my $conf = new FS::Conf;
my $money_char = $opt{'disable_money'} ? '' : $conf->config('money_char');
@@ -89,6 +90,11 @@ $opt{'start_year'} ||= $cgi->param('start_year'); # || 1899+$curyear;
$opt{'end_month'} ||= $cgi->param('end_month'); # || $curmon+1;
$opt{'end_year'} ||= $cgi->param('end_year'); # || 1900+$curyear;
+#find end of projection
+$opt{'project_month'} ||= $cgi->param('project_month') || 0;
+$opt{'project_year'} ||= $cgi->param('project_year') || 0;
+# setting these to zero prevents projection on reports that don't support it
+
if ( $opt{'daily'} ) { # daily granularity
$opt{'start_day'} ||= $cgi->param('start_day');
$opt{'end_day'} ||= $cgi->param('end_day');
@@ -110,20 +116,39 @@ my %reportopts = (
'end_day' => $opt{'end_day'},
'end_month' => $opt{'end_month'},
'end_year' => $opt{'end_year'},
+ 'project_day' => $opt{'project_day'},
+ 'project_month' => $opt{'project_month'},
+ 'project_year' => $opt{'project_year'},
'agentnum' => $opt{'agentnum'},
'remove_empty' => $opt{'remove_empty'},
'doublemonths' => $opt{'doublemonths'},
);
+warn Dumper({ 'REPORTOPTS' => \%reportopts }) if $opt{'debug'};
+
my $report;
$report = new FS::Report::Table::Daily(%reportopts) if $opt{'daily'};
$report = new FS::Report::Table::Monthly(%reportopts) unless $opt{'daily'};
my $data = $report->data;
+warn Dumper({'DATA' => $data}) if $opt{'debug'};
+
+if ( $data->{'error'} ) {
+ die $data->{'error'}; # could be smarter
+}
+
my $col_labels = [ map { my $m = $_; $m =~ s/^(\d+)\//$mon[$1-1] / ; $m }
@{$data->{label}} ];
$col_labels = $data->{label} if $opt{'daily'};
+if ( $opt{'remove_empty'} ) {
+ # need to filter out series labels for collapsed rows
+ $opt{'graph_labels'} = [
+ map { $opt{'graph_labels'}[$_] }
+ @{ $data->{indices} }
+ ];
+}
+
my @links;
foreach my $link (@{ $data->{'links'} }) {
my @speriod = @{$data->{'speriod'}};
diff --git a/httemplate/graph/elements/report.html b/httemplate/graph/elements/report.html
index 2be511aec..3773fbf1d 100644
--- a/httemplate/graph/elements/report.html
+++ b/httemplate/graph/elements/report.html
@@ -155,28 +155,28 @@ any delimiter and linked from the elements in @data.
% );
%
% http_header('Content-Type' => 'image/png' );
+% http_header('Cache-Control' => 'no-cache' );
%
% $chart->_set_colors();
%
<% $chart->scalar_png([ $opt{'axis_labels'}, @data ]) %>
%
% } else {
+% # image and download links should use the cached data
+% # just directly reference this component
+% my $myself = $p.'graph/elements/report.html?session='.$session;
%
<% include('/elements/header.html', $opt{'title'} ) %>
% unless ( $opt{'graph_type'} eq 'none' ) {
-% $cgi->param('_type', 'png');
-
% unless ( $opt{'disable_download'} ) {
-% $cgi->param('_type', "xls" );
Download full results
+
" WIDTH="976" HEIGHT="384">
% }
- as Excel spreadsheet
-% $cgi->param('_type', 'csv');
- as CSV file
+ as ">CSV file