RT# 82137 - default payment amount now has processing fee in total if processing...
[freeside.git] / httemplate / elements / location.html
1 <%doc>
2
3 Example:
4
5   include( '/elements/location.html',
6              'object'         => $cust_location
7              'prefix'         => $pre, # prefixed to form field names
8              'onchange'       => $javascript,
9              'geocode'        => $geocode, #passed through
10              'censustract'    => $censustract, #passed through
11              'no_asterisks'   => 0, #set true to disable the red asterisks next
12                                     #to required fields
13              'address1_label' => 'Address', #label for address
14              'enable_coords'  => 1, #show latitude/longitude fields
15              'enable_district' => 1, #show tax district field
16              'enable_censustract' => 1, #show censustract field
17              
18          )
19
20 </%doc>
21
22 % if ( $opt{'alt_format'} ) {
23
24 <TR>
25     <<%$th%> ALIGN="right">Location&nbsp;kind</<%$th%>>
26     <TD>
27     <% include('/elements/select.html',
28                  'cgi'        => $cgi,
29                  'field'      => 'location_kind',
30                  'id'         => 'location_kind',
31                  'disabled'   => $disabled,
32                  #'style'      => \@style,
33                  'options'    => \@location_kind_options,
34                  'labels'     => $location_kind_labels,
35                  'curr_value' => scalar($cgi->param('location_kind'))
36                                    || $object->get('location_kind'),
37               )
38     %>
39     </TD>
40   </TR>
41
42 % } 
43
44 % if ( $label_prefix eq '_location' ) {
45
46     <TR>
47       <TH ALIGN="right" ><% $opt{'locationname_label'} || emt('Location ID') %></TD>
48       <TD COLSPAN=7>
49         <INPUT TYPE     = "text"
50                NAME     = "<%$pre%>locationname"
51                ID       = "<%$pre%>locationname"
52                VALUE    = "<% $object->get('locationname') |h %>"
53                SIZE     = 24
54                onChange = "<% $onchange %>"
55                <% $disabled %>
56                <% $style %>
57         >
58       </TD>
59     </TR>
60
61 % } else {
62     <& hidden.html, field => $pre.'locationname', value => $object->get('locationname') &>
63
64 % }
65
66 <TR>
67   <<%$th%> STYLE="width:16ex" ALIGN="right"><%$r%><% $opt{'address1_label'} || emt('Address') %></<%$th%>>
68   <TD COLSPAN=7>
69     <INPUT TYPE     = "text"
70            NAME     = "<%$pre%>address1"
71            ID       = "<%$pre%>address1"
72            VALUE    = "<% $object->get('address1') |h %>"
73            SIZE     = 54
74            onChange = "<% $onchange %>"
75            <% $disabled %>
76            <% $style %>
77     >
78   </TD>
79 </TR>
80
81 % if ( ! $opt{'alt_format'} ) { #regular format
82
83 <TR>
84       <TH ALIGN="right"><FONT ID="<% $pre %>address2_required" color="#ff0000" <% $address2_label_style %>>*</FONT>&nbsp;<FONT ID="<% $pre %>address2_label" <% $address2_label_style %>><B>Unit&nbsp;#</B></FONT></TD>
85       <TD COLSPAN=7>
86         <INPUT TYPE     = "text"
87                NAME     = "<%$pre%>address2"
88                ID       = "<%$pre%>address2"
89                VALUE    = "<% $object->get('address2') |h %>"
90                SIZE     = 54
91                onChange = "<% $onchange %>"
92                <% $disabled %>
93                <% $style %>
94         >
95       </TD>
96 </TR>
97
98 % } else { # alternate format
99
100 <& hidden.html, field => $pre.'address2', value => $object->get('address2') &>
101
102 <TR>
103     <<%$th%> ALIGN="right">Unit&nbsp;type&nbsp;and&nbsp;#</<%$th%>>
104     <TD COLSPAN=7>
105
106 %     my $location_type = scalar($cgi->param('location_type'))
107 %                           || $object->get('location_type');
108 %     #my $location_number = scalar($cgi->param('location_number'))
109 %     #                        || $object->get($pre.'location_number');
110 %
111 %   if ( $object->get($pre.'address2') && ! $location_type ) {
112 %   }
113 %
114 %     if ( 1 ) { #ikano, switch on via config
115 %       tie my %location_types, 'Tie::IxHash',
116 %         FS::part_export::ikano->location_types;
117         <% include('/elements/select.html',
118                      'cgi'        => $cgi,
119                      'field'      => 'location_type',
120                      'id'         => 'location_type',
121                      'disabled'   => $disabled,
122                      #'style'      => \@style,
123                      'options'    => [ keys %location_types ],
124                      'labels'     => \%location_types,
125                      'curr_value' => $location_type,
126                      'onchange'   => 'location_type_changed',
127                   )
128         %>
129         <SCRIPT TYPE="text/javascript">
130           function location_type_changed (what) {
131             if ( what.options[what.selectedIndex].value == '' ) {
132               what.form.location_number.disabled = true;
133               what.form.location_number.style.backgroundColor = '#dddddd';
134             } else {
135               what.form.location_number.disabled = false;
136               what.form.location_number.style.backgroundColor = '#ffffff';
137             }
138           }
139         </SCRIPT>
140 %     } else {
141         <INPUT TYPE  = "text" 
142                NAME  = "location_type" 
143                ID    = "location_type"
144                VALUE = "<% $location_type |h %>"
145                SIZE  = "10"
146                <% $disabled %>
147                <% $style %>
148         >
149 %     }
150
151     <INPUT TYPE="text" 
152                NAME  = "location_number"
153                ID    = "location_number"
154                VALUE = "<% scalar($cgi->param('location_number')) || $object->get('location_number') |h %>"
155                SIZE  = "5"
156                <% $disabled || ($location_type ? '' : 'DISABLED') %>
157                <% $style %>
158         >
159
160 %    #XXX i don't work so well when the dropdown is changed :/  i probably need to be triggered by "default service address"
161 %    $alt_err =~ s/(ship_)?address2/'<B>'.encode_entities($object->get($1.'address2')).'<\/B>'/e;
162      <% $alt_err %>
163
164     </TD>
165
166 </TR>
167
168 % } 
169
170
171 <TR>
172   <<%$th%> ALIGN="right">
173 % unless ($conf->exists('cust_main-no_city_in_address')) {
174   <% $r %><% mt('City') |h %>
175 % }
176   </<%$th%>>
177   <TD WIDTH="1"><% include('/elements/city.html', %select_hash, 'text_style' => \@style ) %></TD>
178   <<%$th%> ALIGN="right" WIDTH="1" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</<%$th%>>
179   <TD WIDTH="1"><% include('/elements/select-county.html', %select_hash ) %></TD>
180   <<%$th%> ALIGN="right" WIDTH="1"><%$r%><% mt('State') |h %></<%$th%>>
181   <TD WIDTH="1">
182     <% include('/elements/select-state.html', %select_hash ) %>
183   </TD>
184   <<%$th%> ALIGN="right" WIDTH="1"><%$r%><% mt('Zip') |h %></<%$th%>>
185   <TD>
186     <INPUT TYPE     = "text"
187            NAME     = "<%$pre%>zip"
188            ID       = "<%$pre%>zip"
189            VALUE    = "<% $object->get('zip') |h %>"
190            SIZE     = 11
191            onChange = "<% $onchange %>"
192            <% $disabled %>
193            <% $style %>
194     >
195   </TD>
196 </TR>
197
198 <TR>
199   <<%$th%> ALIGN="right"><%$r%><% mt('Country') |h %></<%$th%>>
200   <TD COLSPAN=6><% include('/elements/select-country.html', %select_hash ) %></TD>
201 </TR>
202
203 % if ( $opt{enable_coords} ) {
204 <TR>
205   <TH ALIGN="right"><% mt('Latitude') |h %></TD>
206   <TD COLSPAN=7>
207     <INPUT TYPE  = "text"
208            NAME  = "<%$pre%>latitude"
209            ID    = "<%$pre%>latitude"
210            VALUE = "<% $object->get('latitude') |h %>"
211            <% $disabled %>
212            <% $style %>
213     >
214     <FONT SIZE="-1" COLOR="#666666"><% mt('Longitude') |h %></FONT>
215     <INPUT TYPE  = "text"
216            NAME  = "<%$pre%>longitude"
217            ID    = "<%$pre%>longitude"
218            VALUE = "<% $object->get('longitude') |h %>"
219            <% $disabled %>
220            <% $style %>
221     >
222   </TD>
223 </TR>
224 % } else {
225 %   foreach (qw(latitude longitude)) {
226 <& hidden.html, field => $pre.$_, value => $object->get($_) &>
227 %   }
228 % }
229 %
230 % foreach (qw(coord_auto geocode censustract censusyear)) {
231   <& hidden.html, field => $pre.$_, value => $object->get($_) &>
232 % }
233 %
234 % if ( $opt{enable_censustract} ) {
235 <TR>
236   <TH ALIGN="right">Census&nbsp;tract</TD>
237   <TD COLSPAN=8>
238     <INPUT TYPE="text" SIZE=15
239            ID="<% $pre %>enter_censustract" 
240            NAME="<% $pre %>enter_censustract" 
241            VALUE="<% $object->censustract |h %>">
242     <FONT SIZE="-1" COLOR="#333333"><% '(automatic)' %></FONT>
243   </TD>
244 </TR>
245 % }
246 % if ( $opt{enable_district} and $conf->config('tax_district_method') ) {
247   <TR>
248     <TH ALIGN="right">Tax&nbsp;district</TH>
249     <TD COLSPAN=8>
250       <INPUT TYPE="text" SIZE=15
251              NAME="<%$pre%>district" 
252              ID="<%$pre%>district"
253              VALUE="<% $object->district |h %>">
254     <FONT SIZE="-1" COLOR="#333333"><% '(automatic)' %></FONT>
255     </TD>
256   </TR>
257 % } else {
258   <& hidden.html, field => $pre.'district', value => $object->get('district') &>
259 % }
260
261 %# For address standardization:
262 %# keep a clean copy of the address so we know if we need
263 %# to re-standardize
264 % foreach (qw(locationname address1 city state country zip latitude
265 %             longitude censustract district addr_clean
266 %             ) ) {
267 <& hidden.html, field => 'old_'.$pre.$_, value => $object->get($_) &>
268 % }
269 %# Placeholders
270 <& hidden.html, field => $pre.'cachenum', value => '' &>
271 <& hidden.html, field => $pre.'addr_clean', value => '' &>
272
273 <SCRIPT TYPE="text/javascript">
274 <&| /elements/onload.js &>
275   var clear_coords_ids = [
276     '<%$pre%>latitude',
277     '<%$pre%>longitude',
278     '<%$pre%>enter_censustract',
279     '<%$pre%>censustract',
280     '<%$pre%>district'
281   ];
282   function clear_coords() {
283     for (var i=0; i < clear_coords_ids.length; i++) {
284       var el = document.getElementById(clear_coords_ids[i]);
285       if ( el ) {
286         el.value = '';
287       }
288     }
289   }
290   var clear_coords_on_change = [
291     '<%$pre%>address1',
292     '<%$pre%>address2',
293     <% $conf->exists('cust_main-no_city_in_address') ? '' : qq('${pre}city',) %>
294     '<%$pre%>state',
295     '<%$pre%>zip',
296     '<%$pre%>country'
297   ];
298   for (var i=0; i < clear_coords_on_change.length; i++) {
299     var el = document.getElementById(clear_coords_on_change[i]);
300     if ( el.addEventListener ) {
301       el.addEventListener('change', clear_coords);
302     } else if ( el.attachEvent ) {
303       el.attachEvent('onchange', clear_coords);
304     }
305   }
306   function clear_censustract() {
307     // if the user manually edits the census tract, clear the 'hard' census
308     // tract field so that we can re-verify and present a confirmation popup 
309
310     // get the ID of the hidden censustract field
311     var censustract_id = this.id.replace('enter_', '');
312     var el = document.getElementById(censustract_id);
313     if (el) {
314       el.value = '';
315     }
316   }
317   var el = document.getElementById('<%$pre%>enter_censustract');
318   if (el) {
319     if ( el.addEventListener ) {
320       el.addEventListener('change', clear_censustract);
321     } else if ( el.attachEvent ) {
322       el.attachEvent('onchange', clear_censustract);
323     }
324   }
325
326 </&>
327 </SCRIPT>
328
329 <%init>
330
331 my %opt = @_;
332
333 my $pre      = $opt{'prefix'};
334 my $object   = $opt{'object'};
335 my $onchange = $opt{'onchange'};
336 my $disabled = $opt{'disabled'};
337
338 my $r = $opt{'no_asterisks'} ? '' : qq!<font color="#ff0000">*</font>&nbsp;!;
339
340 my $conf = new FS::Conf;
341 my $countrydefault = $conf->config('countrydefault') || 'US';
342 my $statedefault   = $conf->config('statedefault') 
343                        || ($countrydefault eq 'US' ? 'CA' : '');
344 my $label_prefix   = $conf->config('cust_location-label_prefix');
345
346 $object ||= FS::cust_location->new({
347   'country' => $countrydefault,
348   'state'   => $statedefault,
349 });
350
351 my $alt_err = ($opt{'alt_format'} && !$disabled) ? $object->alternize : '';
352
353 my @style = ();
354 push @style, 'background-color: #dddddd' if $disabled;
355
356 my @address2_label_style = ();
357 push @address2_label_style, 'visibility:hidden'
358   if $disabled
359   || ! $conf->exists('cust_main-require_address2')
360   || ( !$pre && !$opt{'same_checked'} );
361
362 my @counties = counties( $object->get('state'),
363                          $object->get('country'),
364                        );
365 my @county_style = ();
366 push @county_style, 'display:none' # 'visibility:hidden'
367   unless scalar(@counties) > 1;
368
369 my $style =
370   scalar(@style)
371     ? 'STYLE="'. join(';', @style). '"'
372     : '';
373 my $address2_label_style =
374   scalar(@address2_label_style)
375     ? 'STYLE="'. join(';', @address2_label_style). '"'
376     : '';
377 my $county_style = 
378   scalar(@county_style)
379     ? 'STYLE="'. join(';', @county_style). '"'
380     : '';
381
382 my %select_hash = (
383   'city'     => $object->get('city'),
384   'county'   => $object->get('county'),
385   'state'    => $object->get('state'),
386   'country'  => $object->get('country'),
387   'prefix'   => $pre,
388   'onchange' => $onchange,
389   'disabled' => $disabled,
390   #'style'    => \@style,
391 );
392
393 my $th = $opt{'no_bold'} ? 'TD' : 'TH';
394
395 my @location_kind_options = ( '', 'R', 'B' );
396 my $location_kind_labels = { '' => '', 'R' => 'Residential', 'B' => 'Business' };
397
398 </%init>