more reporting options for failed billing events, RT#6447
authorivan <ivan>
Fri, 30 Oct 2009 23:29:18 +0000 (23:29 +0000)
committerivan <ivan>
Fri, 30 Oct 2009 23:29:18 +0000 (23:29 +0000)
FS/FS/cust_event.pm
FS/FS/cust_main_Mixin.pm
httemplate/elements/select-part_event.html [new file with mode: 0644]
httemplate/elements/select-payby.html
httemplate/elements/tr-select-part_event.html [new file with mode: 0644]
httemplate/search/cust_event.html
httemplate/search/report_cust_event.html

index 10fb0ac..bf3a5b7 100644 (file)
@@ -322,9 +322,23 @@ specified in HASHREF.  Valid parameters are
 
 =over 4
 
-=item
+=item agentnum
 
-=item
+=item custnum
+
+=item invnum
+
+=item pkgnum
+
+=item failed
+
+=item beginning
+
+=item ending
+
+=item payby
+
+=item 
 
 =back
 
@@ -340,12 +354,15 @@ sub search_sql {
          join("\n", map { "  $_: ". $param->{$_} } keys %$param ). "\n";
   }
 
-  my @search = ();
+  my @search = $class->cust_search_sql($param);
 
-  if ( $param->{'agentnum'} && $param->{'agentnum'} =~ /^(\d+)$/ ) {
-    push @search, "cust_main.agentnum = $1";
-    #my $agent = qsearchs('agent', { 'agentnum' => $1 } );
-    #die "unknown agentnum $1" unless $agent;
+  #eventpart
+  my @eventpart = ref($param->{'eventpart'})
+                    ? @{ $param->{'eventpart'} }
+                    : split(',', $param->{'eventpart'});
+  @eventpart = grep /^(\d+)$/, @eventpart;
+  if ( @eventpart ) {
+    push @search, 'eventpart IN ('. join(',', @eventpart). ')';
   }
 
   if ( $param->{'beginning'} =~ /^(\d+)$/ ) {
@@ -361,10 +378,6 @@ sub search_sql {
                   "statustext != 'N/A'";
   }
 
-  #if ( $param->{'part_event.payby'} =~ /^(\w+)$/ ) {
-  #  push @search, "part_event.payby = '$1'";
-  #}
-
   if ( $param->{'custnum'} =~ /^(\d+)$/ ) {
     push @search, "cust_main.custnum = '$1'";
   }
@@ -379,13 +392,8 @@ sub search_sql {
                   "tablenum = '$1'";
   }
 
-  #here is the agent virtualization
-  push @search,
-    $FS::CurrentUser::CurrentUser->agentnums_sql( 'table' => 'cust_main' );
-
   my $where = 'WHERE '. join(' AND ', @search );
 
-
   join(' AND ', @search );
 
 }
index 86751b1..5a29a4c 100644 (file)
@@ -1,11 +1,12 @@
 package FS::cust_main_Mixin;
 
 use strict;
-use vars qw( $DEBUG );
+use vars qw( $DEBUG $me );
 use FS::UID qw(dbh);
 use FS::cust_main;
 
 $DEBUG = 0;
+$me = '[FS::cust_main_Mixin]';
 
 =head1 NAME
 
@@ -273,6 +274,60 @@ foreach my $sub (qw( prospect active inactive suspended cancelled )) {
   die $@ if $@;
 }
 
+=item cust_search_sql
+
+Returns a list of SQL WHERE fragments to search for parameters specified
+in HASHREF.  Valid parameters are:
+
+=over 4
+
+=item agentnum
+
+=item status
+
+=item payby
+
+=back
+
+=cut
+
+sub cust_search_sql {
+  my($class, $param) = @_;
+
+  if ( $DEBUG ) {
+    warn "$me cust_search_sql called with params: \n".
+         join("\n", map { "  $_: ". $param->{$_} } keys %$param ). "\n";
+  }
+
+  my @search = ();
+
+  if ( $param->{'agentnum'} && $param->{'agentnum'} =~ /^(\d+)$/ ) {
+    push @search, "cust_main.agentnum = $1";
+  }
+
+  #status (prospect active inactive suspended cancelled)
+  if ( grep { $param->{'status'} eq $_ } FS::cust_main->statuses() ) {
+    my $method = $param->{'status'}. '_sql';
+    push @search, $class->$method();
+  }
+
+  #payby
+  my @payby = ref($param->{'payby'})
+                ? @{ $param->{'payby'} }
+                : split(',', $param->{'payby'});
+  @payby = grep /^([A-Z]{4})$/, @payby;
+  if ( @payby ) {
+    push @search, 'cust_main.payby IN ('. join(',', map "'$_'", @payby). ')';
+  }
+
+  #here is the agent virtualization
+  push @search,
+    $FS::CurrentUser::CurrentUser->agentnums_sql( 'table' => 'cust_main' );
+  
+  return @search;
+
+}
+
 =back
 
 =head1 BUGS
diff --git a/httemplate/elements/select-part_event.html b/httemplate/elements/select-part_event.html
new file mode 100644 (file)
index 0000000..f510672
--- /dev/null
@@ -0,0 +1,6 @@
+<% include( '/elements/select-table.html',
+              'table'      => 'part_event',
+              'name_col'   => 'event',
+              @_,
+          )
+%>
index 3f19cb9..e0fb4f0 100644 (file)
@@ -8,7 +8,9 @@
 % }
 
 % foreach my $option ( keys %{ $opt{'paybys'} } ) { 
-%   my $sel = ( ref($value) && $value->{$option} ) || $option eq $value;
+%   my $sel = $opt{'all_selected'}
+%               || ( ref($value) && $value->{$option} )
+%               || $option eq $value;
 
     <OPTION VALUE="<% $option %>"
             <% $sel ? 'SELECTED' : '' %>
diff --git a/httemplate/elements/tr-select-part_event.html b/httemplate/elements/tr-select-part_event.html
new file mode 100644 (file)
index 0000000..e1d913f
--- /dev/null
@@ -0,0 +1,20 @@
+% unless ( $opt{'js_only'} ) {
+
+    <% include('tr-td-label.html', @_ ) %>
+
+      <TD <% $style %>>
+% }
+
+        <% include( '/elements/select-part_event.html', %opt ) %>
+
+% unless ( $opt{'js_only'} ) {
+      </TD>
+    </TR>
+% }
+<%init>
+
+my( %opt ) = @_;
+
+my $style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : '';
+
+</%init>
index f8cf6b2..b22644e 100644 (file)
@@ -157,12 +157,18 @@ my $title = $cgi->param('failed') ? 'Failed billing events' : 'Billing events';
 
 my %search = ();
 
-my @scalars = qw ( agentnum custnum invnum pkgnum failed );
-for my $param ( @scalars ) {
+my @scalars = qw( agentnum status custnum invnum pkgnum failed );
+for my $param (@scalars) {
   $search{$param} = scalar( $cgi->param($param) )
     if $cgi->param($param);
 }
 
+#lists
+my @lists = qw( payby eventpart );
+foreach my $param (@lists) {
+  $search{$param} = [ $cgi->param($param) ];
+}
+
 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
 $search{'beginning'} = $beginning;
 $search{'ending'}    = $ending;
@@ -208,6 +214,11 @@ my $html_init = join("\n", map {
         }
         @params #keys %search
   ),
+  ( map { my $value = encode_entities( join(',', @{ $search{$_} } ) );
+          qq(<INPUT TYPE="hidden" NAME="$_" VALUE="$value">);
+        }
+        @lists
+  ),
   qq!</FORM>!
 } qw( print_ email_ fax_ ) ).
 
