5 include( '/elements/location.html',
6 'object' => $cust_main, # or $cust_location
7 'prefix' => $pre, #only for cust_main objects
8 'onchange' => $javascript,
9 'disabled' => $disabled,
10 'same_checked' => $same_checked,
11 'geocode' => $geocode, #passed through
12 'censustract' => $censustract, #passed through
13 'no_asterisks' => 0, #set true to disable the red asterisks next
15 'address1_label' => 'Address', #label for address
20 % if ( $opt{'alt_format'} ) {
23 <<%$th%> ALIGN="right">Location type</<%$th%>>
25 <% include('/elements/select.html',
27 'field' => 'location_kind',
28 'disabled' => $disabled,
30 'options' => \@location_kind_options,
31 'labels' => $location_kind_labels,
32 'curr_value' => scalar($cgi->param('location_kind'))
33 || $object->get($pre.'location_kind'),
42 <<%$th%> ALIGN="right"><%$r%><% $opt{'address1_label'} || 'Address' %></<%$th%>>
45 NAME = "<%$pre%>address1"
46 ID = "<%$pre%>address1"
47 VALUE = "<% $object->get($pre.'address1') |h %>"
49 onChange = "<% $onchange %>"
56 % if ( ! $opt{'alt_format'} ) { #regular format
59 <TD ALIGN="right"><FONT ID="<% $pre %>address2_required" color="#ff0000" <% $address2_label_style %>>*</FONT> <FONT ID="<% $pre %>address2_label" <% $address2_label_style %>><B>Unit #</B></FONT></TD>
62 NAME = "<%$pre%>address2"
63 ID = "<%$pre%>address2"
64 VALUE = "<% $object->get($pre.'address2') |h %>"
66 onChange = "<% $onchange %>"
73 % } else { # alternate format
75 <INPUT TYPE = "hidden"
76 NAME = "<%$pre%>address2"
77 VALUE = "<% $object->get($pre.'address2') |h %>"
81 <<%$th%> ALIGN="right">Unit Type and #</<%$th%>>
84 % my $location_type = scalar($cgi->param('location_type'))
85 % || $object->get($pre.'location_type');
86 % #my $location_number = scalar($cgi->param('location_number'))
87 % # || $object->get($pre.'location_number');
89 % if ( $object->get($pre.'address2') && ! $location_type ) {
92 % if ( 1 ) { #ikano, switch on via config
93 % tie my %location_types, 'Tie::IxHash',
94 % FS::part_export::ikano->location_types;
95 <% include('/elements/select.html',
97 'field' => 'location_type',
98 'disabled' => $disabled,
100 'options' => [ keys %location_types ],
101 'labels' => \%location_types,
102 'curr_value' => $location_type,
103 'onchange' => 'location_type_changed',
106 <SCRIPT TYPE="text/javascript">
107 function location_type_changed (what) {
108 if ( what.options[what.selectedIndex].value == '' ) {
109 what.form.location_number.disabled = true;
110 what.form.location_number.style.backgroundColor = '#dddddd';
112 what.form.location_number.disabled = false;
113 what.form.location_number.style.backgroundColor = '#ffffff';
119 NAME = "location_type"
121 VALUE = "<% $location_type |h %>"
129 NAME="location_number"
131 VALUE="<% scalar($cgi->param('location_number')) || $object->get($pre.'location_number') |h %>"
133 <% $disabled || ($location_type ? '' : 'DISABLED') %>
137 % if ( $object->get($pre.'address2') ) {
139 % #XXX try to parse first
142 Can't parse unit type and number from <B><% $object->get($pre.'address2') |h %></B>
155 <<%$th%> ALIGN="right"><%$r%>City</<%$th%>>
156 <TD WIDTH="1"><% include('/elements/city.html', %select_hash) %></TD>
157 <<%$th%> ALIGN="right" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</<%$th%>>
158 <TD><% include('/elements/select-county.html', %select_hash ) %></TD>
159 <<%$th%> ALIGN="right" WIDTH="1"><%$r%>State</<%$th%>>
161 <% include('/elements/select-state.html', %select_hash ) %>
163 <<%$th%>><%$r%>Zip</<%$th%>>
168 VALUE = "<% $object->get($pre.'zip') |h %>"
170 onChange = "<% $onchange %>"
178 <<%$th%> ALIGN="right"><%$r%>Country</<%$th%>>
179 <TD COLSPAN=6><% include('/elements/select-country.html', %select_hash ) %></TD>
183 <INPUT TYPE="hidden" NAME="geocode" VALUE="<% $opt{geocode} %>">
185 % if ( $pre eq 'ship_' && $conf->exists('cust_main-require_censustract') ) {
186 <TR><<%$th%> ALIGN="right">Census tract<BR>(automatic)</<%$th%>>
188 <INPUT TYPE="text" NAME="censustract" VALUE="<% $opt{censustract} %>">
192 <INPUT TYPE="hidden" NAME="censustract" VALUE="<% $opt{censustract} %>">
200 my $pre = $opt{'prefix'};
201 my $object = $opt{'object'};
202 my $onchange = $opt{'onchange'};
203 my $disabled = $opt{'disabled'};
205 my $conf = new FS::Conf;
207 my $r = $opt{'no_asterisks'} ? '' : qq!<font color="#ff0000">*</font> !;
209 #false laziness with ship state
210 my $countrydefault = $conf->config('countrydefault') || 'US';
211 $object->set($pre.'country', $countrydefault )
212 unless $object->get($pre.'country');
214 my $statedefault = $conf->config('statedefault')
215 || ($countrydefault eq 'US' ? 'CA' : '');
216 $object->set($pre.'state', $statedefault )
217 unless $object->get($pre.'state')
218 || $object->get($pre.'country') ne $countrydefault;
221 push @style, 'background-color: #dddddd' if $disabled;
223 my @address2_label_style = ();
224 push @address2_label_style, 'visibility:hidden'
226 || ! $conf->exists('cust_main-require_address2')
227 || ( !$pre && !$opt{'same_checked'} );
229 my @counties = counties( $object->get($pre.'state'),
230 $object->get($pre.'country'),
232 my @county_style = ();
233 push @county_style, 'display:none' # 'visibility:hidden'
234 unless scalar(@counties) > 1;
238 ? 'STYLE="'. join(';', @style). '"'
240 my $address2_label_style =
241 scalar(@address2_label_style)
242 ? 'STYLE="'. join(';', @address2_label_style). '"'
245 scalar(@county_style)
246 ? 'STYLE="'. join(';', @county_style). '"'
250 'city' => $object->get($pre.'city'),
251 'county' => $object->get($pre.'county'),
252 'state' => $object->get($pre.'state'),
253 'country' => $object->get($pre.'country'),
255 'onchange' => $onchange,
256 'disabled' => $disabled,
260 my $th = $opt{'no_bold'} ? 'TD' : 'TH';
262 my @location_kind_options = ( '', 'R', 'B' );
263 my $location_kind_labels = { '' => '', 'R' => 'Residential', 'B' => 'Business' };