[freeside-commits] freeside/FS/FS/part_pkg voip_cdr.pm, 1.136, 1.137 voip_tiered.pm, 1.4, 1.5
Mark Wells
mark at wavetail.420.am
Tue Jan 3 13:13:35 PST 2012
- Previous message: [freeside-commits] freeside/FS/FS/detail_format accountcode_default.pm, NONE, 1.1 basic.pm, NONE, 1.1 default.pm, NONE, 1.1 description_default.pm, NONE, 1.1 simple2.pm, NONE, 1.1 simple.pm, NONE, 1.1 source_default.pm, NONE, 1.1 sum_count.pm, NONE, 1.1 sum_duration.pm, NONE, 1.1 sum_duration_prefix.pm, NONE, 1.1
- Next message: [freeside-commits] freeside/FS/FS cdr.pm,1.84,1.85
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/cvsroot/freeside/FS/FS/part_pkg
In directory wavetail.420.am:/tmp/cvs-serv18734/FS/FS/part_pkg
Modified Files:
voip_cdr.pm voip_tiered.pm
Log Message:
detail format refactor, #15535
Index: voip_cdr.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/voip_cdr.pm,v
retrieving revision 1.136
retrieving revision 1.137
diff -u -w -d -r1.136 -r1.137
--- voip_cdr.pm 3 Jan 2012 07:47:27 -0000 1.136
+++ voip_cdr.pm 3 Jan 2012 21:13:33 -0000 1.137
@@ -9,6 +9,7 @@
use FS::Conf;
use FS::Record qw(qsearchs qsearch);
use FS::cdr;
+use FS::detail_format;
#use FS::rate;
#use FS::rate_prefix;
#use FS::rate_detail;
@@ -349,9 +350,9 @@
: 'default'
);
- my $use_duration = $self->option('use_duration');
+ my $formatter = FS::detail_format->new($output_format, buffer => $details);
- my $csv = new Text::CSV_XS;
+ my $use_duration = $self->option('use_duration');
my($svc_table, $svc_field) = split('\.', $cdr_svc_method);
@@ -384,7 +385,7 @@
); # $last_bill, $$sdate )
$options{'by_svcnum'} = 1 if $svc_field eq 'svcnum';
- my @invoice_details_sort;
+ #my @invoice_details_sort;
#first rate any outstanding CDRs not yet rated
foreach my $cdr (
@@ -404,118 +405,18 @@
#then add details to invoices & get a total
$options{'status'} = 'rated';
+
foreach my $cdr (
$svc_x->get_cdrs( %options )
) {
-
- my $classnum = '';
- my @call_details = ();
-
- if ( $rating_method eq 'prefix' ) {
-
- $classnum = $cdr->rated_classnum;
-
- unless ( $self->sum_usage ) {
- @call_details = ($cdr->downstream_csv(
- 'format' => $output_format,
- 'granularity' => $cdr->rated_granularity,
- 'seconds' =>($use_duration ? $cdr->duration : $cdr->billsec),
- 'charge' => $cdr->rated_price,
- 'pretty_dst' => $cdr->rated_pretty_dst,
- 'dst_regionname' => $cdr->rated_regionname,
- ));
- }
-
-
- } elsif ( $rating_method eq 'upstream_simple' ) {
-
- $classnum = $cdr->calltypenum; #? meaningful these days?
-
- @call_details = ($cdr->downstream_csv(
- 'format' => $output_format,
- 'charge' => $cdr->rated_price,
- ));
-
- } elsif ( $rating_method eq 'single_price' ) {
-
- my $granularity = length($self->option_cacheable('sec_granularity'))
- ? $self->option_cacheable('sec_granularity')
- : 60;
-
- @call_details = ($cdr->downstream_csv(
- 'format' => $output_format,
- 'charge' => $cdr->rated_price,
- 'seconds' => ($use_duration ? $cdr->duration : $cdr->billsec),
- 'granularity' => $granularity,
- ));
-
- } else {
- die "don't know how to rate CDRs using method: $rating_method\n";
- }
-
+ # at this point we officially Do Not Care about the rating method
$charges += $cdr->rated_price;
-
- #if ( $cdr->rated_price > 0 ) {
- # generate a detail record for every call; filter out
- # $cdr->rated_price == 0 # later.
- my $call_details;
- my $phonenum = $svc_x->phonenum;
-
- if ( scalar(@call_details) == 1 ) {
- $call_details =
- { format => 'C',
- detail => $call_details[0],
- amount => $cdr->rated_price,
- classnum => $classnum,
- phonenum => $phonenum,
- accountcode => $cdr->accountcode,
- startdate => $cdr->startdate,
- duration => $cdr->rated_seconds,
- regionname => $cdr->rated_regionname,
- };
- } else { #only used for $rating_method eq 'upstream' now
- # and for sum_ formats
- $csv->combine(@call_details);
- $call_details =
- { format => 'C',
- detail => $csv->string,
- amount => $cdr->rated_price,
- classnum => $classnum,
- phonenum => $phonenum,
- accountcode => $cdr->accountcode,
- startdate => $cdr->startdate,
- duration => $cdr->rated_seconds,
- regionname => $cdr->rated_regionname,
- };
- }
- $call_details->{'ratename'} = $cdr->rated_ratename;
-
- push @invoice_details_sort, [ $call_details, $cdr->calldate_unix ];
- #} $charge > 0
-
- my $error = $cdr->set_status('done');
- die $error if $error; #??
-
- }
-
- if ( !$self->sum_usage ) {
- #sort them
- my @sorted_invoice_details =
- sort { @{$a}[1] <=> @{$b}[1] } @invoice_details_sort;
- foreach my $sorted_call_detail ( @sorted_invoice_details ) {
- my $d = $sorted_call_detail->[0];
- push @$details, $d if $d->{amount} > 0;
- }
+ $formatter->append($cdr);
}
- else { #$self->sum_usage
- push @$details, $self->sum_detail($svc_x, \@invoice_details_sort);
}
- } # $cust_svc
- unshift @$details, { format => 'C',
- detail => FS::cdr::invoice_header($output_format),
- }
- if @$details && $rating_method ne 'upstream';
+ $formatter->finish; #writes into $details
+ unshift @$details, $formatter->header if @$details;
$charges;
}
@@ -629,51 +530,6 @@
$self->option('output_format') =~ /^sum_/;
}
-sub sum_detail {
- my $self = shift;
- my $svc_x = shift;
- my $invoice_details = shift || [];
- return () if !@$invoice_details;
- my $details_by_rate = {};
- # combine the entire set of CDRs
- foreach ( @$invoice_details ) {
- my $d = $_->[0];
- my $sum = $details_by_rate->{ $d->{ratename} } ||= {
- amount => 0,
- format => 'C',
- classnum => '', #XXX
- duration => 0,
- phonenum => $svc_x->phonenum,
- accountcode => '', #XXX
- startdate => '', #XXX
- regionname => '',
- count => 0,
- };
- $sum->{amount} += $d->{amount};
- $sum->{duration} += $d->{duration};
- $sum->{count}++;
- }
- my @details;
- foreach my $ratename ( sort keys(%$details_by_rate) ) {
- my $sum = $details_by_rate->{$ratename};
- next if $sum->{count} == 0;
- my $total_cdr = FS::cdr->new({
- 'billsec' => $sum->{duration},
- 'src' => $sum->{phonenum},
- });
- $sum->{detail} = $total_cdr->downstream_csv(
- format => $self->option('output_format'),
- seconds => $sum->{duration},
- charge => sprintf('%.2f',$sum->{amount}),
- ratename => $ratename,
- phonenum => $sum->{phonenum},
- count => $sum->{count},
- );
- push @details, $sum;
- }
- @details;
-}
-
# and whether cust_bill should show a detail line for the service label
# (separate from usage details)
sub hide_svc_detail {
Index: voip_tiered.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/voip_tiered.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -d -r1.4 -r1.5
--- voip_tiered.pm 21 Dec 2011 02:56:56 -0000 1.4
+++ voip_tiered.pm 3 Jan 2012 21:13:33 -0000 1.5
@@ -191,10 +191,9 @@
my $output_format = $self->option('output_format', 'Hush!') || 'default';
- my $csv = new Text::CSV_XS;
+ my $formatter = FS::detail_format->new($output_format, buffer => $details);
my $charges = 0;
- my @invoice_details_sort;
$options{'status'} = 'processing-tiered';
@@ -211,6 +210,8 @@
foreach my $pass (split('_', $cdr_inout)) {
$options{'inbound'} = ( $pass eq 'inbound' );
+ # tell the formatter what we're sending it
+ $formatter->inbound($options{'inbound'});
foreach my $cdr (
$svc_x->get_cdrs( %options )
@@ -227,31 +228,6 @@
if ( $charge > 0 ) {
$charges += $charge;
-
- my $detail = $self->sum_usage ? '' :
- $cdr->downstream_csv( 'format' => $output_format,
- 'charge' => $charge,
- 'seconds' => ($use_duration ?
- $cdr->duration :
- $cdr->billsec),
- 'granularity' => $granularity,
- );
-
- my $call_details =
- { format => 'C',
- detail => $detail,
- amount => $charge,
- #classnum => $cdr->calltypenum, #classnum
- #phonenum => $phonenum, #XXX need this to sort on them
- accountcode => $cdr->accountcode,
- startdate => $cdr->startdate,
- duration => $object->rated_seconds,
- };
-
- #warn " adding details on charge to invoice: [ ".
- # join(', ', @{$call_details} ). " ]"
- # if ( $DEBUG && ref($call_details) );
- push @invoice_details_sort, [ $call_details, $cdr->calldate_unix ];
}
my $error = $cdr->set_status_and_rated_price(
@@ -264,32 +240,16 @@
);
die $error if $error;
+ $formatter->append($cdr);
+
} # $cdr
} # $pass
- if ( $self->sum_usage ) {
- # then summarize all accumulated details within this svc_x
- # and then flush them
- push @$details, $self->sum_detail($svc_x, \@invoice_details_sort);
- @invoice_details_sort = ();
- }
-
} # $cust_svc
- if ( !$self->sum_usage ) {
- #sort them
- my @sorted_invoice_details =
- sort { ${$a}[1] <=> ${$b}[1] } @invoice_details_sort;
- foreach my $sorted_call_detail ( @sorted_invoice_details ) {
- push @$details, ${$sorted_call_detail}[0];
- }
- }
-
- unshift @$details, { format => 'C',
- detail => FS::cdr::invoice_header($output_format),
- }
- if @$details;
+ $formatter->finish;
+ unshift @$details, $formatter->header if @$details;
$charges;
}
- Previous message: [freeside-commits] freeside/FS/FS/detail_format accountcode_default.pm, NONE, 1.1 basic.pm, NONE, 1.1 default.pm, NONE, 1.1 description_default.pm, NONE, 1.1 simple2.pm, NONE, 1.1 simple.pm, NONE, 1.1 source_default.pm, NONE, 1.1 sum_count.pm, NONE, 1.1 sum_duration.pm, NONE, 1.1 sum_duration_prefix.pm, NONE, 1.1
- Next message: [freeside-commits] freeside/FS/FS cdr.pm,1.84,1.85
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the freeside-commits
mailing list