fix TeleAPI import (what kind of crack was Christopher smoking that he couldn't fix...
[freeside.git] / FS / FS / cdr / callplus.pm
1 package FS::cdr::callplus;
2 use base qw( FS::cdr );
3
4 use strict;
5 use vars qw( %info );
6 use FS::Record qw( qsearchs );
7 use Time::Local 'timelocal';
8
9 # Date format in the Date/Time col: "13/07/2016 2:40:32 p.m."
10 # d/m/y H:M:S, leading zeroes stripped, 12-hour with "a.m." or "p.m.".
11 # There are also separate d/m/y and 24-hour time columns, but parsing
12 # those separately is hard (DST issues).
13
14 %info = (
15   'name'          => 'CallPlus',
16   'weight'        => 610,
17   'header'        => 1,
18   'type'          => 'csv',
19   'import_fields' => [
20     'uniqueid',           # ID
21     '',                   # Billing Group (charged_party?)
22     'src',                # Origin Number
23     'dst',                # Destination Number
24     '',                   # Description (seems to be dest caller id?)
25     '',                   # Status
26     '',                   # Terminated
27     '',                   # Date
28     '',                   # Time
29     sub {                 # Date/Time
30       # this format overlaps one of the existing parser cases, so give it
31       # its own special parser
32       my ($cdr, $value) = @_;
33       $value =~ m[^(\d{1,2})/(\d{1,2})/(\d{4}) (\d{1,2}):(\d{2}):(\d{2}) (a\.m\.|p\.m\.)$]
34         or die "unparseable date: $value";
35       my ($day, $mon, $year, $hour, $min, $sec) = ( $1, $2, $3, $4, $5, $6 );
36       $hour = $hour % 12;
37       if ($7 eq 'p.m.') {
38         $hour = 12;
39       }
40       $cdr->set('startdate',
41                 timelocal($sec, $min, $hour, $day, $mon-1, $year)
42                );
43     },
44     sub {                 # Call Length (seconds)
45       my ($cdr, $value) = @_;
46       $cdr->set('duration', $value);
47       $cdr->set('billsec', $value);
48     },
49     sub {                 # Call Cost (NZD)
50       my ($cdr,$value) = @_;
51       $value =~ s/^\$//;
52       $cdr->upstream_price($value);
53     },
54     skip(2),              # Smartcode, Smartcode Description
55     sub {                 # Type. "I" = international, which matters.
56       my ($cdr, $value) = @_;
57       if ($value eq 'I') {
58         $cdr->set('dst', '+' . $cdr->dst);
59       } # else leave it alone
60     },
61     '',                   # SubType
62   ],
63 );
64
65 sub skip { map {''} (1..$_[0]) }
66
67 1;