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
95 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
97 $where .= " AND agentnum = '$agentnum' ";
100 my $count_sql = "select count(*) from cust_main $where";
103 'table' => 'cust_main',
105 'select' => "*, $owed_cols, $packages_cols",
106 'extra_sql' => "$where order by coalesce(lower(company), ''), lower(last)",
111 s/cust_bill\.custnum/cust_bill.custnum AND cust_main.agentnum = '$agentnum'/g;
113 my $total_sql = "select $owed_cols";
114 my $total_sth = dbh->prepare($total_sql) or die dbh->errstr;
115 $total_sth->execute or die $total_sth->errstr;
116 my $row = $total_sth->fetchrow_hashref();
118 my $conf = new FS::Conf;
119 my $money_char = $conf->config('money_char') || '$';
121 my $align = join('', map { /#/ ? 'r' : 'l' } FS::UI::Web::cust_header() ).
124 my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];
126 %><%= include( 'elements/search.html',
127 'title' => 'Accounts Receivable Aging Summary',
128 'name' => 'customers',
129 'query' => $sql_query,
130 'count_query' => $count_sql,
132 FS::UI::Web::cust_header(),
134 #'Status', # (cust_main)',
145 scalar(FS::UI::Web::cust_header()-1)
150 sprintf( $money_char.'%.2f',
151 $row->{'owed_0_30'} ),
152 sprintf( $money_char.'%.2f',
153 $row->{'owed_30_60'} ),
154 sprintf( $money_char.'%.2f',
155 $row->{'owed_60_90'} ),
156 sprintf( $money_char.'%.2f',
157 $row->{'owed_90_pl'} ),
158 sprintf( '<b>'. $money_char.'%.2f'. '</b>',
159 $row->{'owed_total'} ),
162 \&FS::UI::Web::cust_fields,
165 my $status = 'Cancelled';
166 my $statuscol = 'FF0000';
167 if ( $row->uncancelled_pkgs ) {
168 $status = 'Suspended';
169 $statuscol = 'FF9900';
170 if ( $row->active_pkgs ) {
172 $statuscol = '00CC00';
177 #sub { ucfirst(shift->status) },
178 sub { sprintf( $money_char.'%.2f',
179 shift->get('owed_0_30') ) },
180 sub { sprintf( $money_char.'%.2f',
181 shift->get('owed_30_60') ) },
182 sub { sprintf( $money_char.'%.2f',
183 shift->get('owed_60_90') ) },
184 sub { sprintf( $money_char.'%.2f',
185 shift->get('owed_90_pl') ) },
186 sub { sprintf( $money_char.'%.2f',
187 shift->get('owed_total') ) },
190 ( map $clink, FS::UI::Web::cust_header() ),
199 #'align' => 'rlccrrrrr',
201 #'size' => [ '', '', '-1', '-1', '', '', '', '', '', ],
202 #'style' => [ '', '', 'b', 'b', '', '', '', '', 'b', ],
203 'size' => [ ( map '', FS::UI::Web::cust_header() ),
204 '-1', '', '', '', '', '', ],
205 'style' => [ ( map '', FS::UI::Web::cust_header() ),
206 'b', '', '', '', '', 'b', ],
208 ( map '', FS::UI::Web::cust_header() ),
211 my $status = 'Cancelled';
212 my $statuscol = 'FF0000';
213 if ( $row->uncancelled_pkgs ) {
214 $status = 'Suspended';
215 $statuscol = 'FF9900';
216 if ( $row->active_pkgs ) {
218 $statuscol = '00CC00';
223 #sub { shift->statuscolor; },