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) = @_;
31 if ($cdr->accountcode eq '' && $field =~ /^(1800|1300)/){
32 $cdr->charged_party($field);
33 $cdr->accountcode($field);
36 'uniqueid', # 4. Record ID
37 sub { # 5. Call Category (LOCAL, NATIONAL, FREECALL, MOBILE)
38 my ($cdr, $data) = @_;
41 my $cdr_type = qsearchs('cdr_type', { 'cdrtypename' => $data } );
42 $cdr->set('cdrtypenum', $cdr_type->cdrtypenum) if $cdr_type;
43 $cdr->set('dcontext', $data);
45 sub { # 6. Start Date (DDMMYYYY
46 my ($cdr, $date) = @_;
47 $date =~ /^(\d{2})(\d{2})(\d{4})$/
48 or die "unparseable date: $date";
49 ($tmp_mday, $tmp_mon, $tmp_year) = ($1, $2, $3);
51 sub { # 7. Start Time (HHMMSS)
52 my ($cdr, $time) = @_;
53 $time =~ /^(\d{2})(\d{2})(\d{2})$/
54 or die "unparseable time: $time";
55 my $dt = DateTime->new(
64 $cdr->set('startdate', $dt->epoch);
66 sub { # 8. Duration (seconds, 3 decimals)
67 my ($cdr, $seconds) = @_;
68 $cdr->set('duration', sprintf('%.0f', $seconds));
69 $cdr->set('billsec', sprintf('%.0f', $seconds));
71 'src', # 9. Calling Number
72 'dst', # 10. Called Number
73 'upstream_src_regionname', # 11. Calling Party Zone
74 'upstream_dst_regionname', # 12. Called Party Zone
75 'upstream_price', # 13. Call Cost
76 '', # 14. Call Cost 2 (seems to be the same?)
77 '', # 15. Service Provider ID
78 ('') x 4, # 16-20. Reserved fields