X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcdr.pm;h=b9a4e41db3725a0111baf2d3f02147f3155d69b1;hb=06a85a88bfdb0d3fc79ee055eb8327658dfe63ab;hp=c5b2ab90ccc52b1120ad97db7fea88b586110e68;hpb=b86aeb14ba5f160450175b430c1132ef56ad7c08;p=freeside.git diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm index c5b2ab90c..b9a4e41db 100644 --- a/FS/FS/cdr.pm +++ b/FS/FS/cdr.pm @@ -1,7 +1,7 @@ package FS::cdr; use strict; -use vars qw( @ISA @EXPORT_OK $DEBUG ); +use vars qw( @ISA @EXPORT_OK $DEBUG $me ); use Exporter; use Tie::IxHash; use Date::Parse; @@ -13,11 +13,13 @@ use FS::Record qw( qsearch qsearchs ); use FS::cdr_type; use FS::cdr_calltype; use FS::cdr_carrier; +use FS::cdr_batch; @ISA = qw(FS::Record); @EXPORT_OK = qw( _cdr_date_parser_maker _cdr_min_parser_maker ); $DEBUG = 0; +$me = '[FS::cdr]'; =head1 NAME @@ -193,7 +195,8 @@ sub table_info { 'svcnum' => 'Freeside service', 'freesidestatus' => 'Freeside status', 'freesiderewritestatus' => 'Freeside rewrite status', - 'cdrbatch' => 'Batch', + 'cdrbatch' => 'Legacy batch', + 'cdrbatchnum' => 'Batch', }, }; @@ -375,7 +378,7 @@ sub set_charged_party { } -=item set_status_and_rated_price STATUS [ RATED_PRICE ] +=item set_status_and_rated_price STATUS [ RATED_PRICE [ SVCNUM ] ] Sets the status to the provided string. If there is an error, returns the error, otherwise returns false. @@ -383,9 +386,10 @@ error, otherwise returns false. =cut sub set_status_and_rated_price { - my($self, $status, $rated_price) = @_; + my($self, $status, $rated_price, $svcnum) = @_; $self->freesidestatus($status); $self->rated_price($rated_price); + $self->svcnum($svcnum) if $svcnum; $self->replace(); } @@ -504,7 +508,9 @@ my $duration_sub = sub { if ( $opt{minutes} ) { $opt{minutes}. ( $opt{granularity} ? 'm' : ' call' ); } else { - sprintf('%.2fm', $cdr->billsec / 60 ); + #config if anyone really wants decimal minutes back + #sprintf('%.2fm', $cdr->billsec / 60 ); + int($cdr->billsec / 60).'m '. ($cdr->billsec % 60).'s'; } }; @@ -757,7 +763,11 @@ Set true to prevent throwing an error on empty imports =cut my %import_options = ( - 'table' => 'cdr', + 'table' => 'cdr', + + 'batch_keycol' => 'cdrbatchnum', + 'batch_table' => 'cdr_batch', + 'batch_namecol' => 'cdrbatch', 'formats' => { map { $_ => $cdr_info{$_}->{'import_fields'}; } keys %cdr_info @@ -804,7 +814,7 @@ sub process_batch_import { my $job = shift; my $opt = _import_options; - $opt->{'params'} = [ 'format', 'cdrbatch' ]; +# $opt->{'params'} = [ 'format', 'cdrbatch' ]; FS::Record::process_batch_import( $job, $opt, @_ ); @@ -813,6 +823,37 @@ sub process_batch_import { # @columns = map { s/^ +//; $_; } @columns; # } +# _ upgrade_data +# +# Used by FS::Upgrade to migrate to a new database. + +sub _upgrade_data { + my ($class, %opts) = @_; + + warn "$me upgrading $class\n" if $DEBUG; + + my $sth = dbh->prepare( + 'SELECT DISTINCT(cdrbatch) FROM cdr WHERE cdrbatch IS NOT NULL' + ) or die dbh->errstr; + + $sth->execute or die $sth->errstr; + + my %cdrbatchnum = (); + while (my $row = $sth->fetchrow_arrayref) { + my $cdr_batch = new FS::cdr_batch { 'cdrbatch' => $row->[0] }; + my $error = $cdr_batch->insert; + die $error if $error; + $cdrbatchnum{$row->[0]} = $cdr_batch->cdrbatchnum; + } + + $sth = dbh->prepare('UPDATE cdr SET cdrbatch = NULL, cdrbatchnum = ? WHERE cdrbatch IS NOT NULL AND cdrbatch = ?') or die dbh->errstr; + + foreach my $cdrbatch (keys %cdrbatchnum) { + $sth->execute($cdrbatchnum{$cdrbatch}, $cdrbatch) or die $sth->errstr; + } + +} + =back =head1 BUGS