36be8d8c3b6733e8943806ff6ee9928b3c0c2535
[freeside.git] / FS / FS / cdr / amcom.pm
1 package FS::cdr::amcom;
2
3 use strict;
4 use base qw( FS::cdr );
5 use vars qw( %info );
6 use DateTime;
7
8 my ($tmp_mday, $tmp_mon, $tmp_year);
9
10 %info = (
11   'name'          => 'Amcom',
12   'weight'        => 500,
13   'header'        => 1,
14   'type'          => 'csv',
15   'sep_char'      => ',',
16   'disabled'      => 0,
17
18   #listref of what to do with each field from the CDR, in order
19   'import_fields' => [
20
21     sub {         # 1. Field Type (must be "DCR", yes, "DCR")
22       my ($cdr, $field, $conf, $hashref) = @_;
23       $hashref->{skiprow} = 1 unless $field eq 'DCR';
24     },
25     '',           # 2. BWGroupID (centrex group)
26     '',           # 3. BWGroupNumber
27     'uniqueid',   # 4. Record ID
28     'dcontext',   # 5. Call Category (LOCAL, NATIONAL, FREECALL, MOBILE)
29     sub {         # 6. Start Date (DDMMYYYY
30       my ($cdr, $date) = @_;
31       $date =~ /^(\d{2})(\d{2})(\d{4})$/
32         or die "unparseable date: $date";
33       ($tmp_mday, $tmp_mon, $tmp_year) = ($1, $2, $3);
34     },
35     sub {         # 7. Start Time (HHMMSS)
36       my ($cdr, $time) = @_;
37       $time =~ /^(\d{2})(\d{2})(\d{2})$/
38         or die "unparseable time: $time";
39       my $dt = DateTime->new(
40         year    => $tmp_year,
41         month   => $tmp_mon,
42         day     => $tmp_mday,
43         hour    => $1,
44         minute  => $2,
45         second  => $3,
46         time_zone => 'local',
47       );
48       $cdr->set('startdate', $dt->epoch);
49     },
50     sub {         # 8. Duration (seconds, 3 decimals)
51       my ($cdr, $seconds) = @_;
52       $cdr->set('duration', sprintf('%.0f', $seconds));
53       $cdr->set('billsec', sprintf('%.0f', $seconds));
54     },
55     'src',        # 9. Calling Number
56     'dst',        # 10. Called Number
57     'upstream_src_regionname',  # 11. Calling Party Zone
58     'upstream_dst_regionname',  # 12. Called Party Zone
59     'upstream_price',           # 13. Call Cost
60     '',                         # 14. Call Cost 2 (seems to be the same?)
61     '',           # 15. Service Provider ID
62     ('') x 4,     # 16-20. Reserved fields
63   ],
64 );
65
66 1;