fix TeleAPI import (what kind of crack was Christopher smoking that he couldn't fix...
[freeside.git] / FS / FS / cdr / freeside_description_default.pm
1 package FS::cdr::freeside_description_default;
2
3 use strict;
4 use vars qw( @ISA %info $tmp_mon $tmp_mday $tmp_year );
5 use Time::Local;
6 use FS::cdr;
7
8 @ISA = qw(FS::cdr);
9
10 %info = (
11   'name'          => 'Freeside default with description field as destination',
12   'weight'        => 25,
13   'type'          => 'csv',
14   'header'        => 1,
15   'import_fields' => [
16     'charged_party',     # Billed number
17     'src',               # Caller
18
19     # Date (YYYY/MM/DD)
20     sub { my($cdr, $date) = @_;
21           $date =~ /^(\d\d(\d\d)?)\/(\d{1,2})\/(\d{1,2})$/
22             or die "unparsable date: $date"; #maybe we shouldn't die...
23           ($tmp_mday, $tmp_mon, $tmp_year) = ( $4, $3-1, $1 );
24         },
25
26     # Time (HH:MM:SS (AM/PM))
27     sub { my($cdr, $time) = @_;
28           $time =~ /^(\d{1,2}):(\d{1,2}):(\d{1,2}) (AM|PM)$/
29             or die "unparsable time: $time"; #maybe we shouldn't die...
30           my $hour = $1;
31           $hour += 12 if $4 eq 'PM' && $hour != 12;
32           $hour = 0 if $4 eq 'AM' && $hour == 12;
33           $cdr->startdate(
34             timelocal($3, $2, $hour ,$tmp_mday, $tmp_mon, $tmp_year)
35           );
36         },
37
38     # Number
39     sub {
40         my($cdr, $number) = @_;
41         $number =~ /(\+|)(\d+)\s([\d\*]+)$/ 
42             or die "unparsable number: $number"; #maybe we shouldn't die...
43         $cdr->dst("$1$2$3");
44     },           
45
46     'description',      # Destination (regionname)
47
48     # Duration
49     sub {
50         my($cdr, $duration) = @_;
51         $duration =~ /^(\d{1,3})m (\d{1,2})s$/
52             or die "unparsable duration: $duration"; #maybe we shouldn't die...
53         my $sec = $1*60 + $2;
54         $cdr->duration($sec);
55         $cdr->billsec($sec);
56     },
57
58     # Price
59     sub {
60         my($cdr, $amount) = @_;
61         $amount =~ s/\$//g;
62         $cdr->upstream_price($amount);
63     }
64
65   ],
66 );
67
68