From 7f10b76569406cadce292208389c644c84e90979 Mon Sep 17 00:00:00 2001 From: Mitch Jackson Date: Mon, 27 May 2019 17:20:27 -0400 Subject: [PATCH] RT# 83320 Fix UI bug managing taxes No longer incorrectly carrying the source and district columns from other tax rows into new tax rows --- httemplate/edit/process/cust_main_county-add.cgi | 71 +++++++++++++++++------- 1 file changed, 52 insertions(+), 19 deletions(-) diff --git a/httemplate/edit/process/cust_main_county-add.cgi b/httemplate/edit/process/cust_main_county-add.cgi index fcc138f49..fcd6be48f 100755 --- a/httemplate/edit/process/cust_main_county-add.cgi +++ b/httemplate/edit/process/cust_main_county-add.cgi @@ -27,26 +27,59 @@ my @expansion = split /[\n\r]{1,2}/, $cgi->param('expansion'); $1; } @expansion; -foreach ( @expansion ) { - my(%hash)=$cust_main_county->hash; - my($new)=new FS::cust_main_county \%hash; - $new->setfield('taxnum',''); - $new->setfield('taxclass', ''); - if ( $cgi->param('what') eq 'state' ) { #?? - $new->setfield('state',$_); - $new->setfield('county', ''); - $new->setfield('city', ''); - } elsif ( $cgi->param('what') eq 'county' ) { - $new->setfield('county',$_); - $new->setfield('city', ''); - } elsif ( $cgi->param('what') eq 'city' ) { - #uppercase cities in the US to try and agree with USPS validation - $new->setfield('city', $new->country eq 'US' ? uc($_) : $_ ); - } else { #??? - die 'unknown what '. $cgi->param('what'); +my $what = $cgi->param('what'); +foreach my $new_tax_area ( @expansion ) { + + # Clone specific tax columns from original tax row + # + # UI Note: Preserving original behavior, of cloning + # tax amounts into new tax record, against better + # judgement. If the new city/county/state has a + # different tax value than the one being populated + # (rather likely?) now the user must remember to + # revisit each newly created tax row, and correct + # the possibly incorrect tax values that were populated. + # Values would be easier to identify and correct if + # they were initially populated with 0% tax rates + # District Note: The 'district' column is NOT cloned + # to the new tax row. Manually entered taxes + # are not be divided into road maintenance districts + # like Washington state sales taxes + my $new = FS::cust_main_county->new({ + map { $_ => $cust_main_county->getfield($_) } + qw/ + charge_prediscount + exempt_amount + exempt_amount_currency + recurtax + setuptax + tax + taxname + / + }); + + # Clone additional location columns, based on the $what value + my %clone_cols_for = ( + state => [qw/country /], + county => [qw/country state/], + city => [qw/country state county/], + ); + + die "unknown what: $what" + unless grep { $_ eq $what } keys %clone_cols_for; + + $new->setfield( $_ => $cust_main_county->getfield($_) ) + for @{ $clone_cols_for{ $cgi->param('what') } }; + + # In the US, store cities upper case for USPS validation + $new_tax_area = uc($new_tax_area) + if $what eq 'city' + && $new->country eq 'US'; + + $new->setfield( $what, $new_tax_area ); + if ( my $error = $new->insert ) { + die $error; } - my $error = $new->insert; - die $error if $error; } -- 2.11.0