From 8e21a8c2ce7617a64ec962b3933c77a868682b94 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 22 Apr 2008 10:56:02 +0000 Subject: [PATCH] voxline cdrs --- FS/FS/cdr.pm | 67 ++++++++++++++++++++++++++++++++++++++-------- FS/FS/part_pkg/voip_cdr.pm | 22 +++++++++++++-- 2 files changed, 76 insertions(+), 13 deletions(-) diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm index 495f5d189..c10eec053 100644 --- a/FS/FS/cdr.pm +++ b/FS/FS/cdr.pm @@ -449,10 +449,11 @@ as keys (for use with batch_import) and "pretty" format names as values. sub import_formats { ( - 'asterisk' => 'Asterisk', - 'taqua' => 'Taqua', - 'unitel' => 'Unitel/RSLCOM', - 'simple' => 'Simple', + 'asterisk' => 'Asterisk', + 'taqua' => 'Taqua', + 'unitel' => 'Unitel/RSLCOM', + 'voxlinesystems' => 'VoxLineSystems', #XXX? get the actual vendor name + 'simple' => 'Simple', ); } @@ -667,6 +668,50 @@ my %import_formats = ( 'carrierid', 'upstream_rateid', ], + 'voxlinesystems' => [ #XXX get the actual vendor name + 'disposition', #Status + 'startdate', #Start (what do you know, a timestamp! + sub { my($cdr, $field) = @_; }, #Start date + sub { my($cdr, $field) = @_; }, #Start time + 'enddate', #End (also a timestamp!) + sub { my($cdr, $field) = @_; }, #End date + sub { my($cdr, $field) = @_; }, #End time + 'accountcode', #Calling customer XXX map to agent_custid?? + sub { my($cdr, $field) = @_; }, #Calling type + sub { shift->src('30000'); }, #XXX FAKE XXX 'src', #Calling number + 'userfield', #Calling name #? + sub { my($cdr, $field) = @_; }, #Called type + 'dst', #Called number + sub { my($cdr, $field) = @_; }, #Destination customer + sub { my($cdr, $field) = @_; }, #Destination type + sub { my($cdr, $field) = @_; }, #Destination Number + sub { my($cdr, $field) = @_; }, #Inbound calling type + sub { my($cdr, $field) = @_; }, #Inbound calling number + sub { my($cdr, $field) = @_; }, #Inbound called type + sub { my($cdr, $field) = @_; }, #Inbound called number + sub { my($cdr, $field) = @_; }, #Inbound destination type + sub { my($cdr, $field) = @_; }, #Inbound destination number + sub { my($cdr, $field) = @_; }, #Outbound calling type + sub { my($cdr, $field) = @_; }, #Outbound calling number + sub { my($cdr, $field) = @_; }, #Outbound called type + sub { my($cdr, $field) = @_; }, #Outbound called number + sub { my($cdr, $field) = @_; }, #Outbound destination type + sub { my($cdr, $field) = @_; }, #Outbound destination number + sub { my($cdr, $field) = @_; }, #Internal calling type + sub { my($cdr, $field) = @_; }, #Internal calling number + sub { my($cdr, $field) = @_; }, #Internal called type + sub { my($cdr, $field) = @_; }, #Internal called number + sub { my($cdr, $field) = @_; }, #Internal destination type + sub { my($cdr, $field) = @_; }, #Internal destination number + 'duration', #Total seconds + sub { my($cdr, $field) = @_; }, #Ring seconds + 'billsec', #Billable seconds + 'upstream_price', #Cost + sub { my($cdr, $field) = @_; }, #Billing customer + sub { my($cdr, $field) = @_; }, #Billing customer name + sub { my($cdr, $field) = @_; }, #Billing type + sub { my($cdr, $field) = @_; }, #Billing reference + ], 'simple' => [ # Date @@ -705,8 +750,9 @@ my %import_formats = ( ); my %import_header = ( - 'simple' => 1, - 'taqua' => 1, + 'simple' => 1, + 'taqua' => 1, + 'voxlinesystems' => 2, #XXX vendor name ); =item batch_import HASHREF @@ -750,14 +796,13 @@ sub batch_import { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - my $body = 0; + my $header_lines = + exists($import_header{$format}) ? $import_header{$format} : 0; + my $line; while ( defined($line=<$fh>) ) { - #skip header... - if ( ! $body++ && $import_header{$format} ) { #&& $line =~ /^[\w, "]+$/ ) { - next; - } + next if $header_lines-- > 0; #&& $line =~ /^[\w, "]+$/ $csv->parse($line) or do { $dbh->rollback if $oldAutoCommit; diff --git a/FS/FS/part_pkg/voip_cdr.pm b/FS/FS/part_pkg/voip_cdr.pm index 856f02fbf..155d8e78c 100644 --- a/FS/FS/part_pkg/voip_cdr.pm +++ b/FS/FS/part_pkg/voip_cdr.pm @@ -17,6 +17,7 @@ $DEBUG = 1; tie my %rating_method, 'Tie::IxHash', 'prefix' => 'Rate calls by using destination prefix to look up a region and rate according to the internal prefix and rate tables', 'upstream' => 'Rate calls based on upstream data: If the call type is "1", map the upstream rate ID directly to an internal rate (rate_detail), otherwise, pass the upstream price through directly.', + 'upstream_simple' => 'Simply pass through and charge the "upstream_price" amount.', ; #tie my %cdr_location, 'Tie::IxHash', @@ -253,6 +254,22 @@ sub calc_recur { } + } elsif ( $self->option('rating_method') eq 'upstream_simple' ) { + + #XXX $charge = sprintf('%.2f', $cdr->upstream_price); + $charge = sprintf('%.3f', $cdr->upstream_price); + $charges += $charge; + + @call_details = ( + #time2str("%Y %b %d - %r", $cdr->calldate_unix ), + time2str("%c", $cdr->calldate_unix), #XXX this should probably be a config option dropdown so they can select US vs- rest of world dates or whatnot + sprintf('%.2f', $cdr->billsec / 60 ).'m', + '$'.$charge, #XXX $money_char + #$pretty_destnum, + $cdr->userfield, #$rate_region->regionname, + $cdr->dst, + ); + } else { die "don't know how to rate CDRs using method: ". $self->option('rating_method'). "\n"; @@ -314,9 +331,10 @@ sub calc_recur { warn " adding details on charge to invoice: ". join(' - ', @call_details ) - if $DEBUG; + if $DEBUG && $charge > 0; - push @$details, join(' - ', @call_details); #\@call_details, + push @$details, join(' - ', @call_details) #\@call_details, + if $charge > 0; # if the customer flag is on, call "downstream_csv" or something # like it to export the call downstream! -- 2.11.0