diff options
author | Mark Wells <mark@freeside.biz> | 2014-10-31 15:45:50 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2014-10-31 15:45:50 -0700 |
commit | 7516e3da0f17eeecba27219ef96a8b5f46af2083 (patch) | |
tree | 772fe13627910a7d0774871633697f2a4d1c6faf /httemplate | |
parent | f31a9212ab3835b815aa87a86cca3b19babcaaff (diff) |
tax engine refactoring for Avalara and Billsoft tax vendors, #25718
Diffstat (limited to 'httemplate')
-rwxr-xr-x | httemplate/browse/part_pkg_taxproduct/avalara.html | 84 | ||||
-rwxr-xr-x | httemplate/browse/part_pkg_taxproduct/billsoft.html | 146 | ||||
-rwxr-xr-x | httemplate/browse/part_pkg_taxproduct/cch.html (renamed from httemplate/browse/part_pkg_taxproduct.cgi) | 43 | ||||
-rwxr-xr-x | httemplate/edit/cust_main.cgi | 2 | ||||
-rw-r--r-- | httemplate/edit/cust_main/basics.html (renamed from httemplate/edit/cust_main/top_misc.html) | 7 | ||||
-rwxr-xr-x | httemplate/edit/process/part_pkg.cgi | 28 | ||||
-rw-r--r-- | httemplate/elements/select-table.html | 13 | ||||
-rw-r--r-- | httemplate/elements/select-taxproduct.html | 5 | ||||
-rw-r--r-- | httemplate/elements/standardize_locations.js | 18 | ||||
-rw-r--r-- | httemplate/elements/tr-select-tax_status.html | 24 | ||||
-rw-r--r-- | httemplate/elements/tr-select-taxoverride.html | 4 | ||||
-rw-r--r-- | httemplate/elements/tr-td-label.html | 3 | ||||
-rw-r--r-- | httemplate/misc/choose_tax_location.html | 28 | ||||
-rw-r--r-- | httemplate/misc/tax-import.cgi | 68 |
14 files changed, 369 insertions, 104 deletions
diff --git a/httemplate/browse/part_pkg_taxproduct/avalara.html b/httemplate/browse/part_pkg_taxproduct/avalara.html new file mode 100755 index 000000000..e8da58962 --- /dev/null +++ b/httemplate/browse/part_pkg_taxproduct/avalara.html @@ -0,0 +1,84 @@ +<& /elements/header-popup.html, { title => 'Select tax product' } &> +<form NAME="myform"> +<table class="inv" width="100%"> +<& /elements/tr-select-table.html, + 'label' => 'Tax product', + 'field' => 'taxproductnum', + 'table' => 'part_pkg_taxproduct', + 'hashref' => { data_vendor => 'avalara' }, + 'name_col' => 'taxproduct', # for sorting + 'label_callback' => $label_callback, + 'curr_value' => $taxproductnum, + 'empty_label' => 'none', + 'onchange' => 'select_onchange', +&> +</table> +<table class="inv" width="100%"> +<tr> + <td style="border-top: 1px solid #7e0079; text-align: center" colspan=2> + Add a new tax product</td> +</tr> +<tr> + <td style="text-align: right">Avalara tax code</td> + <td><input name="taxproduct" size=8></td> +</tr> +<tr> + <td style="text-align: right">Description</td> + <td><input name="description" size=20></td> +</tr> +<tr> + <td colspan="2" style="text-align: center"> + <input type="button" onclick="add_new()" value="Add" /> + </td> +</tr> +</table> +</form> +<SCRIPT TYPE="text/javascript"> +function select_onchange() { + var select = document.forms['myform']['taxproductnum']; + parent.document.getElementById('<% $id %>').value = select.value; + parent.document.getElementById('<% $id %>_description').value = + select.options[select.selectedIndex].text; + parent.nd(1); +} +function add_new() { + parent.document.getElementById('<% $id %>').value = -1; + parent.document.getElementById('<% $id %>_description').value = + document.forms['myform']['taxproduct'].value + ' ' + + document.forms['myform']['description'].value; + parent.nd(1); +} +</SCRIPT> +</BODY> +</HTML> +<%once> + +my $conf = new FS::Conf; + +</%once> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Edit package definitions'); + +warn Dumper({ $cgi->Vars }); + +# id: where to put the taxproductnum (in the parent document) after the user +# selects it +$cgi->param('id') =~ /^([ \w]+)$/ + or die "id parameter required"; +my $id = $1; + +# current value of taxproductnum +my $taxproductnum = ''; +if ($cgi->param('taxproductnum') =~ /^(\d+)$/) { + $taxproductnum = $1; +} + +my $label_callback = sub { + my $part_pkg_taxproduct = shift; + join(' ', $part_pkg_taxproduct->taxproduct, + $part_pkg_taxproduct->description); +}; + +</%init> diff --git a/httemplate/browse/part_pkg_taxproduct/billsoft.html b/httemplate/browse/part_pkg_taxproduct/billsoft.html new file mode 100755 index 000000000..c58ac30fa --- /dev/null +++ b/httemplate/browse/part_pkg_taxproduct/billsoft.html @@ -0,0 +1,146 @@ +<& /elements/header-popup.html, $title &> +<& /browse/elements/browse.html, + 'name_singular' => 'tax product', + 'html_form' => include('.form', $service_code, $trans_code), + 'query' => { + 'table' => 'part_pkg_taxproduct', + 'hashref' => $hashref, + 'order_by' => 'ORDER BY taxproduct', + }, + 'count_query' => $count_query, + 'header' => \@header, + 'fields' => \@fields, + 'align' => $align, + 'links' => [], + 'link_onclicks' => \@link_onclicks, + 'nohtmlheader' => 1, +&> +<%shared> +# populate dropdowns + +# taxproduct is 12 digits. First half is the service type code, second +# half is the transaction code. Description is also two parts, corresponding +# to those codes, separated with a :. + +my (@service_codes, @trans_codes, %service_labels, %trans_labels); +foreach my $row ( qsearch({ + table => 'part_pkg_taxproduct', + select => 'DISTINCT substr(taxproduct, 1, 6) AS code, '. + "substring(description from '(.*):') AS label", + })) +{ + $service_labels{$row->get('code')} = + sprintf('%02d %s', $row->get('code'), $row->get('label')); +} +foreach my $row ( qsearch({ + table => 'part_pkg_taxproduct', + select => 'DISTINCT substr(taxproduct, 7, 6) AS code, '. + "substring(description from ':(.*)') AS label", + })) +{ + $trans_labels{$row->get('code')} = + sprintf('%02d %s', $row->get('code'), $row->get('label')); +} +$service_labels{''} = $trans_labels{''} = ''; + +@service_codes = sort {$a <=> $b} keys %service_labels; +@trans_codes = sort {$a <=> $b} keys %trans_labels; + +</%shared> +<%def .form> +% my ($service_code, $trans_code) = @_; +<FORM ACTION="<% $cgi->url %>" METHOD="GET"> +<& /elements/select.html, + field => 'service_code', + options => \@service_codes, + labels => \%service_labels, + curr_value => $service_code, + onchange => 'this.form.submit()', +&> + +<& /elements/select.html, + field => 'trans_code', + options => \@trans_codes, + labels => \%trans_labels, + curr_value => $trans_code, + onchange => 'this.form.submit()', +&> +<& /elements/hidden.html, + field => 'id', + curr_value => $cgi->param('id'), +&> +</%def> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +$cgi->param('id') =~ /^\w+$/ or die "missing id parameter"; +my $id = $cgi->param('id'); + +my $select_onclick = sub { + my $row = shift; + my $taxnum = $row->taxproductnum; + my $desc = $row->description; + "parent.document.getElementById('$id').value = $taxnum;". + "parent.document.getElementById('${id}_description').value = '$desc';". + "parent.cClick();"; +} + if $id; + +my @menubar; +my $title = 'Tax Products'; + +my $hashref = { data_vendor => 'billsoft' }; + +my ($service_code, $trans_code, $taxproduct); +if ( $cgi->param('service_code') =~ /^(\d+)$/ ) { + $service_code = $1; + $taxproduct = sprintf('%06d', $service_code); +} else { + $taxproduct = '%'; +} + +if ( $cgi->param('trans_code') =~ /^(\d+)$/ ) { + $trans_code = $1; + $taxproduct .= sprintf('%06d', $trans_code); +} elsif ( $service_code ) { + $taxproduct .= '%'; +} + +$hashref->{taxproduct} = { op => 'LIKE', value => $taxproduct }; + +my $count_query = "SELECT COUNT(*) FROM part_pkg_taxproduct ". + "WHERE data_vendor = 'billsoft' AND ". + "taxproduct LIKE '$taxproduct'"; + +my $sub_service_desc = sub { + my $ppt = shift; #part_pkg_taxproduct + my @codes = ($ppt->taxproduct =~ /(\d{6})(\d{6})/); + my @descs = split(':', $ppt->description); + $ppt->set('service_desc' => sprintf('%02d %s', $codes[0], $descs[0])); + $ppt->set('trans_desc' => sprintf('%02d %s', $codes[1], $descs[1])); + $ppt->service_desc; +}; + +my $sub_trans_desc = sub { + my $ppt = shift; + $ppt->trans_desc; +}; + +my @fields = ( + $sub_service_desc, + $sub_trans_desc, + 'note' +); + +my @header = ( + 'Service Type', + 'Transaction', + '', +); + +my $align = 'lll'; +my @link_onclicks = ( $select_onclick, $select_onclick ); + +</%init> diff --git a/httemplate/browse/part_pkg_taxproduct.cgi b/httemplate/browse/part_pkg_taxproduct/cch.html index 7e0cb8191..b901bad9f 100755 --- a/httemplate/browse/part_pkg_taxproduct.cgi +++ b/httemplate/browse/part_pkg_taxproduct/cch.html @@ -1,4 +1,4 @@ -<% include( 'elements/browse.html', +<% include( '../elements/browse.html', 'title' => "Tax Products $title", 'name_singular' => 'tax product', 'menubar' => \@menubar, @@ -33,12 +33,7 @@ my @menubar; my $title = ''; my $onclick = 'cClick'; -my $data_vendor = ''; -if ( $cgi->param('data_vendor') =~ /^(\w+)$/ ) { - $data_vendor = $1; - $title = "$data_vendor"; -} -$cgi->delete('data_vendor'); +my $data_vendor = 'cch'; $title = " for $title" if $title; @@ -83,10 +78,7 @@ if ($taxproductnum) { } my $hashref = {}; -my $extra_sql = ''; -if ( $data_vendor ) { - $extra_sql .= ' WHERE data_vendor = '. dbh->quote($data_vendor); -} +my $extra_sql .= ' WHERE data_vendor = '. dbh->quote($data_vendor); if ($tax_group || $tax_item || $tax_customer || $tax_provider) { my $compare = "LIKE '". ( $tax_group || "%" ). " : ". ( $tax_item || "%" ). " : ". @@ -111,7 +103,6 @@ if ( $tax_group || $tax_item || $tax_provider || $tax_customer ) { $cgi->param('dummy', 1); #restore this so pagination works -$cgi->param('data_vendor', $data_vendor) if $data_vendor; $cgi->param('tax_group', $tax_group) if $tax_group; $cgi->param('tax_item', $tax_item ) if $tax_item; $cgi->param('tax_provider', $tax_provider ) if $tax_provider; @@ -120,23 +111,20 @@ $cgi->param('onclick', $onclick ) if $onclick; my $count_query = "SELECT COUNT(*) FROM part_pkg_taxproduct $extra_sql"; -my @header = ( 'Data Vendor', 'Group', 'Item', 'Provider', 'Customer' ); +my @header = ( 'Group', 'Item', 'Provider', 'Customer' ); my @links = ( $select_link, $select_link, $select_link, $select_link, - $select_link, ); my @link_onclicks = ( $select_onclick, $select_onclick, $select_onclick, $select_onclick, - $select_onclick, ); -my $align = 'lllll'; +my $align = 'llll'; my @fields = ( - 'data_vendor', sub { shift->description =~ /^(.*):.*:.*:.*$/; $1;}, sub { shift->description =~ /^.*:(.*):.*:.*$/; $1;}, sub { shift->description =~ /^.*:.*:(.*):.*$/; $1;}, @@ -162,31 +150,16 @@ $html_init .= qq( <INPUT NAME="id" TYPE="hidden" VALUE="$id"> <TABLE> <TR> - <TD><SELECT NAME="data_vendor" onChange="this.form.submit()"> -); - -my $sql = "SELECT DISTINCT data_vendor FROM part_pkg_taxproduct ORDER BY data_vendor"; -my $dbh = dbh; -my $sth = $dbh->prepare($sql) or die $dbh->errstr; -$sth->execute or die $sth->errstr; -for (['(choose data vendor)'], @{$sth->fetchall_arrayref}) { - $html_init .= '<OPTION VALUE="'. $_->[0]. '"'. - ($_->[0] eq $data_vendor ? " SELECTED" : ""). - '">'. $_->[0]; -} -$html_init .= qq( - </SELECT> - -<!-- cch specific --> <TD><SELECT NAME="tax_group" onChange="this.form.submit()"> ); -$sql = "SELECT DISTINCT ". +my $sql = "SELECT DISTINCT ". qq!substring(description from '#"%#" : % : % : %' for '#'),!. qq!substring(description from '#"%#" : % : % : %' for '#')!. "FROM part_pkg_taxproduct ORDER BY 1"; -$sth = $dbh->prepare($sql) or die $dbh->errstr; +my $dbh = dbh; +my $sth = $dbh->prepare($sql) or die $dbh->errstr; $sth->execute or die $sth->errstr; for (['', '(choose group)'], @{$sth->fetchall_arrayref}) { $html_init .= '<OPTION VALUE="'. $_->[0]. '"'. diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi index ddb61fa64..ae5085e11 100755 --- a/httemplate/edit/cust_main.cgi +++ b/httemplate/edit/cust_main.cgi @@ -25,7 +25,7 @@ %# agent, agent_custid, refnum (advertising source), referral_custnum %# better section title for this? <FONT CLASS="fsinnerbox-title"><% mt('Basics') |h %></FONT> -<& cust_main/top_misc.html, $cust_main, 'custnum' => $custnum &> +<& cust_main/basics.html, $cust_main, 'custnum' => $custnum &> %# birthdate % if ( $conf->config('national_id-country') diff --git a/httemplate/edit/cust_main/top_misc.html b/httemplate/edit/cust_main/basics.html index 41dd5636b..91868d4a8 100644 --- a/httemplate/edit/cust_main/top_misc.html +++ b/httemplate/edit/cust_main/basics.html @@ -145,6 +145,13 @@ 'label' => emt("Class"), &> +%# tax status +<& /elements/tr-select-tax_status.html, + 'curr_value' => $cust_main->taxstatusnum, + 'disable_empty' => 0, + 'empty_label' => ' ', +&> + %#sales person <& /elements/tr-select-sales.html, 'curr_value' => $cust_main->salesnum, diff --git a/httemplate/edit/process/part_pkg.cgi b/httemplate/edit/process/part_pkg.cgi index d27ddb0b0..0343cc0fb 100755 --- a/httemplate/edit/process/part_pkg.cgi +++ b/httemplate/edit/process/part_pkg.cgi @@ -96,11 +96,31 @@ my $args_callback = sub { grep { $_ !~ /^report_option_/ } @options; - foreach ( split(',', $cgi->param('taxproductnums') ) ) { - my $value = $cgi->param("taxproductnum_$_"); - $error ||= "Illegal taxproductnum_$_: $value" + foreach my $class ( '', split(',', $cgi->param('taxproductnums') ) ) { + my $param = 'taxproductnum'; + $param .= "_$class" if length($class); # gah, "_$class"? + my $value = $cgi->param($param); + + if ( $value == -1 ) { + my $desc = $cgi->param($param.'_description'); + # insert a new part_pkg_taxproduct + my $engine = FS::TaxEngine->new; + my $obj_or_error = $engine->add_taxproduct($desc); + if (ref $obj_or_error) { + $value = $obj_or_error->taxproductnum; + $cgi->param($param, $value); # for error handling + } else { + die "$obj_or_error (adding tax product)"; + } + } + + $error ||= "Illegal $param: $value" unless ( $value =~ /^\d*$/ ); - $options{"usage_taxproductnum_$_"} = $value; + if (length($class)) { + $options{"usage_taxproductnum_$_"} = $value; + } else { + $new->set('taxproductnum', $value); + } } foreach ( grep $_, $cgi->param('report_option') ) { diff --git a/httemplate/elements/select-table.html b/httemplate/elements/select-table.html index e73638801..0b04fee6e 100644 --- a/httemplate/elements/select-table.html +++ b/httemplate/elements/select-table.html @@ -89,10 +89,12 @@ Example: <OPTION VALUE=""><% $opt{'empty_label'} || 'all' %> % } -% foreach my $record ( sort { $a->$name_col() cmp $b->$name_col() -% || $a->$key() <=> $b->$key() -% } -% @records +% foreach my $record ( +% # we have the order_by parameter for this +% #sort { $a->$name_col() cmp $b->$name_col() +% # || $a->$key() <=> $b->$key() +% # } +% @records % ) % { % my $recvalue = $record->$key(); @@ -174,7 +176,8 @@ if ( $opt{'agent_virt'} ) { my @records = (); if ( $opt{'records'} ) { - @records = @{ $opt{'records'} }; + @records = sort { $a->get($name_col) cmp $b->get($name_col) } + @{ $opt{'records'} }; } else { @records = qsearch( { 'table' => $opt{'table'}, diff --git a/httemplate/elements/select-taxproduct.html b/httemplate/elements/select-taxproduct.html index 0f6ef5583..07e554927 100644 --- a/httemplate/elements/select-taxproduct.html +++ b/httemplate/elements/select-taxproduct.html @@ -23,6 +23,9 @@ unless ( $description || ! $value ) { if $part_pkg_taxproduct; } -my $onclick = $opt{onclick} || "overlib( OLiframeContent('${p}/browse/part_pkg_taxproduct.cgi?_type=select&id=${name}&taxproductnum='+document.getElementById('${name}').value, 1000, 400, 'tax_product_popup'), CAPTION, 'Select product', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;"; +my $conf = FS::Conf->new; +my $vendor = lc($conf->config('enable_taxproducts')); +my $onclick = $opt{onclick} || + "overlib( OLiframeContent('${p}/browse/part_pkg_taxproduct/$vendor.html?_type=select&id=${name}&taxproductnum='+document.getElementById('${name}').value, 1000, 400, 'tax_product_popup'), CAPTION, 'Select product', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;"; </%init> diff --git a/httemplate/elements/standardize_locations.js b/httemplate/elements/standardize_locations.js index 2d1fc7423..817a2e357 100644 --- a/httemplate/elements/standardize_locations.js +++ b/httemplate/elements/standardize_locations.js @@ -179,7 +179,7 @@ function confirm_manual_address() { function post_standardization() { -% if ( $conf->exists('enable_taxproducts') ) { +% if ( $need_tax_location ) { var cf = document.<% $formname %>; @@ -204,9 +204,8 @@ function post_standardization() { var state_el = cf.elements[prefix + 'state']; var state = state_el.options[ state_el.selectedIndex ].value; - var url = "<% $p %>/misc/choose_tax_location.html" + - "?data_vendor=cch-zip" + - ";city=" + cf.elements[prefix + 'city'].value + + var url = "<% $p %>/misc/choose_tax_location.html?" + + "city=" + cf.elements[prefix + 'city'].value + ";state=" + state + ";zip=" + cf.elements[prefix + 'zip'].value + ";country=" + country + @@ -252,11 +251,9 @@ function update_geocode() { prefix = 'bill_'; } - //alert(what.options[what.selectedIndex].value); - var argsHash = eval('(' + what.options[what.selectedIndex].value + ')'); - cf.elements[prefix + 'city'].value = argsHash['city']; - setselect(cf.elements[prefix + 'state'], argsHash['state']); - cf.elements[prefix + 'zip'].value = argsHash['zip']; +%# this used to set the city/state/zip to the selected value; I think +%# that's wrong. + var argsHash = JSON.parse(what.value); cf.elements[prefix + 'geocode'].value = argsHash['geocode']; <% $post_geocode %>; @@ -343,4 +340,7 @@ if ( $census_functions ) { $post_geocode = 'confirm_censustract()'; } +my $tax_engine = FS::TaxEngine->new; +my $need_tax_location = $tax_engine->info->{manual_tax_location} ? 1 : 0; + </%init> diff --git a/httemplate/elements/tr-select-tax_status.html b/httemplate/elements/tr-select-tax_status.html new file mode 100644 index 000000000..9c2de154f --- /dev/null +++ b/httemplate/elements/tr-select-tax_status.html @@ -0,0 +1,24 @@ +% if ( !$vendor ) { + + <INPUT TYPE="hidden" NAME="<% $opt{'element_name'} || $opt{'field'} || 'taxstatusnum' %>" VALUE=""> + +% } else { + + <& tr-select-table.html, + label => 'Customer tax status', + table => 'tax_status', + name_col => 'description', + hashref => { data_vendor => $vendor }, + order_by => 'order by taxstatus', + %opt + &> + +% } + +<%shared> +my $conf = FS::Conf->new; +my $vendor = $conf->config('enable_taxproducts'); +</%shared> +<%init> +my %opt = @_; +</%init> diff --git a/httemplate/elements/tr-select-taxoverride.html b/httemplate/elements/tr-select-taxoverride.html index e20d37efd..ee3ee4120 100644 --- a/httemplate/elements/tr-select-taxoverride.html +++ b/httemplate/elements/tr-select-taxoverride.html @@ -1,4 +1,4 @@ -% if ( $conf->exists('enable_taxproducts') ) { +% if ( FS::TaxEngine->new->info->{override} ) { <%include('tr-td-label.html', @_) %> <TD <% $cell_style %>><% include('select-taxoverride.html', @_) %></TD> </TR> @@ -9,8 +9,6 @@ <%init> -my $conf = new FS::Conf; - my %opt = @_; my $cell_style = $opt{'cell_style'}? 'STYLE="'. $opt{cell_style}. '"' : ''; my $name = $opt{element_name} || $opt{field} || 'tax_override'; diff --git a/httemplate/elements/tr-td-label.html b/httemplate/elements/tr-td-label.html index 8125541c7..c318722dc 100644 --- a/httemplate/elements/tr-td-label.html +++ b/httemplate/elements/tr-td-label.html @@ -15,5 +15,8 @@ $style .= '; '. $opt{'cell_style'} if $opt{'cell_style'}; my $required = $opt{'required'} ? '<font color="#ff0000">*</font> ' : ''; +if ($required) { + $style .= ';font-weight: bold'; +} </%init> diff --git a/httemplate/misc/choose_tax_location.html b/httemplate/misc/choose_tax_location.html index 23099c421..9c5881fd4 100644 --- a/httemplate/misc/choose_tax_location.html +++ b/httemplate/misc/choose_tax_location.html @@ -4,9 +4,8 @@ <SELECT NAME='geocodes' ID='geocodes' STYLE="<% $style %>"> % foreach my $location (@cust_tax_location) { -% my %value = ( zip => $zip5, -% map { $_ => $location->$_ } -% qw ( city state geocode ) +% my %value = ( map { $_ => $location->$_ } +% qw ( zip city state geocode ) % ); % map { $value{$_} = $location{$_} } qw ( city state ) % if $location{country} eq 'CA'; @@ -36,10 +35,10 @@ <%init> my $conf = new FS::Conf; +my $tax_engine = FS::TaxEngine->new; -my %location = (); - -($location{data_vendor}) = $cgi->param('data_vendor') =~ /^([-\w]+)$/; +my %location; +($location{data_vendor}) = $conf->config('enable_taxproducts'); ($location{city}) = $cgi->param('city') =~ /^([\w ]+)$/; ($location{state}) = $cgi->param('state') =~ /^(\w+)$/; ($location{zip}) = $cgi->param('zip') =~ /^([-\w ]+)$/; @@ -50,22 +49,7 @@ my($geocode) = $cgi->param('geocode') =~ /^([\w]+)$/; my($formname) = $cgi->param('formname') =~ /^([\w]*)$/; $formname ||= 'CustomerForm'; -my($zip5, $zip4) = split('-', $location{zip}); - -#only support US & CA -my $hashref = { 'data_vendor' => $location{data_vendor} }; -$hashref->{zip} = $location{country} eq 'CA' ? substr($zip5,0,1) : $zip5, - -my @keys = keys(%$hashref); -my @cust_tax_location = (); -until ( @cust_tax_location ) { - @cust_tax_location = qsearch({ table => 'cust_tax_location', - hashref => $hashref, - order_by => 'LIMIT 50', - }); - last unless scalar(@keys); - delete $hashref->{ shift @keys }; -} +my @cust_tax_location = $tax_engine->cust_tax_locations(\%location); my %max = ( city => 4, county => 6, state => 5); foreach my $location (@cust_tax_location) { diff --git a/httemplate/misc/tax-import.cgi b/httemplate/misc/tax-import.cgi index 25414b20d..7e72c74e3 100644 --- a/httemplate/misc/tax-import.cgi +++ b/httemplate/misc/tax-import.cgi @@ -1,4 +1,4 @@ -<% include("/elements/header.html",'Batch Tax Rate Import') %> +<& /elements/header.html,'Batch Tax Rate Import' &> Import a CSV file set containing tax rate records. <BR><BR> @@ -6,22 +6,22 @@ Import a CSV file set containing tax rate records. <& /elements/form-file_upload.html, 'name' => 'TaxRateUpload', 'action' => 'process/tax-import.cgi', - 'num_files' => 6, 'fields' => [ 'format', 'reload' ], + 'num_files' => $vendor_info{$data_vendor}->{num_files}, 'message' => 'Tax rates imported', 'onsubmit' => "document.TaxRateUpload.submitButton.disabled=true;", &> -<% &ntable("#cccccc", 2) %> +<& /elements/table-grid.html &> <TR> <TH ALIGN="right">Format</TH> <TD> <SELECT NAME="format"> - <!-- <OPTION VALUE="cch-update" SELECTED>CCH update (CSV) --> - <OPTION VALUE="cch">CCH import (CSV) - <!-- <OPTION VALUE="cch-fixed-update">CCH update (fixed length) --> - <OPTION VALUE="cch-fixed">CCH import (fixed length) +% my @formats = @{ $vendor_info{$data_vendor}->{formats} }; +% while (@formats) { + <OPTION VALUE="<% shift @formats %>"><% shift @formats %></OPTION> +% } </SELECT> </TD> </TR> @@ -33,24 +33,11 @@ Import a CSV file set containing tax rate records. </TD> </TR> - <% include( '/elements/file-upload.html', - 'field' => [ 'geocodefile', - 'codefile', - 'plus4file', - 'zipfile', - 'txmatrixfile', - 'detailfile', - ], - 'label' => [ 'geocode filename', - 'code filename', - 'plus4 filename', - 'zip filename', - 'txmatrix filename', - 'detail filename', - ], + <& /elements/file-upload.html, + 'field' => $vendor_info{$data_vendor}->{field}, + 'label' => $vendor_info{$data_vendor}->{label}, 'debug' => 0, - ) - %> + &> <TR> <TD COLSPAN=2 ALIGN="center" STYLE="padding-top:6px"> @@ -72,4 +59,37 @@ Import a CSV file set containing tax rate records. die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Import'); +my $conf = FS::Conf->new; +my $data_vendor = $conf->config('enable_taxproducts'); + +my %vendor_info = ( + CCH => { + 'num_files' => 6, + 'formats' => [ 'cch' => 'CCH import (CSV)', + 'cch-fixed' => 'CCH import (fixed length)' ], + 'field' => [ 'geocodefile', + 'codefile', + 'plus4file', + 'zipfile', + 'txmatrixfile', + 'detailfile', + ], + 'label' => [ 'geocode filename', + 'code filename', + 'plus4 filename', + 'zip filename', + 'txmatrix filename', + 'detail filename', + ], + }, + Billsoft => { + 'num_files' => 1, + 'formats' => [ 'billsoft-pcode' => 'Billsoft PCodes', + 'billsoft-taxclass' => 'Tax classes', + 'billsoft-taxproduct' => 'Tax products' ], + 'field' => [ 'file' ], + 'label' => [ 'Filename' ], + }, +); + </%init> |