fixes to facilitate using agent_custid as custnum, RT#4190
authorivan <ivan>
Fri, 24 Oct 2008 02:08:21 +0000 (02:08 +0000)
committerivan <ivan>
Fri, 24 Oct 2008 02:08:21 +0000 (02:08 +0000)
FS/FS/cust_main.pm
httemplate/misc/xmlhttp-cust_main-search.cgi

index 772942b..aa97d22 100644 (file)
@@ -5988,22 +5988,28 @@ sub smart_search {
 
   # custnum search (also try agent_custid), with some tweaking options if your
   # legacy cust "numbers" have letters
-  } elsif ( $search =~ /^\s*(\d+)\s*$/
+  } 
+
+  if ( $search =~ /^\s*(\d+)\s*$/
             || ( $conf->config('cust_main-agent_custid-format') eq 'ww?d+'
                  && $search =~ /^\s*(\w\w?\d+)\s*$/
                )
           )
   {
 
-    push @cust_main, qsearch( {
-      'table'     => 'cust_main',
-      'hashref'   => { 'custnum' => $1, %options },
-      'extra_sql' => " AND $agentnums_sql", #agent virtualization
-    } );
+    my $num = $1;
+
+    if ( $num <= 2147483647 ) { #need a bigint custnum?  wow.
+      push @cust_main, qsearch( {
+        'table'     => 'cust_main',
+        'hashref'   => { 'custnum' => $num, %options },
+        'extra_sql' => " AND $agentnums_sql", #agent virtualization
+      } );
+    }
 
     push @cust_main, qsearch( {
       'table'     => 'cust_main',
-      'hashref'   => { 'agent_custid' => $1, %options },
+      'hashref'   => { 'agent_custid' => $num, %options },
       'extra_sql' => " AND $agentnums_sql", #agent virtualization
     } );
 
index 20707da..26e68b5 100644 (file)
@@ -1,11 +1,21 @@
 % if ( $sub eq 'custnum_search' ) {
 % 
 %   my $custnum = $cgi->param('arg');
-%   my $cust_main = qsearchs({
-%     'table'   => 'cust_main',
-%     'hashref' => { 'custnum' => $custnum },
-%     'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
-%   });
+%   my $cust_main = '';
+%   if ( $custnum <= 2147483647 ) {
+%     $cust_main = qsearchs({
+%       'table'   => 'cust_main',
+%       'hashref' => { 'custnum' => $custnum },
+%       'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
+%     });
+%   }
+%   if ( ! $cust_main ) {
+%     $cust_main = qsearchs({
+%       'table'   => 'cust_main',
+%       'hashref' => { 'agent_custid' => $custnum },
+%       'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
+%     });
+%   }
 %     
 "<% $cust_main ? $cust_main->name : '' %>"
 %
@@ -19,6 +29,8 @@
 % } 
 <%init>
 
+my $conf = new FS::Conf;
+
 my $sub = $cgi->param('sub');
 
 </%init>