function status_message(text, caption) {
text = '<P STYLE="position:absolute; top:50%; margin-top:-1em; width:100%; text-align:center"><B><FONT SIZE="+1">' + text + '</FONT></B></P>';
caption = caption || 'Please wait...';
- overlib(text, WIDTH, 444, HEIGHT, 168, CAPTION, caption, STICKY, AUTOSTATUSCAP, CLOSECLICK, MIDX, 0, MIDY, 0);
+ overlib(text, WIDTH, 444, HEIGHT, 168, CAPTION, caption, STICKY, AUTOSTATUSCAP, CLOSECLICK, NOCLOSE, MIDX, 0, MIDY, 0);
}
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;
-% }
% 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)) {
+% for my $field (qw(address1 address2 state zip country), ($conf->exists('cust_main-no_city_in_address') ? () : 'city')) {
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;
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];
% # 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'];
cf.elements['ship_censustract'].value =
address_info['ship_censustract'];
}
+% } else {
+ cf.elements['censustract'].value =
+ address_info['censustract'];
+% }
}
% if ( $conf->config('address_standardize_method') ) {
// then all entered address fields are correct
// but we still need to set the lat/long fields and addr_clean
- status_message('Verified');
+
+ if ( returned['all_clean'] ) {
+ status_message('Verified');
+ } else {
+ status_message('Unverified');
+ }
replace_address();
} else {
function() {
overlib( OLresponseAJAX, CAPTION, 'Address standardization', STICKY,
AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH,
- 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399',
+ 650, HEIGHT, 368, BGCOLOR, '#333399', CGCOLOR, '#333399',
TEXTSIZE, 3 );
}, 0);
var newaddr = returned['new'];
var cf = document.<% $formname %>;
+ var crf = document.forms['confirm_replace_form'];
% foreach my $pre (@prefixes) {
var clean = newaddr['<% $pre %>addr_clean'] == 'Y';
+ var replace = true; // auto_standardize_address won't load the form, so just do it
+ if ( crf && crf['<% $pre %>replace'] ) {
+ replace = crf['<% $pre %>replace'].value == 'Y';
+ }
var error = newaddr['<% $pre %>error'];
- if ( clean ) {
-% foreach my $field (qw(address1 address2 city state zip addr_clean censustract)) {
+ if ( clean && replace ) {
+% foreach my $field (qw(address1 address2 state zip addr_clean ),($conf->exists('cust_main-no_city_in_address') ? () : 'city')) {
cf.elements['<% $pre %><% $field %>'].value = newaddr['<% $pre %><% $field %>'];
% } #foreach $field
cf.elements['<% $pre %>longitude'].value = newaddr['<% $pre %>longitude'];
}
% if ( $withcensus ) {
- if ( clean && newaddr['<% $pre %>censustract'] ) {
+ var census_replace = true;
+ if ( crf && crf['census_replace'] ) {
+ census_replace = crf['census_replace'].value == 'Y';
+ }
+
+ if ( clean && census_replace && newaddr['<% $pre %>censustract'] ) {
cf.elements['<% $pre %>censustract'].value = newaddr['<% $pre %>censustract'];
}
% } #if $withcensus
%# not much to do in this case, just confirm the censustract
% if ( $withcensus ) {
var cf = document.<% $formname %>;
- 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;
- }
-% }
+% 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 ) {
- if ( new String(cf.elements['<% $taxpre %>zip'].value).length < 10 )
- {
+ var cf = document.<% $formname %>;
- var country_el = cf.elements['<% $taxpre %>country'];
+ 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[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 +
+ 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 %>' +
} else {
- cf.elements['geocode'].value = 'DEFAULT';
+ cf.elements[prefix + 'geocode'].value = 'DEFAULT';
<% $post_geocode %>;
}
- } else {
-
- cf.elements['geocode'].value = '';
- <% $post_geocode %>;
-
- }
+// } else {
+//
+// cf.elements[prefix + 'geocode'].value = '';
+// <% $post_geocode %>;
+//
+// }
% } else {
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'];
+%# 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 %>;
}
// 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 );
}
}
}
+
+% 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 %>;
+ if ( form.elements['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() {
+ if ( OLresponseAJAX ) {
+ overlib( OLresponseAJAX, CAPTION, 'Confirm censustract', STICKY,
+ AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH,
+ 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399',
+ TEXTSIZE, 3 );
+ } else {
+ // no response
+ <% $post_censustract %>;
+ }
+ },
+ 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 = @_;
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 $post_censustract;
+
+my $census_functions = $opt{'with_census_functions'} ? 1 : 0;
+if ( $census_functions ) {
+ $post_censustract = $post_geocode;
+ $post_geocode = 'confirm_censustract()';
+}
-my @prefixes = ('ship_');
-unshift @prefixes, 'bill_' unless $onlyship;
+my $tax_engine = FS::TaxEngine->new;
+my $need_tax_location = $tax_engine->info->{manual_tax_location} ? 1 : 0;
</%init>