"simple with accountcode" CDR format, #16348
authorMark Wells <mark@freeside.biz>
Fri, 9 Mar 2012 04:30:02 +0000 (20:30 -0800)
committerMark Wells <mark@freeside.biz>
Fri, 9 Mar 2012 04:30:02 +0000 (20:30 -0800)
FS/FS/cdr.pm
FS/FS/detail_format.pm
FS/FS/detail_format/accountcode_simple.pm [new file with mode: 0644]
FS/FS/part_pkg/voip_inbound.pm

index 9b70719..1769fe9 100644 (file)
@@ -1017,6 +1017,10 @@ my %export_names = (
     'invoice_header' => "Date,Time,Called From,Destination,Duration,Price",
                        #"Date,Time,Name,Called From,Destination,Duration,Price",
   },
+  'accountcode_simple' => {
+    'name'           => 'Simple with accountcode',
+    'invoice_header' => "Date,Time,Called From,Account,Duration,Price",
+  },
   'basic' => {
     'name'           => 'Basic',
     'invoice_header' => "Date/Time,Called Number,Min/Sec,Price",
@@ -1114,6 +1118,14 @@ sub export_formats {
       #sub { sprintf('%.3f', shift->upstream_price ) }, #PRICE
       $price_sub,
     ],
+    'accountcode_simple' => [
+      sub { time2str($date_format, shift->calldate_unix ) },   #DATE
+      sub { time2str('%r', shift->calldate_unix ) },   #TIME
+      'src',                                           #called from
+      'accountcode',                                   #NUMBER_DIALED
+      $duration_sub,                                   #DURATION
+      $price_sub,
+    ],
     'sum_duration' => [ 
       # for summary formats, the CDR is a fictitious object containing the 
       # total billsec and the phone number of the service
index af97f36..f70acc6 100644 (file)
@@ -171,11 +171,12 @@ sub single_detail {
   die "$me error combining ".$self->csv->error_input."\n"
     if !$status;
 
-  my $rated_price = $cdr->rated_price;
-  $rated_price = 0 if $cdr->freesidestatus eq 'no-charge';
+  my $object = $self->{inbound} ? $cdr->cdr_termination(1) : $cdr;
+  my $price = $object->rated_price if $object;
+  $price = 0 if $cdr->freesidestatus eq 'no-charge';
 
   FS::cust_bill_pkg_detail->new( {
-      'amount'      => $rated_price,
+      'amount'      => $price,
       'classnum'    => $cdr->rated_classnum,
       'duration'    => $cdr->rated_seconds,
       'regionname'  => $cdr->rated_regionname,
diff --git a/FS/FS/detail_format/accountcode_simple.pm b/FS/FS/detail_format/accountcode_simple.pm
new file mode 100644 (file)
index 0000000..10a28db
--- /dev/null
@@ -0,0 +1,24 @@
+package FS::detail_format::accountcode_simple;
+
+use strict;
+use base qw(FS::detail_format);
+use Date::Format qw(time2str);
+
+sub name { 'Simple with source' }
+
+sub header_detail { 'Date,Time,Called From,Account,Duration,Price' }
+
+sub columns {
+  my $self = shift;
+  my $cdr = shift;
+  (
+    time2str($self->date_format, $cdr->startdate),
+    time2str('%r', $cdr->startdate),
+    $cdr->src,
+    $cdr->accountcode,
+    $self->duration($cdr),
+    $self->price($cdr),
+  )
+}
+
+1;
index a16ef1f..f4e5183 100644 (file)
@@ -10,6 +10,7 @@ use FS::Conf;
 use FS::Record qw(qsearchs qsearch);
 use FS::cdr;
 use FS::rate_detail;
+use FS::detail_format;
 
 $DEBUG = 0;
 
@@ -208,6 +209,10 @@ sub calc_usage {
   my $included_min  = $self->option('min_included', 1) || 0;
   my $use_duration  = $self->option('use_duration');
   my $output_format = $self->option('output_format', 1) || 'default';
+
+  my $formatter = 
+    FS::detail_format->new($output_format, buffer => $details, inbound => 1);
+
   my $granularity   = length($self->option('sec_granularity'))
                         ? $self->option('sec_granularity')
                         : 60;
@@ -279,31 +284,41 @@ sub calc_usage {
                                 'granularity' => $granularity,
                               )
         );
-        push @$details,
-          { format      => 'C',
-            detail      => $call_details[0],
-            amount      => $charge,
-            classnum    => $cdr->calltypenum, #classnum
-            #phonenum    => $self->phonenum,
-            accountcode => $cdr->accountcode,
-            startdate   => $cdr->startdate,
-            duration    => $seconds,
-            # regionname?? => '', #regionname, not set for inbound calls
-          };
-     }
-
-     my $error = $cdr->set_status_and_rated_price( 'done',
-                                                  $charge,
-                                                  $cust_svc->svcnum,
-                                                  'inbound' => 1 );
-     die $error if $error;
+#        push @$details,
+#          { format      => 'C',
+#            detail      => $call_details[0],
+#            amount      => $charge,
+#            classnum    => $cdr->calltypenum, #classnum
+#            #phonenum    => $self->phonenum,
+#            accountcode => $cdr->accountcode,
+#            startdate   => $cdr->startdate,
+#            duration    => $seconds,
+#            # regionname?? => '', #regionname, not set for inbound calls
+#          };
+      }
+
+      # eventually use FS::cdr::rate for this
+      my $error = $cdr->set_status_and_rated_price(
+        'done',
+        $charge,
+        $cust_svc->svcnum,
+        'rated_seconds'     => $use_duration ? $cdr->duration : $cdr->billsec,
+        'rated_granularity' => $granularity, 
+        'rated_classnum'    => $cdr->calltypenum,
+        'inbound'        => 1,
+      );
+      die $error if $error;
+      $formatter->append($cdr);
 
     } #$cdr
   } # $cust_svc
-  unshift @$details, { format => 'C',
-                       detail => FS::cdr::invoice_header($output_format),
-                     }
-    if @$details;
+#  unshift @$details, { format => 'C',
+#                       detail => FS::cdr::invoice_header($output_format),
+#                     }
+#    if @$details;
+  
+  $formatter->finish;
+  unshift @$details, $formatter->header if @$details;
 
   $charges;
 }