X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcdr.pm;h=a2b9a8ccbfd18c8bc48b0fdab830c622e1c4301b;hp=7a5668d52e2c1979650d9735efb920e672245017;hb=674cb2d9d7105f4cc2871539b2e9f7088cdaa750;hpb=706da330626bab472bf6f4e50cf3c181bfa0cf9f diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm index 7a5668d52..a2b9a8ccb 100644 --- a/FS/FS/cdr.pm +++ b/FS/FS/cdr.pm @@ -161,6 +161,8 @@ following fields are currently supported: =item cdrbatch +=item detailnum - Link to invoice detail (L) + =back =head1 METHODS @@ -214,6 +216,7 @@ sub table_info { #'upstream_rateplanid' => '', #'ratedetailnum' => '', 'rated_price' => 'Rated price', + 'rated_cost' => 'Rated cost', #'distance' => '', #'islocal' => '', #'calltypenum' => '', @@ -226,6 +229,7 @@ sub table_info { 'freesiderewritestatus' => 'Freeside rewrite status', 'cdrbatch' => 'Legacy batch', 'cdrbatchnum' => 'Batch', + 'detailnum' => 'Freeside invoice detail line', }, }; @@ -337,8 +341,12 @@ sub check { #check the foreign keys even? #do we want to outright *reject* the CDR? - my $error = - $self->ut_numbern('acctid'); + my $error = $self->ut_numbern('acctid'); + return $error if $error; + + if ( $self->freesidestatus ne 'done' ) { + $self->set('detailnum', ''); # can't have this on an unbilled call + } #add a config option to turn these back on if someone needs 'em # @@ -351,8 +359,6 @@ sub check { # # Telstra =1, Optus = 2, RSL COM = 3 # || $self->ut_foreign_keyn('carrierid', 'cdr_carrier', 'carrierid' ) - return $error if $error; - $self->SUPER::check; } @@ -463,7 +469,9 @@ Sets the status and rated price. Available options are: inbound, rated_pretty_dst, rated_regionname, rated_seconds, rated_minutes, rated_granularity, rated_ratedetailnum, -rated_classnum, rated_ratename. +rated_classnum, rated_ratename. If rated_ratedetailnum is provided, +will also set a recalculated L in the rated_cost field +after the other fields are set (does not work with inbound.) If there is an error, returns the error, otherwise returns false. @@ -501,6 +509,8 @@ sub set_status_and_rated_price { qw( pretty_dst regionname seconds minutes granularity ratedetailnum classnum ratename ); $self->svcnum($svcnum) if $svcnum; + $self->rated_cost($self->rate_cost) if $opt{'rated_ratedetailnum'}; + return $self->replace(); } @@ -536,6 +546,9 @@ sub parse_number { my $field = $options{column} || 'dst'; my $intl = $options{international_prefix} || '011'; + # Still, don't break anyone's CDR rating if they have an empty string in + # there. Require an explicit statement that there's no prefix. + $intl = '' if lc($intl) eq 'none'; my $countrycode = ''; my $number = $self->$field(); @@ -914,8 +927,10 @@ sub rate_prefix { # by default, set the included minutes for this region/time to # what's in the rate_detail - $included_min->{$regionnum}{$ratetimenum} = $rate_detail->min_included - unless exists $included_min->{$regionnum}{$ratetimenum}; + if (!exists( $included_min->{$regionnum}{$ratetimenum} )) { + $included_min->{$regionnum}{$ratetimenum} = + ($rate_detail->min_included * $cust_pkg->quantity || 1); + } if ( $included_min->{$regionnum}{$ratetimenum} >= $minutes ) { $charge_sec = 0; @@ -1249,6 +1264,10 @@ my %export_names = ( 'name' => 'Number of calls, one line per service', 'invoice_header' => 'Caller,Rate,Messages,Price', }, + 'sum_duration' => { + 'name' => 'Summary, one line per service', + 'invoice_header' => 'Caller,Rate,Calls,Minutes,Price', + }, 'sum_duration_prefix' => { 'name' => 'Summary, one line per destination prefix', 'invoice_header' => 'Caller,Rate,Calls,Minutes,Price', @@ -1257,6 +1276,10 @@ my %export_names = ( 'name' => 'Summary, one line per usage class', 'invoice_header' => 'Caller,Class,Calls,Price', }, + 'sum_duration_accountcode' => { + 'name' => 'Summary, one line per accountcode', + 'invoice_header' => 'Caller,Rate,Calls,Minutes,Price', + }, ); my %export_formats = (); @@ -1458,7 +1481,7 @@ as keys (for use with part_pkg::voip_cdr) and "pretty" format names as values. sub invoice_formats { map { ($_ => $export_names{$_}->{'name'}) } grep { $export_names{$_}->{'invoice_header'} } - keys %export_names; + sort keys %export_names; } =item invoice_header FORMAT @@ -1627,7 +1650,7 @@ sub _cdr_date_parse { # optionally without seconds ($mon, $day, $year, $hour, $min, $sec) = ( $1, $2, $3, $4, $5, $6 ); $sec = 0 if !defined($sec); - } elsif ( $date =~ /^\s*(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d+\.\d+)(\D|$)/ ) { + } elsif ( $date =~ /^\s*(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\.\d+)$/ ) { # broadsoft: 20081223201938.314 ($year, $mon, $day, $hour, $min, $sec) = ( $1, $2, $3, $4, $5, $6 ); } elsif ( $date =~ /^\s*(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})\d+(\D|$)/ ) { @@ -1637,7 +1660,7 @@ sub _cdr_date_parse { # WIP: 20100329121420 ($year, $mon, $day, $hour, $min, $sec) = ( $1, $2, $3, $4, $5, $6 ); } elsif ( $date =~ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/) { - # Telos + # Telos 2014-10-10T05:30:33Z ($year, $mon, $day, $hour, $min, $sec) = ( $1, $2, $3, $4, $5, $6 ); $options{gmt} = 1; } else {