my $taxname = $conf->config('tax_district_taxname') || '';
+ FS::cust_main_county->lock_table;
if ($method eq 'wa_sales') {
# download the update file
my $now = DateTime->now;
if ( lc($text) eq 'location code' ) {
$p->get_tag('td'); # skip to the next column
undef $u;
- $u = $p->get_token until $u->[0] eq 'T'; # and then skip non-text
+ $u = $p->get_token until ($u->[0] || '') eq 'T'; # and then skip non-text
$return->{'district'} = $u->[1];
}
elsif ( lc($text) eq 'total tax rate' ) {
$p->get_tag('td');
undef $u;
- $u = $p->get_token until $u->[0] eq 'T';
+ $u = $p->get_token until ($u->[0] || '') eq 'T';
$return->{'tax'} = $u->[1];
}
} # get_token
my %sales;
foreach my $cust_bill_pkg ( $cust_bill->cust_bill_pkg ) {
+$DB::single = 1;
my $cust_pkg = $cust_pkg{$cust_bill_pkg->pkgnum}
||= $cust_bill_pkg->cust_pkg;
my $pkgpart = $cust_bill_pkg->pkgpart_override || $cust_pkg->pkgpart;
my $class = shift;
# assume taxes in Washington with district numbers, and null name, or
# named 'sales tax', are looked up via the wa_sales method. mark them.
- my $journal = 'cust_main_county__source_wa_sales';
+ my $journal = 'cust_main_county__source_wa_sales_201611';
if (!FS::upgrade_journal->is_done($journal)) {
my @taxes = qsearch({
'table' => 'cust_main_county',
}
my @key_fields = (qw(city county state country district taxname taxclass));
- # remove duplicates (except disabled records)
- my @duplicate_sets = qsearch({
- table => 'cust_main_county',
- select => FS::Record::group_concat_sql('taxnum', ',') . ' AS taxnums, ' .
- join(',', @key_fields),
- extra_sql => ' WHERE tax > 0
- GROUP BY city, county, state, country, district, taxname, taxclass
- HAVING COUNT(*) > 1'
- });
- warn "Found ".scalar(@duplicate_sets)." set(s) of duplicate tax definitions\n"
- if @duplicate_sets;
- foreach my $set (@duplicate_sets) {
- my @taxnums = split(',', $set->get('taxnums'));
- my $first = FS::cust_main_county->by_key(shift @taxnums);
- foreach my $taxnum (@taxnums) {
- my $record = FS::cust_main_county->by_key($taxnum);
- $record->_merge_into($first);
- }
- }
-
# trim whitespace and convert to uppercase in the 'city' field.
foreach my $record (qsearch({
table => 'cust_main_county',
my $district_taxname = $conf->config('tax_district_taxname');
$journal = 'cust_main_county__district_taxclass';
if (!FS::upgrade_journal->is_done($journal)
- and $conf->config('enable_taxclasses')) {
+ and $conf->exists('enable_taxclasses')) {
eval "use FS::part_pkg_taxclass";
my @taxes = qsearch({
'table' => 'cust_main_county',
}
}
}
+
+ # remove duplicates (except disabled records)
+ my @duplicate_sets = qsearch({
+ table => 'cust_main_county',
+ select => FS::Record::group_concat_sql('taxnum', ',') . ' AS taxnums, ' .
+ join(',', @key_fields),
+ extra_sql => ' WHERE tax > 0
+ GROUP BY city, county, state, country, district, taxname, taxclass
+ HAVING COUNT(*) > 1'
+ });
+ warn "Found ".scalar(@duplicate_sets)." set(s) of duplicate tax definitions\n"
+ if @duplicate_sets;
+ foreach my $set (@duplicate_sets) {
+ my @taxnums = split(',', $set->get('taxnums'));
+ my $first = FS::cust_main_county->by_key(shift @taxnums);
+ foreach my $taxnum (@taxnums) {
+ my $record = FS::cust_main_county->by_key($taxnum);
+ $record->_merge_into($first);
+ }
+ }
+
'';
}
die $@ if $@;
die "$class has no location data" if !$class->can('location_hash');
+ my $error;
my $conf = FS::Conf->new;
my $method = $conf->config('tax_district_method')
or return; #nothing to do if null
my $tax_info = get_district({ $self->location_hash }, $method);
return unless $tax_info;
- $self->set('district', $tax_info->{'district'} );
- my $error = $self->replace;
- die $error if $error;
+ if ($self->district ne $tax_info->{'district'}) {
+ $self->set('district', $tax_info->{'district'} );
+ $error = $self->replace;
+ die $error if $error;
+ }
my %hash = map { $_ => uc( $tax_info->{$_} ) }
qw( district city county state country );
my $taxname = $conf->config('tax_district_taxname');
# there must be exactly one cust_main_county for each district+taxclass.
# do NOT exclude taxes that are zero.
+
+ # mutex here so that concurrent queue jobs can't make duplicates.
+ FS::cust_main_county->lock_table;
foreach my $taxclass (@classes) {
my @existing = qsearch('cust_main_county', {
%hash,
if ( $dbh->{Driver}->{Name} =~ /^mysql/i && ! $opt_s ) {
- foreach my $table (qw( svc_acct svc_phone )) {
+ foreach my $table (qw( svc_acct svc_phone cust_main_county )) {
my $sth = $dbh->prepare(
"SELECT COUNT(*) FROM duplicate_lock WHERE lockname = '$table'"
'Phone numbers (DIDs)' => [ $fsurl.'misc/phone_avail-import.html', '' ],
'Call Detail Records (CDRs)' => [ $fsurl.'misc/cdr-import.html', '' ],
;
-if ( $conf->config('tax_data_vendor') eq 'cch' ) {
+if ( $conf->config('tax_data_vendor') ) {
if ( $conf->exists('taxdatadirectdownload') ) {
$tools_importing{'Tax rates from vendor site'} =
[ $fsurl.'misc/tax-fetch_and_import.cgi', '' ];
prefix = 'bill_';
}
- if ( new String(cf.elements[prefix + 'zip'].value).length < 10 )
- {
+// 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;
}
- } else {
-
- cf.elements[prefix + 'geocode'].value = '';
- <% $post_geocode %>;
-
- }
+// } else {
+//
+// cf.elements[prefix + 'geocode'].value = '';
+// <% $post_geocode %>;
+//
+// }
% } else {
</TR>
% }
-% if ( $conf->config('tax_data_vendor') eq 'cch' ) {
+% if ( $conf->config('tax_data_vendor') ) {
<TR>
<TH ALIGN="right"><% mt('Tax location') |h %></TH>
% my $tax_location = $conf->exists('tax-ship_address')
% ? $cust_main->ship_location
% : $cust_main->bill_location;
- <TD><% $tax_location->geocode('cch') %></TD>
+ <TD><% $tax_location->geocode %></TD>
</TR>
% }
<TR>
my( $cust_bill, %opt ) = @_;
-my $invoice = emt("Invoice #[_1] (Balance [_2])",$cust_bill->display_invnum,$cust_bill->owed);
-
my $under = '';
-if ( $cust_bill->owed > 0 ) {
+my $invoice;
+if ( $cust_bill->pending ) {
+ $invoice = '<I><FONT SIZE="+1" COLOR="#D05000">' .
+ emt("Pending Invoice #[_1] (Charges of [_2])", $cust_bill->display_invnum, $cust_bill->charged);
+} elsif ( $cust_bill->owed > 0 ) {
$invoice = '<B><FONT SIZE="+1" COLOR="#FF0000">' .
emt("Open Invoice #[_1] (Balance [_2])",$cust_bill->display_invnum,$cust_bill->owed) .
'</FONT></B>';
$under .= '<BR>'. emt('Payment promised on [_1]',
time2str($opt{'date_format'}, $cust_bill->promised_date));
}
-} #if $cust_bill->owed
+} else {
+ $invoice = emt("Invoice #[_1] (Balance [_2])",$cust_bill->display_invnum,$cust_bill->owed);
+}
my $invnum = $cust_bill->invnum;