fix 'Can't call method "setup" on an undefined value' error when using into rates...
[freeside.git] / FS / FS / cust_bill_ApplicationCommon.pm
index 322728f..cadb8a7 100644 (file)
@@ -418,10 +418,10 @@ sub apply_to_lineitems {
 
         foreach my $cust_svc ( $cust_pkg->cust_svc ) {
           my $svc_x = $cust_svc->svc_x;
-          my @part_export = grep { $_->can('export_insert_on_payment') }
+          my @part_export = grep { $_->can('_export_insert_on_payment') }
                                  $cust_svc->part_svc->part_export;
       
-          foreach my $part_export ( $cust_svc->part_svc->part_export ) {
+          foreach my $part_export ( @part_export ) {
             $error = $part_export->_export_insert_on_payment($svc_x);
             if ( $error ) {
               $dbh->rollback if $oldAutoCommit;
@@ -435,6 +435,17 @@ sub apply_to_lineitems {
 
   }
 
+  # unset promised payment date if there is one
+  my $cust_bill = $self->cust_bill;
+  if ( $cust_bill->promised_date and $cust_bill->owed <= 0 ) {
+    $cust_bill->set('promised_date', '');
+    my $error = $cust_bill->replace;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+  
   #everything should always be applied to line items in full now... sanity check
   $applied = sprintf('%.2f', $applied);
   unless ( $applied == $self->amount ) {