Enswitch CDR changes
[freeside.git] / FS / FS / cdr / enswitch.pm
1 package FS::cdr::enswitch;
2 use base qw( FS::cdr );
3
4 use strict;
5 use vars qw( %info $tmp_mon $tmp_mday $tmp_year );
6 use FS::Record qw( qsearchs );
7 use FS::cdr_type;
8
9 %info = (
10   'name'          => 'Enswitch',
11   'weight'        => 515,
12   'header'        => 2,
13   'type'          => 'csv',
14   'import_fields' => [
15     'disposition',  #Status
16     'startdate',    #Start, already a unix timestamp
17     skip(2),        #Start date, Start time
18     'enddate',      #End
19     skip(6),        #End date, End time
20                     #Calling customer, Calling type
21     'src',          #Calling number     
22     skip(1),        #Called type
23     'dst',          #Called number
24     skip(26),       #Destination customer, Destination type
25                     #Destination number
26                     #Destination group ID, Destination group name,
27                     #Inbound calling type,
28                     #Inbound calling number,
29                     #Inbound called type,
30                     #Inbound called number,
31                     #Inbound destination type, Inbound destination number,
32                     #Outbound calling type, Outbound calling number,
33                     #Outbound called type, Outbound called number,
34                     #Outbound destination type, Outbound destination number,
35                     #Internal calling type, Internal calling number,
36                     #Internal called type, Internal called number,
37                     #Internal destination type, Internal destination number
38     'duration',     #Total seconds
39     skip(1),        #Ring seconds
40     'billsec',      #Billable seconds
41     'upstream_price', #Cost
42     skip(1),        #Cost including taxes
43     'accountcode',  #Billing customer
44     skip(3),        #Billing customer name, Billing type, Billing reference
45   ],
46 );
47
48 sub skip { map {''} (1..$_[0]) }
49
50 #create CDR types with names matching in_calling_type valuesj - 'none'
51 # (without the quotes) for blank
52 our %cdr_type = ();
53 sub in_calling_type {
54   my ($record, $data) = @_;
55
56   $data ||= 'none';
57
58   my $cdr_type = exists($cdr_type{$data})
59                    ? $cdr_type{$data}
60                    : qsearchs('cdr_type', { 'cdrtypename' => $data } );
61
62   $cdr_type{$data} = $cdr_type;
63
64   $record->set('in_calling_type', $data); #for below
65   $record->set('cdrtypenum', $cdr_type->cdrtypenum) if $cdr_type;
66
67 }
68
69 1;