summaryrefslogtreecommitdiff
path: root/httemplate/graph
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2014-10-08 21:41:28 -0700
committerIvan Kohler <ivan@freeside.biz>2014-10-08 21:41:28 -0700
commit3146245f510ef873c4176bc06dc891f990db8f1e (patch)
tree804feb45a96db31ae11e4a11e75bc67f79159073 /httemplate/graph
parent7f2c31cd55d1f5c49db10e997b9e4756e4f46279 (diff)
parentf31bdd8e04ddd743cd7e89b59e83dde2afc3aea0 (diff)
Merge branch 'master' of git.freeside.biz:/home/git/freeside
Diffstat (limited to 'httemplate/graph')
-rw-r--r--httemplate/graph/cust_bill_pkg.cgi25
-rw-r--r--httemplate/graph/cust_pkg.cgi134
-rw-r--r--httemplate/graph/report_cust_pkg.html57
3 files changed, 188 insertions, 28 deletions
diff --git a/httemplate/graph/cust_bill_pkg.cgi b/httemplate/graph/cust_bill_pkg.cgi
index 151b29504..ea7fee932 100644
--- a/httemplate/graph/cust_bill_pkg.cgi
+++ b/httemplate/graph/cust_bill_pkg.cgi
@@ -1,7 +1,7 @@
<% include('elements/monthly.html',
#Dumper(
'title' => $title,
- 'graph_type' => 'Mountain',
+ 'graph_type' => $graph_type,
'items' => \@items,
'params' => \@params,
'labels' => \@labels,
@@ -10,7 +10,8 @@
'links' => \@links,
'no_graph' => \@no_graph,
'remove_empty' => 1,
- 'bottom_total' => 1,
+ 'bottom_total' => $show_total,
+ 'nototal' => !$show_total,
'bottom_link' => $bottom_link,
'agentnum' => $agentnum,
'cust_classnum'=> \@cust_classnums,
@@ -30,6 +31,15 @@ my $use_override = $cgi->param('use_override') ? 1 : 0;
my $average_per_cust_pkg = $cgi->param('average_per_cust_pkg') ? 1 : 0;
my $distribute = $cgi->param('distribute') ? 1 : 0;
+my $show_total = 1;
+my $graph_type = 'Mountain';
+
+if ( $average_per_cust_pkg ) {
+ # then the rows are not additive
+ $show_total = 0;
+ $graph_type = 'LinesPoints';
+}
+
my %charge_labels = (
'SR' => 'setup + recurring',
'RU' => 'recurring',
@@ -356,6 +366,17 @@ foreach my $agent ( $all_agent || $sel_agent || $FS::CurrentUser::CurrentUser->a
}
+# may be useful at some point...
+#if ( $average_per_cust_pkg ) {
+# @items = map { ('cust_bill_pkg', 'cust_bill_pkg_count_pkgnum') } @items;
+# @labels = map { $_, "Packages" } @labels;
+# @params = map { $_, $_ } @params;
+# @links = map { $_, $_ } @links;
+# @colors = map { $_, $_ } @colors;
+# @no_graph = map { $_, 1 } @no_graph;
+#}
+#
+
#use Data::Dumper;
if ( $cgi->param('debug') == 1 ) {
$FS::Report::Table::DEBUG = 1;
diff --git a/httemplate/graph/cust_pkg.cgi b/httemplate/graph/cust_pkg.cgi
index 21ce07d21..cdd95e10a 100644
--- a/httemplate/graph/cust_pkg.cgi
+++ b/httemplate/graph/cust_pkg.cgi
@@ -1,20 +1,22 @@
-<% include('elements/monthly.html',
- 'title' => $agentname. 'Package Churn',
- 'items' => \@items,
- 'labels' => \%label,
- 'graph_labels' => \%graph_label,
- 'colors' => \%color,
- 'links' => \%link,
- 'agentnum' => $agentnum,
- 'sprintf' => '%u',
- 'disable_money' => 1,
- )
-%>
+<& elements/monthly.html,
+ 'title' => $agentname. 'Package Churn',
+ 'items' => \@items,
+ 'labels' => \@labels,
+ 'graph_labels' => \@labels,
+ 'colors' => \@colors,
+ 'links' => \@links,
+ 'params' => \@params,
+ 'agentnum' => $agentnum,
+ 'sprintf' => '%u',
+ 'disable_money' => 1,
+ 'remove_empty' => (scalar(@group_keys) > 1 ? 1 : 0),
+&>
<%init>
#XXX use a different ACL for package churn?
+my $curuser = $FS::CurrentUser::CurrentUser;
die "access denied"
- unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
+ unless $curuser->access_right('Financial reports');
#false laziness w/money_time.cgi, cust_bill_pkg.cgi
@@ -28,24 +30,23 @@ if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
my $agentname = $agent ? $agent->agent.' ' : '';
-my @items = qw( setup_pkg susp_pkg cancel_pkg );
+my @base_items = qw( setup_pkg susp_pkg cancel_pkg );
-my %label = (
+my %base_labels = (
'setup_pkg' => 'New orders',
'susp_pkg' => 'Suspensions',
# 'unsusp' => 'Unsuspensions',
'cancel_pkg' => 'Cancellations',
);
-my %graph_label = %label;
-my %color = (
+my %base_colors = (
'setup_pkg' => '00cc00', #green
'susp_pkg' => 'ff9900', #yellow
#'unsusp' => '', #light green?
'cancel_pkg' => 'cc0000', #red ? 'ff0000'
);
-my %link = (
+my %base_links = (
'setup_pkg' => { 'link' => "${p}search/cust_pkg.cgi?agentnum=$agentnum;",
'fromparam' => 'setup_begin',
'toparam' => 'setup_end',
@@ -60,4 +61,101 @@ my %link = (
},
);
+my %filter_params = (
+ # not agentnum, that's elsewhere
+ 'refnum' => [ $cgi->param('refnum') ],
+ 'classnum' => [ $cgi->param('classnum') ],
+ 'towernum' => [ $cgi->param('towernum') ],
+);
+if ( $cgi->param('zip') =~ /^(\w+)/ ) {
+ $filter_params{zip} = $1;
+}
+foreach my $link (values %base_links) {
+ foreach my $key (keys(%filter_params)) {
+ my $value = $filter_params{$key};
+ if (ref($value)) {
+ $value = join(',', @$value);
+ }
+ $link->{'link'} .= "$key=$value;" if length($value);
+ }
+}
+
+
+# In order to keep this from being the same trainwreck as cust_bill_pkg.cgi,
+# we allow ONE breakdown axis, besides the setup/susp/cancel inherent in
+# the report.
+
+my $breakdown = $cgi->param('breakdown_by');
+my ($name_col, $table);
+if ($breakdown eq 'classnum') {
+ $table = 'pkg_class';
+ $name_col = 'classname';
+} elsif ($breakdown eq 'refnum') {
+ $table = 'part_referral';
+ $name_col = 'referral';
+} elsif ($breakdown eq 'towernum') {
+ $table = 'tower';
+ $name_col = 'towername';
+} elsif ($breakdown) {
+ die "unknown breakdown column '$breakdown'\n";
+}
+
+my @group_keys;
+my @group_labels;
+if ( $table ) {
+ my @groups;
+ if ( $cgi->param($breakdown) ) {
+ foreach my $key ($cgi->param($breakdown)) {
+ next if $key =~ /\D/;
+ push @groups, qsearch( $table, { $breakdown => $key });
+ }
+ } else {
+ @groups = qsearch( $table );
+ }
+ foreach (@groups) {
+ push @group_keys, $_->get($breakdown);
+ push @group_labels, $_->get($name_col);
+ }
+}
+
+my (@items, @labels, @colors, @links, @params);
+if (scalar(@group_keys) > 1) {
+ my $hue = 180;
+ foreach my $key (@group_keys) {
+ # this gives a decent level of contrast as long as there aren't too many
+ # result sets
+ my $scheme = Color::Scheme->new
+ ->scheme('triade')
+ ->from_hue($hue)
+ ->distance(0.5);
+ my $label = shift @group_labels;
+ my $i = 0; # item index
+ foreach (@base_items) {
+ # append the item
+ push @items, $_;
+ # and its parameters
+ push @params, [
+ %filter_params,
+ $breakdown => $key
+ ];
+ # and a label prefixed with the group label
+ push @labels, "$label - $base_labels{$_}";
+ # and colors (?!)
+ push @colors, $scheme->colorset->[$i]->[1];
+ # and links...
+ my %this_link = %{ $base_links{$_} };
+ $this_link{link} .= "$breakdown=$key;";
+ push @links, \%this_link;
+ $i++;
+ } #foreach (@base_items
+ $hue += 35;
+ } # foreach @group_keys
+} else {
+ @items = @base_items;
+ @labels = @base_labels{@base_items};
+ @colors = @base_colors{@base_items};
+ @links = @base_links{@base_items};
+ @params = map { [ %filter_params ] } @base_items;
+}
+
</%init>
diff --git a/httemplate/graph/report_cust_pkg.html b/httemplate/graph/report_cust_pkg.html
index 22ccd5def..1425ff089 100644
--- a/httemplate/graph/report_cust_pkg.html
+++ b/httemplate/graph/report_cust_pkg.html
@@ -2,16 +2,57 @@
<FORM ACTION="cust_pkg.cgi" METHOD="GET">
-<TABLE>
+<TABLE BGCOLOR="#cccccc" CELLSPACING=0>
-<% include('/elements/tr-select-from_to.html' ) %>
+<& /elements/tr-select-from_to.html &>
-<% include('/elements/tr-select-agent.html',
- 'curr_value' => scalar($cgi->param('agentnum')),
- 'label' => 'For agent: ',
- 'disable_empty' => 0,
- )
-%>
+<& /elements/tr-select-agent.html,
+ 'curr_value' => scalar($cgi->param('agentnum')),
+ 'label' => 'For agent: ',
+ 'disable_empty' => 0,
+&>
+
+<& /elements/tr-select-pkg_class.html,
+ 'multiple' => 1,
+ 'pre_options' => [ '0' => '(empty class)' ],
+ 'disable_empty' => 1,
+&>
+
+<& /elements/tr-select-part_referral.html,
+ 'multiple' => 1,
+ 'disable_empty' => 1,
+&>
+
+<& /elements/tr-select-table.html,
+ 'label' => 'Tower',
+ 'table' => 'tower',
+ 'field' => 'towernum',
+ 'name_col' => 'towername',
+ 'multiple' => 1,
+ 'pre_options' => [ 0 => '(none)' ],
+ 'size' => 8,
+ 'hashref' => { disabled => '' },
+&>
+
+<& /elements/tr-input-text.html,
+ 'field' => 'zip',
+ 'label' => 'Zip',
+&>
+
+<& /elements/tablebreak-tr-title.html,
+ 'value' => mt('Display options')
+&>
+
+<& /elements/tr-select.html,
+ 'field' => 'breakdown_by',
+ 'label' => 'Breakdown by: ',
+ 'options' => [ '', 'classnum', 'refnum', 'towernum' ],
+ 'labels' => { '' => '(none)',
+ 'classnum' => 'Package class',
+ 'refnum' => 'Advertising source',
+ 'towernum' => 'Tower',
+ },
+&>
</TABLE>