voxlinesystems CDRs and quantity bs
[freeside.git] / FS / FS / cdr.pm
index 495f5d1..5b1a4b4 100644 (file)
@@ -392,6 +392,18 @@ sub _convergent_format {
 
 =cut
 
+my %export_names = (
+  'convergent'      => {},
+  'voxlinesystems'  => { 'name'           => 'VoxLineSystems',
+                         'invoice_header' =>
+                           "Date,Time,Name,Destination,Duration,Price",
+                       },
+  'voxlinesystems2' => { 'name'           => 'VoxLineSystems with source',
+                         'invoice_header' =>
+                           "Date,Time,Name,Destination,Called From,Duration,Price",
+                       },
+);
+
 my %export_formats = (
   'convergent' => [
     'carriername', #CARRIER
@@ -408,6 +420,23 @@ my %export_formats = (
     sub { shift->rated_price ? 'Y' : 'N' }, #RATED
     '', #OTHER_INFO
   ],
+  'voxlinesystems' => [
+    sub { time2str('%D', shift->calldate_unix ) },   #DATE
+    sub { time2str('%r', shift->calldate_unix ) },   #TIME
+    'userfield',                                     #USER
+    'dst',                                           #NUMBER_DIALED
+    sub { sprintf('%.2fm', shift->billsec / 60 ) },  #DURATION
+    sub { sprintf('%.3f', shift->upstream_price ) }, #PRICE
+  ],
+  'voxlinesystems2' => [
+    sub { time2str('%D', shift->calldate_unix ) },   #DATE
+    sub { time2str('%T', shift->calldate_unix ) },   #TIME
+    'userfield',                                     #USER
+    'dst',                                           #NUMBER_DIALED
+    'src',                                           #called from
+    sub { sprintf('%.2fm', shift->billsec / 60 ) },  #DURATION
+    sub { sprintf('%.3f', shift->upstream_price ) }, #PRICE
+  ],
 );
 
 sub downstream_csv {
@@ -440,6 +469,30 @@ sub downstream_csv {
 
 =over 4
 
+=item invoice_formats
+
+Returns an ordered list of key value pairs containing invoice format names
+as keys (for use with part_pkg::voip_cdr) and "pretty" format names as values.
+
+=cut
+
+sub invoice_formats {
+  map { ($_ => $export_names{$_}->{'name'}) }
+    grep { $export_names{$_}->{'invoice_header'} }
+    keys %export_names;
+}
+
+=item invoice_header FORMAT
+
+Returns a scalar containing the CSV column header for invoice format FORMAT.
+
+=cut
+
+sub invoice_header {
+  my $format = shift;
+  $export_names{$format}->{'invoice_header'};
+}
+
 =item import_formats
 
 Returns an ordered list of key value pairs containing import format names
@@ -449,10 +502,11 @@ as keys (for use with batch_import) and "pretty" format names as values.
 
 sub import_formats {
   (
-    'asterisk' => 'Asterisk',
-    'taqua'    => 'Taqua',
-    'unitel'   => 'Unitel/RSLCOM',
-    'simple'   => 'Simple',
+    'asterisk'       => 'Asterisk',
+    'taqua'          => 'Taqua',
+    'unitel'         => 'Unitel/RSLCOM',
+    'voxlinesystems' => 'VoxLineSystems',  #XXX? get the actual vendor name
+    'simple'         => 'Simple',
   );
 }
 
@@ -667,6 +721,50 @@ my %import_formats = (
     'carrierid',
     'upstream_rateid',
   ],
+  'voxlinesystems' => [ #XXX get the actual vendor name
+    'disposition',                        #Status
+    'startdate',                          #Start (what do you know, a timestamp!
+    sub { my($cdr, $field) = @_; },       #Start date
+    sub { my($cdr, $field) = @_; },       #Start time
+    'enddate',                            #End (also a timestamp!)
+    sub { my($cdr, $field) = @_; },       #End date
+    sub { my($cdr, $field) = @_; },       #End time
+    'accountcode',                        #Calling customer... map to agent_custid??
+    sub { my($cdr, $field) = @_; },       #Calling type
+    'src',
+    'userfield',                          #Calling name #?
+    sub { my($cdr, $field) = @_; },       #Called type
+    'dst',                                #Called number
+    sub { my($cdr, $field) = @_; },       #Destination customer
+    sub { my($cdr, $field) = @_; },       #Destination type
+    sub { my($cdr, $field) = @_; },       #Destination Number
+    sub { my($cdr, $field) = @_; },       #Inbound calling type
+    sub { my($cdr, $field) = @_; },       #Inbound calling number
+    sub { my($cdr, $field) = @_; },       #Inbound called type
+    sub { my($cdr, $field) = @_; },       #Inbound called number
+    sub { my($cdr, $field) = @_; },       #Inbound destination type
+    sub { my($cdr, $field) = @_; },       #Inbound destination number
+    sub { my($cdr, $field) = @_; },       #Outbound calling type
+    sub { my($cdr, $field) = @_; },       #Outbound calling number
+    sub { my($cdr, $field) = @_; },       #Outbound called type
+    sub { my($cdr, $field) = @_; },       #Outbound called number
+    sub { my($cdr, $field) = @_; },       #Outbound destination type
+    sub { my($cdr, $field) = @_; },       #Outbound destination number
+    sub { my($cdr, $field) = @_; },       #Internal calling type
+    sub { my($cdr, $field) = @_; },       #Internal calling number
+    sub { my($cdr, $field) = @_; },       #Internal called type
+    sub { my($cdr, $field) = @_; },       #Internal called number
+    sub { my($cdr, $field) = @_; },       #Internal destination type
+    sub { my($cdr, $field) = @_; },       #Internal destination number
+    'duration',                           #Total seconds
+    sub { my($cdr, $field) = @_; },       #Ring seconds
+    'billsec',                            #Billable seconds
+    'upstream_price',                     #Cost
+    sub { my($cdr, $field) = @_; },       #Billing customer
+    sub { my($cdr, $field) = @_; },       #Billing customer name
+    sub { my($cdr, $field) = @_; },       #Billing type
+    sub { my($cdr, $field) = @_; },       #Billing reference
+  ],
   'simple' => [
 
     # Date
@@ -705,8 +803,9 @@ my %import_formats = (
 );
 
 my %import_header = (
-  'simple' => 1,
-  'taqua'  => 1,
+  'simple'         => 1,
+  'taqua'          => 1,
+  'voxlinesystems' => 2, #XXX vendor name
 );
 
 =item batch_import HASHREF
@@ -750,14 +849,13 @@ sub batch_import {
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
-  my $body = 0;
+  my $header_lines =
+    exists($import_header{$format}) ? $import_header{$format} : 0;
+
   my $line;
   while ( defined($line=<$fh>) ) {
 
-    #skip header...
-    if ( ! $body++ && $import_header{$format} ) { #&& $line =~ /^[\w, "]+$/ ) {
-      next;
-    }
+    next if $header_lines-- > 0; #&& $line =~ /^[\w, "]+$/ 
 
     $csv->parse($line) or do {
       $dbh->rollback if $oldAutoCommit;