97ab402ca862725e8a9c653c616970d8a097696e
[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     'accountcode',# 2. BWGroupID (centrex group)
26     sub {         # 3. BWGroupNumber
27       my ($cdr, $field) = @_; #, $conf, $hashref) = @_;
28       $cdr->charged_party($field)
29         if $cdr->accountcode eq '' && $field =~ /^(1800|1300)/;
30     },
31     'uniqueid',   # 4. Record ID
32     'dcontext',   # 5. Call Category (LOCAL, NATIONAL, FREECALL, MOBILE)
33     sub {         # 6. Start Date (DDMMYYYY
34       my ($cdr, $date) = @_;
35       $date =~ /^(\d{2})(\d{2})(\d{4})$/
36         or die "unparseable date: $date";
37       ($tmp_mday, $tmp_mon, $tmp_year) = ($1, $2, $3);
38     },
39     sub {         # 7. Start Time (HHMMSS)
40       my ($cdr, $time) = @_;
41       $time =~ /^(\d{2})(\d{2})(\d{2})$/
42         or die "unparseable time: $time";
43       my $dt = DateTime->new(
44         year    => $tmp_year,
45         month   => $tmp_mon,
46         day     => $tmp_mday,
47         hour    => $1,
48         minute  => $2,
49         second  => $3,
50         time_zone => 'local',
51       );
52       $cdr->set('startdate', $dt->epoch);
53     },
54     sub {         # 8. Duration (seconds, 3 decimals)
55       my ($cdr, $seconds) = @_;
56       $cdr->set('duration', sprintf('%.0f', $seconds));
57       $cdr->set('billsec', sprintf('%.0f', $seconds));
58     },
59     'src',        # 9. Calling Number
60     'dst',        # 10. Called Number
61     'upstream_src_regionname',  # 11. Calling Party Zone
62     'upstream_dst_regionname',  # 12. Called Party Zone
63     'upstream_price',           # 13. Call Cost
64     '',                         # 14. Call Cost 2 (seems to be the same?)
65     '',           # 15. Service Provider ID
66     ('') x 4,     # 16-20. Reserved fields
67   ],
68 );
69
70 1;