X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Felements%2Fstandardize_locations.js;h=debd9e7c45ee27f3e4b5fe97fdc7094d1681332b;hb=adc62b5c44f6e6fddda75aff0d594d7a7d95a403;hp=15c5761a06caf087286656d7c52d20139e68080e;hpb=a60615bf7bde77aa2b9faf3fc268c149eecdb5ab;p=freeside.git diff --git a/httemplate/elements/standardize_locations.js b/httemplate/elements/standardize_locations.js index 15c5761a0..debd9e7c4 100644 --- a/httemplate/elements/standardize_locations.js +++ b/httemplate/elements/standardize_locations.js @@ -7,17 +7,17 @@ function status_message(text, caption) { function form_address_info() { var cf = document.<% $formname %>; - var returnobj = { onlyship: <% $onlyship ? 1 : 0 %> }; -% if ( !$onlyship ) { + var returnobj = { billship: <% $billship %> }; +% if ( $billship ) { returnobj['same'] = cf.elements['same'].checked; % } -% if ( $withfirm ) { -% # not part of either address, really - returnobj['company'] = cf.elements['company'].value; -% } % if ( $withcensus ) { % # "entered" censustract always goes with the ship_ address if there is one - returnobj['ship_censustract'] = cf.elements['enter_censustract'].value; +% if ( $billship ) { + returnobj['ship_censustract'] = cf.elements['enter_censustract'].value; +% } else { # there's only a package address, so it's just "censustract" + returnobj['censustract'] = cf.elements['enter_censustract'].value; +% } % } % for my $pre (@prefixes) { if ( <% $pre eq 'ship_' ? 1 : 0 %> && returnobj['same'] ) { @@ -59,16 +59,12 @@ function standardize_locations() { cf.elements['<% $pre %>coord_auto'].value = 'Y'; changed = true; } - -% } #foreach $pre - // standardize if the old address wasn't clean - if ( cf.elements['old_ship_addr_clean'].value == '' || - cf.elements['old_bill_addr_clean'].value == '' ) { - + if ( cf.elements['<% $pre %>addr_clean'].value == '' ) { changed = true; - } +% } #foreach $pre + // or if it was clean but has been changed for (var key in address_info) { var old_el = cf.elements['old_'+key]; @@ -81,7 +77,8 @@ function standardize_locations() { % # If address hasn't been changed, auto-confirm the existing value of % # censustract so that we don't ask the user to confirm it again. - if ( !changed ) { + if ( !changed && <% $withcensus %> ) { +% if ( $billship ) { if ( address_info['same'] ) { cf.elements['bill_censustract'].value = address_info['bill_censustract']; @@ -89,6 +86,10 @@ function standardize_locations() { cf.elements['ship_censustract'].value = address_info['ship_censustract']; } +% } else { + cf.elements['censustract'].value = + address_info['censustract']; +% } } % if ( $conf->config('address_standardize_method') ) { @@ -180,6 +181,7 @@ function confirm_manual_address() { %# not much to do in this case, just confirm the censustract % if ( $withcensus ) { var cf = document.<% $formname %>; +% if ( $billship ) { if ( cf.elements['same'] && cf.elements['same'].checked ) { cf.elements['bill_censustract'].value = cf.elements['enter_censustract'].value; @@ -187,6 +189,9 @@ function confirm_manual_address() { cf.elements['ship_censustract'].value = cf.elements['enter_censustract'].value; } +% } else { + cf.elements['censustract'].value = cf.elements['enter_censustract'].value; +% } % } post_standardization(); } @@ -195,23 +200,34 @@ function post_standardization() { % if ( $conf->exists('enable_taxproducts') ) { - if ( new String(cf.elements['<% $taxpre %>zip'].value).length < 10 ) + var cf = document.<% $formname %>; + + var prefix = '<% $taxpre %>'; + // fix edge case with cust_main + if ( cf.elements['same'] + && cf.elements['same'].checked + && prefix == 'ship_' ) { + + prefix = 'bill_'; + } + + if ( new String(cf.elements[prefix + 'zip'].value).length < 10 ) { - var country_el = cf.elements['<% $taxpre %>country']; + var country_el = cf.elements[prefix + 'country']; var country = country_el.options[ country_el.selectedIndex ].value; - var geocode = cf.elements['geocode'].value; + var geocode = cf.elements[prefix + 'geocode'].value; if ( country == 'CA' || country == 'US' ) { - var state_el = cf.elements['<% $taxpre %>state']; + var state_el = cf.elements[prefix + 'state']; var state = state_el.options[ state_el.selectedIndex ].value; var url = "<% $p %>/misc/choose_tax_location.html" + "?data_vendor=cch-zip" + - ";city=" + cf.elements['<% $taxpre %>city'].value + + ";city=" + cf.elements[prefix + 'city'].value + ";state=" + state + - ";zip=" + cf.elements['<% $taxpre %>zip'].value + + ";zip=" + cf.elements[prefix + 'zip'].value + ";country=" + country + ";geocode=" + geocode + ";formname=" + '<% $formname %>' + @@ -222,14 +238,14 @@ function post_standardization() { } else { - cf.elements['geocode'].value = 'DEFAULT'; + cf.elements[prefix + 'geocode'].value = 'DEFAULT'; <% $post_geocode %>; } } else { - cf.elements['geocode'].value = ''; + cf.elements[prefix + 'geocode'].value = ''; <% $post_geocode %>; } @@ -248,20 +264,26 @@ function update_geocode() { set_geocode = function (what) { var cf = document.<% $formname %>; + var prefix = '<% $taxpre %>'; + if ( cf.elements['same'] + && cf.elements['same'].checked + && prefix == 'ship_' ) { + prefix = 'bill_'; + } //alert(what.options[what.selectedIndex].value); var argsHash = eval('(' + what.options[what.selectedIndex].value + ')'); - cf.elements['<% $taxpre %>city'].value = argsHash['city']; - setselect(cf.elements['<% $taxpre %>state'], argsHash['state']); - cf.elements['<% $taxpre %>zip'].value = argsHash['zip']; - cf.elements['geocode'].value = argsHash['geocode']; + cf.elements[prefix + 'city'].value = argsHash['city']; + setselect(cf.elements[prefix + 'state'], argsHash['state']); + cf.elements[prefix + 'zip'].value = argsHash['zip']; + cf.elements[prefix + 'geocode'].value = argsHash['geocode']; <% $post_geocode %>; } // popup a chooser - overlib( OLresponseAJAX, CAPTION, 'Select tax location', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 ); + overlib( OLresponseAJAX, CAPTION, 'Select tax location', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, WIDTH, 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 ); } @@ -279,21 +301,19 @@ function setselect(el, value) { my %opt = @_; my $conf = new FS::Conf; -my $withfirm = 1; -my $withcensus = 1; +my $withcensus = $opt{'with_census'} ? 1 : 0; + +my @prefixes = ''; +my $billship = $opt{'billship'} ? 1 : 0; # whether to have bill_ and ship_ prefixes +my $taxpre = ''; +# probably should just geocode both addresses, since either one could +# be a package address in the future +if ($billship) { + @prefixes = qw(bill_ ship_); + $taxpre = $conf->exists('tax-ship_address') ? 'ship_' : 'bill_'; +} my $formname = $opt{form} || 'CustomerForm'; -my $onlyship = $opt{onlyship} || ''; -#my $main_prefix = $opt{main_prefix} || ''; -#my $ship_prefix = $opt{ship_prefix} || ($onlyship ? '' : 'ship_'); -# The prefixes are now 'ship_' and 'bill_'. -my $taxpre = 'bill_'; -$taxpre = 'ship_' if ( $conf->exists('tax-ship_address') || $onlyship ); my $post_geocode = $opt{callback} || 'post_geocode();'; -$withfirm = 0 if $opt{no_company}; -$withcensus = 0 if $opt{no_census}; - -my @prefixes = ('ship_'); -unshift @prefixes, 'bill_' unless $onlyship;