'precheck_callback' => $precheck_callback,
'args_callback' => $args_callback,
'process_m2m' => \@process_m2m,
+ 'process_o2m' => \@process_o2m,
)
%>
<%init>
}
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');
}
( $optionname => $value );
}
+ 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 ( split(',', $cgi->param('report_option') ) ) {
+ foreach ( grep $_, $cgi->param('report_option') ) {
$error ||= "Illegal optional report class: $_" unless ( $_ =~ /^\d*$/ );
$options{"report_option_$_"} = 1;
}
$options{$_} = scalar( $cgi->param($_) )
- for (qw( setup_fee recur_fee ));
+ for (qw( setup_fee recur_fee disable_line_item_date_ranges ));
push @args, 'options' => \%options;
+ ###
+ #part_pkg_currency
+ ###
+
+ my %part_pkg_currency = (
+ map { $_ => scalar($cgi->param($_)) }
+ #grep /._[A-Z]{3}$/, #support other options
+ grep /^(setup|recur)_fee_[A-Z]{3}$/,
+ $cgi->param
+ );
+
+ 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
###
- my %pkg_svc = map { $_ => scalar($cgi->param("pkg_svc$_")) }
- map { $_->svcpart }
- qsearch('part_svc', {} );
+ my @svcparts = map { $_->svcpart } qsearch('part_svc', {});
+ my %pkg_svc = map { $_ => scalar($cgi->param("pkg_svc$_" )) } @svcparts;
+ my %hidden_svc = map { $_ => scalar($cgi->param("hidden$_" )) } @svcparts;
+ my %bulk_skip = map { $_ => ( $cgi->param("no_bulk_skip$_") eq 'Y'
+ ? '' : 'Y'
+ )
+ } @svcparts;
- push @args, 'pkg_svc' => \%pkg_svc;
+ push @args, 'pkg_svc' => \%pkg_svc,
+ 'hidden_svc' => \%hidden_svc,
+ 'bulk_skip' => \%bulk_skip;
###
# cust_pkg and custnum_ref (inserts only)
'custnum_ref' => \$custnum;
}
- warn "args: ".join('/', @args). "\n";
+ my %part_pkg_vendor;
+ foreach my $param ( $cgi->param ) {
+ if ( $param =~ /^export(\d+)$/ && length($cgi->param($param)) > 0 ) {
+ $part_pkg_vendor{$1} = $cgi->param($param);
+ }
+ }
+ if ( keys %part_pkg_vendor > 0 ) {
+ push @args, 'part_pkg_vendor' => \%part_pkg_vendor;
+ }
+
+ #warn "args: ".join('/', @args). "\n";
@args;
'target_table' => 'tax_class',
'params' => \@tax_overrides,
},
+ { 'link_table' => 'part_pkg_discount',
+ 'target_table' => 'discount',
+ 'params' => [ map $cgi->param($_),
+ grep /^discountnum/, $cgi->param
+ ],
+ },
{ 'link_table' => 'part_pkg_link',
'target_table' => 'part_pkg',
'base_field' => 'src_pkgpart',
grep /^svc_dst_pkgpart/, $cgi->param
],
},
+ { 'link_table' => 'part_pkg_link',
+ 'target_table' => 'part_pkg',
+ 'base_field' => 'src_pkgpart',
+ 'target_field' => 'dst_pkgpart',
+ 'hashref' => { 'link_type' => 'supp', 'hidden' => '' },
+ 'params' => [ map $cgi->param($_),
+ grep /^supp_dst_pkgpart/, $cgi->param
+ ],
+ },
map {
my $hidden = $_;
{ 'link_table' => 'part_pkg_link',
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 = (
+ {
+ 'table' => 'part_pkg_msgcat',
+ 'fields' => [qw( locale pkg )],
+ },
+ {
+ 'table' => 'part_pkg_usageprice',
+ 'fields' => [qw( price currency action target amount )],
+
+ }
+);
</%init>