RT#8026: WIP CDR format
authormark <mark>
Tue, 4 May 2010 22:26:06 +0000 (22:26 +0000)
committermark <mark>
Tue, 4 May 2010 22:26:06 +0000 (22:26 +0000)
FS/FS/cdr.pm
FS/FS/cdr/wip.pm [new file with mode: 0644]

index b9a4e41..2426f41 100644 (file)
@@ -14,6 +14,7 @@ use FS::cdr_type;
 use FS::cdr_calltype;
 use FS::cdr_carrier;
 use FS::cdr_batch;
+use FS::cdr_termination;
 
 @ISA = qw(FS::Record);
 @EXPORT_OK = qw( _cdr_date_parser_maker _cdr_min_parser_maker );
@@ -386,11 +387,33 @@ error, otherwise returns false.
 =cut
 
 sub set_status_and_rated_price {
-  my($self, $status, $rated_price, $svcnum) = @_;
-  $self->freesidestatus($status);
-  $self->rated_price($rated_price);
-  $self->svcnum($svcnum) if $svcnum;
-  $self->replace();
+  my($self, $status, $rated_price, $svcnum, %opt) = @_;
+  if($opt{'inbound'}) {
+    my $term = qsearchs('cdr_termination', {
+        acctid   => $self->acctid, 
+        termpart => 1 # inbound
+    });
+    my $error;
+    if($term) {
+      warn "replacing existing cdr status (".$self->acctid.")\n" if $term;
+      $error = $term->delete;
+      return $error if $error;
+    }
+    $term = FS::cdr_termination->new({
+        acctid      => $self->acctid,
+        termpart    => 1,
+        rated_price => $rated_price,
+        status      => $status,
+        svcnum      => $svcnum,
+    });
+    return $term->insert;
+  }
+  else {
+    $self->freesidestatus($status);
+    $self->rated_price($rated_price);
+    $self->svcnum($svcnum) if $svcnum;
+    return $self->replace();
+  }
 }
 
 =item calldate_unix 
@@ -723,7 +746,10 @@ sub _cdr_date_parse {
     ($mon, $day, $year, $hour, $min, $sec) = ( $1, $2, $3, $4, $5, $6 );
   } elsif ( $date  =~ /^\s*(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d+\.\d+)(\D|$)/ ) {
     # broadsoft: 20081223201938.314
-    ($year, $mon, $day, $hour, $min, $sec) = ( $1, $2, $3, $4, $5, $6);
+    ($year, $mon, $day, $hour, $min, $sec) = ( $1, $2, $3, $4, $5, $6 );
+  } elsif ( $date  =~ /^\s*(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/ ) {
+    # WIP: 20100329121420
+    ($year, $mon, $day, $hour, $min, $sec) = ( $1, $2, $3, $4, $5, $6 );
   } else {
      die "unparsable date: $date"; #maybe we shouldn't die...
   }
diff --git a/FS/FS/cdr/wip.pm b/FS/FS/cdr/wip.pm
new file mode 100644 (file)
index 0000000..070e253
--- /dev/null
@@ -0,0 +1,49 @@
+package FS::cdr::wip;
+
+use strict;
+use vars qw( @ISA %info );
+use FS::cdr qw(_cdr_date_parser_maker);
+
+@ISA = qw(FS::cdr);
+
+%info = (
+  'name'          => 'WIP',
+  'weight'        => 100,
+  'header'        => 1,
+  'type'          => 'csv',
+  'sep_char'      => ':',
+  'import_fields' => [
+# All of these are based on the January 2010 version of the spec,
+# except that we assume that before all the fields mentioned in the
+# spec, there's a counter field.
+    skip(4),          # counter, id, APCSJursID, RecordType
+    'unique_id',      # CDRID
+    skip(1),          # AccountNumber; empty
+    'charged_party',  # ServiceNumber
+    skip(1),          # ServiceNumberType
+    'src',            # PointOrigin
+    'dst',            # PointTarget
+    'calltypenum',    # Jurisdiction: need to remap
+    _cdr_date_parser_maker('startdate'), #TransactionDate
+    skip(3),          # BillClass, TypeIDUsage, ElementID
+    'duration',       # PrimaryUnits
+    skip(6),          # CompletionStatus, Latitude, Longitude, 
+                      # OriginDescription, TargetDescription, RatePeriod
+    'billsec',        # RatedUnits; seems to always be equal to PrimaryUnits
+    skip(6),  #SecondsUnits, ThirdUnits, FileID, OriginalExtractSequenceNumber,
+              #RateClass, #ProviderClass
+    skip(8),  #ProviderID, CurrencyCode, EquipmentTypeCode, ClassOfServiceCode,
+              #RateUnitsType, DistanceBandID, ZoneClass, CDRStatus
+    'upstream_price', # ISPBuy
+    skip(2),          # EUBuy, CDRFromCarrier
+    ],
+# Need clarification on:
+# Values for RecordType, Jurisdiction, CompletionStatus, and ProviderClass
+# Do we care about the following:
+# AccountNumber, ServiceNumberType, CDRStatus
+
+);
+
+sub skip { map {''} (1..$_[0]) }
+
+1;