should hopefully fix old services showing up on invoices, RT#5451/RT#5514/RT#5564...
[freeside.git] / FS / FS / cust_bill_pkg.pm
index 6bd39d4..bb07173 100644 (file)
@@ -276,6 +276,23 @@ sub cust_bill {
   qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
 }
 
+=item previous_cust_bill_pkg
+
+Returns the previous cust_bill_pkg for this package, if any.
+
+=cut
+
+sub previous_cust_bill_pkg {
+  my $self = shift;
+  qsearchs({
+    'table'    => 'cust_bill_pkg',
+    'hashref'  => { 'pkgnum' => $self->pkgnum,
+                    'sdate'  => { op=>'<', value=>$self->sdate },
+                  },
+    'order_by' => 'ORDER BY sdate DESC LIMIT 1',
+  });
+}
+
 =item details [ OPTION => VALUE ... ]
 
 Returns an array of detail information for the invoice line item.