From 9d3055def8da004cc1b7c7f9b1ce88da3eca3bba Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 6 Nov 2003 14:45:59 +0000 Subject: [PATCH] add totals & simplify expressions --- httemplate/search/report_receivables.cgi | 147 +++++++++---------------------- 1 file changed, 41 insertions(+), 106 deletions(-) diff --git a/httemplate/search/report_receivables.cgi b/httemplate/search/report_receivables.cgi index 1fd7d03c7..d0665164c 100755 --- a/httemplate/search/report_receivables.cgi +++ b/httemplate/search/report_receivables.cgi @@ -1,24 +1,25 @@ <% - my $sql = < extract(epoch from now())-2592000 and cust_main.custnum = cust_bill.custnum ) @@ -26,20 +27,7 @@ select *, ) as owed_0_30, coalesce( - ( select sum( charged - - coalesce( - ( select sum(amount) from cust_bill_pay - where cust_bill.invnum = cust_bill_pay.invnum ) - ,0 - ) - - coalesce( - ( select sum(amount) from cust_credit_bill - where cust_bill.invnum = cust_credit_bill.invnum ) - ,0 - ) - - ) - from cust_bill + ( select $charged from cust_bill where cust_bill._date > extract(epoch from now())-5184000 and cust_bill._date <= extract(epoch from now())-2592000 and cust_main.custnum = cust_bill.custnum @@ -48,20 +36,7 @@ select *, ) as owed_30_60, coalesce( - ( select sum( charged - - coalesce( - ( select sum(amount) from cust_bill_pay - where cust_bill.invnum = cust_bill_pay.invnum ) - ,0 - ) - - coalesce( - ( select sum(amount) from cust_credit_bill - where cust_bill.invnum = cust_credit_bill.invnum ) - ,0 - ) - - ) - from cust_bill + ( select $charged from cust_bill where cust_bill._date > extract(epoch from now())-7776000 and cust_bill._date <= extract(epoch from now())-5184000 and cust_main.custnum = cust_bill.custnum @@ -70,20 +45,7 @@ select *, ) as owed_60_90, coalesce( - ( select sum( charged - - coalesce( - ( select sum(amount) from cust_bill_pay - where cust_bill.invnum = cust_bill_pay.invnum ) - ,0 - ) - - coalesce( - ( select sum(amount) from cust_credit_bill - where cust_bill.invnum = cust_credit_bill.invnum ) - ,0 - ) - - ) - from cust_bill + ( select $charged from cust_bill where cust_bill._date <= extract(epoch from now())-7776000 and cust_main.custnum = cust_bill.custnum ) @@ -91,43 +53,19 @@ select *, ) as owed_90_plus, coalesce( - ( select sum( charged - - coalesce( - ( select sum(amount) from cust_bill_pay - where cust_bill.invnum = cust_bill_pay.invnum ) - ,0 - ) - - coalesce( - ( select sum(amount) from cust_credit_bill - where cust_bill.invnum = cust_credit_bill.invnum ) - ,0 - ) - - ) - from cust_bill + ( select $charged from cust_bill where cust_main.custnum = cust_bill.custnum ) ,0 ) as owed_total +END -from cust_main + my $sql = <company cmp $b->company - # || $a->last cmp $b->last } - # grep { $_->balance } - # qsearch('cust_main', {} ); - - my $totals_table = table(). 'Total'. - '0-30'. - '30-60'. - '60-90'. - '90+'. - 'total'. - ''; - $totals_table = ''; + my $total_sql = "select $owed_cols"; my $sth = dbh->prepare($sql) or die dbh->errstr; $sth->execute or die $sth->errstr; + my $total_sth = dbh->prepare($total_sql) or die dbh->errstr; + $total_sth->execute or die $total_sth->errstr; + %> <%= header('Accounts Receivable Aging Summary', menubar( 'Main Menu'=>$p, ) ) %> -<%= $totals_table %> <%= table() %> Customer @@ -184,7 +108,18 @@ END $<%= sprintf("%.2f", $row->{'owed_total'} ) %> <% } %> +<% my $row = $total_sth->fetchrow_hashref(); %> + +   + + + Total + $<%= sprintf("%.2f", $row->{'owed_0_30'} ) %> + $<%= sprintf("%.2f", $row->{'owed_30_60'} ) %> + $<%= sprintf("%.2f", $row->{'owed_60_90'} ) %> + $<%= sprintf("%.2f", $row->{'owed_90_plus'} ) %> + $<%= sprintf("%.2f", $row->{'owed_total'} ) %> + -<%= $totals_table %> -- 2.11.0