38973: Bill for time worked on ticket resolution [v3 bug fix]
[freeside.git] / FS / FS / cust_pkg.pm
index b577702..548d000 100644 (file)
@@ -815,9 +815,13 @@ the date.  You are PROBABLY looking to expire the account instead of using
 this.
 
 =item reason - can be set to a cancellation reason (see L<FS:reason>), 
-either a reasonnum of an existing reason, or passing a hashref will create 
-a new reason.  The hashref should have the following keys: typenum - Reason 
-type (see L<FS::reason_type>, reason - Text of the new reason.
+either a reasonnum of an existing reason, or a hashref to create 
+a new reason.  The hashref should have the following keys:
+typenum - Reason type (see L<FS::reason_type>
+reason - Text of the new reason.
+
+If this argument isn't given or is a false value, then the package will be
+canceled with no reason.
 
 =item date - can be set to a unix style timestamp to specify when to 
 cancel (expire)
@@ -1078,6 +1082,10 @@ Cancels this package if its expire date has been reached.
 
 =cut
 
+# XXX should look for an expire reason
+# but seems to be unused; this is now handled more holistically in
+# cust_main::Billing
+
 sub cancel_if_expired {
   my $self = shift;
   my $time = shift || time;
@@ -2585,6 +2593,19 @@ sub change {
     return "canceling old package: $error";
   }
 
+  # transfer rt_field_charge, if we're not changing pkgpart
+  # after billing of old package, before billing of new package
+  if ( $same_pkgpart ) {
+    foreach my $rt_field_charge ($self->rt_field_charge) {
+      $rt_field_charge->set('pkgnum', $cust_pkg->pkgnum);
+      $error = $rt_field_charge->replace;
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return "transferring rt_field_charge: $error";
+      }
+    }
+  }
+
   if ( $conf->exists('cust_pkg-change_pkgpart-bill_now') ) {
     #$self->cust_main
     my $error = $cust_pkg->cust_main->bill( 
@@ -6087,6 +6108,12 @@ sub _upgrade_data {  # class method
   }
 }
 
+# will autoload in v4+
+sub rt_field_charge {
+  my $self = shift;
+  qsearch('rt_field_charge',{ 'pkgnum' => $self->pkgnum });
+}
+
 =back
 
 =head1 BUGS