clarify interface difference between calc_setup and calc_recur: calc_setup takes...
[freeside.git] / FS / FS / part_pkg.pm
index 956cf79..bf60784 100644 (file)
@@ -232,6 +232,19 @@ sub insert {
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
+  if ( length($self->classnum) && $self->classnum !~ /^(\d+)$/ ) {
+    my $pkg_class = qsearchs('pkg_class', { 'classname' => $self->classnum } )
+                 || new FS::pkg_class { classname => $self->classnum };
+    unless ( $pkg_class->classnum ) {
+      my $error = $pkg_class->insert;
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return $error;
+      }
+    }
+    $self->classnum( $pkg_class->classnum );
+  }
+
   warn "  inserting part_pkg record" if $DEBUG;
   my $error = $self->SUPER::insert( $options{options} );
   if ( $error ) {
   warn "  inserting part_pkg record" if $DEBUG;
   my $error = $self->SUPER::insert( $options{options} );
   if ( $error ) {
@@ -680,6 +693,25 @@ sub replace {
   '';
 }
 
   '';
 }
 
+sub validate_number {
+  my ($option, $valref) = @_;
+
+  $$valref = 0 unless $$valref;
+  return "Invalid $option"
+    unless ($$valref) = ($$valref =~ /^\s*(\d+)\s*$/);
+  return '';
+}
+
+sub validate_number_blank {
+  my ($option, $valref) = @_;
+
+  if ($$valref) {
+    return "Invalid $option"
+      unless ($$valref) = ($$valref =~ /^\s*(\d+)\s*$/);
+  }
+  return '';
+}
+
 =item check
 
 Checks all fields to make sure this is a valid package definition.  If
 =item check
 
 Checks all fields to make sure this is a valid package definition.  If
@@ -774,11 +806,17 @@ sub check {
 
 =item check_options
 
 
 =item check_options
 
-For a passed I<$options> hashref, validates any options that
-have 'validate' subroutines defined in the info hash, 
-then validates the entire hashref if the price plan has 
-its own 'validate' subroutine defined in the info hash 
-(I<$options> values might be altered.)  
+Pass an I<$options> hashref that contains the values to be
+inserted or updated for any FS::part_pkg::MODULE.pm.
+
+For each key in I<$options>, validates the value by calling
+the 'validate' subroutine defined for that option e.g.
+FS::part_pkg::MODULE::plan_info()->{$KEY}->{validate}.  The
+option validation function is only called when the hashkey for
+that option exists in I<$options>.
+
+Then the module validation function is called, from
+FS::part_pkg::MODULE::plan_info()->{validate}
 
 Returns error message, or empty string if valid.
 
 
 Returns error message, or empty string if valid.
 
@@ -1842,7 +1880,7 @@ sub _rebless {
 
 =item calc_setup CUST_PKG START_DATE DETAILS_ARRAYREF OPTIONS_HASHREF
 
 
 =item calc_setup CUST_PKG START_DATE DETAILS_ARRAYREF OPTIONS_HASHREF
 
-=item calc_recur CUST_PKG START_DATE DETAILS_ARRAYREF OPTIONS_HASHREF
+=item calc_recur CUST_PKG START_DATE_SCALARREF DETAILS_ARRAYREF OPTIONS_HASHREF
 
 Calculates and returns the setup or recurring fees, respectively, for this
 package.  Implementation is in the FS::part_pkg:* module specific to this price
 
 Calculates and returns the setup or recurring fees, respectively, for this
 package.  Implementation is in the FS::part_pkg:* module specific to this price
@@ -1862,11 +1900,11 @@ Frequency override (for calc_recur)
 
 This option is filled in by the method rather than controlling its operation.
 It is an arrayref.  Applicable discounts will be added to the arrayref, as
 
 This option is filled in by the method rather than controlling its operation.
 It is an arrayref.  Applicable discounts will be added to the arrayref, as
-L<FS::cust_bill_pkg_discount|FS::cust_bill_pkg_discount records>.
+L<FS::cust_bill_pkg_discount> records.
 
 =item real_pkgpart
 
 
 =item real_pkgpart
 
-For package add-ons, is the base L<FS::part_pkg|package definition>, otherwise
+For package add-ons, is the base L<FS::part_pkg> package definition, otherwise
 no different than pkgpart.
 
 =item precommit_hooks
 no different than pkgpart.
 
 =item precommit_hooks
@@ -1890,7 +1928,7 @@ plan option prorate_defer_bill).
 =back
 
 Note: Don't calculate prices when not actually billing the package.  For that,
 =back
 
 Note: Don't calculate prices when not actually billing the package.  For that,
-see the L</base_setup|base_setup> and L</base_recur|base_recur> methods.
+see the L<FS::cust_pkg/base_setup> and L<FS::cust_pkg/base_recur> methods.
 
 =cut
 
 
 =cut
 
@@ -2597,4 +2635,3 @@ schema.html from the base documentation.
 =cut
 
 1;
 =cut
 
 1;
-