diff --git a/lib/WebGUI/Shop/Tax.pm b/lib/WebGUI/Shop/Tax.pm index c01b4807f..e59a8a2d6 100644 --- a/lib/WebGUI/Shop/Tax.pm +++ b/lib/WebGUI/Shop/Tax.pm @@ -141,7 +141,7 @@ sub calculate { =head2 canEdit ( [ $user ] ) -Determine whether or not the current user can perform commerce functions +Determine whether or not a user can perform commerce functions =head3 $user @@ -212,6 +212,21 @@ sub exportTaxData { #------------------------------------------------------------------- +=head2 getAllItems ( ) + +Returns an arrayref of hashrefs, where each hashref is the data for one row of +tax data. taxId is dropped from the dataset. + +=cut + +sub getAllItems { + my $self = shift; + my $taxes = $self->session->db->buildArrayRefOfHashRefs('select country,state,city,code,taxRate from tax order by country, state'); + return $taxes; +} + +#------------------------------------------------------------------- + =head2 getItems ( ) Returns a WebGUI::SQL::Result object for accessing all of the data in the tax table. This @@ -221,7 +236,7 @@ is a convenience method for listing and/or exporting tax data. sub getItems { my $self = shift; - my $result = $self->session->db->read('select * from tax'); + my $result = $self->session->db->read('select * from tax order by country, state'); return $result; } @@ -353,6 +368,28 @@ sub www_view { my $self = shift; return $self->session->privileges->insufficient unless $self->canEdit; + my $session = $self->session; + ##YUI specific datatable CSS + $session->setLink($session->url->extras('yui/build/datatable/assets/skins/sam/datatable.css'), {type => 'text/CSS'}); + ##YUI basics + $session->style->setScript($session->url->extras('yui/build/yahoo-dom-event/yahoo-dom-event.js'), {type => 'text/javascript'}); + $session->style->setScript($session->url->extras('yui/build/element/element-beta-min.js'), {type => 'text/javascript'}); + $session->style->setScript($session->url->extras('yui/build/datasource/datasource-beta-min.js'), {type => 'text/javascript'}); + ##YUI Datatable + $session->style->setScript($session->url->extras('yui/build/datatable/datatable-beta-min.js'), {type => 'text/javascript'}); + ##YUI JSON handler + $session->style->setScript($session->url->extras('yui/build/json/json-min.js'), {type => 'text/javascript'}); + ##Build column headers. TODO: I18N + my $i18n=WebGUI::International->new($session, 'Tax'); + $session->style->setRawHeadTags(sprintf <<'EOCHJS', $i18n->get('country'), $i18n->get('state'), $i18n->get('city'), $i18n->get('code')); +var taxColumnDefs = [ + {key:"country", label:"%s"}, + {key:"state", label:"%s"}, + {key:"city", label:"%s"}, + {key:"code", label:"%s"} +]; +EOCHJS + $session->style->setRawHeadTags(); return ''; } diff --git a/lib/WebGUI/i18n/English/Tax.pm b/lib/WebGUI/i18n/English/Tax.pm new file mode 100644 index 000000000..8d26c5ddd --- /dev/null +++ b/lib/WebGUI/i18n/English/Tax.pm @@ -0,0 +1,32 @@ +package WebGUI::i18n::English::Tax; + +use strict; + +our $I18N = { + + 'country' => { + message => q|Country|, + lastUpdated => 1205120607, + context => q|The name of a country, such as Portugal or Canada.|, + }, + + 'state' => { + message => q|State|, + lastUpdated => 1205120615, + context => q|A political subdivision of a country, such as California.|, + }, + + 'city' => { + message => q|City|, + lastUpdated => 1205120661, + }, + + 'code' => { + message => q|Code|, + lastUpdated => 1205120660, + context => q|A postal code, or zip code.|, + }, + +}; + +1; diff --git a/t/Shop/Tax.t b/t/Shop/Tax.t index bd6cf8608..0be5057ea 100644 --- a/t/Shop/Tax.t +++ b/t/Shop/Tax.t @@ -36,7 +36,7 @@ my $session = WebGUI::Test->session; my $addExceptions = getAddExceptions($session); -my $tests = 72 + 2*scalar(@{$addExceptions}); +my $tests = 73 + 2*scalar(@{$addExceptions}); plan tests => 1 + $tests; #---------------------------------------------------------------------------- @@ -138,7 +138,7 @@ $taxIterator = $taxer->getItems; is($taxIterator->rows, 2, 'add added another row to the tax table'); $taxData = { - country => 'state', + country => 'USA', state => 'Oregon', taxRate => '0.1', }; @@ -153,6 +153,42 @@ is($taxIterator->rows, 3, 'add permits adding duplicate information.'); ##city rate: 0.5% ##Wisconsin rate 5.0% +####################################################################### +# +# getAllItems +# +####################################################################### + +my $expectedTaxData = [ + { + country => 'USA', + state => 'OR', + city => undef, + code => undef, + taxRate => 0, + }, + { + country => 'USA', + state => 'Wisconsin', + city => 'Madcity', + code => '53702', + taxRate => 5, + }, + { + country => 'USA', + state => 'Oregon', + city => undef, + code => undef, + taxRate => 0.1, + }, +]; + +cmp_bag( + $taxer->getAllItems, + $expectedTaxData, + 'getAllItems returns the whole set of tax data', +); + ####################################################################### # # delete @@ -307,9 +343,8 @@ ok( $taxIterator = $taxer->getItems; is($taxIterator->rows, 3, 'import: Old data deleted, new data imported'); -my @goodTaxData = _grabTaxData($taxIterator); cmp_bag( - \@goodTaxData, + $taxer->getAllItems, $expectedTaxData, 'Correct data inserted.', ); @@ -323,9 +358,8 @@ ok( $taxIterator = $taxer->getItems; is($taxIterator->rows, 3, 'import: Old data deleted, new data imported again'); -my @orderedTaxData = _grabTaxData($taxIterator); cmp_bag( - \@orderedTaxData, + $taxer->getAllItems, $expectedTaxData, 'Correct data inserted, with CSV in different columnar order.', ); @@ -339,9 +373,8 @@ ok( $taxIterator = $taxer->getItems; is($taxIterator->rows, 3, 'import: Old data deleted, new data imported the third time'); -my @orderedTaxData = _grabTaxData($taxIterator); cmp_bag( - \@orderedTaxData, + $taxer->getAllItems, $expectedTaxData, 'Correct data inserted, with comments in the CSV file', ); @@ -572,16 +605,6 @@ $cart->delete; $book->delete; } -sub _grabTaxData { - my $tax = shift; - my @taxData = (); - while (my $taxRow = $tax->hashRef) { - delete $taxRow->{'taxId'}; - push @taxData, $taxRow; - } - return @taxData; -} - sub getAddExceptions { my $session = shift; my $inputValidion = [