X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_bill.pm;h=9cce591d464c2964ea91a96caf630aea46ab1f4f;hb=26755cb13672400adb5a7f8bda76eac5244a93b4;hp=e44747b8a36ec387429198a0eb4c1e7ca5f75808;hpb=b9d2d7f2c80e5e89358bba0b2c3ba1de9f406c82;p=freeside.git diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index e44747b8a..9cce591d4 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -2515,6 +2515,21 @@ sub print_generic { 'total_pages' => 1, ); + + my $min_sdate = 999999999999; + my $max_edate = 0; + foreach my $cust_bill_pkg ( $self->cust_bill_pkg ) { + next unless $cust_bill_pkg->pkgnum > 0; + $min_sdate = $cust_bill_pkg->sdate + if length($cust_bill_pkg->sdate) && $cust_bill_pkg->sdate < $min_sdate; + $max_edate = $cust_bill_pkg->edate + if length($cust_bill_pkg->edate) && $cust_bill_pkg->edate > $max_edate; + } + + $invoice_data{'bill_period'} = ''; + $invoice_data{'bill_period'} = time2str('%e %h', $min_sdate) + . " to " . time2str('%e %h', $max_edate) + if ($max_edate != 0 && $min_sdate != 999999999999); $invoice_data{finance_section} = ''; if ( $conf->config('finance_pkgclass') ) { @@ -4143,6 +4158,85 @@ sub _items_svc_phone_sections { push @lines, $l; } } + + if($conf->exists('phone_usage_class_summary')) { + # this only works with Latex + my @newlines; + my @newsections; + + # after this, we'll have only two sections per DID: + # Calls Summary and Calls Detail + foreach my $section ( @sections ) { + if($section->{'post_total'}) { + $section->{'description'} = 'Calls Summary: '.$section->{'phonenum'}; + $section->{'total_line_generator'} = sub { '' }; + $section->{'total_generator'} = sub { '' }; + $section->{'header_generator'} = sub { '' }; + $section->{'description_generator'} = ''; + push @newsections, $section; + my %calls_detail = %$section; + $calls_detail{'post_total'} = ''; + $calls_detail{'sort_weight'} = ''; + $calls_detail{'description_generator'} = sub { '' }; + $calls_detail{'header_generator'} = sub { + return ' & Date/Time & Called Number & Duration & Price' + if $format eq 'latex'; + ''; + }; + $calls_detail{'description'} = 'Calls Detail: ' + . $section->{'phonenum'}; + push @newsections, \%calls_detail; + } + } + + # after this, each usage class is collapsed/summarized into a single + # line under the Calls Summary section + foreach my $newsection ( @newsections ) { + if($newsection->{'post_total'}) { # this means Calls Summary + foreach my $section ( @sections ) { + next unless ($section->{'phonenum'} eq $newsection->{'phonenum'} + && !$section->{'post_total'}); + my $newdesc = $section->{'description'}; + my $tn = $section->{'phonenum'}; + $newdesc =~ s/$tn//g; + my $line = { ext_description => [], + pkgnum => '', + ref => '', + quantity => '', + calls => $section->{'calls'}, + section => $newsection, + duration => $section->{'duration'}, + description => $newdesc, + amount => sprintf("%.2f",$section->{'amount'}), + product_code => 'N/A', + }; + push @newlines, $line; + } + } + } + + # after this, Calls Details is populated with all CDRs + foreach my $newsection ( @newsections ) { + if(!$newsection->{'post_total'}) { # this means Calls Details + foreach my $line ( @lines ) { + next unless (scalar(@{$line->{'ext_description'}}) && + $line->{'section'}->{'phonenum'} eq $newsection->{'phonenum'} + ); + my @extdesc = @{$line->{'ext_description'}}; + my @newextdesc; + foreach my $extdesc ( @extdesc ) { + $extdesc =~ s/scriptsize/normalsize/g if $format eq 'latex'; + push @newextdesc, $extdesc; + } + $line->{'ext_description'} = \@newextdesc; + $line->{'section'} = $newsection; + push @newlines, $line; + } + } + } + + return(\@newsections, \@newlines); + } return(\@sections, \@lines);