fix total links on sales graph when a package class is specified, RT#5449
[freeside.git] / httemplate / graph / cust_bill_pkg.cgi
index cb82255..a96eed7 100644 (file)
@@ -1,13 +1,22 @@
-<%
-
-
-#find first month
-my $syear = $cgi->param('start_year'); # || 1899+$curyear;
-my $smonth = $cgi->param('start_month'); # || $curmon+1;
+<% include('elements/monthly.html',
+                'title'        => $title. 'Sales Report (Gross)',
+                'graph_type'   => 'Mountain',
+                'items'        => \@items,
+                'params'       => \@params,
+                'labels'       => \@labels,
+                'graph_labels' => \@labels,
+                'colors'       => \@colors,
+                'links'        => \@links,
+                'remove_empty' => 1,
+                'bottom_total' => 1,
+                'bottom_link'  => $bottom_link,
+                'agentnum'     => $agentnum,
+             )
+%>
+<%init>
 
-#find last month
-my $eyear = $cgi->param('end_year'); # || 1900+$curyear;
-my $emonth = $cgi->param('end_month'); # || $curmon+1;
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
 
 #XXX or virtual
 my( $agentnum, $sel_agent ) = ('', '');
@@ -18,22 +27,45 @@ if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
 }
 my $title = $sel_agent ? $sel_agent->agent.' ' : '';
 
+my $link = "${p}search/cust_bill_pkg.cgi?nottax=1;include_comp_cust=1";
+my $bottom_link = "$link;";
+
+#classnum (here)
+# 0: all classes
+# not specified: empty class
+# N: classnum
+#classnum (link)
+# not specified: all classes
+# 0: empty class
+# N: classnum
+
+#false lazinessish w/FS::cust_pkg::search_sql (previously search/cust_pkg.cgi)
 my $classnum = 0;
 my @pkg_class = ();
 if ( $cgi->param('classnum') =~ /^(\d*)$/ ) {
   $classnum = $1;
-  if ( $classnum ) {
+
+  if ( $classnum ) { #a specific class
+
     @pkg_class = ( qsearchs('pkg_class', { 'classnum' => $classnum } ) );
     die "classnum $classnum not found!" unless $pkg_class[0];
     $title .= $pkg_class[0]->classname.' ';
-  } elsif ( $classnum eq '' ) {
+    $bottom_link .= "classnum=$classnum;";
+
+  } elsif ( $classnum eq '' ) { #the empty class
+
     $title .= 'Empty class ';
     @pkg_class = ( '(empty class)' );
-  } elsif ( $classnum eq '0' ) {
+    $bottom_link .= "classnum=0;";
+
+  } elsif ( $classnum eq '0' ) { #all classes
+
     @pkg_class = qsearch('pkg_class', {} ); # { 'disabled' => '' } );
     push @pkg_class, '(empty class)';
+
   }
 }
+#eslaf
 
 my $hue = 0;
 #my $hue_increment = 170;
@@ -46,8 +78,6 @@ my @labels = ();
 my @colors = ();
 my @links  = ();
 
-my $link = "${p}search/cust_bill_pkg.cgi?nottax=1;include_comp_cust=1";
-
 foreach my $agent ( $sel_agent || qsearch('agent', { 'disabled' => '' } ) ) {
 
   my $col_scheme = Color::Scheme->new
@@ -95,22 +125,4 @@ foreach my $agent ( $sel_agent || qsearch('agent', { 'disabled' => '' } ) ) {
 #use Data::Dumper;
 #warn Dumper(\@items);
 
-%><%= include('elements/monthly.html',
-                'title'        => $title. 'Sales Report (Gross)',
-                'graph_type'   => 'Mountain',
-                'items'        => \@items,
-                'params'       => \@params,
-                'labels'       => \@labels,
-                'graph_labels' => \@labels,
-                'colors'       => \@colors,
-                'links'        => \@links,
-                'remove_empty' => 1,
-                'bottom_total' => 1,
-                'bottom_link'  => "$link;",
-                'start_month'  => $smonth,
-                'start_year'   => $syear,
-                'end_month'    => $emonth,
-                'end_year'     => $eyear,
-                'agentnum'     => $agentnum,
-             )
-%>
+</%init>