[freeside-commits] branch master updated. daa09251fec52517b630b3f6935041dc7c795f90

Ivan ivan at 420.am
Wed Jun 13 14:35:01 PDT 2012


The branch, master has been updated
       via  daa09251fec52517b630b3f6935041dc7c795f90 (commit)
       via  15dbf6151b7e6e3b32e55fd6609725f650349460 (commit)
      from  41967a7cac39ce2156b9b86436ade82f9a99104e (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 daa09251fec52517b630b3f6935041dc7c795f90
Merge: 15dbf61 41967a7
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Wed Jun 13 14:34:53 2012 -0700

    Merge branch 'master' of git.freeside.biz:/home/git/freeside


commit 15dbf6151b7e6e3b32e55fd6609725f650349460
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Wed Jun 13 14:34:46 2012 -0700

    quick payment entry: if both a custnum and an agent_custid match, allow the user to pick, RT#18100

diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm
index 75859c3..3a8acb2 100644
--- a/FS/FS/cust_main/Search.pm
+++ b/FS/FS/cust_main/Search.pm
@@ -140,10 +140,12 @@ sub smart_search {
     my $num = $1;
 
     if ( $num =~ /^(\d+)$/ && $num <= 2147483647 ) { #need a bigint custnum? wow
+      my $agent_custid_null = $conf->exists('cust_main-default_agent_custid')
+                                ? ' AND agent_custid IS NULL ' : '';
       push @cust_main, qsearch( {
         'table'     => 'cust_main',
         'hashref'   => { 'custnum' => $num, %options },
-        'extra_sql' => " AND $agentnums_sql", #agent virtualization
+        'extra_sql' => " AND $agentnums_sql $agent_custid_null",
       } );
     }
 
diff --git a/httemplate/elements/customer-table.html b/httemplate/elements/customer-table.html
index a1e9732..79443dc 100644
--- a/httemplate/elements/customer-table.html
+++ b/httemplate/elements/customer-table.html
@@ -179,15 +179,16 @@ Example:
     if ( ( <% $opt{prefix} %>rownum - searchrow ) == 1 ) {
       <% $opt{prefix} %>addRow();
     }
-    var customer = document.getElementById('customer'+searchrow);
-    customer.value = 'searching...';
-    customer.disabled = true;
-    customer.style.color = '#000000';
-    customer.style.backgroundColor = '#dddddd';
+
+    var customer_obj = document.getElementById('customer'+searchrow);
+    customer_obj.value = 'searching...';
+    customer_obj.disabled = true;
+    customer_obj.style.color = '#000000';
+    customer_obj.style.backgroundColor = '#dddddd';
 
     var customer_select = document.getElementById('cust_select'+searchrow);
 
-    customer.style.display = '';
+    customer_obj.style.display = '';
     customer_select.style.display = 'none';
 
     var invnum = document.getElementById('invnum'+searchrow);
@@ -200,12 +201,40 @@ Example:
 
     function search_custnum_update(customers) {
 
-      var customerArray = eval('(' + customers + ')') || [];
-      update_customer(searchrow, customerArray);
+      var customerArrayArray = eval('(' + customers + ')') || [];
 
+      if ( customerArrayArray.length == 1 ) {
+
+        update_customer(searchrow, customerArrayArray[0]);
 % if ( $opt{custnum_update_callback} ) {
-        <% $opt{custnum_update_callback} %>(searchrow, '<% $opt{prefix} %>')
+          <% $opt{custnum_update_callback} %>(searchrow, '<% $opt{prefix} %>')
 % }
+
+      } else {
+
+        custnum_obj.value = 'Multiple'; // or something
+        custnum_obj.style.color = '#ff0000';
+
+        //blank the current list
+        customer_select.options.length = 0;
+
+        opt(customer_select, '', 'Multiple customers match "' + custnum + '" - select one', '#ff0000');
+        //add the multiple customers
+        for ( var s = 0; s < customerArrayArray.length; s++ ) {
+          opt(customer_select,
+              JSON.stringify(customerArrayArray[s]),
+              customerArrayArray[s][1],
+              '#000000');
+        }
+
+        opt(customer_select, 'cancel', '(Edit search string)', '#000000');
+
+        customer_obj.style.display = 'none';
+
+        customer_select.style.display = '';
+
+      }
+
     }
 
     custnum_search(custnum, search_custnum_update );
diff --git a/httemplate/misc/xmlhttp-cust_main-search.cgi b/httemplate/misc/xmlhttp-cust_main-search.cgi
index 86983e4..16f7cd2 100644
--- a/httemplate/misc/xmlhttp-cust_main-search.cgi
+++ b/httemplate/misc/xmlhttp-cust_main-search.cgi
@@ -1,9 +1,9 @@
 % if ( $sub eq 'custnum_search' ) { 
 %   my $custnum = $cgi->param('arg');
 %   my $return = [];
-%   if ( $custnum =~ /^(\d+)$/ ) {
-%	$return = findbycustnum($1,0);
-%   	$return = findbycustnum($1,1) if(!scalar(@$return));
+%   if ( $custnum =~ /^(\d+)$/ ) { #should also handle
+%                                  # cust_main-agent_custid-format') eq 'ww?d+'
+%	$return = findbycustnum_or_agent_custid($1);
 %   }
 <% objToJson($return) %>
 % } elsif ( $sub eq 'smart_search' ) {
@@ -12,7 +12,15 @@
 %   my @cust_main = smart_search( 'search' => $string,
 %                                 'no_fuzzy_on_exact' => 1, #pref?
 %                               );
-%   my $return = [ map [ $_->custnum, $_->name, $_->balance, $_->ucfirst_status, $_->statuscolor, scalar($_->open_cust_bill) ], @cust_main ];
+%   my $return = [ map [ $_->custnum,
+%                        $_->name,
+%                        $_->balance,
+%                        $_->ucfirst_status,
+%                        $_->statuscolor,
+%                        scalar($_->open_cust_bill)
+%                      ],
+%                    @cust_main
+%                ];
 %     
 <% objToJson($return) %>
 % } elsif ( $sub eq 'invnum_search' ) {
@@ -20,7 +28,7 @@
 %   my $string = $cgi->param('arg');
 %   if ( $string =~ /^(\d+)$/ ) {
 %     my $inv = qsearchs('cust_bill', { 'invnum' => $1 });
-%     my $return = $inv ? findbycustnum($inv->custnum,0) : [];
+%     my $return = $inv ? findbycustnum($inv->custnum) : [];
 <% objToJson($return) %>
 %   } else { #return nothing
 []
@@ -43,22 +51,58 @@
 % }
 <%init>
 
-my $conf = new FS::Conf;
-
 my $sub = $cgi->param('sub');
 
-sub findbycustnum{
-    my $custnum = shift;
-    my $agent = shift;
-    my $hashref = { 'custnum' => $custnum };
-    $hashref = { 'agent_custid' => $custnum } if $agent;
-    my $c = qsearchs({
-       	'table'   => 'cust_main',
-       	'hashref' => $hashref,
-       	'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
-     		});
-   return [ $c->custnum, $c->name, $c->balance, $c->ucfirst_status, $c->statuscolor, scalar($c->open_cust_bill) ] 
-	if $c;
-   [];
+sub findbycustnum {
+
+  my $c = qsearchs({
+    'table'     => 'cust_main',
+    'hashref'   => { 'custnum' => shift },
+    'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
+  }) or return [];
+
+  [ $c->custnum,
+    $c->name,
+    $c->balance,
+    $c->ucfirst_status,
+    $c->statuscolor,
+    scalar($c->open_cust_bill)
+  ];
+}
+
+sub findbycustnum_or_agent_custid {
+  my $num = shift;
+
+  my @or = ( 'agent_custid = ?' );
+  my @param = ( $num );
+
+  if ( $num =~ /^\d+$/ && $num <= 2147483647 ) { #need a bigint custnum? wow
+    my $conf = new FS::Conf;
+    if ( $conf->exists('cust_main-default_agent_custid') ) {
+      push @or, "( agent_custid IS NULL AND custnum = $num )";
+    } else {
+      push @or, "custnum = $num";
+    }
+  }
+
+  my $extra_sql = ' WHERE '. $FS::CurrentUser::CurrentUser->agentnums_sql.
+                  ' AND ( '. join(' OR ', @or). ' )';
+                      
+  [ map [ $_->custnum,
+          $_->name,
+          $_->balance,
+          $_->ucfirst_status,
+          $_->statuscolor,
+          scalar($_->open_cust_bill),
+        ],
+
+      qsearch({
+        'table'       => 'cust_main',
+        'hashref'     => {},
+        'extra_sql'   => $extra_sql,
+        'extra_param' => \@param,
+      })
+  ];
 }
+
 </%init>

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

Summary of changes:
 FS/FS/cust_main/Search.pm                    |    4 +-
 httemplate/elements/customer-table.html      |   47 ++++++++++++---
 httemplate/misc/xmlhttp-cust_main-search.cgi |   84 +++++++++++++++++++------
 3 files changed, 105 insertions(+), 30 deletions(-)




More information about the freeside-commits mailing list