bug squashing for multiple usage classes
[freeside.git] / httemplate / edit / process / part_pkg.cgi
index faaedf9..669b759 100755 (executable)
@@ -38,10 +38,10 @@ my $precheck_callback = sub {
     push @agents, $1 if $1;
   }
   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')
-          );
+    unless scalar(@agents)
+           || ( $cgi->param('clone') && $cgi->param('clone') =~ /^\d+$/ )
+           || ( !$cgi->param('pkgpart') && $conf->exists('agent-defaultpkg') )
+           || $cgi->param('disabled');
 
   return '';
 
@@ -84,6 +84,13 @@ my $args_callback = sub {
         }
         @options;
 
+  foreach ( split(',', $cgi->param('taxproductnums') ) ) {
+    my $value = $cgi->param("taxproductnum_$_");
+    $error ||= "Illegal taxproductnum_$_: $value"
+      unless ( $value =~ /^\d*$/  );
+    $options{"usage_taxproductnum_$_"} = $value;
+  }
+
   $options{$_} = scalar( $cgi->param($_) )
     for (qw( setup_fee recur_fee ));
   
@@ -146,6 +153,22 @@ my @process_m2m = (
   },
 );
 
+foreach my $override_class ($cgi->param) {
+  next unless $override_class =~ /^tax_override_(\w+)$/;
+  my $class = $1;
+
+  my (@tax_overrides) = (grep "$_", split (",", $1))
+    if $cgi->param($override_class) =~ /^([\d,]+)$/;
+
+  push @process_m2m, {
+    'link_table'   => 'part_pkg_taxoverride',
+    'target_table' => 'tax_class',
+    'hashref'      => { 'usage_class' => $class },
+    'params'       => [ @tax_overrides ],
+  };
+
+}
+
 my $conf = new FS::Conf;
 
 if ( $cgi->param('pkgpart') || ! $conf->exists('agent_defaultpkg') ) {