From: Ivan Kohler <ivan@freeside.biz>
Date: Mon, 7 Dec 2015 18:54:37 +0000 (-0800)
Subject: fix customer browse in the presense of non-numeric agent_custid, RT#31388
X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=f2f7d6f2c69951862436cea6707d54451f6c4c65

fix customer browse in the presense of non-numeric agent_custid, RT#31388
---

diff --git a/httemplate/search/cust_main.cgi b/httemplate/search/cust_main.cgi
index ff13f072b..fb5988259 100755
--- a/httemplate/search/cust_main.cgi
+++ b/httemplate/search/cust_main.cgi
@@ -341,7 +341,12 @@ if ( $cgi->param('browse')
     if ( $query eq 'custnum' ) {
       if ( $conf->exists('cust_main-default_agent_custid') ) {
         $sortby=\*display_custnum_sort;
-        $orderby = "ORDER BY CASE WHEN agent_custid IS NOT NULL AND agent_custid != '' THEN CAST(agent_custid AS BIGINT) ELSE custnum END";
+        $orderby = "ORDER BY CASE WHEN agent_custid IS NOT NULL
+                                   AND agent_custid != ''
+                                   AND agent_custid ". regexp_sql. " '^[0-9]+\$'
+                             THEN CAST(agent_custid AS BIGINT)
+                             ELSE custnum
+                             END";
       } else {
         $sortby=\*custnum_sort;
         $orderby = "ORDER BY custnum";