restrict additinal package order option, RT#6029
authorivan <ivan>
Thu, 22 Oct 2009 12:50:05 +0000 (12:50 +0000)
committerivan <ivan>
Thu, 22 Oct 2009 12:50:05 +0000 (12:50 +0000)
FS/FS/ClientAPI/MasonComponent.pm
FS/FS/Conf.pm
FS/FS/Schema.pm
FS/FS/part_pkg.pm
httemplate/browse/part_pkg.cgi
httemplate/edit/part_pkg.cgi

index 88baf07..2027840 100644 (file)
@@ -59,6 +59,21 @@ my %session_callbacks = (
            }
       qsearch( 'part_pkg', { 'disabled' => '' }, '', 'ORDER BY pkg' ); # case?
 
            }
       qsearch( 'part_pkg', { 'disabled' => '' }, '', 'ORDER BY pkg' ); # case?
 
+    my $conf = new FS::Conf;
+    if ( $conf->exists('pkg-addon_classnum') ) {
+
+      my %classnum = map  { ( $_->addon_classnum => 1 ) }
+                     grep { $_->freq !~ /^0/ }
+                     map  { $_->part_pkg }
+                          $cust_main->ncancelled_pkgs;
+
+      warn "classnums: ". join(',', keys %classnum). "\n";
+
+      unless ( $classnum{''} ) {
+        @part_pkg = grep $classnum{ $_->classnum }, @part_pkg;
+      }
+    }
+
     my %args = @$argsref;
     $args{part_pkg} = \@part_pkg;
     @$argsref = ( %args );
     my %args = @$argsref;
     $args{part_pkg} = \@part_pkg;
     @$argsref = ( %args );
index 13bec18..f0e2f45 100644 (file)
@@ -230,6 +230,7 @@ sub invoice_templatenames {
     }
   }
   
     }
   }
   
+  map { $_ } #handle scalar context
   sort keys %templatenames;
 
 }
   sort keys %templatenames;
 
 }
@@ -576,7 +577,7 @@ worry that config_items is freeside-specific and icky.
   {
     'key'         => 'alert_expiration',
     'section'     => 'billing',
   {
     'key'         => 'alert_expiration',
     'section'     => 'billing',
-    'description' => 'Enable alerts about billing method expiration.',
+    'description' => 'Enable alerts about billing method expiration (i.e. expiring credit cards).',
     'type'        => 'checkbox',
     'per_agent'   => 1,
   },
     'type'        => 'checkbox',
     'per_agent'   => 1,
   },
@@ -584,7 +585,7 @@ worry that config_items is freeside-specific and icky.
   {
     'key'         => 'alerter_template',
     'section'     => 'billing',
   {
     'key'         => 'alerter_template',
     'section'     => 'billing',
-    'description' => 'Template file for billing method expiration alerts.  See the <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:1.7:Documentation:Administration#Credit_cards_and_Electronic_checks">billing documentation</a> for details.',
+    'description' => 'Template file for billing method expiration alerts (i.e. expiring credit cards).  See the <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:1.7:Documentation:Administration#Credit_cards_and_Electronic_checks">billing documentation</a> for details.',
     'type'        => 'textarea',
     'per_agent'   => 1,
   },
     'type'        => 'textarea',
     'per_agent'   => 1,
   },
@@ -1583,14 +1584,14 @@ worry that config_items is freeside-specific and icky.
   {
     'key'         => 'declinetemplate',
     'section'     => 'billing',
   {
     'key'         => 'declinetemplate',
     'section'     => 'billing',
-    'description' => 'Template file for credit card decline emails.',
+    'description' => 'Template file for credit card and electronic check decline emails.',
     'type'        => 'textarea',
   },
 
   {
     'key'         => 'emaildecline',
     'section'     => 'billing',
     'type'        => 'textarea',
   },
 
   {
     'key'         => 'emaildecline',
     'section'     => 'billing',
-    'description' => 'Enable emailing of credit card decline notices.',
+    'description' => 'Enable emailing of credit card and electronic check decline notices.',
     'type'        => 'checkbox',
   },
 
     'type'        => 'checkbox',
   },
 
