finish up working bell_west CDR format, RT#4403
[freeside.git] / FS / FS / cdr / bell_west.pm
1 package FS::cdr::bell_west;
2
3 use strict;
4 use base qw( FS::cdr );
5 use vars qw( %info $tmp_mon $tmp_mday $tmp_year );
6 use Time::Local;
7 use FS::cdr qw( _cdr_date_parser_maker _cdr_min_parser_maker );
8
9 %info = (
10   'name'          => 'Bell West',
11   'weight'        => 210,
12   'header'        => 1,     #0 default, set to 1 to ignore the first line
13   'type'          => 'xls', #csv (default), fixedlength or xls
14
15   'import_fields' => [
16
17     # CDR FIELD / REQUIRED / Notes
18
19     # CHG TYPE / No / Internal Code only (no need to import)
20     sub {},
21
22     # ACCOUNT # / No / Internal Number only (no need to import)
23     sub {},
24
25     # DATE / Yes / "DATE"   Excel date format MM/DD/YYYY
26     sub { my($cdr, $date) = @_;
27
28           #$date =~ /^(\d{1,2})\/(\d{1,2})\/(\d\d(\d\d)?)$/
29           #  or die "unparsable date: $date"; #maybe we shouldn't die...
30           ##$cdr->startdate( timelocal(0, 0, 0 ,$2, $1-1, $3) );
31           #($tmp_mday, $tmp_mon, $tmp_year) = ( $2, $1-1, $3 );
32
33           my $datetime = DateTime::Format::Excel->parse_datetime( $date );
34           $tmp_mon  = $datetime->mon_0;
35           $tmp_mday = $datetime->mday;
36           $tmp_year = $datetime->year;
37         },
38
39     # CUST NO / Yes / "TIME"    "075959" Text based time
40     # Note: This is really the start time but Bell header says "Cust No" which
41     #       is wrong
42     sub { my($cdr, $time) = @_;
43           #my($sec, $min, $hour, $mday, $mon, $year)= localtime($cdr->startdate);
44           $time =~ /^(\d{2})(\d{2})(\d{2})$/
45             or die "unparsable time: $time"; #maybe we shouldn't die...
46           #$cdr->startdate( timelocal($3, $2, $1 ,$mday, $mon, $year) );
47           $cdr->startdate(
48             timelocal($3, $2, $1 ,$tmp_mday, $tmp_mon, $tmp_year)
49           );
50         },
51
52     # BTN / Yes / Main billing number but not DID or real number (I guess put in SRC field)
53     'src',
54
55     # ORIG CITY / No / We will use your Freeside rating and description name
56     'channel',
57
58     # TERM / YES / All calls should be billed, however all calls are missing "1+" and "011+" & DIR ASST = "411"
59     'dst',
60
61     # TERM CITY / No / We will use your Freeside rating and description name
62     'dstchannel',
63
64     # WTN / Yes / Bill to number (I guess put in "charged_party")
65     'charged_party',
66
67     # CODE / Yes / Account Code (security) and we need on invoice (suggestions ?)
68     'accountcode',
69
70     # PROV/COUNTRY / No / We will use your Freeside rating and description name
71     # (but use this to add "011" for "International" calls)
72     sub { my( $cdr, $prov ) = @_;
73           my $pre = ( $prov =~ /^\s*International\s*/i ) ? '011' : '1';
74           $cdr->dst( $pre. $cdr->dst ) unless $cdr->dst =~ /^$pre/;
75         },
76
77     # CALL TYPE / Possibly / Not sure if you need this to determine correct billing method ?
78     # DDD normal call (Direct Dial Dsomething? ="LD"?)
79     # TF  Toll Free
80     #     (toll free dst# should be sufficient to rate)
81     # DAT Directory AssisTance
82     #     (dst# 411 "area code" should be sufficient to rate)
83     # DNS (Another sort of directory assistance?... only one record with
84     #      "8195551212" in the dst#)
85     'dcontext', #probably don't need... map to cdr_type?  calltypenum?
86
87     # DURATION  Yes     Units = seconds
88     'billsec', #need to trim .00 ?
89
90     # AMOUNT CHARGED    No      Will use Freeside rating and description name
91     sub { my( $cdr, $amount) = @_;
92           $amount =~ s/^\$//;
93           $cdr->upstream_price( $amount );
94         },
95
96   ],
97
98 );
99
100 1;
101
102 __END__
103
104 CHG TYPE        (unused)
105 ACCOUNT #       (unused)
106
107 DATE            startdate (+ CUST NO)
108 CUST NO         (startdate time)
109                 - Start of call (UNIX-style integer timestamp)
110
111 BTN            *src - Caller*ID number / Source number
112 ORIG CITY       channel - Channel used
113 TERM #         *dst - Destination extension
114 TERM CITY       dstchannel - Destination channel if appropriate
115 WTN            *charged_party - Service number to be billed
116 CODE           *accountcode - CDR account number to use: account
117
118 PROV/COUNTRY    (used to prefix TERM # w/ 1 or 011)
119
120 CALL TYPE       dcontext - Destination context
121 DURATION       *billsec - Total time call is up, in seconds
122 AMOUNT CHARGED *upstream_price - Wholesale price from upstream
123