4 use base qw( FS::cdr );
6 use FS::cdr qw(_cdr_date_parser_maker);
8 my %CURRENCY = ( #Table 2.1.3
14 my %UNIT_SCALE = ( #Table 2.1.4
19 #(irrelevant, because we don't yet support these usage types, but still)
24 401 => 2**10 * 1000, # "decimal MB"
25 402 => 2**20 * 1000, # "decimal GB"
26 451 => 1, # Kbps--conveniently the same as our base unit
27 452 => 1000, # Mbps (decimal)
31 'name' => 'AAPT CTOP',
34 'type' => 'fixedlength',
35 'row_callback' => sub { $DB::single = 1; }, #XXX
36 'parser_opt' => { trim => 1 },
37 'fixedlength_format' => [qw(
39 transaction_id:20R:7:26
48 rated_units:10R:169:178
49 rated_price:18R:179:196
50 jurisdiction:18R:197:214
52 foreign_amount:18R:233:250
58 raw_unittype:6R:302:307
59 rated_unittype:6R:308:313
60 base_amount:18R:314:331
61 second_units:10R:332:341
62 third_units:10R:342:351
65 service_type:6:703:708
67 sec_id_value:48:715:762
72 my ($cdr, $data, $conf, $param) = @_;
73 $param->{skiprow} = 1 if $data ne 'PWTDET'; # skip non-detail records
76 '', # product ID (CPRD)
77 'calltypenum', # usage ID (CUSG)
79 my ($cdr, $data, $conf, $param) = @_;
81 warn "AAPT: service ID type is not telephone number.\n";
82 $param->{skiprow} = 1;
85 'charged_party', # ID value (phone number, if ID type = 1)
86 _cdr_date_parser_maker('startdate'), # trans date/time
87 '', # secondary date (unused?)
88 'dst', # Target (B-party)
89 'src', # Origin (A-party)
90 'billsec', # Rated units (may need unit scaling)
91 sub { # Amount charged
92 my ($cdr, $data) = @_;
93 $cdr->set('upstream_price', sprintf('%.5f', $data/100));
95 'dcontext', # Jurisdiction code; we use dcontext for this
96 '', # Full National Number (unused?)
97 '', # "Foreign Amount"
99 my ($cdr, $data) = @_;
100 $cdr->set('upstream_currency', $CURRENCY{$data});
102 '', # Reseller account number
103 '', # Completion status
104 'uniqueid', # CTOP Record ID
105 'duration', # Raw units
106 sub { # Raw unit type
107 my ($cdr, $data) = @_;
108 if (exists($UNIT_SCALE{$data})) {
109 $cdr->set('duration',
110 sprintf('%.0f', $cdr->get('duration') * $UNIT_SCALE{$data})
114 sub { # Rated unit type
115 my ($cdr, $data) = @_;
116 if (exists($UNIT_SCALE{$data})) {
118 sprintf('%.0f', $cdr->get('billsec') * $UNIT_SCALE{$data})
122 # trailing fields we don't care about