Allow alternations in the tax data, so that it is case insensitive
and allows multiple definitions of an entry (like state, city or country)
This commit is contained in:
parent
50fc494759
commit
52cf8b672c
4 changed files with 64 additions and 7 deletions
|
|
@ -181,6 +181,9 @@ sub exportTaxData {
|
||||||
my $taxData = WebGUI::Text::joinCSV(@columns) . "\n";
|
my $taxData = WebGUI::Text::joinCSV(@columns) . "\n";
|
||||||
while (my $taxRow = $taxIterator->hashRef() ) {
|
while (my $taxRow = $taxIterator->hashRef() ) {
|
||||||
my @taxData = @{ $taxRow }{@columns};
|
my @taxData = @{ $taxRow }{@columns};
|
||||||
|
foreach my $column (@taxData) {
|
||||||
|
$column =~ tr/,/|/; ##Convert to the alternation syntax for the text file
|
||||||
|
}
|
||||||
$taxData .= WebGUI::Text::joinCSV(@taxData) . "\n";
|
$taxData .= WebGUI::Text::joinCSV(@taxData) . "\n";
|
||||||
}
|
}
|
||||||
my $storage = WebGUI::Storage->createTemp($self->session);
|
my $storage = WebGUI::Storage->createTemp($self->session);
|
||||||
|
|
@ -222,10 +225,10 @@ sub getTaxRates {
|
||||||
my $code = $address->get('code');
|
my $code = $address->get('code');
|
||||||
my $result = $self->session->db->buildArrayRef(
|
my $result = $self->session->db->buildArrayRef(
|
||||||
q{
|
q{
|
||||||
select taxRate from tax where country=?
|
select taxRate from tax where find_in_set(?, country)
|
||||||
and (state='' or state=?)
|
and (state='' or find_in_set(?, lower(state)))
|
||||||
and (city='' or city=?)
|
and (city='' or find_in_set(?, lower(city)))
|
||||||
and (code='' or code=?)
|
and (code='' or find_in_set(?, lower(code)))
|
||||||
},
|
},
|
||||||
[ $country, $state, $city, $code, ]);
|
[ $country, $state, $city, $code, ]);
|
||||||
return $result;
|
return $result;
|
||||||
|
|
@ -273,7 +276,8 @@ sub importTaxData {
|
||||||
chomp $taxRow;
|
chomp $taxRow;
|
||||||
$taxRow =~ s/\s*#.+$//;
|
$taxRow =~ s/\s*#.+$//;
|
||||||
next unless $taxRow;
|
next unless $taxRow;
|
||||||
my @taxRow = WebGUI::Text::splitCSV($taxRow);
|
local $_;
|
||||||
|
my @taxRow = map { tr/|/,/; $_; } WebGUI::Text::splitCSV($taxRow);
|
||||||
WebGUI::Error::InvalidFile->throw(error => qq{Error found in the CSV file}, brokenFile => $filePath, brokenLine => $line)
|
WebGUI::Error::InvalidFile->throw(error => qq{Error found in the CSV file}, brokenFile => $filePath, brokenLine => $line)
|
||||||
unless scalar @taxRow == 5;
|
unless scalar @taxRow == 5;
|
||||||
push @taxData, [ @taxRow ];
|
push @taxData, [ @taxRow ];
|
||||||
|
|
|
||||||
53
t/Shop/Tax.t
53
t/Shop/Tax.t
|
|
@ -36,7 +36,7 @@ my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
my $addExceptions = getAddExceptions($session);
|
my $addExceptions = getAddExceptions($session);
|
||||||
|
|
||||||
my $tests = 68 + 2*scalar(@{$addExceptions});
|
my $tests = 72 + 2*scalar(@{$addExceptions});
|
||||||
plan tests => 1 + $tests;
|
plan tests => 1 + $tests;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -209,6 +209,23 @@ my $wiData = $taxer->getItems->hashRef;
|
||||||
##Need to ignore the taxId from the database
|
##Need to ignore the taxId from the database
|
||||||
cmp_bag([ @{ $wiData }{ @expectedHeader } ], \@row1, 'exportTaxData: first line of data is correct');
|
cmp_bag([ @{ $wiData }{ @expectedHeader } ], \@row1, 'exportTaxData: first line of data is correct');
|
||||||
|
|
||||||
|
my $newTaxId = $taxer->add({
|
||||||
|
country => 'USA|U.S.A.',
|
||||||
|
state => 'washington|WA',
|
||||||
|
taxRate => '7',
|
||||||
|
code => '',
|
||||||
|
city => '',
|
||||||
|
});
|
||||||
|
$taxer->delete({taxId => $wisconsinTaxId});
|
||||||
|
$storage = $taxer->exportTaxData();
|
||||||
|
@fileLines = split /\n+/, $storage->getFileContentsAsScalar('siteTaxData.csv');
|
||||||
|
my @row1 = WebGUI::Text::splitCSV($fileLines[1]);
|
||||||
|
my $wiData = $taxer->getItems->hashRef;
|
||||||
|
##Need to ignore the taxId from the database
|
||||||
|
cmp_bag([ @{ $wiData }{ @expectedHeader } ], \@row1, 'exportTaxData: first line of data is correct');
|
||||||
|
|
||||||
|
$taxer->delete({taxId => $newTaxId});
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
#
|
#
|
||||||
# import
|
# import
|
||||||
|
|
@ -392,6 +409,27 @@ cmp_deeply(
|
||||||
'importTaxData: error handling for a file with a bad header',
|
'importTaxData: error handling for a file with a bad header',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ok(
|
||||||
|
$taxer->importTaxData(
|
||||||
|
WebGUI::Test->getTestCollateralPath('taxTables/alternations.csv')
|
||||||
|
),
|
||||||
|
'Tax data with alternations inserted',
|
||||||
|
);
|
||||||
|
|
||||||
|
my $altData = $taxer->getItems->hashRef; ##Just 1 row
|
||||||
|
cmp_deeply(
|
||||||
|
$altData,
|
||||||
|
{
|
||||||
|
taxId => ignore,
|
||||||
|
country => q{U.S.A.,USA},
|
||||||
|
state => q{WI,Wisconsin},
|
||||||
|
city => q{Madison},
|
||||||
|
code => 53701,
|
||||||
|
taxRate => 0.5,
|
||||||
|
},
|
||||||
|
'import: Data correctly loaded with alternations'
|
||||||
|
);
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
#
|
#
|
||||||
# getTaxRates
|
# getTaxRates
|
||||||
|
|
@ -417,6 +455,13 @@ my $taxFreeAddress = $book->addAddress({
|
||||||
code => '97123',
|
code => '97123',
|
||||||
country => 'USA',
|
country => 'USA',
|
||||||
});
|
});
|
||||||
|
my $alternateAddress = $book->addAddress({
|
||||||
|
label => 'using alternations',
|
||||||
|
city => 'Los Angeles',
|
||||||
|
state => 'CalifornIA',
|
||||||
|
code => '97123',
|
||||||
|
country => 'U.S.A.',
|
||||||
|
});
|
||||||
|
|
||||||
eval { $taxer->getTaxRates(); };
|
eval { $taxer->getTaxRates(); };
|
||||||
$e = Exception::Class->caught();
|
$e = Exception::Class->caught();
|
||||||
|
|
@ -443,6 +488,12 @@ cmp_deeply(
|
||||||
'getTaxRates: return correct data for a state with no tax data'
|
'getTaxRates: return correct data for a state with no tax data'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
cmp_deeply(
|
||||||
|
$taxer->getTaxRates($alternateAddress),
|
||||||
|
[7.25], #Only 7.25 because it uses the alternate address for USA
|
||||||
|
'getTaxRates: return correct data for a state when the address has alternations'
|
||||||
|
);
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
#
|
#
|
||||||
# calculate
|
# calculate
|
||||||
|
|
|
||||||
2
t/supporting_collateral/taxTables/alternations.csv
Normal file
2
t/supporting_collateral/taxTables/alternations.csv
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
country,state,city,code,taxRate
|
||||||
|
U.S.A.|USA,WI|Wisconsin,Madison,53701,0.5
|
||||||
|
|
|
@ -5,5 +5,5 @@ USA,WI,,53701,0.5
|
||||||
USA,WI,,53702,0.5
|
USA,WI,,53702,0.5
|
||||||
USA,WI,,53703,0.5
|
USA,WI,,53703,0.5
|
||||||
USA,WI,,53704,0.5
|
USA,WI,,53704,0.5
|
||||||
USA,CA,,,7.25
|
USA|U.S.A.,CA|California,,,7.25
|
||||||
USA,,,97123,0.0
|
USA,,,97123,0.0
|
||||||
|
|
|
||||||
|
Loading…
Add table
Add a link
Reference in a new issue