index e63b637..f77a072 100644 (file)
@@ -6,52 +6,36 @@
 
     <FORM ACTION="cust_event.html" METHOD="GET">
     <INPUT TYPE="hidden" NAME="failed" VALUE="<% $cgi->param('failed') ? 1 : 0 %>">
-    <TABLE>
+    <TABLE BGCOLOR="#cccccc" CELLSPACING=0>
+
+      <TR>
+        <TH BGCOLOR="#e8e8e8" COLSPAN=2 ALIGN="left"><FONT SIZE="+1">Search options</FONT></TH>
+      </TR>
 
       <% include( '/elements/tr-select-agent.html', 'disable_empty'=>0 ) %>
 
-      <!--<TR>
-        <TD ALIGN="right">Customer type</TD>
-        <TD><SELECT MULTIPLE NAME="perhaps_payby">
-          <OPTION SELECTED VALUE="CARD">Credit card (automatic)
-          <OPTION SELECTED VALUE="CHEK">E-check (automatic)
-          <OPTION SELECTED VALUE="LECB">Phone bill billing
-          <OPTION SELECTED VALUE="BILL">Billing
-          <OPTION SELECTED VALUE="DCRD">Credit card (on-demand)
-          <OPTION SELECTED VALUE="DCHK">E-check (on-demand)
-        </TD>
-      </TR>
-      -->
+      <% include( '/elements/tr-select-cust_main-status.html',
+                    'label' => 'Status'
+                )
+      %>
+
+      <% include( '/elements/tr-select-payby.html',
+                    'label'        => 'Customer payment type',
+                    'payby_type'   => 'cust',
+                    'multiple'     => 1,
+                    'all_selected' => 1,
+                )
+      %>
+
+      <% include( '/elements/tr-select-part_event.html',
+                    'label'        => 'Events',
+                    'multiple'     => 1,
+                    'all_selected' => 1,
+                )
+      %>
+
       <% include( '/elements/tr-input-beginning_ending.html' ) %>
-      <!--
-      <TR>
-        <TD ALIGN="right">Events: </TD>
-        <TD>
-          <SELECT NAME="eventpart">
-            <OPTION SELECTED VALUE=""><% $cgi->param('failed') ? '(all failed events)' : '(all events)' %>
-% #foreach my $part_bill_event ( qsearch( 'part_bill_event', {} ) ) { 
-% #} 
 
-          </SELECT>
-        </TD>
-      </TR>
-      -->
-<!--      <TR>
-        <TD ALIGN="right">Events for payment type: </TD>
-        <TD>
-          <SELECT NAME="part_bill_event.payby">
-            <OPTION SELECTED VALUE="">(all)
-            <OPTION VALUE="CARD">Credit card (automatic)
-            <OPTION VALUE="BILL">Billing
-            <OPTION VALUE="CHEK">Electronic check (automatic)
-            <OPTION VALUE="DCRD">Credit card (on-demand)
-            <OPTION VALUE="DCHK">Electronic check (on-demand)
-            <OPTION VALUE="LECB">Phone bill billing
-            <OPTION VALUE="COMP">Complimentary
-          </SELECT>
-        </TD>
-      </TR>
--->
     </TABLE>
     <BR><INPUT TYPE="submit" VALUE="Get Report">
     </FORM>