cdr types for AMCom CDR's
[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 use FS::Record qw( qsearchs );
8 use FS::cdr_type;
9
10 my ($tmp_mday, $tmp_mon, $tmp_year);
11
12 %info = (
13   'name'          => 'Amcom',
14   'weight'        => 500,
15   'header'        => 1,
16   'type'          => 'csv',
17   'sep_char'      => ',',
18   'disabled'      => 0,
19
20   #listref of what to do with each field from the CDR, in order
21   'import_fields' => [
22
23     sub {         # 1. Field Type (must be "DCR", yes, "DCR")
24       my ($cdr, $field, $conf, $hashref) = @_;
25       $hashref->{skiprow} = 1 unless $field eq 'DCR';
26     },
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)/;
32     },
33     'uniqueid',   # 4. Record ID
34     sub {          # 5. Call Category (LOCAL, NATIONAL, FREECALL, MOBILE)
35       my ($cdr, $data) = @_;
36       $data ||= 'none';
37
38       my $cdr_type = qsearchs('cdr_type', { 'cdrtypename' => $data } );
39       $cdr->set('cdrtypenum', $cdr_type->cdrtypenum) if $cdr_type;
40       $cdr->set('dcontext', $data);  
41     },
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);
47     },
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(
53         year    => $tmp_year,
54         month   => $tmp_mon,
55         day     => $tmp_mday,
56         hour    => $1,
57         minute  => $2,
58         second  => $3,
59         time_zone => 'local',
60       );
61       $cdr->set('startdate', $dt->epoch);
62     },
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));
67     },
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
76   ],
77 );
78
79 1;