X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Felements%2Fstandardize_locations.js;h=817a2e3576878c47ded33f30637505af5251da66;hp=d7c36701ee57ce26aec5d25bf3f9ef10c894c5b2;hb=7516e3da0f17eeecba27219ef96a8b5f46af2083;hpb=3d0a1bb06b895c5be6e3f0517d355442a6b1e125 diff --git a/httemplate/elements/standardize_locations.js b/httemplate/elements/standardize_locations.js index d7c36701e..817a2e357 100644 --- a/httemplate/elements/standardize_locations.js +++ b/httemplate/elements/standardize_locations.js @@ -11,26 +11,14 @@ function form_address_info() { % if ( $billship ) { returnobj['same'] = cf.elements['same'].checked; % } -% if ( $withcensus ) { -% # "entered" censustract always goes with the ship_ address if there is one -% 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'] ) { -% # special case: don't include any ship_ fields, and move the entered -% # censustract over to bill_. - returnobj['bill_censustract'] = returnobj['ship_censustract']; - delete returnobj['ship_censustract']; - } else { % # normal case % for my $field (qw(address1 address2 city state zip country)) { returnobj['<% $pre %><% $field %>'] = cf.elements['<% $pre %><% $field %>'].value; % } #for $field - } // if returnobj['same'] +% if ( $withcensus ) { + returnobj['<% $pre %>censustract'] = cf.elements['<% $pre %>enter_censustract'].value; +% } % } #foreach $pre return returnobj; @@ -157,7 +145,7 @@ function replace_address() { var clean = newaddr['<% $pre %>addr_clean'] == 'Y'; var error = newaddr['<% $pre %>error']; if ( clean ) { -% foreach my $field (qw(address1 address2 city state zip addr_clean censustract)) { +% foreach my $field (qw(address1 address2 city state zip addr_clean )) { cf.elements['<% $pre %><% $field %>'].value = newaddr['<% $pre %><% $field %>']; % } #foreach $field @@ -181,44 +169,45 @@ 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; - } else { - cf.elements['ship_censustract'].value = - cf.elements['enter_censustract'].value; - } -% } else { - cf.elements['censustract'].value = cf.elements['enter_censustract'].value; +% foreach my $pre (@prefixes) { + cf.elements['<% $pre %>censustract'].value = + cf.elements['<% $pre %>enter_censustract'].value; % } -% } +% } # $withcensus post_standardization(); } function post_standardization() { -% if ( $conf->exists('enable_taxproducts') ) { +% if ( $need_tax_location ) { var cf = document.<% $formname %>; - if ( new String(cf.elements['<% $taxpre %>zip'].value).length < 10 ) + 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['bill_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 + + var url = "<% $p %>/misc/choose_tax_location.html?" + + "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 %>' + @@ -229,14 +218,14 @@ function post_standardization() { } else { - cf.elements['bill_geocode'].value = 'DEFAULT'; + cf.elements[prefix + 'geocode'].value = 'DEFAULT'; <% $post_geocode %>; } } else { - cf.elements['bill_geocode'].value = ''; + cf.elements[prefix + 'geocode'].value = ''; <% $post_geocode %>; } @@ -255,13 +244,17 @@ 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['bill_geocode'].value = argsHash['geocode']; +%# this used to set the city/state/zip to the selected value; I think +%# that's wrong. + var argsHash = JSON.parse(what.value); + cf.elements[prefix + 'geocode'].value = argsHash['geocode']; <% $post_geocode %>; } @@ -281,6 +274,45 @@ function setselect(el, value) { } } + +% if ($census_functions) { # do not use this in cust_main +function confirm_censustract() { +% if ( FS::Conf->new->exists('cust_main-require_censustract') ) { + var form = document.<% $formname %>; + // this is the existing/confirmed censustract, not the manually entered one + if ( form.elements['censustract'].value == '' || + form.elements['censustract'].value != + form.elements['enter_censustract'].value ) { + var address_info = form_address_info(); + address_info['latitude'] = form.elements['latitude'].value; + address_info['longitude'] = form.elements['longitude'].value; + OLpostAJAX( + '<%$p%>/misc/confirm-censustract.html', + 'q=' + encodeURIComponent(JSON.stringify(address_info)), + function() { + overlib( OLresponseAJAX, CAPTION, 'Confirm censustract', STICKY, + AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, + 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', + TEXTSIZE, 3 ); + }, + 0); + } else { + <% $post_censustract %>; + } +% } else { # skip this step + <% $post_censustract %>; +% } +} + +function set_censustract(tract, year) { + var form = document.<% $formname %>; + form.elements['censustract'].value = tract; + form.elements['censusyear'].value = year; + <% $post_censustract %>; +} + +% } # $census_functions + <%init> my %opt = @_; @@ -300,5 +332,15 @@ if ($billship) { my $formname = $opt{form} || 'CustomerForm'; my $post_geocode = $opt{callback} || 'post_geocode();'; +my $post_censustract; + +my $census_functions = $opt{'with_census_functions'} ? 1 : 0; +if ( $census_functions ) { + $post_censustract = $post_geocode; + $post_geocode = 'confirm_censustract()'; +} + +my $tax_engine = FS::TaxEngine->new; +my $need_tax_location = $tax_engine->info->{manual_tax_location} ? 1 : 0;