X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FBilling.pm;h=c0c15e44c863a6e7548e586ee84277d10c11aedf;hp=1be7d39f959a6c6183e648bada1ccbf8ceecd06c;hb=07ed221540128b8c75f4cb5a2af1e01b25fa8e18;hpb=d5988a9f7a3617de33da3058f2e9f1151b24420e diff --git a/FS/FS/cust_main/Billing.pm b/FS/FS/cust_main/Billing.pm index 1be7d39f9..c0c15e44c 100644 --- a/FS/FS/cust_main/Billing.pm +++ b/FS/FS/cust_main/Billing.pm @@ -152,6 +152,41 @@ sub bill_and_collect { else { die $error; } } + my $tax_district_method = $conf->config('tax_district_method'); + if ( $tax_district_method && $tax_district_method eq 'wa_sales' ) { + # When using Washington State Sales Tax Districts, + # Bail out of billing customer if sales tax district for location is missing + + $log->debug('checking cust_location tax districts', %logopt); + + if ( + my @cust_locations_missing_district = + $self->cust_locations_missing_district + ) { + $error = sprintf + 'cust_location missing tax district: '. + join( ', ' => ( + map( + { + sprintf + 'locationnum(%s) %s %s %s %s', + $_->locationnum, + $_->address1, + $_->city, + $_->state, + $_->zip + } + @cust_locations_missing_district + ) + )); + } + } + if ( $error ) { + $error = "Error calculating taxes ".$self->custnum. ": $error"; + if ( $options{fatal} && $options{fatal} eq 'return' ) { return $error; } + else { die $error; } + } + $job->update_statustext('20,billing packages') if $job; $log->debug('billing packages', %logopt); $error = $self->bill( %options ); @@ -1052,7 +1087,9 @@ sub _make_lines { } $lineitems++ - if $cust_pkg->waive_setup && $part_pkg->can('prorate_setup') && $part_pkg->prorate_setup($cust_pkg, $time); + if $cust_pkg->waive_setup + && $part_pkg->can('prorate_setup') + && $part_pkg->prorate_setup($cust_pkg, $time); if ( $cust_pkg->get('setup') ) { # don't change it @@ -1614,10 +1651,28 @@ sub _handle_taxes { my @taxes = (); # entries are cust_main_county objects my %taxhash_elim = %taxhash; my @elim = qw( district city county state ); + + # WA state district city names are not stable in the WA tax tables + # Allow districts to match with just a district id + if ( $taxhash{district} ) { + @taxes = qsearch( cust_main_county => { + district => $taxhash{district}, + taxclass => $taxhash{taxclass}, + }); + if ( !scalar(@taxes) && $taxhash{taxclass} ) { + qsearch( cust_main_county => { + district => $taxhash{district}, + taxclass => '', + }); + } + } + do { #first try a match with taxclass - @taxes = qsearch( 'cust_main_county', \%taxhash_elim ); + if ( !scalar(@taxes) ) { + @taxes = qsearch( 'cust_main_county', \%taxhash_elim ); + } if ( !scalar(@taxes) && $taxhash_elim{'taxclass'} ) { #then try a match without taxclass