Ticket 33385 Changes to enswitch cdr import modules
[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     'dcontext',     #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
24     sub { my ($cdr, $dst) = @_; $dst =~ s/*//g;
25
26         $cdr->set('dst', $dst);
27
28     },              #Called number
29
30     skip(14),       #Destination customer, Destination type
31                     #Destination number
32                     #Destination group ID, Destination group name,
33                     #Inbound calling type,
34                     #Inbound calling number,
35                     #Inbound called type,
36                     #Inbound called number,
37                     #Inbound destination type, Inbound destination number,
38     'disposition',  #Outbound calling type,
39       skip(11),     #Outbound calling number,
40                     #Outbound called type, Outbound called number,
41                     #Outbound destination type, Outbound destination number,
42                     #Internal calling type, Internal calling number,
43                     #Internal called type, Internal called number,
44                     #Internal destination type, Internal destination number
45     'duration',     #Total seconds
46     skip(1),        #Ring seconds
47     'billsec',      #Billable seconds
48     skip(2),        #Cost
49                     #Cost including taxes
50     'accountcode',  #Billing customer
51     skip(3),        #Billing customer name, Billing type, Billing reference
52   ],
53 );
54
55 sub skip { map {''} (1..$_[0]) }
56
57 #create CDR types with names matching in_calling_type valuesj - 'none'
58 # (without the quotes) for blank
59 our %cdr_type = ();
60 sub in_calling_type {
61   my ($record, $data) = @_;
62
63   $data ||= 'none';
64
65   my $cdr_type = exists($cdr_type{$data})
66                    ? $cdr_type{$data}
67                    : qsearchs('cdr_type', { 'cdrtypename' => $data } );
68
69   $cdr_type{$data} = $cdr_type;
70
71   $record->set('in_calling_type', $data); #for below
72   $record->set('cdrtypenum', $cdr_type->cdrtypenum) if $cdr_type;
73
74 }
75
76 1;