1 package FS::cdr::amcom;
4 use base qw( FS::cdr );
7 use FS::Record qw( qsearchs );
10 my ($tmp_mday, $tmp_mon, $tmp_year);
20 #listref of what to do with each field from the CDR, in order
23 sub { # 1. Field Type (must be "DCR", yes, "DCR")
24 my ($cdr, $field, $conf, $hashref) = @_;
25 $hashref->{skiprow} = 1 unless $field eq 'DCR';
27 'accountcode',# 2. BWGroupID (centrex group)
28 sub { # 3. BWGroupNumber
29 my ($cdr, $field) = @_; #, $conf, $hashref) = @_;
30 $cdr->charged_party($field)
31 if $cdr->accountcode eq '' && $field =~ /^(1800|1300)/;
33 'uniqueid', # 4. Record ID
34 sub { # 5. Call Category (LOCAL, NATIONAL, FREECALL, MOBILE)
35 my ($cdr, $data) = @_;
38 my $cdr_type = qsearchs('cdr_type', { 'cdrtypename' => $data } );
39 $cdr->set('cdrtypenum', $cdr_type->cdrtypenum) if $cdr_type;
40 $cdr->set('dcontext', $data);
42 sub { # 6. Start Date (DDMMYYYY
43 my ($cdr, $date) = @_;
44 $date =~ /^(\d{2})(\d{2})(\d{4})$/
45 or die "unparseable date: $date";
46 ($tmp_mday, $tmp_mon, $tmp_year) = ($1, $2, $3);
48 sub { # 7. Start Time (HHMMSS)
49 my ($cdr, $time) = @_;
50 $time =~ /^(\d{2})(\d{2})(\d{2})$/
51 or die "unparseable time: $time";
52 my $dt = DateTime->new(
61 $cdr->set('startdate', $dt->epoch);
63 sub { # 8. Duration (seconds, 3 decimals)
64 my ($cdr, $seconds) = @_;
65 $cdr->set('duration', sprintf('%.0f', $seconds));
66 $cdr->set('billsec', sprintf('%.0f', $seconds));
68 'src', # 9. Calling Number
69 'dst', # 10. Called Number
70 'upstream_src_regionname', # 11. Calling Party Zone
71 'upstream_dst_regionname', # 12. Called Party Zone
72 'upstream_price', # 13. Call Cost
73 '', # 14. Call Cost 2 (seems to be the same?)
74 '', # 15. Service Provider ID
75 ('') x 4, # 16-20. Reserved fields