ebb2677befbb640d335f995b0207a83f31ea4866
[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(4),        #End date, End time
20                     #Calling customer, Calling type
21     'src',          #Calling number     
22     skip(1),     #Called type
23     'dst',          #Called number
24     skip(14),       #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     'dcontext',     #Outbound calling type,
33       skip(11),     #Outbound calling number,
34                     #Outbound called type, Outbound called number,
35                     #Outbound destination type, Outbound destination number,
36                     #Internal calling type, Internal calling number,
37                     #Internal called type, Internal called number,
38                     #Internal destination type, Internal destination number
39     'duration',     #Total seconds
40     skip(1),        #Ring seconds
41     'billsec',      #Billable seconds
42     skip(2),        #Cost
43                     #Cost including taxes
44     'accountcode',  #Billing customer
45     skip(3),        #Billing customer name, Billing type, Billing reference
46   ],
47 );
48
49 sub skip { map {''} (1..$_[0]) }
50
51 #create CDR types with names matching in_calling_type valuesj - 'none'
52 # (without the quotes) for blank
53 our %cdr_type = ();
54 sub in_calling_type {
55   my ($record, $data) = @_;
56
57   $data ||= 'none';
58
59   my $cdr_type = exists($cdr_type{$data})
60                    ? $cdr_type{$data}
61                    : qsearchs('cdr_type', { 'cdrtypename' => $data } );
62
63   $cdr_type{$data} = $cdr_type;
64
65   $record->set('in_calling_type', $data); #for below
66   $record->set('cdrtypenum', $cdr_type->cdrtypenum) if $cdr_type;
67
68 }
69
70 1;