[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 79b0b57ad2d21d18e0808f17a83feb6b1d735839

Ivan ivan at 420.am
Fri May 4 17:07:22 PDT 2012


The branch, FREESIDE_2_3_BRANCH has been updated
       via  79b0b57ad2d21d18e0808f17a83feb6b1d735839 (commit)
      from  a6230544e6104fa908abe3fdff92aa37de71562a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 79b0b57ad2d21d18e0808f17a83feb6b1d735839
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Fri May 4 17:07:19 2012 -0700

    add searchable and displayable legacy service id (cust_svc.agent_svcid), RT#17619

diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index d5cbcff..4b0422c 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -1638,14 +1638,15 @@ sub tables_hashref {
 
     'cust_svc' => {
       'columns' => [
-        'svcnum',    'serial',    '',   '', '', '', 
-        'pkgnum',    'int',    'NULL',   '', '', '', 
-        'svcpart',   'int',    '',   '', '', '', 
-        'overlimit', @date_type, '', '', 
+        'svcnum',      'serial',     '', '', '', '', 
+        'pkgnum',         'int', 'NULL', '', '', '', 
+        'svcpart',        'int',     '', '', '', '', 
+        'agent_svcid',    'int', 'NULL', '', '', '',
+        'overlimit',           @date_type,   '', '', 
       ],
       'primary_key' => 'svcnum',
       'unique' => [],
-      'index' => [ ['svcnum'], ['pkgnum'], ['svcpart'] ],
+      'index' => [ ['svcnum'], ['pkgnum'], ['svcpart'], [ 'agent_svcid' ] ],
     },
 
     'cust_svc_option' => {
diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm
index fc6e605..dacf41d 100644
--- a/FS/FS/cust_svc.pm
+++ b/FS/FS/cust_svc.pm
@@ -69,6 +69,8 @@ The following fields are currently supported:
 
 =item svcpart - Service definition (see L<FS::part_svc>)
 
+=item agent_svcid - Optional legacy service ID
+
 =item overlimit - date the service exceeded its usage limit
 
 =back
@@ -297,6 +299,7 @@ sub check {
     $self->ut_numbern('svcnum')
     || $self->ut_numbern('pkgnum')
     || $self->ut_number('svcpart')
+    || $self->ut_numbern('agent_svcid')
     || $self->ut_numbern('overlimit')
   ;
   return $error if $error;
@@ -424,9 +427,12 @@ sub svc_label_long { shift->_svc_label('label_long', @_); }
 sub _svc_label {
   my( $self, $method, $svc_x ) = ( shift, shift, shift );
 
+  my $identifier = $svc_x->$method(@_);
+  $identifier = '['.$self->agent_svcid.']'. $identifier if $self->agent_svcid;
+
   (
     $self->part_svc->svc,
-    $svc_x->$method(@_),
+    $identifier,
     $self->part_svc->svcdb,
     $self->svcnum
   );
@@ -758,6 +764,70 @@ sub get_session_history {
 
 =back
 
+=head1 SUBROUTINES
+
+=over 4
+
+=item smart_search OPTION => VALUE ...
+
+Accepts the option I<search>, the string to search for.  The string will 
+be searched for as a username, email address, IP address, MAC address, 
+phone number, and hardware serial number.  Unlike the I<smart_search> on 
+customers, this always requires an exact match.
+
+=cut
+
+# though perhaps it should be fuzzy in some cases?
+
+sub smart_search {
+  my %param = __PACKAGE__->smart_search_param(@_);
+  qsearch(\%param);
+}
+
+sub smart_search_param {
+  my $class = shift;
+  my %opt = @_;
+
+  my $string = $opt{'search'};
+  $string =~ s/(^\s+|\s+$)//; #trim leading & trailing whitespace
+
+  my @or = 
+      map { my $table = $_;
+            my $search_sql = "FS::$table"->search_sql($string);
+            " ( svcdb = '$table'
+	        AND 0 < ( SELECT COUNT(*) FROM $table
+	                    WHERE $table.svcnum = cust_svc.svcnum
+		              AND $search_sql
+	                )
+	      ) ";
+          }
+      FS::part_svc->svc_tables;
+
+  if ( $string =~ /^(\d+)$/ ) {
+    unshift @or, " ( agent_svcid IS NOT NULL AND agent_svcid = $1 ) ";
+  }
+
+  my @extra_sql = ' ( '. join(' OR ', @or). ' ) ';
+
+  push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql(
+    'null_right' => 'View/link unlinked services'
+  );
+  my $extra_sql = ' WHERE '.join(' AND ', @extra_sql);
+  #for agentnum
+  my $addl_from = ' LEFT JOIN cust_pkg  USING ( pkgnum  )'.
+                  ' LEFT JOIN cust_main USING ( custnum )'.
+                  ' LEFT JOIN part_svc  USING ( svcpart )';
+
+  (
+    'table'     => 'cust_svc',
+    'addl_from' => $addl_from,
+    'hashref'   => {},
+    'extra_sql' => $extra_sql,
+  );
+}
+
+=back
+
 =head1 BUGS
 
 Behaviour of changing the svcpart of cust_svc records is undefined and should
diff --git a/httemplate/search/cust_svc.html b/httemplate/search/cust_svc.html
index 9cf4bbd..585431e 100644
--- a/httemplate/search/cust_svc.html
+++ b/httemplate/search/cust_svc.html
@@ -42,79 +42,75 @@
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('List services');
 
-my $addl_from = ' LEFT JOIN part_svc  USING ( svcpart ) '.
-                ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
-                ' LEFT JOIN cust_main USING ( custnum ) ';
+my $sql_query;
 
-my @extra_sql = ();
 my $orderby = 'ORDER BY svcnum'; #has to be ordered by something
                                  #for pagination to work
+
 if ( length( $cgi->param('search_svc') ) ) {
 
-  my $string = $cgi->param('search_svc');
-  $string =~ s/(^\s+|\s+$)//; #trim leading & trailing whitespace
-
-  # implement fuzzy searching in subclasses too at some point?
-  # service searching maybe shouldn't be fuzzy...
-
-  push @extra_sql,
-    ' ( '. join(' OR ',
-      map { my $table = $_;
-            my $search_sql = "FS::$table"->search_sql($string);
-            " ( svcdb = '$table'
-	        AND 0 < ( SELECT COUNT(*) FROM $table
-	                    WHERE $table.svcnum = cust_svc.svcnum
-		              AND $search_sql
-	                )
-	      ) ";
-          }
-      FS::part_svc->svc_tables
-    ). ' ) ';
-
-} elsif ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
-
-  $cgi->param('svcdb') =~ /^(svc_\w+)$/ or die "unknown svcdb";
-  push @extra_sql, "svcdb = '$1'";
-  $addl_from .= " LEFT JOIN $1 USING ( svcnum ) ";
-
-  push @extra_sql, 'pkgnum IS NULL'
-    if $cgi->param('magic') eq 'unlinked';
-
-  if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
-    my $sortby = $1;
-    $orderby = "ORDER BY $sortby";
+  $sql_query = {
+    FS::cust_svc->smart_search_param(
+     'search' => scalar($cgi->param('search_svc'))
+    )
+  };
+
+} else {
+
+  my $addl_from = ' LEFT JOIN part_svc  USING ( svcpart ) '.
+                  ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
+                  ' LEFT JOIN cust_main USING ( custnum ) ';
+
+  my @extra_sql = ();
+
+  if ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
+
+    $cgi->param('svcdb') =~ /^(svc_\w+)$/ or die "unknown svcdb";
+    push @extra_sql, "svcdb = '$1'";
+    $addl_from .= " LEFT JOIN $1 USING ( svcnum ) ";
+
+    push @extra_sql, 'pkgnum IS NULL'
+      if $cgi->param('magic') eq 'unlinked';
+
+    if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
+      my $sortby = $1;
+      $orderby = "ORDER BY $sortby";
+    }
+
+  } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
+
+    push @extra_sql, "svcpart = $1";
+
+  } else {
+    errorpage("No search term specified");
   }
 
-} elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
+  #here is the agent virtualization
+  push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql( 
+                     'null_right' => 'View/link unlinked services'
+                   );
 
