accountcode billing, RT12181
authorlevinse <levinse>
Tue, 26 Jul 2011 23:48:01 +0000 (23:48 +0000)
committerlevinse <levinse>
Tue, 26 Jul 2011 23:48:01 +0000 (23:48 +0000)
FS/FS/Schema.pm
FS/FS/cust_bill.pm
FS/FS/cust_bill_pkg.pm
FS/FS/cust_bill_pkg_detail.pm
FS/FS/part_pkg/voip_cdr.pm
FS/FS/part_pkg/voip_inbound.pm

index 6fde8b1..49eddf6 100644 (file)
@@ -701,6 +701,7 @@ sub tables_hashref {
         'duration', 'int', 'NULL', '',  0, '',
         'phonenum', 'varchar', 'NULL', 15, '', '',
         'accountcode', 'varchar',  'NULL',      20, '', '',
+        'startdate',  @date_type, '', '', 
         'regionname', 'varchar', 'NULL', $char_d, '', '',
         'detail',  'varchar', '', 255, '', '', 
       ],
index 7669479..4ea67b6 100644 (file)
@@ -2351,7 +2351,6 @@ notice_name - overrides "Invoice" as the name of the sent document (templates fr
 # (alignment in text invoice?) problems to change them all to '%.2f' ?
 # yes: fixed width (dot matrix) text printing will be borked
 sub print_generic {
-
   my( $self, %params ) = @_;
   my $today = $params{today} ? $params{today} : time;
   warn "$me print_generic called on $self with suffix $params{template}\n"
@@ -4222,21 +4221,25 @@ sub _items_accountcode_cdr {
                     quantity    => '',
                     product_code => 'N/A',
                     section     => $section,
-                    ext_description => [],
+                    ext_description => [ $section->{'header'} ],
+                    detail_temp => [],
             };
 
             $section->{'amount'} += $amount;
             $accountcodes{$accountcode}{'amount'} += $amount;
             $accountcodes{$accountcode}{calls}++;
             $accountcodes{$accountcode}{duration} += $detail->duration;
-            push @{$accountcodes{$accountcode}{ext_description}},
-                $detail->formatted('format' => $format);
+            push @{$accountcodes{$accountcode}{detail_temp}}, $detail;
         }
     }
 
     foreach my $l ( values %accountcodes ) {
         $l->{amount} = sprintf( "%.2f", $l->{amount} );
-        unshift @{$l->{ext_description}}, $section->{'header'};
+        my @sorted_detail = sort { $a->startdate <=> $b->startdate } @{$l->{detail_temp}};
+        foreach my $sorted_detail ( @sorted_detail ) {
+            push @{$l->{ext_description}}, $sorted_detail->formatted('format'=>$format);
+        }
+        delete $l->{detail_temp};
         push @lines, $l;
     }
 
index d332e36..29663c5 100644 (file)
@@ -154,8 +154,9 @@ sub insert {
         'classnum'   => (ref($detail) ? $detail->[3] : '' ),
         'phonenum'   => (ref($detail) ? $detail->[4] : '' ),
         'accountcode' => (ref($detail) ? $detail->[5] : '' ),
-        'duration'   => (ref($detail) ? $detail->[6] : '' ),
-        'regionname' => (ref($detail) ? $detail->[7] : '' ),
+        'startdate'  => (ref($detail) ? $detail->[6] : '' ),
+        'duration'   => (ref($detail) ? $detail->[7] : '' ),
+        'regionname' => (ref($detail) ? $detail->[8] : '' ),
       };
       $error = $cust_bill_pkg_detail->insert;
       if ( $error ) {
index 9ac164c..eb0ae96 100644 (file)
@@ -57,6 +57,8 @@ inherits from FS::Record.  The following fields are currently supported:
 
 =item accountcode - accountcode
 
+=item startdate - CDR startdate, if any
+
 =item detail - detail description
 
 =back
index 8363873..5f191f2 100644 (file)
@@ -774,6 +774,7 @@ sub calc_usage {
                 $classnum,
                 $phonenum,
                 $cdr->accountcode,
+                $cdr->startdate,
                 $seconds,
                 $regionname,
               ];
@@ -786,6 +787,7 @@ sub calc_usage {
                 $classnum,
                 $phonenum,
                 $cdr->accountcode,
+                $cdr->startdate,
                 $seconds,
                 $regionname,
               ];
index a96e978..15faf5b 100644 (file)
@@ -285,6 +285,7 @@ sub calc_usage {
               $cdr->calltypenum, #classnum
               $self->phonenum,
               $cdr->accountcode,
+              $cdr->startdate,
               $seconds,
               '', #regionname, not set for inbound calls
             ];