taqua accountcode billing, part 1 of 2, RT12181
[freeside.git] / FS / FS / cust_bill.pm
index 5d38512..ba5ca24 100644 (file)
@@ -2829,6 +2829,9 @@ sub print_generic {
       push @{$late_sections}, @$phone_sections;
       push @detail_items, @$phone_lines;
     }
+    if ($conf->exists('voip-cust_accountcode_cdr') && $cust_main->accountcode_cdr) {
+        # XXX: do something not unlike _items_svc_phone_sections, except generate only one section
+    }
   }else{
     push @sections, { 'description' => '', 'subtotal' => '' };
   }
@@ -4062,10 +4065,12 @@ sub _items_extra_usage_sections {
 sub _did_summary {
     my $self = shift;
     my $end = $self->_date;
-    my @cust_bill = sort { $a->_date <=> $b->_date }
-        grep { $_->_date < $self->_date }
-          qsearch( 'cust_bill', { 'custnum' => $self->custnum } );
-    my $start = $cust_bill[-1]->_date+1; # since last invoice
+
+    # start at date of previous invoice + 1 second or 0 if no previous invoice
+    my $start = $self->scalar_sql("SELECT max(_date) FROM cust_bill WHERE custnum = ? and invnum != ?",$self->custnum,$self->invnum);
+    $start = 0 if !$start;
+    $start++;
+
     my $cust_main = $self->cust_main;
     my @pkgs = $cust_main->all_pkgs;
     my($num_activated,$num_deactivated,$num_portedin,$num_portedout,$minutes)
@@ -4698,7 +4703,6 @@ sub _items_cust_bill_pkg {
                 ext_description => \@d,
               };
             }
-
           }
 
         } # recurring or usage with recurring charge