X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FTemplate_Mixin.pm;h=346e78167c1e96e1792fa13b0a67cd022b103c39;hb=be2a6e7068337aa57b04bd7fa88090002d79a64b;hp=05972c0b76c0eabaff48ff70dc98755d4380d643;hpb=8dd41f364aaba88969dfd0908feb22709025e7f6;p=freeside.git diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm index 05972c0b7..346e78167 100644 --- a/FS/FS/Template_Mixin.pm +++ b/FS/FS/Template_Mixin.pm @@ -702,25 +702,24 @@ sub print_generic { # "balance_date_range" unfortunately is unsuitable for this, since it # cares about application dates. We want to know the sum of all # _top-level transactions_ dated before the last invoice. - my @sql = ( - 'SELECT SUM(charged) FROM cust_bill WHERE _date <= ? AND custnum = ?', - 'SELECT -1*SUM(amount) FROM cust_credit WHERE _date <= ? AND custnum = ?', - 'SELECT -1*SUM(paid) FROM cust_pay WHERE _date <= ? AND custnum = ?', - 'SELECT SUM(refund) FROM cust_refund WHERE _date <= ? AND custnum = ?', - ); + my @sql = + map "$_ WHERE _date <= ? AND custnum = ?", ( + "SELECT COALESCE( SUM(charged), 0 ) FROM cust_bill", + "SELECT -1 * COALESCE( SUM(amount), 0 ) FROM cust_credit", + "SELECT -1 * COALESCE( SUM(paid), 0 ) FROM cust_pay", + "SELECT COALESCE( SUM(refund), 0 ) FROM cust_refund", + ); # the customer's current balance immediately after generating the last # bill my $last_bill_balance = $last_bill->charged; foreach (@sql) { - #warn "$_\n"; my $delta = FS::Record->scalar_sql( $_, $last_bill->_date - 1, $self->custnum, ); - #warn "$delta\n"; $last_bill_balance += $delta; } @@ -739,13 +738,11 @@ sub print_generic { # to immediately before this one my $before_this_bill_balance = 0; foreach (@sql) { - #warn "$_\n"; my $delta = FS::Record->scalar_sql( $_, $self->_date - 1, $self->custnum, ); - #warn "$delta\n"; $before_this_bill_balance += $delta; } $invoice_data{'balance_adjustments'} = @@ -2729,7 +2726,7 @@ sub _items_cust_bill_pkg { 'pkgnum' => $cust_bill_pkg->pkgpart, #so it displays in Ref 'description' => $description, 'amount' => sprintf("%.2f", $cust_bill_pkg->setup), - 'unit_amount' => sprintf("%.2f", $cust_bill_pkg->unitsetup), + 'unit_amount' => sprintf("%.2f", $cust_bill_pkg->unitsetup), 'quantity' => $cust_bill_pkg->quantity, 'preref_html' => ( $opt{preref_callback} ? &{ $opt{preref_callback} }( $cust_bill_pkg ) @@ -2742,9 +2739,9 @@ sub _items_cust_bill_pkg { 'pkgnum' => $cust_bill_pkg->pkgpart, #so it displays in Ref 'description' => "$desc (". $cust_bill_pkg->part_pkg->freq_pretty.")", 'amount' => sprintf("%.2f", $cust_bill_pkg->recur), - 'unit_amount' => sprintf("%.2f", $cust_bill_pkg->unitrecur), + 'unit_amount' => sprintf("%.2f", $cust_bill_pkg->unitrecur), 'quantity' => $cust_bill_pkg->quantity, - 'preref_html' => ( $opt{preref_callback} + 'preref_html' => ( $opt{preref_callback} ? &{ $opt{preref_callback} }( $cust_bill_pkg ) : '' ),