Enswitch CDR format changes 30992 and 33014
[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     'clid',         #Calling name
23     skip(1),        #Called type
24     'dst',          #Called number
25     skip(10),       #Destination customer, Destination type
26                     #Destination number
27                     #Destination group ID, Destination group name,
28     \&in_calling_type,  #Inbound calling type,
29     \&in_calling_num,   #Inbound calling number,
30     '',                 #Inbound called type,
31     \&in_called_num,    #Inbound called number,
32     skip(11),
33                     #Inbound destination type, Inbound destination number,
34                     #Outbound calling type, Outbound calling number,
35                     #Outbound called type, Outbound called number,
36                     #Outbound destination type, Outbound destination number,
37                     #Internal calling type, Internal calling number,
38                     #Internal called type, Internal called number,
39                     #Internal destination type, Internal destination number
40     'duration',     #Total seconds
41     skip(1),        #Ring seconds
42     'billsec',      #Billable seconds
43     'upstream_price', #Cost
44     skip(1),        #Cost including taxes
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 #create CDR types with names matching in_calling_type valuesj - 'none'
53 # (without the quotes) for blank
54 our %cdr_type = ();
55 sub in_calling_type {
56   my ($record, $data) = @_;
57
58   $data ||= 'none';
59
60   my $cdr_type = exists($cdr_type{$data})
61                    ? $cdr_type{$data}
62                    : qsearchs('cdr_type', { 'cdrtypename' => $data } );
63
64   $cdr_type{$data} = $cdr_type;
65
66   $record->set('in_calling_type', $data); #for below
67   $record->set('cdrtypenum', $cdr_type->cdrtypenum) if $cdr_type;
68
69 }
70
71 sub in_calling_num {
72   my ($record, $data) = @_;
73   $record->src($data) if ( ($record->in_calling_type || '') eq 'external' );
74 }
75
76 sub in_called_num {
77   my ($record, $data) = @_;
78   $record->dst($data) if ( ($record->in_calling_type || '') eq 'external' );
79 }
80
81 1;