X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_bill.pm;h=9d250eba375aa0419958c850dc3c033fa5c6a269;hp=dd8fab231fb58e63e3b0ce7f457cb10b2f18f3d9;hb=c15077a092c6b194923b72d9baaa50573c1ececb;hpb=a1cde9ea31bf9f019ecf706efb158c2baa11efa7 diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index dd8fab231..9d250eba3 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -245,6 +245,7 @@ sub delete { cust_pay_batch cust_bill_pay_batch cust_bill_pkg + cust_bill_batch )) { foreach my $linked ( $self->$table() ) { @@ -683,8 +684,8 @@ sub cust_bill_pay_pkg { 'table' => 'cust_bill_pay_pkg', 'addl_from' => ' LEFT JOIN cust_bill_pay USING ( billpaynum ) '. ' LEFT JOIN cust_bill_pkg USING ( billpkgnum ) ', - 'extra_sql' => ' WHERE invnum = '. $self->invnum. - " AND pkgnum = $pkgnum", + 'extra_sql' => ' WHERE cust_bill_pkg.invnum = '. $self->invnum. + " AND cust_bill_pkg.pkgnum = $pkgnum", }); } @@ -727,12 +728,23 @@ sub cust_credit_bill_pkg { 'table' => 'cust_credit_bill_pkg', 'addl_from' => ' LEFT JOIN cust_credit_bill USING ( creditbillnum ) '. ' LEFT JOIN cust_bill_pkg USING ( billpkgnum ) ', - 'extra_sql' => ' WHERE invnum = '. $self->invnum. - " AND pkgnum = $pkgnum", + 'extra_sql' => ' WHERE cust_bill_pkg.invnum = '. $self->invnum. + " AND cust_bill_pkg.pkgnum = $pkgnum", }); } +=item cust_bill_batch + +Returns all invoice batch records (L) for this invoice. + +=cut + +sub cust_bill_batch { + my $self = shift; + qsearch('cust_bill_batch', { 'invnum' => $self->invnum }); +} + =item tax Returns the tax amount (see L) for this invoice. @@ -2553,6 +2565,7 @@ sub print_generic { #invoice from info 'company_name' => scalar( $conf->config('company_name', $agentnum) ), 'company_address' => join("\n", $conf->config('company_address', $agentnum) ). "\n", + 'company_phonenum'=> scalar( $conf->config('company_phonenum', $agentnum) ), 'returnaddress' => $returnaddress, 'agent' => &$escape_function($cust_main->agent->agent), @@ -2828,6 +2841,14 @@ sub print_generic { push @{$late_sections}, @$phone_sections; push @detail_items, @$phone_lines; } + if ($conf->exists('voip-cust_accountcode_cdr') && $cust_main->accountcode_cdr) { + my ($accountcode_section, $accountcode_lines) = + $self->_items_accountcode_cdr($escape_function_nonbsp,$format); + if ( scalar(@$accountcode_lines) ) { + push @{$late_sections}, $accountcode_section; + push @detail_items, @$accountcode_lines; + } + } }else{ push @sections, { 'description' => '', 'subtotal' => '' }; } @@ -2865,7 +2886,7 @@ sub print_generic { } } - + if ( @pr_cust_bill && !$conf->exists('disable_previous_balance') ) { push @buf, ['','-----------']; push @buf, [ 'Total Previous Balance', @@ -2878,12 +2899,11 @@ sub print_generic { if $DEBUG > 1; my ($didsummary,$minutes) = $self->_did_summary; - my $didsummary_desc = 'DID Activity Summary (Past 30 days)'; + my $didsummary_desc = 'DID Activity Summary (since last invoice)'; push @detail_items, { 'description' => $didsummary_desc, 'ext_description' => [ $didsummary, $minutes ], - } - if !$multisection; + }; } foreach my $section (@sections, @$late_sections) { @@ -3344,7 +3364,7 @@ sub print_ps { my ($file, $logofile, $barcodefile) = $self->print_latex(@_); my $ps = generate_ps($file); unlink($logofile); - unlink($barcodefile); + unlink($barcodefile) if $barcodefile; $ps; } @@ -3373,7 +3393,7 @@ sub print_pdf { my ($file, $logofile, $barcodefile) = $self->print_latex(@_); my $pdf = generate_pdf($file); unlink($logofile); - unlink($barcodefile); + unlink($barcodefile) if $barcodefile; $pdf; } @@ -3696,7 +3716,7 @@ sub _items_sections { } } @sections; push @early, @$extra_sections if $extra_sections; - + sort { $a->{sort_weight} <=> $b->{sort_weight} } @early; } @@ -4061,7 +4081,12 @@ sub _items_extra_usage_sections { sub _did_summary { my $self = shift; my $end = $self->_date; - my $start = $end - 2592000; # 30 days + + # start at date of previous invoice + 1 second or 0 if no previous invoice + my $start = $self->scalar_sql("SELECT max(_date) FROM cust_bill WHERE custnum = ? and invnum != ?",$self->custnum,$self->invnum); + $start = 0 if !$start; + $start++; + my $cust_main = $self->cust_main; my @pkgs = $cust_main->all_pkgs; my($num_activated,$num_deactivated,$num_portedin,$num_portedout,$minutes) @@ -4124,6 +4149,75 @@ 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' => '', + '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 => [], + }; + + $section->{'amount'} += $amount; + $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; + } + + my @sorted_lines = sort { $a->{'description'} <=> $b->{'description'} } @lines; + + return ($section,\@sorted_lines); +} + sub _items_svc_phone_sections { my $self = shift; my $escape = shift; @@ -4480,23 +4574,10 @@ sub _items_cust_bill_pkg { foreach my $cust_bill_pkg ( @$cust_bill_pkgs ) { - warn "$me _items_cust_bill_pkg considering cust_bill_pkg $cust_bill_pkg\n" + warn "$me _items_cust_bill_pkg considering cust_bill_pkg ". + $cust_bill_pkg->billpkgnum. ", pkgnum ". $cust_bill_pkg->pkgnum. "\n" if $DEBUG > 1; - $discount_show_always = ($cust_bill_pkg->cust_bill_pkg_discount - && $conf->exists('discount-show-always')); - - foreach ( $s, $r, ($opt{skip_usage} ? () : $u ) ) { - if ( $_ && !$cust_bill_pkg->hidden ) { - $_->{amount} = sprintf( "%.2f", $_->{amount} ), - $_->{amount} =~ s/^\-0\.00$/0.00/; - $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ), - push @b, { %$_ } - unless ( $_->{amount} == 0 && !$discount_show_always ); - $_ = undef; - } - } - foreach my $display ( grep { defined($section) ? $_->section eq $section : 1 @@ -4575,9 +4656,13 @@ sub _items_cust_bill_pkg { } - if ( ( $cust_bill_pkg->recur != 0 || $cust_bill_pkg->setup == 0 || - ($discount_show_always && $cust_bill_pkg->recur == 0) ) && - ( !$type || $type eq 'R' || $type eq 'U' ) + if ( ( !$type || $type eq 'R' || $type eq 'U' ) + && ( + $cust_bill_pkg->recur != 0 + || $cust_bill_pkg->setup == 0 + || $discount_show_always + || $cust_bill_pkg->recur_show_zero + ) ) { @@ -4694,7 +4779,6 @@ sub _items_cust_bill_pkg { ext_description => \@d, }; } - } } # recurring or usage with recurring charge @@ -4723,21 +4807,38 @@ sub _items_cust_bill_pkg { } + $discount_show_always = ($cust_bill_pkg->cust_bill_pkg_discount + && $conf->exists('discount-show-always')); + + foreach ( $s, $r, ($opt{skip_usage} ? () : $u ) ) { + if ( $_ && !$cust_bill_pkg->hidden ) { + $_->{amount} = sprintf( "%.2f", $_->{amount} ), + $_->{amount} =~ s/^\-0\.00$/0.00/; + $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ), + push @b, { %$_ } + if $_->{amount} != 0 + || $discount_show_always + || $cust_bill_pkg->recur_show_zero; + $_ = undef; + } + } + } + #foreach ( $s, $r, ($opt{skip_usage} ? () : $u ) ) { + # if ( $_ ) { + # $_->{amount} = sprintf( "%.2f", $_->{amount} ), + # $_->{amount} =~ s/^\-0\.00$/0.00/; + # $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ), + # push @b, { %$_ } + # if $_->{amount} != 0 + # || $discount_show_always + # } + #} + warn "$me _items_cust_bill_pkg done considering cust_bill_pkgs\n" if $DEBUG > 1; - foreach ( $s, $r, ($opt{skip_usage} ? () : $u ) ) { - if ( $_ ) { - $_->{amount} = sprintf( "%.2f", $_->{amount} ), - $_->{amount} =~ s/^\-0\.00$/0.00/; - $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ), - push @b, { %$_ } - unless ( $_->{amount} == 0 && !$discount_show_always ); - } - } - @b; }