fix address standardization when changing package locations, #13763
authorMark Wells <mark@freeside.biz>
Sun, 13 Jan 2013 22:22:21 +0000 (14:22 -0800)
committerMark Wells <mark@freeside.biz>
Sun, 13 Jan 2013 22:22:21 +0000 (14:22 -0800)
httemplate/edit/cust_main/bottomfixup.js
httemplate/elements/order_pkg.js
httemplate/elements/standardize_locations.js
httemplate/misc/change_pkg.cgi
httemplate/misc/confirm-address_standardize.html
httemplate/misc/order_pkg.html
httemplate/misc/xmlhttp-address_standardize.html

index 1cfa52d..0de6d9d 100644 (file)
@@ -70,8 +70,8 @@ function copy_payby_fields() {
 
 <& /elements/standardize_locations.js,
   'callback' => 'submit_continue();',
-  'main_prefix' => 'bill_',
-  'no_company' => 1,
+  'billship' => 1,
+  'with_census' => 1, # no with_firm, apparently
 &>
 
 function copyelement(from, to) {
index 8c1efd9..1069a0e 100644 (file)
@@ -44,4 +44,5 @@ function standardize_new_location() {
 
 function submit_abort() {
   document.OrderPkgForm.submitButton.disabled = false;
+  nd(1);
 }
index 15c5761..88c87c1 100644 (file)
@@ -7,8 +7,8 @@ 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 ) {
@@ -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,7 @@ 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 ( address_info['same'] ) {
       cf.elements['bill_censustract'].value =
         address_info['bill_censustract'];
@@ -279,21 +275,18 @@ function setselect(el, value) {
 my %opt = @_;
 my $conf = new FS::Conf;
 
-my $withfirm = 1;
-my $withcensus = 1;
+my $withfirm = $opt{'with_firm'} ? 1 : 0;
+my $withcensus = $opt{'with_census'} ? 1 : 0;
+
+my @prefixes = '';
+my $billship = $opt{'billship'} ? 1 : 0; # whether to have bill_ and ship_ prefixes
+my $taxpre = '';
+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;
 
 </%init>
index 7b08f7b..03e336c 100755 (executable)
@@ -32,9 +32,6 @@
 
 <& /elements/standardize_locations.html,
             'form'       => "OrderPkgForm",
-            'onlyship'   => 1,
-            'no_company' => 1,
-            'no_census'  => 1,
             'callback'   => 'document.OrderPkgForm.submit();',
 &>
 
index 57201ea..420e8ea 100644 (file)
@@ -11,16 +11,14 @@ Confirm address standardization
 
 </B><BR><BR>
 <TABLE WIDTH="100%">
-% my @prefixes;
-% if ( $old{onlyship} ) {
-%   @prefixes = ('ship_');
-% } elsif ( $old{same} ) {
+% my @prefixes = ('');
+% if ( $old{same} ) {
 %   @prefixes = ('bill_');
-% } else {
+% } elsif ( $old{billship} ) {
 %   @prefixes = ('bill_', 'ship_');
 % }
 % for my $pre (@prefixes) {
-%   my $name = $pre eq 'ship_' ? 'service' : 'billing';
+%   my $name = $pre eq 'bill_' ? 'billing' : 'service';
 %   if ( $new{$pre.'addr_clean'} ) {
   <TR>
     <TH>Entered <%$name%> address</TH>
@@ -128,6 +126,6 @@ my $q = decode_json($cgi->param('q'));
 my %old = %{ $q->{old} };
 my %new = %{ $q->{new} };
 
-my $addresses = $old{onlyship} ? 'address' : 'addresses';
+my $addresses = $old{billship} ? 'addresses' : 'address';
 
 </%init>
index bfc7b69..993ea36 100644 (file)
 
   <& /elements/standardize_locations.html,
                 'form'       => "OrderPkgForm",
-                'onlyship'   => 1,
-                'no_company' => 1,
-                'no_census'  => 1,
                 'callback'   => 'document.OrderPkgForm.submit();',
   &>
 
index 9880571..15f266a 100644 (file)
@@ -16,12 +16,10 @@ my %old = %{ decode_json($cgi->param('arg')) }
 
 my %new;
 
-my @prefixes;
-if ($old{onlyship}) {
-  @prefixes = ('ship_');
-} elsif ( $old{same} ) {
+my @prefixes = ('');
+if ( $old{same} ) {
   @prefixes = ('bill_');
-} else {
+} elsif ( $old{billship} ) {
   @prefixes = ('bill_', 'ship_');
 }
 my $all_same = 1;
@@ -44,6 +42,8 @@ foreach my $pre ( @prefixes ) {
     $all_same = 0 if ( $new{$pre.$_} ne $old{$pre.$_} );
     last if !$all_same;
   }
+
+  $all_same = 0 if $new{$pre.'error'};
 }
 
 my $return = { old => \%old, new => \%new, all_same => $all_same };