fix to Enswitch CDR import, #11613
[freeside.git] / FS / FS / cdr / enswitch.pm
1 package FS::cdr::enswitch;
2
3 use strict;
4 use vars qw( @ISA %info $tmp_mon $tmp_mday $tmp_year );
5 use Time::Local;
6 use FS::cdr qw(_cdr_min_parser_maker);
7
8 @ISA = qw(FS::cdr);
9
10 %info = (
11   'name'          => 'Enswitch',
12   'weight'        => 515,
13   'header'        => 2,
14   'type'          => 'csv',
15   'import_fields' => [
16     'disposition',  #Status
17     'startdate',    #Start, already a unix timestamp
18     skip(2),        #Start date, Start time
19     'enddate',      #End
20     skip(4),        #End date, End time
21                     #Calling customer, Calling type
22     'src',          #Calling number
23     'clid',         #Calling name
24     skip(1),        #Called type
25     'dst',          #Called number
26     skip(5),        #Destination customer, Destination type
27                     #Destination number
28                     #Destination group ID, Destination group name,
29     'in_calling_type',  #Inbound calling type,
30     \&in_calling_num,   #Inbound calling number,
31     '',                 #Inbound called type,
32     \&in_called_num,    #Inbound called number,
33     skip(14),
34                     #Inbound destination type, Inbound destination number,
35                     #Outbound calling type, Outbound calling number,
36                     #Outbound called type, Outbound called number,
37                     #Outbound destination type, Outbound destination number,
38                     #Internal calling type, Internal calling number,
39                     #Internal called type, Internal called number,
40                     #Internal destination type, Internal destination number
41     'duration',     #Total seconds
42     skip(1),        #Ring seconds
43     'billsec',      #Billable seconds
44     'upstream_price', #Cost
45     'accountcode',  #Billing customer
46     skip(3),        #Billing customer name, Billing type, Billing reference
47   ],
48 );
49
50 sub skip { map {''} (1..$_[0]) }
51
52 sub in_calling_num {
53   my ($record, $data) = @_;
54   $record->src($data) if ( ($record->in_calling_type || '') eq 'external' );
55 }
56
57 sub in_called_num {
58   my ($record, $data) = @_;
59   $record->dst($data) if ( ($record->in_calling_type || '') eq 'external' );
60 }
61
62 1;