make package churn report actually show package churn, #7990
[freeside.git] / httemplate / graph / cust_bill_pkg.cgi
index 44498c8..ea7fee9 100644 (file)
@@ -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',
@@ -129,7 +139,6 @@ if ( $cgi->param('class_agg_break') eq 'aggregate' or
     # The new way:
     # Actually break down all subsets of the (selected) report classes.
     my @subsets = FS::part_pkg_report_option->subsets(@classnums);
-    warn "SUBSETS:\n".Dumper(\@subsets)."\n\n";
     my @classnum_space = @classnums;
     @classnums = @classnames = ();
     while(@subsets) {
@@ -139,13 +148,12 @@ if ( $cgi->param('class_agg_break') eq 'aggregate' or
       my $i = 0;
       foreach (@$these) {
         $i++ until $not_these->[$i] == $_;
-        splice($not_these, $i, 1);
+        splice(@$not_these, $i, 1);
       }
       push @classnums, $these;
       push @not_classnums, $not_these;
       push @classnames, shift @subsets;
     } #while subsets
-    warn "COMPLEMENTS:\n".Dumper(\@not_classnums)."\n\n";
   }
   # else it's 'pkg', i.e. part_pkg.classnum, which is singular on pkgpart
   # and much simpler
@@ -256,12 +264,17 @@ foreach my $agent ( $all_agent || $sel_agent || $FS::CurrentUser::CurrentUser->a
 
     } elsif ( $cgi->param('class_agg_break') eq 'breakdown' ) {
 
-      # if we're working with report options, @classnums here contains 
-      # arrays of multiple classnums
       for (my $i = 0; $i < scalar @classnums; $i++) {
-        my $row_classnum = join(',', @{ $classnums[$i] });
-        my $row_classname = join(', ', @{ $classnames[$i] });
-        my $not_row_classnum = join(',', @{ $not_classnums[$i] });
+        my $row_classnum = $classnums[$i];
+        my $row_classname = $classnames[$i];
+        my $not_row_classnum = '';
+        if ( $class_param eq 'report_optionnum' ) {
+          # if we're working with report options, @classnums here contains 
+          # arrays of multiple classnums
+          $row_classnum = join(',', @$row_classnum);
+          $row_classname = join(', ', @$row_classname);
+          $not_row_classnum = join(',', @{ $not_classnums[$i] });
+        }
         foreach my $component ( @components ) {
 
           push @items, 'cust_bill_pkg';
@@ -353,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;