-  push @extra_sql, "svcpart = $1";
+  my $extra_sql = ' WHERE '. join(' AND ', @extra_sql );
+
+  $sql_query = {
+    'table'      => 'cust_svc',
+    'addl_from'  => $addl_from,
+    'hashref'    => {},
+    'extra_sql'  => $extra_sql,
+  };
 
-} else {
-  errorpage("No search term specified");
 }
 
-#here is the agent virtualization
-push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql( 
-                   'null_right' => 'View/link unlinked services'
-                 );
-
-my $extra_sql = ' WHERE '. join(' AND ', @extra_sql );
-
-my $sql_query = {
-  'select'     => join(', ',
-                    'cust_svc.*',
-		    'part_svc.*',
-		    'cust_main.custnum',
-		    FS::UI::Web::cust_sql_fields(),
-                  ),
-  'table'      => 'cust_svc',
-  'addl_from'  => $addl_from,
-  'hashref'    => {},
-  'extra_sql'  => $extra_sql,
-  'order_by'   => $orderby,
-};
+$sql_query->{'select'} = join(', ',
+                                    'cust_svc.*',
+                                    'part_svc.*',
+                                    'cust_main.custnum',
+                                    FS::UI::Web::cust_sql_fields(),
+                             );
+$sql_query->{'order_by'} = $orderby;
 
