From: levinse <levinse>
Date: Tue, 21 Jun 2011 22:15:58 +0000 (+0000)
Subject: cust_bill.pm: if DID summary is turned on, don't try to get CDRs in the unlikely... 
X-Git-Tag: freeside_2_3_0~95
X-Git-Url: http://git.freeside.biz/gitweb/?a=commitdiff_plain;h=57adda68a7d445553c43eec5cdcb34490d68b522;p=freeside.git

cust_bill.pm: if DID summary is turned on, don't try to get CDRs in the unlikely case that the h_svc_phone record isn't found with the correct insert time, RT13361
---

diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index 9d250eba3..3a543de57 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -4100,7 +4100,7 @@ sub _did_summary {
 
 	    my $inserted = $h_cust_svc->date_inserted;
 	    my $deleted = $h_cust_svc->date_deleted;
-	    my $phone_inserted = $h_cust_svc->h_svc_x($inserted);
+	    my $phone_inserted = $h_cust_svc->h_svc_x($inserted+5);
 	    my $phone_deleted;
 	    $phone_deleted =  $h_cust_svc->h_svc_x($deleted) if $deleted;
 	    
@@ -4133,10 +4133,15 @@ sub _did_summary {
 	    }
 
 	    # increment usage minutes
-	    my @cdrs = $phone_inserted->get_cdrs('begin'=>$start,'end'=>$end);
-	    foreach my $cdr ( @cdrs ) {
-		$minutes += $cdr->billsec/60;
-	    }
+        if ( $phone_inserted ) {
+            my @cdrs = $phone_inserted->get_cdrs('begin'=>$start,'end'=>$end);
+            foreach my $cdr ( @cdrs ) {
+                $minutes += $cdr->billsec/60;
+            }
+        }
+        else {
+            warn "WARNING: no matching h_svc_phone insert record for insert time $inserted, svcnum " . $h_cust_svc->svcnum;
+        }
 
 	    # don't look at this service again
 	    push @seen, $h_cust_svc->svcnum;