add cust_pkg.order_date, RT6628
[freeside.git] / FS / FS / cust_pkg.pm
index 2ed25a0..324dbba 100644 (file)
@@ -125,6 +125,10 @@ Billing item definition (see L<FS::part_pkg>)
 
 Optional link to package location (see L<FS::location>)
 
+=item order_date
+
+date package was ordered (also remains same on changes)
+
 =item start_date
 
 date
@@ -271,6 +275,8 @@ sub insert {
     }
   }
 
+  $self->order_date(time);
+
   local $SIG{HUP} = 'IGNORE';
   local $SIG{INT} = 'IGNORE';
   local $SIG{QUIT} = 'IGNORE';
@@ -3396,6 +3402,10 @@ sub _upgrade_data {  # class method
   'UPDATE cust_pkg SET bill = bill + (365*24*60*60) WHERE bill < last_bill
   AND bill > 1259654400 AND bill < 1262332800 AND (SELECT plan FROM part_pkg 
   WHERE part_pkg.pkgpart = cust_pkg.pkgpart) = \'prorate\'',
+    # RT6628, add order_date to cust_pkg
+    'update cust_pkg set order_date = (select history_date from h_cust_pkg 
+       where h_cust_pkg.pkgnum = cust_pkg.pkgnum and 
+       history_action = \'insert\') where order_date is null',
   );
   foreach my $sql (@statements) {
     my $sth = dbh->prepare($sql);