From 7516e3da0f17eeecba27219ef96a8b5f46af2083 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Fri, 31 Oct 2014 15:45:50 -0700 Subject: tax engine refactoring for Avalara and Billsoft tax vendors, #25718 --- httemplate/edit/process/part_pkg.cgi | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'httemplate/edit/process/part_pkg.cgi') 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') ) { -- cgit v1.2.1