searching kingcon's idea of legacy customer numbers without remembering leading 0s
[freeside.git] / FS / FS / cust_main / Search.pm
index ad24ff8..4582072 100644 (file)
@@ -112,8 +112,17 @@ sub smart_search {
   # custnum search (also try agent_custid), with some tweaking options if your
   # legacy cust "numbers" have letters
   } 
-
-  if ( $search =~ /^\s*(\d+)\s*$/
+  
+  
+  if ( $search =~ /@/ ) {
+      push @cust_main,
+         map $_->cust_main,
+             qsearch( {
+                        'table'     => 'cust_main_invoice',
+                        'hashref'   => { 'dest' => $search },
+                      }
+                    );
+  } elsif ( $search =~ /^\s*(\d+)\s*$/
          || ( $conf->config('cust_main-agent_custid-format') eq 'ww?d+'
               && $search =~ /^\s*(\w\w?\d+)\s*$/
             )
@@ -133,9 +142,14 @@ sub smart_search {
       } );
     }
 
+    my $anum = $num;
+    if ( $conf->config('cust_main-agent_custid-format') =~ /^\\d\{(\d+)\}$/ ) {
+      $anum = sprintf("%0$1u", $num);
+    }
+
     push @cust_main, qsearch( {
       'table'     => 'cust_main',
-      'hashref'   => { 'agent_custid' => $num, %options },
+      'hashref'   => { 'agent_custid' => $anum, %options },
       'extra_sql' => " AND $agentnums_sql", #agent virtualization
     } );