X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main.pm;h=501fca45abc9ac05a80abbb6720e537103a8db75;hb=3b53cfb49162c9a1f32027b67ba4cbe86d65d3e5;hp=b5a8f0d2e51b869354203a84dae752d3b8ca3cfb;hpb=e1578c35520ffb7676a4f1fb2b285ce6020db4b6;p=freeside.git diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index b5a8f0d2e..501fca45a 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -2717,6 +2717,23 @@ sub bill { $tax = sprintf('%.2f', $tax ); $total_setup = sprintf('%.2f', $total_setup+$tax ); + my $pkg_category = qsearchs( 'pkg_category', { 'categoryname' => $taxname, + 'disabled' => '', + }, + ); + + my @display = (); + if ( $pkg_category and + $conf->config('invoice_latexsummary') || + $conf->config('invoice_htmlsummary') + ) + { + + my %hash = ( 'section' => $pkg_category->categoryname ); + push @display, new FS::cust_bill_pkg_display { type => 'S', %hash }; + + } + push @cust_bill_pkg, new FS::cust_bill_pkg { 'pkgnum' => 0, 'setup' => $tax, @@ -2724,6 +2741,7 @@ sub bill { 'sdate' => '', 'edate' => '', 'itemdesc' => $taxname, + 'display' => \@display, 'cust_bill_pkg_tax_location' => \@cust_bill_pkg_tax_location, 'cust_bill_pkg_tax_rate_location' => \@cust_bill_pkg_tax_rate_location, }; @@ -2761,11 +2779,24 @@ sub bill { my $charged = sprintf('%.2f', $total_setup + $total_recur ); + my @cust_bill = $self->cust_bill; + my $balance = $self->balance; + my $previous_balance = scalar(@cust_bill) + ? $cust_bill[$#cust_bill]->billing_balance + : 0; + + $previous_balance += $cust_bill[$#cust_bill]->charged + if scalar(@cust_bill); + #my $balance_adjustments = + # sprintf('%.2f', $balance - $prior_prior_balance - $prior_charged); + #create the new invoice my $cust_bill = new FS::cust_bill ( { - 'custnum' => $self->custnum, - '_date' => ( $invoice_time ), - 'charged' => $charged, + 'custnum' => $self->custnum, + '_date' => ( $invoice_time ), + 'charged' => $charged, + 'billing_balance' => $balance, + 'previous_balance' => $previous_balance, } ); $error = $cust_bill->insert; if ( $error ) { @@ -3116,7 +3147,9 @@ sub _handle_taxes { } my @display = (); - if ( $conf->exists('separate_usage') || $cust_bill_pkg->hidden ) { + my $separate = $conf->exists('separate_usage'); + my $usage_mandate = $cust_pkg->part_pkg->option('usage_mandate', 'Hush!'); + if ( $separate || $cust_bill_pkg->hidden || $usage_mandate ) { my $temp_pkg = new FS::cust_pkg { pkgpart => $real_pkgpart }; my %hash = $cust_bill_pkg->hidden # maybe for all bill linked? @@ -3125,18 +3158,28 @@ sub _handle_taxes { my $section = $cust_pkg->part_pkg->option('usage_section', 'Hush!'); my $summary = $cust_pkg->part_pkg->option('summarize_usage', 'Hush!'); - push @display, new FS::cust_bill_pkg_display { type => 'S', %hash }; - push @display, new FS::cust_bill_pkg_display { type => 'R', %hash }; + if ( $separate ) { + push @display, new FS::cust_bill_pkg_display { type => 'S', %hash }; + push @display, new FS::cust_bill_pkg_display { type => 'R', %hash }; + } else { + push @display, new FS::cust_bill_pkg_display + { type => '', + %hash, + ( ( $usage_mandate ) ? ( 'summary' => 'Y' ) : () ), + }; + } - if ($section && $summary) { + if ($separate && $section && $summary) { push @display, new FS::cust_bill_pkg_display { type => 'U', summary => 'Y', %hash, }; + } + if ($usage_mandate || $section && $summary) { $hash{post_total} = 'Y'; } - $hash{section} = $section if $conf->exists('separate_usage'); + $hash{section} = $section if ($separate || $usage_mandate); push @display, new FS::cust_bill_pkg_display { type => 'U', %hash }; }