6 ( select sum(amount) from cust_bill_pay
7 where cust_bill.invnum = cust_bill_pay.invnum )
11 ( select sum(amount) from cust_credit_bill
12 where cust_bill.invnum = cust_credit_bill.invnum )
19 my $owed_cols = <<END;
21 ( select $charged from cust_bill
22 where cust_bill._date > extract(epoch from now())-2592000
23 and cust_main.custnum = cust_bill.custnum
29 ( select $charged from cust_bill
30 where cust_bill._date > extract(epoch from now())-5184000
31 and cust_bill._date <= extract(epoch from now())-2592000
32 and cust_main.custnum = cust_bill.custnum
38 ( select $charged from cust_bill
39 where cust_bill._date > extract(epoch from now())-7776000
40 and cust_bill._date <= extract(epoch from now())-5184000
41 and cust_main.custnum = cust_bill.custnum
47 ( select $charged from cust_bill
48 where cust_bill._date <= extract(epoch from now())-7776000
49 and cust_main.custnum = cust_bill.custnum
55 ( select $charged from cust_bill
56 where cust_main.custnum = cust_bill.custnum
62 my $recurring = <<END;
63 '0' != ( select freq from part_pkg
64 where cust_pkg.pkgpart = part_pkg.pkgpart )
67 my $packages_cols = <<END;
69 ( select count(*) from cust_pkg
70 where cust_main.custnum = cust_pkg.custnum
72 and ( cancel = 0 or cancel is null )
73 ) as uncancelled_pkgs,
75 ( select count(*) from cust_pkg
76 where cust_main.custnum = cust_pkg.custnum
78 and ( cancel = 0 or cancel is null )
79 and ( susp = 0 or susp is null )
87 ( select $charged from cust_bill
88 where cust_main.custnum = cust_bill.custnum
94 my $count_sql = "select count(*) from cust_main $where";
97 'table' => 'cust_main',
99 'select' => "*, $owed_cols, $packages_cols",
100 'extra_sql' => "$where order by coalesce(lower(company), ''), lower(last)",
103 my $total_sql = "select $owed_cols";
104 my $total_sth = dbh->prepare($total_sql) or die dbh->errstr;
105 $total_sth->execute or die $total_sth->errstr;
106 my $row = $total_sth->fetchrow_hashref();
108 my $conf = new FS::Conf;
109 my $money_char = $conf->config('money_char') || '$';
111 %><%= include( 'elements/search.html',
112 'title' => 'Accounts Receivable Aging Summary',
113 'name' => 'customers',
114 'query' => $sql_query,
115 'count_query' => $count_sql,
120 'Status (cust_main)',
132 sprintf( $money_char.'%.2f',
133 $row->{'owed_0_30'} ),
134 sprintf( $money_char.'%.2f',
135 $row->{'owed_30_60'} ),
136 sprintf( $money_char.'%.2f',
137 $row->{'owed_60_90'} ),
138 sprintf( $money_char.'%.2f',
139 $row->{'owed_90_pl'} ),
140 sprintf( '<b>'. $money_char.'%.2f'. '</b>',
141 $row->{'owed_total'} ),
143 'align' => 'rlccrrrrr',
144 'size' => [ '', '', '-1', '-1', '', '', '', '', '', ],
145 'style' => [ '', '', 'b', 'b', '', '', '', '', 'b', ],
151 my $status = 'Cancelled';
152 my $statuscol = 'FF0000';
153 if ( $row->uncancelled_pkgs ) {
154 $status = 'Suspended';
155 $statuscol = 'FF9900';
156 if ( $row->active_pkgs ) {
158 $statuscol = '00CC00';
163 sub { shift->statuscolor; },
175 my $status = 'Cancelled';
176 my $statuscol = 'FF0000';
177 if ( $row->uncancelled_pkgs ) {
178 $status = 'Suspended';
179 $statuscol = 'FF9900';
180 if ( $row->active_pkgs ) {
182 $statuscol = '00CC00';
187 sub { ucfirst(shift->status) },
188 sub { sprintf( $money_char.'%.2f',
189 shift->get('owed_0_30') ) },
190 sub { sprintf( $money_char.'%.2f',
191 shift->get('owed_30_60') ) },
192 sub { sprintf( $money_char.'%.2f',
193 shift->get('owed_60_90') ) },
194 sub { sprintf( $money_char.'%.2f',
195 shift->get('owed_90_pl') ) },
196 sub { sprintf( $money_char.'%.2f',
197 shift->get('owed_total') ) },