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() {
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 = '';
<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_',
'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) ) {
%
% $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,
'empty_label' => emt('Select agent'),
'disable_empty' => ( $cust_main->agentnum ? 1 : 0 ),
'viewall_right' => emt('None'),
+ 'onchange' => 'agent_changed(this)',
&>
% }
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>
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