X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Fprocess%2Fpart_pkg.cgi;h=0343cc0fb65ff3edd783d3e1f90150bfad1eb2c2;hb=7516e3da0f17eeecba27219ef96a8b5f46af2083;hp=82c4e1e1583b31e9d7a911e92bfbc3a63ac15011;hpb=013646e6629fc94b4cda03c495aa56677f2de381;p=freeside.git diff --git a/httemplate/edit/process/part_pkg.cgi b/httemplate/edit/process/part_pkg.cgi index 82c4e1e15..0343cc0fb 100755 --- a/httemplate/edit/process/part_pkg.cgi +++ b/httemplate/edit/process/part_pkg.cgi @@ -50,8 +50,7 @@ my $precheck_callback = sub { } return "At least one agent type must be specified." unless scalar(@agents) - || ( $cgi->param('clone') && $cgi->param('clone') =~ /^\d+$/ ) - || ( !$cgi->param('pkgpart') && $conf->exists('agent-defaultpkg') ) + #wtf? || ( $cgi->param('clone') && $cgi->param('clone') =~ /^\d+$/ ) || $cgi->param('disabled') || $cgi->param('agentnum'); @@ -97,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') ) { @@ -128,6 +147,14 @@ my $args_callback = sub { push @args, 'part_pkg_currency' => \%part_pkg_currency; ### + # fcc options + ### + my $fcc_options_string = $cgi->param('fcc_options_string'); + if ($fcc_options_string) { + push @args, 'fcc_options' => decode_json($fcc_options_string); + } + + ### #pkg_svc ### @@ -251,17 +278,30 @@ foreach my $override_class ($cgi->param) { my $conf = new FS::Conf; -if ( $cgi->param('pkgpart') || ! $conf->exists('agent_defaultpkg') ) { - my @agents = (); - foreach ($cgi->param('agent_type')) { - /^(\d+)$/; - push @agents, $1 if $1; - } - push @process_m2m, { - 'link_table' => 'type_pkgs', - 'target_table' => 'agent_type', - 'params' => \@agents, - }; +my @agents = (); +foreach ($cgi->param('agent_type')) { + /^(\d+)$/; + push @agents, $1 if $1; +} +push @process_m2m, { + 'link_table' => 'type_pkgs', + 'target_table' => 'agent_type', + 'params' => \@agents, +}; + +my $targets = FS::part_pkg_usageprice->targets; +foreach my $amount_param ( grep /^usagepricepart(\d+)_amount$/, $cgi->param ) { + $amount_param =~ /^usagepricepart(\d+)_amount$/ or die 'unpossible'; + my $num = $1; + my $amount = $cgi->param($amount_param); + if ( ! $amount && ! $cgi->param("usagepricepart${num}_price") ) { + #don't add empty rows just because the dropdowns have a value + $cgi->param("usagepricepart${num}_$_", '') for qw( currency action target ); + next; + } + my $target = $cgi->param("usagepricepart${num}_target"); + $amount *= $targets->{$target}{multiplier} if $targets->{$target}{multiplier}; + $cgi->param($amount_param, $amount); } my @process_o2m = ( @@ -272,6 +312,7 @@ my @process_o2m = ( { 'table' => 'part_pkg_usageprice', 'fields' => [qw( price currency action target amount )], + } );