fix missing invoice details (RT#11561), but will this cause them to show up when...
[freeside.git] / FS / FS / cust_bill.pm
index 2da7ee3..2c58a98 100644 (file)
@@ -2551,8 +2551,10 @@ sub print_generic {
   my $max_edate = 0;
   foreach my $cust_bill_pkg ( $self->cust_bill_pkg ) {
     next unless $cust_bill_pkg->pkgnum > 0;
-    $min_sdate = $cust_bill_pkg->sdate if $cust_bill_pkg->sdate < $min_sdate;
-    $max_edate = $cust_bill_pkg->edate if $cust_bill_pkg->edate > $max_edate;
+    $min_sdate = $cust_bill_pkg->sdate
+      if length($cust_bill_pkg->sdate) && $cust_bill_pkg->sdate < $min_sdate;
+    $max_edate = $cust_bill_pkg->edate
+      if length($cust_bill_pkg->edate) && $cust_bill_pkg->edate > $max_edate;
   }
 
   $invoice_data{'bill_period'} = '';
@@ -4192,6 +4194,9 @@ sub _items_svc_phone_sections {
       # this only works with Latex
       my @newlines;
       my @newsections;
+
+      # after this, we'll have only two sections per DID:
+      # Calls Summary and Calls Detail
       foreach my $section ( @sections ) {
        if($section->{'post_total'}) {
            $section->{'description'} = 'Calls Summary: '.$section->{'phonenum'};
@@ -4214,8 +4219,11 @@ sub _items_svc_phone_sections {
            push @newsections, \%calls_detail;  
        }
       }
+
+      # after this, each usage class is collapsed/summarized into a single
+      # line under the Calls Summary section
       foreach my $newsection ( @newsections ) {
-       if($newsection->{'post_total'}) {
+       if($newsection->{'post_total'}) { # this means Calls Summary
            foreach my $section ( @sections ) {
                next unless ($section->{'phonenum'} eq $newsection->{'phonenum'} 
                                && !$section->{'post_total'});
@@ -4237,21 +4245,27 @@ sub _items_svc_phone_sections {
            }
        }
       }
+
+      # after this, Calls Details is populated with all CDRs
       foreach my $newsection ( @newsections ) {
-       if(!$newsection->{'post_total'}) {
+       if(!$newsection->{'post_total'}) { # this means Calls Details
            foreach my $line ( @lines ) {
                next unless (scalar(@{$line->{'ext_description'}}) &&
                        $line->{'section'}->{'phonenum'} eq $newsection->{'phonenum'}
                            );
                my @extdesc = @{$line->{'ext_description'}};
-               my $extdesc = $extdesc[0];
-               $extdesc =~ s/scriptsize/normalsize/g if $format eq 'latex';
-               $line->{'ext_description'} = [ $extdesc ];
+               my @newextdesc;
+               foreach my $extdesc ( @extdesc ) {
+                   $extdesc =~ s/scriptsize/normalsize/g if $format eq 'latex';
+                   push @newextdesc, $extdesc;
+               }
+               $line->{'ext_description'} = \@newextdesc;
                $line->{'section'} = $newsection;
                push @newlines, $line;
            }
        }
       }
+
       return(\@newsections, \@newlines);
   }
 
@@ -4540,7 +4554,7 @@ sub _items_cust_bill_pkg {
             if $DEBUG > 1;
 
           push @d, $cust_bill_pkg->details(%details_opt)
-            unless ($is_summary || $type && $type eq 'R');
+            unless $is_summary; # || ($type && $type eq 'R');
 
           warn "$me _items_cust_bill_pkg calculating amount\n"
             if $DEBUG > 1;