summaryrefslogtreecommitdiff
path: root/FS/FS/cdr/callplus.pm
blob: fa6c799ad5e433a2a54d467818a014e89f7ce7d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package FS::cdr::callplus;
use base qw( FS::cdr );

use strict;
use vars qw( %info );
use FS::Record qw( qsearchs );
use Time::Local 'timelocal';

# Date format in the Date/Time col: "13/07/2016 2:40:32 p.m."
# d/m/y H:M:S, leading zeroes stripped, 12-hour with "a.m." or "p.m.".
# There are also separate d/m/y and 24-hour time columns, but parsing
# those separately is hard (DST issues).

%info = (
  'name'          => 'CallPlus',
  'weight'        => 610,
  'header'        => 1,
  'type'          => 'csv',
  'import_fields' => [
    'uniqueid',           # ID
    '',                   # Billing Group (charged_party?)
    'src',                # Origin Number
    'dst',                # Destination Number
    '',                   # Description (seems to be dest caller id?)
    '',                   # Status
    '',                   # Terminated
    '',                   # Date
    '',                   # Time
    sub {                 # Date/Time
      # this format overlaps one of the existing parser cases, so give it
      # its own special parser
      my ($cdr, $value) = @_;
      $value =~ m[^(\d{1,2})/(\d{1,2})/(\d{4}) (\d{1,2}):(\d{2}):(\d{2}) (a\.m\.|p\.m\.)$]
        or die "unparseable date: $value";
      my ($day, $mon, $year, $hour, $min, $sec) = ( $1, $2, $3, $4, $5, $6 );
      $hour = $hour % 12;
      if ($7 eq 'p.m.') {
        $hour = 12;
      }
      $cdr->set('startdate',
                timelocal($sec, $min, $hour, $day, $mon-1, $year)
               );
    },
    sub {                 # Call Length (seconds)
      my ($cdr, $value) = @_;
      $cdr->set('duration', $value);
      $cdr->set('billsec', $value);
    },
    sub {                 # Call Cost (NZD)
      my ($cdr,$value) = @_;
      $value =~ s/^\$//;
      $cdr->upstream_price($value);
    },
    skip(4),              # Smartcode, Smartcode Description, Type, SubType
  ],
);

sub skip { map {''} (1..$_[0]) }

1;