Option to ignore old CDRs, RT#81480
[freeside.git] / httemplate / graph / report_cust_bill_pkg.html
index 31792e8..96bfdc0 100644 (file)
@@ -1,8 +1,19 @@
-<% include('/elements/header.html', 'Sales Report' ) %>
+<& /elements/header.html,
+     { title => 'Sales Report',
+       head  => '
+  <SCRIPT TYPE="text/javascript"  SRC="'. $p. 'elements/jquery.js"></SCRIPT>
+  <SCRIPT TYPE="text/javascript"  SRC="'. $p. 'elements/spectrum.js"></SCRIPT>
+  <LINK   REL="stylesheet"       HREF="'. $p. 'elements/spectrum.css" />',
+     }
+&>
 
-<FORM ACTION="cust_bill_pkg.cgi" METHOD="GET">
+<FORM ACTION="cust_bill_pkg.cgi" METHOD="POST">
 
-<TABLE>
+<TABLE BGCOLOR="#cccccc" CELLSPACING=0>
+
+<TR>
+  <TH CLASS="background" COLSPAN=2 ALIGN="left"><FONT SIZE="+1"><% mt('Search options') |h %></FONT></TH>
+</TR>
 
 <% include('/elements/tr-select-from_to.html' ) %>
 
 </TR>
 
 <SCRIPT TYPE="text/javascript">
+
+function agent_changed(obj) {
+
+  if ( obj.value == '' ) { //breakdown, one color list per agent needed
+    document.getElementById('agent0-label').style.display = '';
+%   for ( 1 .. $#agents ) {
+      document.getElementById('agent<% $_ %>-colors').style.display = '';
+%   }
+  } else { //aggregate, only one color list needed
+    document.getElementById('agent0-label').style.display = 'none';
+%   for ( 1 .. $#agents ) {
+      document.getElementById('agent<% $_ %>-colors').style.display = 'none';
+%   }
+  } 
+
+  enable_agent_totals(obj);
+}
+
 function enable_agent_totals(obj) {
 %# enable it iff we are breaking down by agent AND something else
   obj.form.agent_totals.disabled = !(
     obj.form.agentnum.value == '' && (
       obj.form.refnum.value == ''   ||
-      obj.form.classnum.value == 0  ||
+      document.getElementById('class_agg_break_breakdown').checked ||
       obj.form.use_setup.value == 1 ||
       obj.form.use_usage.value == 1
     )
   );
 }
+
+function class_mode_changed() {
+  var options = document.getElementsByName('class_mode');
+  var mode;
+  for(var i=0; i < options.length; i++) {
+    if (options[i].checked) {
+      mode = options[i].value;
+    }
+  }
+    
+  var div_pkg = document.getElementById('pkg_class');
+  var div_report = document.getElementById('report_class');
+  var span_exact = document.getElementById('exact_match');
+  if (mode == 'pkg') {
+    div_pkg.style.display = '';
+    div_report.style.display = 'none';
+    span_exact.style.display = 'none';
+  } else if (mode == 'report') {
+    div_pkg.style.display = 'none';
+    div_report.style.display = '';
+    span_exact.style.display = '';
+  }
+}
+window.onload = class_mode_changed;
 </SCRIPT>
 
 <& /elements/tr-select-agent.html,
