communigate (phase 2): rules. RT#7514
[freeside.git] / httemplate / edit / part_pkg.cgi
index 690e884..538ba34 100755 (executable)
@@ -29,6 +29,7 @@
                             'pkg'              => 'Package (customer-visible)',
                             'comment'          => 'Comment (customer-hidden)',
                             'classnum'         => 'Package class',
+                            'addon_classnum'   => 'Restrict additional orders to package class',
                             'promo_code'       => 'Promotional code',
                             'freq'             => 'Recurring fee frequency',
                             'setuptax'         => 'Setup fee tax exempt',
                                 onchange      => 'agent_changed',
                               },
                               {field=>'classnum', type=>'select-pkg_class' },
+                              ( $conf->exists('pkg-addon_classnum')
+                                  ? ( { field=>'addon_classnum',
+                                        type =>'select-pkg_class',
+                                      }
+                                    )
+                                   : ()
+                              ),
                               {field=>'disabled', type=>$disabled_type, value=>'Y'},
 
                               { type  => 'tablebreak-tr-title',
 
                             { type => 'columnend' },
 
-                            { 'type'  => $census ? 'tablebreak-tr-title'
-                                                 : 'hidden',
+                            { 'type'  => $report_option ? 'tablebreak-tr-title'
+                                                        : 'hidden',
                               'value' => 'Optional report classes',
                               'field' => 'census_title',
                             },
                             { 'field'    => 'report_option',
-                              'type'     => $census ? 'select-table' : 'hidden',
+                              'type'     => $report_option ? 'select-table'
+                                                           : 'hidden',
                               'table'    => 'part_pkg_report_option',
                               'name_col' => 'name',
+                              'hashref'  => { 'disabled' => '' },
                               'multiple' => 1,
                             },
 
@@ -239,6 +249,11 @@ my $begin_callback = sub {
 
 my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
 
+#arg.  access rights for cloning are Hard.
+# on the one hand we don't really want cloning (customizing a package) to fail 
+#  for want of finding the source package in normal usage
+# on the other hand, we don't want people using the clone link to be able to
+#  see 
 my $agent_clone_extra_sql = 
   ' ( '. FS::part_pkg->curuser_pkgs_sql.
   "   OR ( part_pkg.custom = 'Y' ) ".
@@ -246,7 +261,12 @@ my $agent_clone_extra_sql =
 
 my $conf = new FS::Conf;
 my $taxproducts = $conf->exists('enable_taxproducts');
-my $census = scalar( qsearch( 'part_pkg_report_option', {} ) );
+
+my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option".
+                       "  WHERE disabled IS NULL OR disabled = ''  ")
+  or die dbh->errstr;
+$sth->execute or die $sth->errstr;
+my $report_option = $sth->fetchrow_arrayref->[0];
 
 #XXX
 # - tr-part_pkg_freq: month_increments_only (from price plans)
@@ -322,7 +342,8 @@ my $edit_callback = sub {
 
   $recur_disabled = $object->freq ? 0 : 1;
 
-  (@agent_type) = map {$_->typenum} qsearch('type_pkgs',{'pkgpart'=>$1});
+  (@agent_type) =
+    map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } );
 
   my @report_option = ();
   foreach ($object->options) {
@@ -379,6 +400,11 @@ my $clone_callback = sub {
 
     $object->disabled('Y');
 
+  } else { #not when cloning...
+
+    (@agent_type) =
+      map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } );
+
   }
 
   %options = $object->options;
@@ -393,7 +419,6 @@ my $m2_error_callback_maker = sub {
   my $link_type = shift; #yay closures
   return sub {
     my( $cgi, $object ) = @_;
-    my $num;
     map {
 
           if ( /^${link_type}_dst_pkgpart(\d+)$/ &&