From: Mark Wells Date: Fri, 1 Mar 2013 07:21:19 +0000 (-0800) Subject: enforce agent-ship_address in backend interface, #21327 X-Git-Url: http://git.freeside.biz/gitweb/?a=commitdiff_plain;h=6aa4566a38f2ef9a9580b976138bfa83e1a7d69d;p=freeside.git enforce agent-ship_address in backend interface, #21327 --- diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi index 3d9aa8002..3f25db173 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) {
<% mt('Service address') |h %> -(><% mt('same as billing address') |h %>) +(><% 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 558250cc2..0bdcae0f9 100644 --- a/httemplate/edit/cust_main/top_misc.html +++ b/httemplate/edit/cust_main/top_misc.html @@ -6,6 +6,39 @@ 'cgi' => $cgi, &> + %# agent % if ( $cgi->param('lock_agentnum') =~ /^(\d+)$/ && $curuser->agentnum($1) ) { % @@ -13,12 +46,13 @@ % $cust_main->agentnum($agentnum); - + <% mt('Agent') |h %> <% $cust_main->agent->agent |h %> - + % } 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!* !; +# 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) + }; +} + diff --git a/httemplate/edit/process/cust_main.cgi b/httemplate/edit/process/cust_main.cgi index c6c8ea1aa..29805beeb 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