@@ -3190,6 +3191,13 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
   },
 
   {
+    'key'         => 'pkg-addon_classnum',
+    'section'     => 'billing',
+    'description' => 'Enable the ability to restrict additional package orders based on package class.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'cust_main-edit_signupdate',
     'section'     => 'UI',
     'descritpion' => 'Enable manual editing of the signup date.',
     'key'         => 'cust_main-edit_signupdate',
     'section'     => 'UI',
     'descritpion' => 'Enable manual editing of the signup date.',
index cf3a889..dfa3328 100644 (file)
@@ -1274,6 +1274,7 @@ sub tables_hashref {
         'custom',        'char', 'NULL', 1, '', '', 
         'taxclass',      'varchar', 'NULL', $char_d, '', '', 
         'classnum',      'int',     'NULL', '', '', '', 
         'custom',        'char', 'NULL', 1, '', '', 
         'taxclass',      'varchar', 'NULL', $char_d, '', '', 
         'classnum',      'int',     'NULL', '', '', '', 
+        'addon_classnum','int',     'NULL', '', '', '', 
         'taxproductnum', 'int',     'NULL', '', '', '', 
         'setup_cost',    @money_typen,          '', '',
         'recur_cost',    @money_typen,          '', '',
         'taxproductnum', 'int',     'NULL', '', '', '', 
         'setup_cost',    @money_typen,          '', '',
         'recur_cost',    @money_typen,          '', '',
@@ -1284,7 +1285,9 @@ sub tables_hashref {
       ],
       'primary_key' => 'pkgpart',
       'unique' => [],
       ],
       'primary_key' => 'pkgpart',
       'unique' => [],
-      'index' => [ [ 'promo_code' ], [ 'disabled' ], [ 'agentnum' ], ],
+      'index' => [ [ 'promo_code' ], [ 'disabled' ], [ 'classnum' ],
+                   [ 'agentnum' ],
+                 ],
     },
 
     'part_pkg_link' => {
     },
 
     'part_pkg_link' => {
index 287453f..70dcd49 100644 (file)
@@ -465,6 +465,8 @@ sub check {
     || $self->ut_floatn('pay_weight')
     || $self->ut_floatn('credit_weight')
     || $self->ut_numbern('taxproductnum')
     || $self->ut_floatn('pay_weight')
     || $self->ut_floatn('credit_weight')
     || $self->ut_numbern('taxproductnum')
+    || $self->ut_foreign_keyn('classnum',       'pkg_class', 'classnum')
+    || $self->ut_foreign_keyn('addon_classnum', 'pkg_class', 'classnum')
     || $self->ut_foreign_keyn('taxproductnum',
                               'part_pkg_taxproduct',
                               'taxproductnum'
     || $self->ut_foreign_keyn('taxproductnum',
                               'part_pkg_taxproduct',
                               'taxproductnum'
@@ -477,13 +479,6 @@ sub check {
   ;
   return $error if $error;
 
   ;
   return $error if $error;
 
-  if ( $self->classnum !~ /^$/ ) {
-    my $error = $self->ut_foreign_key('classnum', 'pkg_class', 'classnum');
-    return $error if $error;
-  } else {
-    $self->classnum('');
-  }
-
   return 'Unknown plan '. $self->plan
     unless exists($plans{$self->plan});
 
   return 'Unknown plan '. $self->plan
     unless exists($plans{$self->plan});
 
@@ -536,6 +531,22 @@ sub pkg_class {
   }
 }
 
   }
 }
 
+=item addon_pkg_class
+
+Returns the add-on package class, as an FS::pkg_class object, or the empty
+string if there is no add-on package class.
+
+=cut
+
+sub addon_pkg_class {
+  my $self = shift;
+  if ( $self->addon_classnum ) {
+    qsearchs('pkg_class', { 'classnum' => $self->addon_classnum } );
+  } else {
+    return '';
+  }
+}
+
 =item categoryname 
 
 Returns the package category name, or the empty string if there is no package
 =item categoryname 
 
 Returns the package category name, or the empty string if there is no package
@@ -566,6 +577,21 @@ sub classname {
     : '';
 }
 
     : '';
 }
 
+=item addon_classname 
+
+Returns the add-on package class name, or the empty string if there is no
+add-on package class.
+
+=cut
+
+sub addon_classname {
+  my $self = shift;
+  my $pkg_class = $self->addon_pkg_class;
+  $pkg_class
+    ? $pkg_class->classname
+    : '';
+}
+
 =item agent 
 
 Returns the associated agent for this event, if any, as an FS::agent object.
 =item agent 
 
 Returns the associated agent for this event, if any, as an FS::agent object.
index c6cbb81..e226ce1 100755 (executable)
@@ -177,6 +177,12 @@ unless ( 0 ) { #already showing only one class or something?
   $align .= 'l';
 }
 
   $align .= 'l';
 }
 
+if ( $conf->exists('pkg-addon_classnum') ) {
+  push @header, "Add'l order class";
+  push @fields, sub { shift->addon_classname || '(none)'; };
+  $align .= 'l';
+}
+
 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
 
 tie my %plan_labels, 'Tie::IxHash',
 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
 
 tie my %plan_labels, 'Tie::IxHash',
index 690e884..fcde22b 100755 (executable)
@@ -29,6 +29,7 @@
                             'pkg'              => 'Package (customer-visible)',
                             'comment'          => 'Comment (customer-hidden)',
                             'classnum'         => 'Package class',
                             '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',
                             'promo_code'       => 'Promotional code',
                             'freq'             => 'Recurring fee frequency',
                             'setuptax'         => 'Setup fee tax exempt',
                                 onchange      => 'agent_changed',
                               },
                               {field=>'classnum', type=>'select-pkg_class' },
                                 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',
                               {field=>'disabled', type=>$disabled_type, value=>'Y'},
 
                               { type  => 'tablebreak-tr-title',