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