fix TeleAPI import (what kind of crack was Christopher smoking that he couldn't fix...
[freeside.git] / FS / FS / cdr / vocus.pm
1 package FS::cdr::vocus;
2
3 use strict;
4 use vars qw( @ISA %info $CDR_TYPES );
5 use FS::cdr qw( _cdr_date_parse );
6 use FS::Record qw( qsearch );
7
8
9 @ISA = qw(FS::cdr);
10
11 %info = (
12   'name'          => 'Vocus',
13   'weight'        => 120,  
14   'import_fields' => [
15
16     #The first column is reserved for future use.
17     skip(1),
18     #The second column is the call identifier generated on our system.
19     'uniqueid',
20     #The third column is the date of the call in UTC.
21     'startdate',
22     #The fourth column is the time of the call in UTC.
23     sub {
24       # combine cols 3 & 4 and parse
25       my($cdr, $time, $conf, $param) = @_;
26       $cdr->startdate(_cdr_date_parse($cdr->startdate.' '.$time, gmt => 1));
27     },
28     #The fifth column is for Vocus use.
29     skip(1),
30     #The sixth column is the call duration in seconds.
31     'billsec',
32     #The seventh column is the calling number presented to our soft switch in E164 format.
33     'src',
34     #The eight column is the called number presented to our soft switch in E164 format.
35     'dst',
36     #The ninth column is the time and date at which the call was rated and the
37     #  CDR generated in our system. It's just there for your information.
38     skip(1),
39     #The tenth column is the SZU of the calling party.
40     'upstream_src_regionname',
41     #The eleventh column is the SZU of the called party, if applicable.
42     'upstream_dst_regionname',
43     #The twelfth column is the tariff type - Mobile, Regional, International,
44     #etc. This matches up with the tariff types under the Voice Access Point on your bill.
45     sub {
46       my($cdr, $cdrtypename, $conf, $param) = @_;
47       return unless length($cdrtypename);
48       _init_cdr_types();
49       die "no matching cdrtypenum for $cdrtypename"
50         unless defined $CDR_TYPES->{$cdrtypename};
51       $cdr->cdrtypenum($CDR_TYPES->{$cdrtypename});
52     },
53     #The thirteenth column is the cost of the call, ex GST.
54     'upstream_price',
55
56   ],
57 );
58
59 sub skip { map {''} (1..$_[0]) }
60
61 sub _init_cdr_types {
62   unless ($CDR_TYPES) {
63     $CDR_TYPES = {};
64     foreach my $cdr_type ( qsearch('cdr_type') ) {
65       die "multiple cdr_types with same cdrtypename".$cdr_type->cdrtypename
66         if defined $CDR_TYPES->{$cdr_type->cdrtypename};
67       $CDR_TYPES->{$cdr_type->cdrtypename} = $cdr_type->cdrtypenum;
68     }
69   }
70 }
71
72 1;
73