From: levinse Date: Thu, 28 Apr 2011 00:59:40 +0000 (+0000) Subject: taqua accountcode billing, part 2 of 2, RT12181 X-Git-Tag: freeside_2_3_0~326 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=2705b64bb669ba94492a185410e8d67f6ea82edd taqua accountcode billing, part 2 of 2, RT12181 --- diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index ba5ca2467..3f94796c6 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -2830,7 +2830,10 @@ sub print_generic { push @detail_items, @$phone_lines; } if ($conf->exists('voip-cust_accountcode_cdr') && $cust_main->accountcode_cdr) { - # XXX: do something not unlike _items_svc_phone_sections, except generate only one section + my ($accountcode_section, $accountcode_lines) = + $self->_items_accountcode_cdr($escape_function_nonbsp,$format); + push @{$late_sections}, $accountcode_section; + push @detail_items, @$accountcode_lines; } }else{ push @sections, { 'description' => '', 'subtotal' => '' }; @@ -4133,6 +4136,73 @@ sub _did_summary { "Total Minutes: $minutes"); } +sub _items_accountcode_cdr { + my $self = shift; + my $escape = shift; + my $format = shift; + + my $section = { 'amount' => 0, + 'calls' => 0, + 'duration' => 0, + 'sort_weight' => '', + 'phonenum' => '', + 'description' => 'Usage by Account Code', + 'post_total' => '', + 'summarized' => '', + 'total_generator' => sub { '' }, + 'header' => '', + }; + my @lines; + my %accountcodes = (); + + foreach my $cust_bill_pkg ( $self->cust_bill_pkg ) { + next unless $cust_bill_pkg->pkgnum > 0; + + my @header = $cust_bill_pkg->details_header; + next unless scalar(@header); + $section->{'header'} = join(',',@header); + + foreach my $detail ( $cust_bill_pkg->cust_bill_pkg_detail ) { + + $section->{'header'} = $detail->formatted('format' => $format) + if($detail->detail eq $section->{'header'}); + + my $accountcode = $detail->accountcode; + next unless $accountcode; + + my $amount = $detail->amount; + next unless $amount && $amount > 0; + + $accountcodes{$accountcode} ||= { + description => $accountcode, + pkgnum => '', + ref => '', + amount => 0, + calls => 0, + duration => 0, + quantity => '', + product_code => 'N/A', + section => $section, + ext_description => [], + }; + + $accountcodes{$accountcode}{'amount'} += $amount; + $accountcodes{$accountcode}{calls}++; + $accountcodes{$accountcode}{duration} += $detail->duration; + push @{$accountcodes{$accountcode}{ext_description}}, + $detail->formatted('format' => $format); + } + } + + foreach my $l ( values %accountcodes ) { + $l->{amount} = sprintf( "%.2f", $l->{amount} ); + unshift @{$l->{ext_description}}, $section->{'header'}; + push @lines, $l; + } + + return ($section,\@lines); +} + sub _items_svc_phone_sections { my $self = shift; my $escape = shift;