7 ( select sum(amount) from cust_bill_pay
8 where cust_bill.invnum = cust_bill_pay.invnum )
12 ( select sum(amount) from cust_credit_bill
13 where cust_bill.invnum = cust_credit_bill.invnum )
20 my $owed_cols = <<END;
22 ( select $charged from cust_bill
23 where cust_bill._date > extract(epoch from now())-2592000
24 and cust_main.custnum = cust_bill.custnum
30 ( select $charged from cust_bill
31 where cust_bill._date > extract(epoch from now())-5184000
32 and cust_bill._date <= extract(epoch from now())-2592000
33 and cust_main.custnum = cust_bill.custnum
39 ( select $charged from cust_bill
40 where cust_bill._date > extract(epoch from now())-7776000
41 and cust_bill._date <= extract(epoch from now())-5184000
42 and cust_main.custnum = cust_bill.custnum
48 ( select $charged from cust_bill
49 where cust_bill._date <= extract(epoch from now())-7776000
50 and cust_main.custnum = cust_bill.custnum
56 ( select $charged from cust_bill
57 where cust_main.custnum = cust_bill.custnum
63 my $recurring = <<END;
64 0 < ( select freq from part_pkg
65 where cust_pkg.pkgpart = part_pkg.pkgpart )
68 my $packages_cols = <<END;
70 ( select count(*) from cust_pkg
71 where cust_main.custnum = cust_pkg.custnum
73 and ( cancel = 0 or cancel is null )
74 ) as uncancelled_pkgs,
76 ( select count(*) from cust_pkg
77 where cust_main.custnum = cust_pkg.custnum
79 and ( cancel = 0 or cancel is null )
80 and ( susp = 0 or susp is null )
87 select *, $owed_cols, $packages_cols from cust_main
90 ( select $charged from cust_bill
91 where cust_main.custnum = cust_bill.custnum
96 order by coalesce(lower(company), ''), lower(last)
100 my $total_sql = "select $owed_cols";
102 my $sth = dbh->prepare($sql) or die dbh->errstr;
103 $sth->execute or die $sth->errstr;
105 my $total_sth = dbh->prepare($total_sql) or die dbh->errstr;
106 $total_sth->execute or die $total_sth->errstr;
109 <%= header('Accounts Receivable Aging Summary', menubar( 'Main Menu'=>$p, ) ) %>
120 <% while ( my $row = $sth->fetchrow_hashref() ) {
121 my $status = 'Cancelled';
122 my $statuscol = 'FF0000';
123 if ( $row->{uncancelled_pkgs} ) {
124 $status = 'Suspended';
125 $statuscol = 'FF9900';
126 if ( $row->{active_pkgs} ) {
128 $statuscol = '00CC00';
133 <TD><A HREF="<%= $p %>view/cust_main.cgi?<%= $row->{'custnum'} %>"><%= $row->{'custnum'} %>:
134 <%= $row->{'company'} ? $row->{'company'}. ' (' : '' %><%= $row->{'last'}. ', '. $row->{'first'} %><%= $row->{'company'} ? ')' : '' %></A>
136 <TD><B><FONT SIZE=-1 COLOR="#<%= $statuscol %>"><%= $status %></FONT></B></TD>
137 <TD ALIGN="right">$<%= sprintf("%.2f", $row->{'owed_0_30'} ) %></TD>
138 <TD ALIGN="right">$<%= sprintf("%.2f", $row->{'owed_30_60'} ) %></TD>
139 <TD ALIGN="right">$<%= sprintf("%.2f", $row->{'owed_60_90'} ) %></TD>
140 <TD ALIGN="right">$<%= sprintf("%.2f", $row->{'owed_90_plus'} ) %></TD>
141 <TD ALIGN="right"><B>$<%= sprintf("%.2f", $row->{'owed_total'} ) %></B></TD>
144 <% my $row = $total_sth->fetchrow_hashref(); %>
146 <TD COLSPAN=6> </TD>
149 <TD COLSPAN=2><I>Total</I></TD>
150 <TD ALIGN="right"><I>$<%= sprintf("%.2f", $row->{'owed_0_30'} ) %></TD>
151 <TD ALIGN="right"><I>$<%= sprintf("%.2f", $row->{'owed_30_60'} ) %></TD>
152 <TD ALIGN="right"><I>$<%= sprintf("%.2f", $row->{'owed_60_90'} ) %></TD>
153 <TD ALIGN="right"><I>$<%= sprintf("%.2f", $row->{'owed_90_plus'} ) %></TD>
154 <TD ALIGN="right"><I><B>$<%= sprintf("%.2f", $row->{'owed_total'} ) %></B></I></TD>