X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_bill.pm;h=ba308bebac24aed3037948c9e93f4b678a08f08c;hp=7f162c95c58da187dfda5b3faf8ad461f85f0390;hb=da86d5a8af2f915a340a74f6c97772451a1e23ef;hpb=4fc9163c63678a4fd19ed0b31f25f97cc0ac2748 diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 7f162c95c..ba308beba 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -2433,6 +2433,12 @@ sub print_generic { ); my $embolden_function = $embolden_functions{$format}; + my %newline_tokens = ( 'latex' => '\\\\', + 'html' => '
', + 'template' => "\n", + ); + my $newline_token = $newline_tokens{$format}; + warn "$me generating template variables\n" if $DEBUG > 1; @@ -2551,8 +2557,10 @@ sub print_generic { 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 $cust_bill_pkg->sdate < $min_sdate; - $max_edate = $cust_bill_pkg->edate if $cust_bill_pkg->edate > $max_edate; + $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'} = ''; @@ -3115,6 +3123,26 @@ sub print_generic { push @buf,[$self->balance_due_msg, $money_char. sprintf("%10.2f", $balance_due ) ]; } + + if ( $conf->exists('previous_balance-show_credit') + and $cust_main->balance < 0 ) { + my $credit_total = { + 'total_item' => &$embolden_function($self->credit_balance_msg), + 'total_amount' => &$embolden_function( + $other_money_char. sprintf('%.2f', -$cust_main->balance) + ), + }; + if ( $multisection ) { + $adjust_section->{'posttotal'} .= $newline_token . + $credit_total->{'total_item'} . ' ' . $credit_total->{'total_amount'}; + } + else { + push @total_items, $credit_total; + } + push @buf,['','-----------']; + push @buf,[$self->credit_balance_msg, $money_char. + sprintf("%10.2f", -$cust_main->balance ) ]; + } } if ( $multisection ) { @@ -3474,6 +3502,8 @@ sub balance_due_date { $duedate; } +sub credit_balance_msg { 'Credit Balance Remaining' } + =item invnum_date_pretty Returns a string with the invoice number and date, for example: @@ -4192,6 +4222,9 @@ sub _items_svc_phone_sections { # 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'}; @@ -4214,8 +4247,11 @@ sub _items_svc_phone_sections { 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'}) { + if($newsection->{'post_total'}) { # this means Calls Summary foreach my $section ( @sections ) { next unless ($section->{'phonenum'} eq $newsection->{'phonenum'} && !$section->{'post_total'}); @@ -4230,28 +4266,34 @@ sub _items_svc_phone_sections { section => $newsection, duration => $section->{'duration'}, description => $newdesc, - amount => $section->{'amount'}, + 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'}) { + 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 $extdesc = $extdesc[0]; - $extdesc =~ s/scriptsize/normalsize/g if $format eq 'latex'; - $line->{'ext_description'} = [ $extdesc ]; + 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); } @@ -4540,7 +4582,7 @@ sub _items_cust_bill_pkg { if $DEBUG > 1; push @d, $cust_bill_pkg->details(%details_opt) - unless ($is_summary || $type && $type eq 'R'); + unless $is_summary; # || ($type && $type eq 'R'); warn "$me _items_cust_bill_pkg calculating amount\n" if $DEBUG > 1;