get rid of cdr_upstream_rate table and some other old convergent cruft
authorivan <ivan>
Fri, 17 Jul 2009 00:10:34 +0000 (00:10 +0000)
committerivan <ivan>
Fri, 17 Jul 2009 00:10:34 +0000 (00:10 +0000)
FS/FS.pm
FS/FS/Schema.pm
FS/FS/cdr.pm
FS/FS/cdr_upstream_rate.pm [deleted file]
FS/FS/part_pkg/voip_cdr.pm
FS/t/cdr_upstream_rate.t [deleted file]

index 00286d4..09ef298 100644 (file)
--- a/FS/FS.pm
+++ b/FS/FS.pm
@@ -150,8 +150,6 @@ L<FS::cdr_calltype> - CDR calltype class
 
 L<FS::cdr_carrier> - CDR carrier class
 
-L<FS::cdr_upstream_rate> - CDR upstream rate class
-
 L<FS::cdr_type> - CDR type class
 
 L<FS::svc_external> - Externally tracked service class.
index 475cec8..8b53184 100644 (file)
@@ -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',     '', '', '', '',
index efccd4b..152f1d6 100644 (file)
@@ -472,51 +472,11 @@ sub calltypename {
   $cdr_calltype ? $cdr_calltype->calltypename : '';
 }
 
-=item cdr_upstream_rate
-
-Returns the upstream rate mapping (see L<FS::cdr_upstream_rate>), 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 (file)
index 2fd9782..0000000
+++ /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::rate_detail>).  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<FS::cdr>)
-
-=item ratedetailnum - Rate detail - see L<FS::rate_detail>
-
-=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<hash> 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<FS::rate_detail>).
-
-=cut
-
-sub rate_detail {
-  my $self = shift;
-  qsearchs('rate_detail', { 'ratedetailnum' => $self->ratedetailnum } );
-}
-
-=back
-
-=head1 BUGS
-
-=head1 SEE ALSO
-
-L<FS::Record>, schema.html from the base documentation.
-
-=cut
-
-1;
-
index 1195b16..929a2d7 100644 (file)
@@ -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 (file)
index f9458c5..0000000
+++ /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";