fix small bug in last commit for RT12078
[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   'header'        => 1,
14   'import_fields' => [
15     'charged_party',     # Billed number
16     'src',               # Caller
17
18     # Date (YYYY/MM/DD)
19     sub { my($cdr, $date) = @_;
20           $date =~ /^(\d\d(\d\d)?)\/(\d{1,2})\/(\d{1,2})$/
21             or die "unparsable date: $date"; #maybe we shouldn't die...
22           ($tmp_mday, $tmp_mon, $tmp_year) = ( $4, $3-1, $1 );
23         },
24
25     # Time (HH:MM:SS (AM/PM))
26     sub { my($cdr, $time) = @_;
27           $time =~ /^(\d{1,2}):(\d{1,2}):(\d{1,2}) (AM|PM)$/
28             or die "unparsable time: $time"; #maybe we shouldn't die...
29           my $hour = $1;
30           $hour += 12 if $4 eq 'PM' && $hour != 12;
31           $hour = 0 if $4 eq 'AM' && $hour == 12;
32           $cdr->startdate(
33             timelocal($3, $2, $hour ,$tmp_mday, $tmp_mon, $tmp_year)
34           );
35         },
36
37     # Number
38     sub {
39         my($cdr, $number) = @_;
40         $number =~ /(\d+)$/ 
41             or die "unparsable number: $number"; #maybe we shouldn't die...
42         $cdr->dst($1);
43     },           
44
45     'description',      # Destination (regionname)
46
47     # Duration
48     sub {
49         my($cdr, $duration) = @_;
50         $duration =~ /^(\d{1,2})m (\d{1,2})s$/
51             or die "unparsable duration: $duration"; #maybe we shouldn't die...
52         my $sec = $1*60 + $2;
53         $cdr->duration($sec);
54         $cdr->billsec($sec);
55     },
56
57     # Price
58     sub {
59         my($cdr, $amount) = @_;
60         $amount =~ s/\$//g;
61         $cdr->upstream_price($amount);
62     }
63
64   ],
65 );
66
67