connection fee for initial N seconds support, RT#7018
[freeside.git] / FS / FS / part_pkg / voip_cdr.pm
index 47102c1..38e5941 100644 (file)
@@ -15,7 +15,7 @@ use FS::part_pkg::recur_Common;
 
 @ISA = qw(FS::part_pkg::recur_Common);
 
-$DEBUG = 1;
+$DEBUG = 0;
 
 tie my %rating_method, 'Tie::IxHash',
   'prefix' => 'Rate calls by using destination prefix to look up a region and rate according to the internal prefix and rate tables',
@@ -535,6 +535,9 @@ sub calc_usage {
                       # length($cdr->billsec) ? $cdr->billsec : $cdr->duration;
           $seconds = $use_duration ? $cdr->duration : $cdr->billsec;
 
+          $seconds -= $rate_detail->conn_sec;
+          $seconds = 0 if $seconds < 0;
+
           $seconds += $granularity - ( $seconds % $granularity )
             if $seconds      # don't granular-ize 0 billsec calls (bills them)
             && $granularity; # 0 is per call
@@ -546,12 +549,15 @@ sub calc_usage {
 
           $included_min{$regionnum} -= $minutes;
 
+          $charge = sprintf('%.2f', $rate_detail->conn_charge);
+
           if ( $included_min{$regionnum} < 0 ) {
             my $charge_min = 0 - $included_min{$regionnum}; #XXX should preserve
                                                             #(display?) this
             $included_min{$regionnum} = 0;
-            $charge = sprintf('%.2f', ( $rate_detail->min_charge * $charge_min )
-                                      + 0.00000001 ); #so 1.005 rounds to 1.01
+            $charge += sprintf('%.2f', ($rate_detail->min_charge * $charge_min)
+                                       + 0.00000001 ); #so 1.005 rounds to 1.01
+            $charge = sprintf('%.2f', $charge);
             $charges += $charge;
           }
 
@@ -624,7 +630,14 @@ sub calc_usage {
 
   } # $cust_svc
 
-  unshift @$details, [ 'C', FS::cdr::invoice_header($output_format) ]
+  unshift @$details, [ 'C',
+                       FS::cdr::invoice_header($output_format),
+                       '',
+                       '',
+                       '',
+                       '',
+                       '',
+                     ]
     if @$details && $rating_method ne 'upstream';
 
 #  if ( $spool_cdr && length($downstream_cdr) ) {