fix cloning w/new package editor
[freeside.git] / httemplate / edit / process / part_pkg.cgi
index be6e2f8..faaedf9 100755 (executable)
@@ -1,6 +1,7 @@
 <% include( 'elements/process.html',
               #'debug'             => 1,
               'table'             => 'part_pkg',
+              'redirect'          => $redirect_callback,
               'viewall_dir'       => 'browse',
               'viewall_ext'       => 'cgi',
               'edit_ext'          => 'cgi',
@@ -8,7 +9,6 @@
               'precheck_callback' => $precheck_callback,
               'args_callback'     => $args_callback,
               'process_m2m'       => \@process_m2m,
-              'debug' => 1,
           )
 %>
 <%init>
@@ -84,7 +84,8 @@ my $args_callback = sub {
         }
         @options;
 
-  $options{$_} = scalar($cgi->param($_)) for (qw( setup_fee recur_fee ));
+  $options{$_} = scalar( $cgi->param($_) )
+    for (qw( setup_fee recur_fee ));
   
   push @args, 'options' => \%options;
 
@@ -106,10 +107,20 @@ my $args_callback = sub {
                 'custnum_ref' => \$custnum;
   }
 
+  warn "args: ".join('/', @args). "\n";
+
   @args;
 
 };
 
+my $redirect_callback = sub {
+  #my( $cgi, $new ) = @_;
+  return '' unless $custnum;
+  popurl(3). "view/cust_main.cgi?keywords=$custnum;dummy=";
+};
+
+#these should probably move to @args above and be processed by part_pkg.pm...
+
 $cgi->param('tax_override') =~ /^([\d,]+)$/;
 my (@tax_overrides) = (grep "$_", split (",", $1));
 
@@ -118,7 +129,21 @@ my @process_m2m = (
     'link_table'   => 'part_pkg_taxoverride',
     'target_table' => 'tax_class',
     'params'       => \@tax_overrides,
-  }
+  },
+  { 'link_table'   => 'part_pkg_link',
+    'target_table' => 'part_pkg',
+    'base_field'   => 'src_pkgpart',
+    'target_field' => 'dst_pkgpart',
+    'hashref'      => { 'link_type' => 'bill' },
+    'params'       => [ map $cgi->param($_), grep /^bill_dst_pkgpart/, $cgi->param ],
+  },
+  { 'link_table'   => 'part_pkg_link',
+    'target_table' => 'part_pkg',
+    'base_field'   => 'src_pkgpart',
+    'target_field' => 'dst_pkgpart',
+    'hashref'      => { 'link_type' => 'svc' },
+    'params'       => [ map $cgi->param($_), grep /^svc_dst_pkgpart/, $cgi->param ],
+  },
 );
 
 my $conf = new FS::Conf;
@@ -129,7 +154,6 @@ if ( $cgi->param('pkgpart') || ! $conf->exists('agent_defaultpkg') ) {
     /^(\d+)$/;
     push @agents, $1 if $1;
   }
-  warn "AGENTS: @agents";
   push @process_m2m, {
     'link_table'   => 'type_pkgs',
     'target_table' => 'agent_type',