improve speed in customer search, #13364
[freeside.git] / httemplate / search / report_cust_pkg.html
index 98e9121..d9b6cd7 100755 (executable)
-<%= include('/elements/header.html', 'Package Report' ) %>
+<% include('/elements/header.html', $title ) %>
 
 <FORM ACTION="cust_pkg.cgi" METHOD="GET">
 <INPUT TYPE="hidden" NAME="magic" VALUE="bill">
+<INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
 
   <TABLE BGCOLOR="#cccccc" CELLSPACING=0>
 
     <TR>
-      <TH BGCOLOR="#e8e8e8" COLSPAN=2 ALIGN="left"><FONT SIZE="+1">Search options</FONT></TH>
+      <TH CLASS="background" COLSPAN=2 ALIGN="left">
+        <FONT SIZE="+1">Search options</FONT>
+      </TH>
     </TR>
-    <%= include( '/elements/tr-select-agent.html',
-                   $cgi->param('agentnum'),
+
+% unless ( $custnum ) {
+    <% include( '/elements/tr-select-agent.html',
+                   'curr_value'    => scalar( $cgi->param('agentnum') ),
+                   'disable_empty' => 0,
                )
     %>
-    <%= include( '/elements/tr-select-cust_pkg-status.html' ) %>
-    <%= include( '/elements/tr-select-pkg_class.html', '',
+% }
+
+    <% include( '/elements/tr-select-cust_pkg-status.html',
+                  'onchange' => 'status_changed(this);',
+              )
+    %>
+
+    <SCRIPT TYPE="text/javascript">
+  
+      function status_changed(what) {
+
+%       foreach my $status ( '', FS::cust_pkg->statuses() ) {
+
+          if ( what.options[what.selectedIndex].value == '<% $status %>' ) {
+
+%           foreach my $field (@date_fields) {
+%             if ( $disable{$status}->{$field} ) {
+
+                what.form.<% $field %>_beginning_text.disabled = true;
+                what.form.<% $field %>_ending_text.disabled = true;
+                what.form.<% $field %>_beginning_text.style.backgroundColor = '#dddddd';
+                what.form.<% $field %>_ending_text.style.backgroundColor = '#dddddd';
+
+                what.form.<% $field %>_beginning_button.style.display = 'none';
+                what.form.<% $field %>_ending_button.style.display = 'none';
+                what.form.<% $field %>_beginning_disabled.style.display = '';
+                what.form.<% $field %>_ending_disabled.style.display = '';
+
+%             } else {
+
+                what.form.<% $field %>_beginning_text.disabled = false;
+                what.form.<% $field %>_ending_text.disabled = false;
+                what.form.<% $field %>_beginning_text.style.backgroundColor = '#ffffff';
+                what.form.<% $field %>_ending_text.style.backgroundColor = '#ffffff';
+
+                what.form.<% $field %>_beginning_button.style.display = '';
+                what.form.<% $field %>_ending_button.style.display = '';
+                what.form.<% $field %>_beginning_disabled.style.display = 'none';
+                what.form.<% $field %>_ending_disabled.style.display = 'none';
+
+%             }
+%           }
+
+          }
+
+%       }
+
+      }
+
+    </SCRIPT>
+
+    <% include( '/elements/tr-select-pkg_class.html',
                    'pre_options' => [ '0' => 'all' ],
                    'empty_label' => '(empty class)',
                )
     %>
-    <% #include( '/elements/tr-selectmultiple-part_pkg.html' ) %>
-    <TR>
-      <TD ALIGN="right" VALIGN="center">Next bill date</TD>
-      <TD>
-        <TABLE>
-          <%= include( '/elements/tr-input-beginning_ending.html' ) %>
-        </TABLE>
-      </TD>
-    </TR>
+
+%   if ( scalar( qsearch( 'part_pkg_report_option', { 'disabled' => '' } ) ) ) {
+
+    <% include( '/elements/tr-select-table.html',
+                   'label'        => 'Report classes',
+                   'table'        => 'part_pkg_report_option',
+                   'name_col'     => 'name',
+                   'hashref'      => { 'disabled' => '' },
+                   'element_name' => 'report_option',
+                   'multiple'     => 'multiple',
+               )
+    %>
+
+%   }
+
+%   foreach my $field (@date_fields) {
+
+      <TR>
+        <TD ALIGN="right" VALIGN="center"><% $label{$field} %></TD>
+        <TD>
+          <TABLE>
+            <% include( '/elements/tr-input-beginning_ending.html',
+                          prefix   => $field,
+                          layout   => 'horiz',
+                      )
+            %>
+          </TABLE>
+        </TD>
+      </TR>
+
+%   }
     
+    <SCRIPT TYPE="text/javascript">
+  
+      function custom_changed(what) {
+
+        if ( what.checked  ) {
+
+          what.form.pkgpart.disabled = true;
+          what.form.pkgpart.style.backgroundColor = '#dddddd';
+
+        } else {
+
+          what.form.pkgpart.disabled = false;
+          what.form.pkgpart.style.backgroundColor = '#ffffff';
+
+        }
+
+      }
+
+    </SCRIPT>
+
+    <% include( '/elements/tr-checkbox.html',
+                'label' => 'Custom packages',
+                'field' => 'custom',
+                'value' => 1,
+                'onchange' => 'custom_changed(this);',
+              )
+    %> 
+
+    <% include( '/elements/tr-selectmultiple-part_pkg.html' ) %> 
+
     <TR>
-      <TH BGCOLOR="#e8e8e8" COLSPAN=2>&nbsp;</TH>
+      <TH CLASS="background" COLSPAN=2>&nbsp;</TH>
     </TR>
 
     <TR>
-      <TH BGCOLOR="#e8e8e8" COLSPAN=2 ALIGN="left"><FONT SIZE="+1">Display options</FONT></TH>
+      <TH CLASS="background" COLSPAN=2 ALIGN="left"><FONT SIZE="+1">Display options</FONT></TH>
     </TR>
-    <%= include( '/elements/tr-select-cust-fields.html' ) %>
+    <% include( '/elements/tr-select-cust-fields.html' ) %>
     
   </TABLE>
 
 
 </FORM>
 
-<%= include('/elements/footer.html') %>
+<% include('/elements/footer.html') %>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('List packages');
+
+my $title = 'Package Report';
+
+my $custnum = '';
+if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
+  $custnum = $1;
+  my $cust_main = qsearchs({
+    'table'     => 'cust_main', 
+    'hashref'   => { 'custnum' => $custnum },
+    'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
+  }) or die "unknown custnum $custnum";
+  $title .= ': '. $cust_main->name;
+}
+
+</%init>
+<%once>
+
+tie my %label, 'Tie::IxHash',
+  'setup'        => 'Setup',
+  'last_bill'    => 'Last bill',
+  'bill'         => 'Next bill',
+  'adjourn'      => 'Adjourns',
+  'susp'         => 'Suspended',
+  'dundate'      => 'Suspension delayed until',
+  'expire'       => 'Expires',
+  'contract_end' => 'Contract ends',
+  'cancel'       => 'Cancelled',
+;
+my @date_fields = keys %label;
+
+#false laziness w/cust_pkg.cgi
+my %disable = (
+  'all'             => {},
+  'not yet billed'  => { 'setup'=>1, 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, },
+  'one-time charge' => { 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, 'contract_end'=>1, 'dundate'=>1, },
+  'active'          => { 'susp'=>1, 'cancel'=>1 },
+  'suspended'       => { 'cancel'=>1, 'dundate'=>1, },
+  'cancelled'       => {},
+  ''                => {},
+);
+
+#hmm?
+my %checkbox = (
+  'setup'     => 0,
+  'last_bill' => 0,
+  'bill'      => 0,
+  'susp'      => 1,
+  'dundate'   => 1,
+  'expire'    => 1,
+  'cancel'    => 1,
+);
+
+</%once>