@@ -31,7 +84,13 @@ function enable_agent_totals(obj) {
   'disable_empty' => 0,
   'pre_options'   => [ 'all' => 'all (aggregate)' ],
   'empty_label'   => 'all (breakdown)',
-  'onchange'      => 'enable_agent_totals',
+  'onchange'      => 'agent_changed',
+&>
+
+<& /elements/tr-select-cust_class.html,
+  'field'         => 'cust_classnum',
+  'label'         => 'Customer class',
+  'multiple'      => 1,
 &>
 
 <& /elements/tr-select-part_referral.html,
@@ -43,13 +102,76 @@ function enable_agent_totals(obj) {
   'onchange'      => 'enable_agent_totals'
 &>
 
-<& /elements/tr-select-pkg_class.html,
-  'field'       => 'classnum',
-  'pre_options' => [ 'all'  => 'all (aggregate)',
-                        '0' => 'all (breakdown)' ],
-  'empty_label' => '(empty class)',
-  'onchange'    => 'enable_agent_totals',
-&>
+<TR>
+
+  <TD>
+    <INPUT TYPE="radio" NAME="class_mode" VALUE="pkg" onchange="class_mode_changed('pkg')" CHECKED>
+    <% emt('Package class') %>
+    <BR>
+    <INPUT TYPE="radio" NAME="class_mode" VALUE="report" onchange="class_mode_changed('report')">
+    <% emt('Report class') %>
+  </TD>
+
+  <TD>
+    <TABLE>
+      <TR>
+
+        <TD>
+          <DIV ID="pkg_class">
+          <& /elements/select-pkg_class.html,
+            'field'         => 'classnum',
+            'multiple'      => 1,
+            'all_selected'  => 1,
+            'pre_options'   => [ #'all'  => 'all (aggregate)',
+                                #   ''  => 'all (breakdown)',
+                                  '0'  => '(empty class)' ],
+            'disable_empty' => 1,
+            'onchange'      => 'enable_agent_totals',
+          &>
+          </DIV>
+          <DIV ID="report_class" STYLE="display: none">
+          <& /elements/select-table.html,
+            'field'         => 'report_optionnum',
+            'table'         => 'part_pkg_report_option',
+            'name_col'      => 'name',
+            'value_col'     => 'num',
+            'multiple'      => 1,
+            'all_selected'  => 1,
+            'pre_options'   => [ #'all' => 'all (aggregate)',
+                               #   '' => 'all (breakdown)', 
+                                 '0'  => '(empty class)' ],
+            'disable_empty' => 1,
+            'onchange'      => 'enable_agent_totals',
+          &>
+          </DIV>
+        </TD>
+
+        <TD>
+          <INPUT TYPE="radio" NAME="class_agg_break" ID="class_agg_break_aggregate" VALUE="aggregate" onchange="enable_agent_totals(this)" CHECKED>
+          <% emt('Aggregate') %>
+          <BR>
+          <INPUT TYPE="radio" NAME="class_agg_break" ID="class_agg_break_breakdown" VALUE="breakdown" onchange="enable_agent_totals(this)">
+          <% emt('Breakdown') %>
+          <BR>
+          <SPAN ID="exact_match" style="display:none">
+          <INPUT TYPE="radio" NAME="class_agg_break" ID="class_agg_break_exact" VALUE="exact" onchange="enable_agent_totals(this)">
+          <% emt('Exact match') %>
+          </SPAN>
+        </TD>
+
+      </TR>
+    </TABLE>
+  </TD>
+
+</TR>
+
+<TR>
+  <TH CLASS="background" COLSPAN=2>&nbsp;</TH>
+</TR>
+
+<TR>
+  <TH CLASS="background" COLSPAN=2 ALIGN="left"><FONT SIZE="+1"><% mt('Display options') |h %></FONT></TH>
+</TR>
 
 <!--
 <TR>
@@ -67,6 +189,76 @@ function enable_agent_totals(obj) {
     'onchange'=> 'enable_agent_totals',
 &>
 % }
+<& /elements/tr-select.html,
+    'label'   => 'Discounts',
+    'field'   => 'use_discount',
+    'options' => [ 1, 2 ],
+    'labels'  => { 1 => 'Separate', 2 => 'Do not show' },
+&>
+<& /elements/tr-select.html,
+    'label'   => 'Taxes',
+    'field'   => 'use_taxes',
+    'options' => [ 1, 2 ],
+    'labels'  => { 1 => 'Separate', 2 => 'Do not show' },
+&>
+
+<TR>
+  <TD ALIGN="right">Colors</TD>
+  <TD>
+%   my @names = ();
+%
+%   #no particular long-term attachment to this, just trying to replicate
+%   # historical behavior so people's graphs don't change color suddenly in 3.x
+%   my $hue = 0;
+%   my $hue_increment = 125;
+
+      <TABLE>
+%       my $anum = 0;
+%       foreach my $agent ( @agents ) {
+          <TR <% $anum ? 'STYLE="display:none"' : '' %>
+              ID="agent<%$anum%>-colors"
+          >
+            <TD <% $anum ? '' :'STYLE="display:none"' %>
+                ID="agent<%$anum%>-label"
+            >
+              <% $agent->agent |h %>
+            </TD>
+            <TD>
+%            my $col_scheme = Color::Scheme->new
+%                               ->from_hue($hue) #->from_hex($agent->color)
+%                               ->scheme('analogic')
+%                             ;
+%
+%            my $cnum = 0;
+%            my @colors = ($col_scheme->colors)[ 0,4,8,1,5,9 ];#again some some random historical shite
+%            for (@colors) {
+%              my $name = "agent$anum-color$cnum";
+%              push @names, $name;
+%              $cnum++;
+               <INPUT TYPE  = "color"
+                      NAME  = "<% $name %>"
+                      ID    = "<% $name %>"
+                      VALUE = "#<%$_%>"
+               >
+%            }
+            </TD>
+          </TR>
+%         $anum++;
+%         $hue += $hue_increment;
+%       }
+     </TABLE>
+  </TD>
+</TR>
+
+<SCRIPT TYPE="text/javascript">
+  $(document).ready(function() {
+%   foreach my $name (@names) {
+      $("#<% $name %>").spectrum({
+        clickoutFiresChange: true
+      });
+%   }
+  });
+</SCRIPT>
 
 <TR>
   <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="agent_totals" VALUE="1" DISABLED="1"></TD>
@@ -99,4 +291,6 @@ function enable_agent_totals(obj) {
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
 
+my @agents = $FS::CurrentUser::CurrentUser->agents;
+
 </%init>