From 2b7f02dec42a7b63cb66f6521eaddd2ea54f9b57 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 17 Jul 2009 00:10:34 +0000 Subject: [PATCH] get rid of cdr_upstream_rate table and some other old convergent cruft --- FS/FS.pm | 2 - FS/FS/Schema.pm | 12 ---- FS/FS/cdr.pm | 57 +------------------ FS/FS/cdr_upstream_rate.pm | 138 --------------------------------------------- FS/FS/part_pkg/voip_cdr.pm | 121 +++++++++++++++++++-------------------- FS/t/cdr_upstream_rate.t | 5 -- 6 files changed, 62 insertions(+), 273 deletions(-) delete mode 100644 FS/FS/cdr_upstream_rate.pm delete mode 100644 FS/t/cdr_upstream_rate.t diff --git a/FS/FS.pm b/FS/FS.pm index 00286d477..09ef298e7 100644 --- a/FS/FS.pm +++ b/FS/FS.pm @@ -150,8 +150,6 @@ L - CDR calltype class L - CDR carrier class -L - CDR upstream rate class - L - CDR type class L - Externally tracked service class. diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 475cec833..8b5318421 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -2206,18 +2206,6 @@ sub tables_hashref { 'index' => [], }, - #map upstream rateid to ours... - 'cdr_upstream_rate' => { - 'columns' => [ - 'upstreamratenum', 'serial', '', '', '', '', - 'upstream_rateid', 'varchar', '', $char_d, '', '', - 'ratedetailnum', 'int', 'NULL', '', '', '', - ], - 'primary_key' => 'upstreamratenum', #XXX need a primary key - 'unique' => [ [ 'upstream_rateid' ] ], #unless we add another field, yeah - 'index' => [], - }, - #'cdr_file' => { # 'columns' => [ # 'filenum', 'serial', '', '', '', '', diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm index efccd4bae..152f1d680 100644 --- a/FS/FS/cdr.pm +++ b/FS/FS/cdr.pm @@ -472,51 +472,11 @@ sub calltypename { $cdr_calltype ? $cdr_calltype->calltypename : ''; } -=item cdr_upstream_rate - -Returns the upstream rate mapping (see L), or the empty -string if no FS::cdr_upstream_rate object is associated with this CDR. - -=cut - -sub cdr_upstream_rate { - my $self = shift; - return '' unless $self->upstream_rateid; - qsearchs('cdr_upstream_rate', { 'upstream_rateid' => $self->upstream_rateid }) - or ''; -} - -=item _convergent_format COLUMN [ COUNTRYCODE ] - -Returns the number in COLUMN formatted as follows: - -If the country code does not match COUNTRYCODE (default "61"), it is returned -unchanged. - -If the country code does match COUNTRYCODE (default "61"), it is removed. In -addiiton, "0" is prepended unless the number starts with 13, 18 or 19. (???) - -=cut - -sub _convergent_format { - my( $self, $field ) = ( shift, shift ); - my $countrycode = scalar(@_) ? shift : '61'; #+61 = australia - #my $number = $self->$field(); - my $number = $self->get($field); - #if ( $number =~ s/^(\+|011)$countrycode// ) { - if ( $number =~ s/^\+$countrycode// ) { - $number = "0$number" - unless $number =~ /^1[389]/; #??? - } - $number; -} - =item downstream_csv [ OPTION => VALUE, ... ] =cut my %export_names = ( - 'convergent' => {}, 'simple' => { 'name' => 'Simple', 'invoice_header' => "Date,Time,Name,Destination,Duration,Price", @@ -550,21 +510,6 @@ my $duration_sub = sub { }; my %export_formats = ( - 'convergent' => [ - 'carriername', #CARRIER - sub { shift->_convergent_format('src') }, #SERVICE_NUMBER - sub { shift->_convergent_format('charged_party') }, #CHARGED_NUMBER - sub { time2str('%Y-%m-%d', shift->calldate_unix ) }, #DATE - sub { time2str('%T', shift->calldate_unix ) }, #TIME - 'billsec', #'duration', #DURATION - sub { shift->_convergent_format('dst') }, #NUMBER_DIALED - '', #XXX add (from prefixes in most recent email) #FROM_DESC - '', #XXX add (from prefixes in most recent email) #TO_DESC - 'calltypename', #CLASS_CODE - 'rated_price', #PRICE - sub { shift->rated_price ? 'Y' : 'N' }, #RATED - '', #OTHER_INFO - ], 'simple' => [ sub { time2str('%D', shift->calldate_unix ) }, #DATE sub { time2str('%r', shift->calldate_unix ) }, #TIME @@ -618,7 +563,7 @@ $export_formats{'accountcode_default'} = sub downstream_csv { my( $self, %opt ) = @_; - my $format = $opt{'format'}; # 'convergent'; + my $format = $opt{'format'}; return "Unknown format $format" unless exists $export_formats{$format}; #my $conf = new FS::Conf; diff --git a/FS/FS/cdr_upstream_rate.pm b/FS/FS/cdr_upstream_rate.pm deleted file mode 100644 index 2fd978203..000000000 --- a/FS/FS/cdr_upstream_rate.pm +++ /dev/null @@ -1,138 +0,0 @@ -package FS::cdr_upstream_rate; - -use strict; -use vars qw( @ISA ); -use FS::Record qw( qsearch qsearchs ); -use FS::rate_detail; - -@ISA = qw(FS::Record); - -=head1 NAME - -FS::cdr_upstream_rate - Object methods for cdr_upstream_rate records - -=head1 SYNOPSIS - - use FS::cdr_upstream_rate; - - $record = new FS::cdr_upstream_rate \%hash; - $record = new FS::cdr_upstream_rate { 'column' => 'value' }; - - $error = $record->insert; - - $error = $new_record->replace($old_record); - - $error = $record->delete; - - $error = $record->check; - -=head1 DESCRIPTION - -An FS::cdr_upstream_rate object represents an upstream rate mapping to -internal rate detail (see L). FS::cdr_upstream_rate inherits -from FS::Record. The following fields are currently supported: - -=over 4 - -=item upstreamratenum - primary key - -=item upstream_rateid - CDR upstream Rate ID (cdr.upstream_rateid - see L) - -=item ratedetailnum - Rate detail - see L - -=back - -=head1 METHODS - -=over 4 - -=item new HASHREF - -Creates a new upstream rate mapping. To add the upstream rate to the database, -see L<"insert">. - -Note that this stores the hash reference, not a distinct copy of the hash it -points to. You can ask the object for a copy with the I method. - -=cut - -# the new method can be inherited from FS::Record, if a table method is defined - -sub table { 'cdr_upstream_rate'; } - -=item insert - -Adds this record to the database. If there is an error, returns the error, -otherwise returns false. - -=cut - -# the insert method can be inherited from FS::Record - -=item delete - -Delete this record from the database. - -=cut - -# the delete method can be inherited from FS::Record - -=item replace OLD_RECORD - -Replaces the OLD_RECORD with this one in the database. If there is an error, -returns the error, otherwise returns false. - -=cut - -# the replace method can be inherited from FS::Record - -=item check - -Checks all fields to make sure this is a valid upstream rate. If there is -an error, returns the error, otherwise returns false. Called by the insert -and replace methods. - -=cut - -# the check method should currently be supplied - FS::Record contains some -# data checking routines - -sub check { - my $self = shift; - - my $error = - $self->ut_numbern('upstreamratenum') - #|| $self->ut_number('upstream_rateid') - || $self->ut_alpha('upstream_rateid') - #|| $self->ut_text('upstream_rateid') - || $self->ut_foreign_key('ratedetailnum', 'rate_detail', 'ratedetailnum' ) - ; - return $error if $error; - - $self->SUPER::check; -} - -=item rate_detail - -Returns the internal rate detail object for this upstream rate (see -L). - -=cut - -sub rate_detail { - my $self = shift; - qsearchs('rate_detail', { 'ratedetailnum' => $self->ratedetailnum } ); -} - -=back - -=head1 BUGS - -=head1 SEE ALSO - -L, schema.html from the base documentation. - -=cut - -1; - diff --git a/FS/FS/part_pkg/voip_cdr.pm b/FS/FS/part_pkg/voip_cdr.pm index 1195b1694..929a2d725 100644 --- a/FS/FS/part_pkg/voip_cdr.pm +++ b/FS/FS/part_pkg/voip_cdr.pm @@ -19,8 +19,9 @@ $DEBUG = 0; 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' => '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.', + 'flat' => 'A single price per minute for all calls.', ; tie my %recur_method, 'Tie::IxHash', @@ -243,7 +244,7 @@ sub calc_recur { my $charges = 0; - my $downstream_cdr = ''; +# my $downstream_cdr = ''; my $rating_method = $self->option('rating_method') || 'prefix'; my $intl = $self->option('international_prefix') || '011'; @@ -396,36 +397,36 @@ sub calc_recur { } - } elsif ( $rating_method eq 'upstream' ) { #XXX this was convergent, not currently used. very much becoming the odd one out. remove? - - if ( $cdr->cdrtypenum == 1 ) { #rate based on upstream rateid - - $rate_detail = $cdr->cdr_upstream_rate->rate_detail; - - $regionnum = $rate_detail->dest_regionnum; - $rate_region = $rate_detail->dest_region; - - $pretty_destnum = $cdr->dst; - - warn " found rate for regionnum $regionnum and ". - "rate detail $rate_detail\n" - if $DEBUG; - - } else { #pass upstream price through - - $charge = sprintf('%.2f', $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 - 'N/A', #minutes... - '$'.$charge, - #$pretty_destnum, - $cdr->description, #$rate_region->regionname, - ); - - } +# } elsif ( $rating_method eq 'upstream' ) { #XXX this was convergent, not currently used. very much becoming the odd one out. remove? +# +# if ( $cdr->cdrtypenum == 1 ) { #rate based on upstream rateid +# +# $rate_detail = $cdr->cdr_upstream_rate->rate_detail; +# +# $regionnum = $rate_detail->dest_regionnum; +# $rate_region = $rate_detail->dest_region; +# +# $pretty_destnum = $cdr->dst; +# +# warn " found rate for regionnum $regionnum and ". +# "rate detail $rate_detail\n" +# if $DEBUG; +# +# } else { #pass upstream price through +# +# $charge = sprintf('%.2f', $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 +# 'N/A', #minutes... +# '$'.$charge, +# #$pretty_destnum, +# $cdr->description, #$rate_region->regionname, +# ); +# +# } } elsif ( $rating_method eq 'upstream_simple' ) { @@ -526,8 +527,8 @@ sub calc_recur { # if the customer flag is on, call "downstream_csv" or something # like it to export the call downstream! # XXX price plan option to pick format, or something... - $downstream_cdr .= $cdr->downstream_csv( 'format' => 'convergent' ) - if $spool_cdr; + #$downstream_cdr .= $cdr->downstream_csv( 'format' => 'XXX format' ) + # if $spool_cdr; my $error = $cdr->set_status_and_rated_price('done', $charge); die $error if $error; @@ -541,32 +542,32 @@ sub calc_recur { unshift @$details, [ 'C', FS::cdr::invoice_header($output_format) ] if @$details && $rating_method ne 'upstream'; - if ( $spool_cdr && length($downstream_cdr) ) { - - use FS::UID qw(datasrc); - my $dir = '/usr/local/etc/freeside/export.'. datasrc. '/cdr'; - mkdir $dir, 0700 unless -d $dir; - $dir .= '/'. $cust_pkg->custnum. - mkdir $dir, 0700 unless -d $dir; - my $filename = time2str("$dir/CDR%Y%m%d-spool.CSV", time); #XXX invoice date instead? would require changing the order things are generated in cust_main::bill insert cust_bill first - with transactions it could be done though - - push @{ $param->{'precommit_hooks'} }, - sub { - #lock the downstream spool file and append the records - use Fcntl qw(:flock); - use IO::File; - my $spool = new IO::File ">>$filename" - or die "can't open $filename: $!\n"; - flock( $spool, LOCK_EX) - or die "can't lock $filename: $!\n"; - seek($spool, 0, 2) - or die "can't seek to end of $filename: $!\n"; - print $spool $downstream_cdr; - flock( $spool, LOCK_UN ); - close $spool; - }; - - } #if ( $spool_cdr && length($downstream_cdr) ) +# if ( $spool_cdr && length($downstream_cdr) ) { +# +# use FS::UID qw(datasrc); +# my $dir = '/usr/local/etc/freeside/export.'. datasrc. '/cdr'; +# mkdir $dir, 0700 unless -d $dir; +# $dir .= '/'. $cust_pkg->custnum. +# mkdir $dir, 0700 unless -d $dir; +# my $filename = time2str("$dir/CDR%Y%m%d-spool.CSV", time); #XXX invoice date instead? would require changing the order things are generated in cust_main::bill insert cust_bill first - with transactions it could be done though +# +# push @{ $param->{'precommit_hooks'} }, +# sub { +# #lock the downstream spool file and append the records +# use Fcntl qw(:flock); +# use IO::File; +# my $spool = new IO::File ">>$filename" +# or die "can't open $filename: $!\n"; +# flock( $spool, LOCK_EX) +# or die "can't lock $filename: $!\n"; +# seek($spool, 0, 2) +# or die "can't seek to end of $filename: $!\n"; +# print $spool $downstream_cdr; +# flock( $spool, LOCK_UN ); +# close $spool; +# }; +# +# } #if ( $spool_cdr && length($downstream_cdr) ) if ($param->{'increment_next_bill'}) { my $recur_method = $self->option('recur_method', 1) || 'anniversary'; diff --git a/FS/t/cdr_upstream_rate.t b/FS/t/cdr_upstream_rate.t deleted file mode 100644 index f9458c527..000000000 --- a/FS/t/cdr_upstream_rate.t +++ /dev/null @@ -1,5 +0,0 @@ -BEGIN { $| = 1; print "1..1\n" } -END {print "not ok 1\n" unless $loaded;} -use FS::cdr_upstream_rate; -$loaded=1; -print "ok 1\n"; -- 2.11.0