-my $count_query = "SELECT COUNT(*) FROM cust_svc $addl_from $extra_sql";
+my $count_query = "SELECT COUNT(*) FROM cust_svc ". $sql_query->{addl_from}.
+                                               ' '. $sql_query->{extra_sql};
 
 my $link = sub {
   my $cust_svc = shift;
diff --git a/httemplate/view/svc_acct.cgi b/httemplate/view/svc_acct.cgi
index e6507e6..5ea66a6 100755
--- a/httemplate/view/svc_acct.cgi
+++ b/httemplate/view/svc_acct.cgi
@@ -47,6 +47,7 @@
 <& svc_acct/basics.html,
               'svc_acct' => $svc_acct,
               'part_svc' => $part_svc,
+              'cust_svc' => $cust_svc,
               %gopt,
 &>
 
diff --git a/httemplate/view/svc_acct/basics.html b/httemplate/view/svc_acct/basics.html
index 8f180b6..bcd8469 100644
--- a/httemplate/view/svc_acct/basics.html
+++ b/httemplate/view/svc_acct/basics.html
@@ -1,6 +1,9 @@
 <% &ntable("#cccccc") %><TR><TD><% &ntable("#cccccc",2) %>
 
 <& /view/elements/tr.html, label=>mt('Service'),  value=>$part_svc->svc &>
+% if ( $opt{cust_svc}->agent_svcid ) {
+  <& /view/elements/tr.html, label=>mt('Legacy ID'),  value=>$opt{cust_svc}->agent_svcid &>
+% }
 <& /view/elements/tr.html, label=>mt('Username'), value=>$svc_acct->username &>
 <& /view/elements/tr.html, label=>mt('Domain'),   value=>$domain &>
 

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Schema.pm                      |   11 ++--
 FS/FS/cust_svc.pm                    |   72 ++++++++++++++++++++-
 httemplate/search/cust_svc.html      |  118 ++++++++++++++++-----------------
 httemplate/view/svc_acct.cgi         |    1 +
 httemplate/view/svc_acct/basics.html |    3 +
 5 files changed, 138 insertions(+), 67 deletions(-)




More information about the freeside-commits mailing list