[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 6aa4566a38f2ef9a9580b976138bfa83e1a7d69d

Mark Wells mark at 420.am
Thu Feb 28 23:32:59 PST 2013


The branch, FREESIDE_2_3_BRANCH has been updated
       via  6aa4566a38f2ef9a9580b976138bfa83e1a7d69d (commit)
      from  8e901031d883660ed0052f49600c5dd3c5c65e05 (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 6aa4566a38f2ef9a9580b976138bfa83e1a7d69d
Author: Mark Wells <mark at freeside.biz>
Date:   Thu Feb 28 23:21:19 2013 -0800

    enforce agent-ship_address in backend interface, #21327

diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi
index 3d9aa80..3f25db1 100755
--- a/httemplate/edit/cust_main.cgi
+++ b/httemplate/edit/cust_main.cgi
@@ -79,7 +79,9 @@ function bill_changed(what) {
     function fix_ship_city() {
       what.form.ship_city_select.selectedIndex = what.form.city_select.selectedIndex;
       what.form.ship_city.style.display = what.form.city.style.display;
-      what.form.ship_city_select.style.display = what.form.city_select.style.display;
+      if ( what.form.ship_city_select ) {
+        what.form.ship_city_select.style.display = what.form.city_select.style.display;
+      }
     }
 
     function fix_ship_county() {
@@ -100,11 +102,15 @@ function samechanged(what) {
   if ( what.checked ) {
     bill_changed(what);
 
-%   my @fields = qw( last first company address1 address2 city city_select county state zip country latitude longitude daytime night fax mobile );
+%   my @fields = qw( last first company address1 address2 city county state zip country latitude longitude daytime night fax mobile );
 %   for (@fields) { 
       what.form.ship_<%$_%>.disabled = true;
       what.form.ship_<%$_%>.style.backgroundColor = '#dddddd';
-%   } 
+%   }
+    if ( what.form.ship_city_select ) {
+      what.form.ship_city_select.disabled = true;
+      what.form.ship_city_select.style.backgroundColor = '#dddddd';
+    }
 
 %   if ( $conf->exists('cust_main-require_address2') ) {
       document.getElementById('address2_required').style.visibility = '';
@@ -134,7 +140,7 @@ function samechanged(what) {
 <BR>
 <FONT SIZE="+1"><B><% mt('Service address') |h %></B></FONT>
 
-(<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$same_checked%>><% mt('same as billing address') |h %>)
+(<INPUT TYPE="checkbox" ID="same" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$same_checked%>><% mt('same as billing address') |h %>)
 <& cust_main/contact.html,
              'cust_main' => $cust_main,
              'pre'       => 'ship_',
diff --git a/httemplate/edit/cust_main/top_misc.html b/httemplate/edit/cust_main/top_misc.html
index 558250c..0bdcae0 100644
--- a/httemplate/edit/cust_main/top_misc.html
+++ b/httemplate/edit/cust_main/top_misc.html
@@ -6,6 +6,39 @@
              'cgi'     => $cgi,
 &>
 
+<SCRIPT TYPE="text/javascript">
+var ship_locked_agents = <% encode_json(\%ship_locked_agents) %>;
+var ship_fields = ['address1', 'city', 'state', 
+  'zip', 'country', 'latitude', 'longitude'];
+function agent_changed(what) {
+  var agentnum = what.value;
+  var f = what.form;
+  if ( ship_locked_agents[agentnum] ) {
+    f['same'].checked = false;
+    f['same'].disabled = true;
+    samechanged(f['same']);
+    for(var x in ship_locked_agents[agentnum]) {
+      f['ship_'+x].value = ship_locked_agents[agentnum][x];
+      f['ship_'+x].disabled = true;
+      f['ship_'+x].style.backgroundColor = '#dddddd';
+    }
+    f['ship_address2'].disabled = false;
+    f['ship_address2'].style.backgroundColor = '#ffffff';
+  } else {
+    for(var i=0; i<ship_fields.length; i++) {
+      x = ship_fields[i];
+      f['ship_'+x].value = '';
+      f['ship_'+x].disabled = false;
+    }
+    f['same'].checked = true;
+    f['same'].disabled = false;
+    samechanged(f['same']);
+  }
+}
+window.onload = function() {
+  agent_changed(document.getElementById('agentnum'));
+};
+</SCRIPT>
 %# agent
 % if ( $cgi->param('lock_agentnum') =~ /^(\d+)$/ && $curuser->agentnum($1) ) {
 %
@@ -13,12 +46,13 @@
 %   $cust_main->agentnum($agentnum);
 
     <INPUT TYPE="hidden" NAME="lock_agentnum" VALUE="<% $agentnum %>">
-    <INPUT TYPE="hidden" NAME="agentnum"      VALUE="<% $agentnum %>">
+    <INPUT TYPE="hidden" NAME="agentnum"      ID="agentnum" 
+      VALUE="<% $agentnum %>">
     <TR>
       <TD ALIGN="right"><% mt('Agent') |h %></TD>
       <TD CLASS="fsdisabled"><% $cust_main->agent->agent |h %></TD>
     </TR>
- 
+
 % } else {
 
   <& /elements/tr-select-agent.html, 
@@ -27,6 +61,7 @@
                 'empty_label'   => emt('Select agent'),
                 'disable_empty' => ( $cust_main->agentnum ? 1 : 0 ),
                 'viewall_right' => emt('None'), 
+                'onchange'      => 'agent_changed(this)',
   &>
 
 % }
@@ -146,4 +181,18 @@ my $curuser = $FS::CurrentUser::CurrentUser;
 
 my $r = qq!<font color="#ff0000">*</font> !;
 
+# which agents lock the service address, if any
+my %ship_locked_agents;
+foreach (qsearch('agent',{})) {
+  my $agentnum = $_->agentnum;
+  next unless $conf->exists('agent-ship_address', $_->agentnum);
+  my $agent_cust_main = $_->agent_cust_main or next;
+  my $pre = '';
+  $pre = 'ship_' if $agent_cust_main->has_ship_address;
+  $ship_locked_agents{$agentnum} = +{
+    map { $_ => $agent_cust_main->get($pre.$_) }
+    qw(address1 city state zip country latitude longitude)
+  };
+}
+
 </%init>
diff --git a/httemplate/edit/process/cust_main.cgi b/httemplate/edit/process/cust_main.cgi
index c6c8ea1..29805be 100755
--- a/httemplate/edit/process/cust_main.cgi
+++ b/httemplate/edit/process/cust_main.cgi
@@ -78,6 +78,23 @@ if ( $duplicate_of ) {
     or die "nonexistent existing customer (custnum $duplicate_of)";
 }
 
+# if this is enabled, enforce it
+if ( $conf->exists('agent-ship_address', $cgi->param('agentnum')) ) {
+  my $agent = FS::agent->by_key($cgi->param('agentnum'));
+  my $agent_cust_main = $agent->agent_cust_main;
+  if ( $agent_cust_main ) {
+    my $pre = '';
+    $pre = 'ship_' if $agent_cust_main->has_ship_address;
+    foreach (qw(address1 city state zip country latitude longitude)) {
+      $new->set("ship_$_", $agent_cust_main->get($pre.$_));
+    }
+    foreach (qw(first last company)) {
+      $new->set("ship_$_", $cgi->param($_));
+    }
+    $cgi->param('same', '');
+  }
+}
+
 if ( defined($cgi->param('same')) && $cgi->param('same') eq "Y" ) {
   $new->setfield("ship_$_", '') foreach qw(
     last first company address1 address2 city county state zip

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

Summary of changes:
 httemplate/edit/cust_main.cgi           |   14 ++++++--
 httemplate/edit/cust_main/top_misc.html |   53 +++++++++++++++++++++++++++++-
 httemplate/edit/process/cust_main.cgi   |   17 ++++++++++
 3 files changed, 78 insertions(+), 6 deletions(-)




More information about the freeside-commits mailing list