add "Edit package definition costs" ACL, RT#27140
[freeside.git] / FS / FS / cust_pkg.pm
index 088eee9..392bab3 100644 (file)
@@ -268,7 +268,8 @@ The following options are available:
 =item change
 
 If set true, supresses actions that should only be taken for new package
-orders.  (Currently this includes: intro periods when delay_setup is on.)
+orders.  (Currently this includes: intro periods when delay_setup is on,
+auto-adding a 1st start date, auto-adding expiration/adjourn/contract_end dates)
 
 =item options
 
@@ -301,7 +302,8 @@ sub insert {
 
   my $part_pkg = $self->part_pkg;
 
-  if (! $import) {
+  if ( ! $import && ! $options{'change'} ) {
+
     # if the package def says to start only on the first of the month:
     if ( $part_pkg->option('start_1st', 1) && !$self->start_date ) {
       my ($sec,$min,$hour,$mday,$mon,$year) = (localtime(time) )[0,1,2,3,4,5];
@@ -320,11 +322,11 @@ sub insert {
       }
     }
 
-    # if this package has "free days" and delayed setup fee, teh
+    # if this package has "free days" and delayed setup fee, the
     # set start date that many days in the future.
     # (this should have been set in the UI, but enforce it here)
     if (    ! $options{'change'}
-         && ( my $free_days = $part_pkg->option('free_days',1) )
+         && $part_pkg->option('free_days', 1)
          && $part_pkg->option('delay_setup',1)
          #&& ! $self->start_date
        )
@@ -334,7 +336,9 @@ sub insert {
   }
 
   # set order date unless it was specified as part of an import
-  $self->order_date(time) unless $import && $self->order_date;
+  # or this was previously a different package
+  $self->order_date(time) unless ($import && $self->order_date)
+                              or $self->change_pkgnum;
 
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
@@ -1792,6 +1796,9 @@ sub change {
       $hash{$date} = $self->getfield($date);
     }
   }
+  # always keep this date, regardless of anything
+  # (the date of the package change is in a different field)
+  $hash{'order_date'} = $self->getfield('order_date');
 
   # allow $opt->{'locationnum'} = '' to specifically set it to null
   # (i.e. customer default location)
@@ -3541,6 +3548,7 @@ sub transfer {
     }
   }
 
+  my $error;
   foreach my $cust_svc ($self->cust_svc) {
     my $svcnum = $cust_svc->svcnum;
     if($target{$cust_svc->svcpart} > 0
@@ -3548,8 +3556,7 @@ sub transfer {
       $target{$cust_svc->svcpart}--;
       my $new = new FS::cust_svc { $cust_svc->hash };
       $new->pkgnum($dest_pkgnum);
-      my $error = $new->replace($cust_svc);
-      return "svcnum $svcnum: $error" if $error;
+      $error = $new->replace($cust_svc);
     } elsif ( exists $opt{'change_svcpart'} && $opt{'change_svcpart'} ) {
       if ( $DEBUG ) {
         warn "looking for alternates for svcpart ". $cust_svc->svcpart. "\n";
@@ -3569,14 +3576,17 @@ sub transfer {
         my $new = new FS::cust_svc { $cust_svc->hash };
         $new->svcpart($change_svcpart);
         $new->pkgnum($dest_pkgnum);
-        my $error = $new->replace($cust_svc);
-        return "svcnum $svcnum: $error" if $error;
+        $error = $new->replace($cust_svc);
       } else {
         $remaining++;
       }
     } else {
       $remaining++
     }
+    if ( $error ) {
+      my @label = $cust_svc->label;
+      return "$label[0] $label[1]: $error";
+    }
   }
   return $remaining;
 }