add basic part_pkg cost columns for agent wholsale price plan, RT#4696
[freeside.git] / httemplate / edit / part_pkg.cgi
index 5a9bb10..6391db9 100755 (executable)
@@ -5,8 +5,7 @@
 
               'agent_virt'            => 1,
               'agent_null_right'      => $edit_global,
-              'agent_clone_extra_sql' => FS::part_pkg->curuser_pkgs_sql,
-
+              'agent_clone_extra_sql' => $agent_clone_extra_sql,
               #'viewall_dir'           => 'browse',
               'viewall_url'           => $p.'browse/part_pkg.cgi',
               'html_init'             => include('/elements/init_overlib.html').
@@ -23,6 +22,7 @@
               'clone_callback'        => $clone_callback,
               'edit_callback'         => $edit_callback,
               'error_callback'        => $error_callback,
+              'field_callback'        => $field_callback,
 
               'labels' => { 
                             'pkgpart'          => 'Package Definition',
@@ -37,6 +37,8 @@
                             'taxproduct_select'=> 'Tax products',
                             'plan'             => 'Price plan',
                             'disabled'         => 'Disable new orders',
+                            'setup_cost'       => 'Setup cost',
+                            'recur_cost'       => 'Recur cost',
                             'pay_weight'       => 'Payment weight',
                             'credit_weight'    => 'Credit weight',
                             'agentnum'         => 'Agent',
                               { field=>'promo_code', type=>'text', size=>15 },
 
                               { type  => 'tablebreak-tr-title',
-                                value => 'Line-item revenue recogition', #better name?
+                                value => 'Cost tracking', #better name?
                               },
-                              { field=>'pay_weight',    type=>'text', size=>6 },
-                              { field=>'credit_weight', type=>'text', size=>6 },
+                              { field=>'setup_cost', type=>'money', },
+                              { field=>'recur_cost', type=>'money', },
 
                             { type => 'columnnext' },
 
                                 },
                               },
 
+                              { type  => 'tablebreak-tr-title',
+                                value => 'Line-item revenue recogition', #better name?
+                              },
+                              { field=>'pay_weight',    type=>'text', size=>6 },
+                              { field=>'credit_weight', type=>'text', size=>6 },
+
+
                             { type => 'columnend' },
 
                             { 'type'  => 'tablebreak-tr-title',
@@ -206,6 +215,14 @@ my $begin_callback = sub {
 
 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
 
+my $agent_clone_extra_sql = 
+  ' ( '. FS::part_pkg->curuser_pkgs_sql.
+  #kludge to clone custom customer packages you otherwise couldn't see
+  #really need a proper "CUSTOM" flag that's distinct from disabled
+  #"   OR ( part_pkg.disabled = 'Y' AND part_pkg.comment LIKE '(CUSTOM)%' ) ".
+  "   OR ( part_pkg.disabled = 'Y' ) ".
+  ' ) ';
+
 my $conf = new FS::Conf;
 my $taxproducts = $conf->exists('enable_taxproducts');
 
@@ -225,6 +242,7 @@ my %tax_override = ();
 
 my %taxproductnums = map { ($_->classnum => 1) }
                      qsearch('usage_class', { 'disabled' => '' });
+my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
 
 my %options = ();
 my $recur_disabled = 1;
@@ -546,7 +564,6 @@ my %usage_class = map { ($_->classnum => $_->classname) }
 $usage_class{setup} = 'Setup';
 $usage_class{recur} = 'Recurring';
 
-my @taxproductnums = ();
 my %taxproduct_fields = ();
 my $end_callback = sub {
   my( $cgi, $object, $fields, $opt ) = @_;
@@ -611,4 +628,21 @@ my $taxproduct_values = sub {
   
 };
 
+my $field_callback = sub {
+  my ($cgi, $object, $fieldref) = @_;
+
+  my $field = $fieldref->{field};
+  if ($field eq 'taxproductnums') {
+    $fieldref->{value} = join(',', @taxproductnums);
+  } elsif ($field eq 'taxproduct_select') {
+    $fieldref->{options} = [ '(default)', @taxproductnums ];
+    $fieldref->{labels}  = { ( '(default)' => '(default)' ),
+                             map {( $_ => ($usage_class{$_} || $_) )}
+                               @taxproductnums
+                           };
+    $fieldref->{layer_fields} = \%taxproduct_fields;
+    $fieldref->{layer_values_callback} = $taxproduct_values;
+  }
+};
+
 </%init>