add cdr-charged_party-truncate_{length,prefix} in order to trim charged_party to...
[freeside.git] / FS / FS / cdr.pm
index 0230adc..2a235cc 100644 (file)
@@ -295,9 +295,9 @@ or to the dst field if it is a toll free number.
 sub set_charged_party {
   my $self = shift;
 
-  unless ( $self->charged_party ) {
+  my $conf = new FS::Conf;
 
-    my $conf = new FS::Conf;
+  unless ( $self->charged_party ) {
 
     if ( $conf->exists('cdr-charged_party-accountcode') && $self->accountcode ){
 
@@ -315,6 +315,14 @@ sub set_charged_party {
 
   }
 
+  my $prefix = $conf->config('cdr-charged_party-truncate_prefix');
+  my $prefix_len = length($prefix);
+  my $trunc_len = $conf->config('cdr-charged_party-truncate_length');
+
+  $self->charged_party( substr($self->charged_party, 0, $trunc_len) )
+    if $prefix_len && $trunc_len
+    && substr($self->charged_party, 0, $prefix_len) eq $prefix;
+
 }
 
 =item set_status_and_rated_price STATUS [ RATED_PRICE ]
@@ -681,10 +689,11 @@ sub _cdr_min_parse {
 
 sub _cdr_date_parser_maker {
   my $field = shift;
+  my %options = @_;
   my @fields = ref($field) ? @$field : ($field);
   return sub {
     my( $cdr, $datestring ) = @_;
-    my $unixdate = eval { _cdr_date_parse($datestring) };
+    my $unixdate = eval { _cdr_date_parse($datestring, %options) };
     die "error parsing date for @fields from $datestring: $@\n" if $@;
     $cdr->$_($unixdate) foreach @fields;
   };
@@ -692,6 +701,7 @@ sub _cdr_date_parser_maker {
 
 sub _cdr_date_parse {
   my $date = shift;
+  my %options = @_;
 
   return '' unless length($date); #that's okay, it becomes NULL
 
@@ -711,7 +721,11 @@ sub _cdr_date_parse {
   return '' if $year == 1900 && $mon == 1 && $day == 1
             && $hour == 0    && $min == 0 && $sec == 0;
 
-  timelocal($sec, $min, $hour, $day, $mon-1, $year);
+  if ($options{gmt}) {
+    timegm($sec, $min, $hour, $day, $mon-1, $year);
+  } else {
+    timelocal($sec, $min, $hour, $day, $mon-1, $year);
+  }
 }
 
 =item batch_import HASHREF