01755a8bf3f7741c19c22a1349520d9326c7662b
[freeside.git] / FS / FS / cdr / broadsoft.pm
1 package FS::cdr::broadsoft;
2
3 =head1 NAME
4
5 FS::cdr::broadsoft - CDR parse module for Broadsoft
6
7 =head1 DESCRIPTION
8
9 Ref: BW-AccountingCDRInterfaceSpec-R22.pdf
10
11 =cut
12
13 use strict;
14 use base qw( FS::cdr );
15 use vars qw( %info );
16 use FS::cdr qw( _cdr_date_parser_maker _cdr_min_parser_maker );
17
18 %info = (
19   name     => 'Broadsoft',
20   weight   => 500,
21   header   => 1,
22   type     => 'csv',
23   sep_char => ',',
24   disabled => 0,
25
26   row_callback => sub {
27     my $line = shift;
28     #try to deal with broadsoft's awful non-standard CSV escaping :/
29     $line =~ s/\\,/ /g;  # \, becomes just a space... not entirely accurate,
30                           #  but better than skewing data into the wrong fields
31     $line =~ s/\\\\/\\/g; # undo double backslashes?  none in my test data
32     $line;
33   },
34
35   import_fields => [
36
37     # 1: recordId
38     # 2: serviceProvider
39     skip(2),
40
41     # 3: type
42     sub {
43       my ( $cdr, $data, $conf, $param ) = @_;
44       $param->{skiprow} = 1
45         if lc($data) ne 'normal';
46       '';
47     },
48
49     # 4: userNumber
50     # 5: groupNumber
51     skip(2),
52
53     # 6: direction
54     'dcontext',
55
56     # 7: callingNumber
57     trim('src'),
58
59     # 8: callingPresentationINdicator
60     skip(1),
61
62     # 9: calledNumber
63     trim('dst'),
64
65     # 10: startTime
66     _cdr_date_parser_maker('startdate'),
67
68     # 11: userTimeZone
69     skip(1),
70
71     # 12: answerIndicator
72     sub {
73       my( $cdr, $data ) = @_;
74       $cdr->disposition( $data =~ /^yes/i ? 'ANSWERED' : 'NO ANSWER');
75     },
76
77     # 13: answerTime
78     _cdr_date_parser_maker('answerdate'),
79
80     # 14: releaseTime
81     _cdr_date_parser_maker('enddate'),
82
83     # 15: terminationCause
84     # 16: networkType
85     # 17: carrierIdentificationCode
86     # 18: dialedDigits
87     # 19: callCategory
88     # 20: networkCallType
89     # 21: networkTranslatedNumber
90     # 22: networkTranslatedGroup
91     # 23: releasingParty
92     # 24: route
93     skip(10),
94
95     # 25: networkCallID
96     'sipcallid',
97
98     # 26: codedc
99     # 27: accessDeviceAddress
100     # 28: accessCallID
101     # 29: spare
102     # 30: failoverCorrelationId
103     # 31: spare
104     # 32: group
105     # 33: department
106     skip(8),
107
108     # 34: accountCode
109     'accountcode',
110
111     # 35: authorizationCode
112     # 36: originalCalledNumber
113     # 37: originalCalledPresentationIndicator
114     # 38: originalCalledReason
115     # 39: redirectingNumber
116     # 40: redirectingPresentationIndicator
117     # 41: redirectingReason
118     # 42: chargeIndicator
119     # 43: typeOfNetwork
120     # 44: voicePortalCalling.invocationTime
121     # 45: localCallId
122     # 46: remoteCallId
123     # 47: callingPartyCategory
124     #
125     # Also... cols 48 - 448 see Broadsoft documentation
126     skip(87), #35-121 inclusive
127
128     #122: otherPartyName
129     'clid',
130
131     #123: otherPartyNamePresentationIndicator
132     sub {
133       my( $cdr, $data ) = @_;
134       $cdr->clid( $data ) unless $data =~ /^Public$/i;
135     },
136
137     skip(22), #124-145 inclusive
138
139     # 146: chargedNumber
140     'charged_party',
141
142   ],
143
144 );
145
146 sub trim {
147   my $fieldname = shift;
148   return sub {
149     my($cdr, $data) = @_;
150     $data =~ s/^\+1//;
151     $cdr->$fieldname($data);
152     ''
153   }
154 }
155
156 sub skip {
157   map { undef } (1..$_[0]);
158 }
159
160 1;
161
162 __END__
163
164 list of freeside CDR fields, useful ones marked with *
165
166            acctid - primary key
167     *[1]   calldate - Call timestamp (SQL timestamp)
168            clid - Caller*ID with text
169 7   *      src - Caller*ID number / Source number
170 9   *      dst - Destination extension
171            dcontext - Destination context
172            channel - Channel used
173            dstchannel - Destination channel if appropriate
174            lastapp - Last application if appropriate
175            lastdata - Last application data
176 10  *      startdate - Start of call (UNIX-style integer timestamp)
177 13         answerdate - Answer time of call (UNIX-style integer timestamp)
178 14  *      enddate - End time of call (UNIX-style integer timestamp)
179     *      duration - Total time in system, in seconds
180     *      billsec - Total time call is up, in seconds
181 12  *[2]   disposition - What happened to the call: ANSWERED, NO ANSWER, BUSY
182            amaflags - What flags to use: BILL, IGNORE etc, specified on a per
183            channel basis like accountcode.
184 4   *[3]   accountcode - CDR account number to use: account
185            uniqueid - Unique channel identifier
186            userfield - CDR user-defined field
187            cdr_type - CDR type - see FS::cdr_type (Usage = 1, S&E = 7, OC&C = 8)
188     *[4]   charged_party - Service number to be billed
189            upstream_currency - Wholesale currency from upstream
190     *[5]   upstream_price - Wholesale price from upstream
191            upstream_rateplanid - Upstream rate plan ID
192            rated_price - Rated (or re-rated) price
193            distance - km (need units field?)
194            islocal - Local - 1, Non Local = 0
195     *[6]   calltypenum - Type of call - see FS::cdr_calltype
196            description - Description (cdr_type 7&8 only) (used for
197            cust_bill_pkg.itemdesc)
198            quantity - Number of items (cdr_type 7&8 only)
199            carrierid - Upstream Carrier ID (see FS::cdr_carrier)
200            upstream_rateid - Upstream Rate ID
201            svcnum - Link to customer service (see FS::cust_svc)
202            freesidestatus - NULL, done (or something)
203
204 [1] Auto-populated from startdate if not present
205 [2] Package options available to ignore calls without a specific disposition
206 [3] When using 'cdr-charged_party-accountcode' config
207 [4] Auto-populated from src (normal calls) or dst (toll free calls) if not present
208 [5] When using 'upstream_simple' rating method.
209 [6] Set to usage class classnum when using pre-rated CDRs and usage class-based
210     taxation (local/intrastate/interstate/international)