1 <& elements/search.html,
5 'count_query' => $count_query,
6 'header' => [ emt('#'),
7 FS::UI::Web::cust_header(
8 $cgi->param('cust_fields')
10 { label => "Packages on $start_date", colspan => 3 },
13 { label => "Packages on $end_date", colspan => 3 },
18 map({ '' } (FS::UI::Web::cust_header())),
28 \&FS::UI::Web::cust_fields,
38 FS::UI::Web::cust_sql_fields,
48 FS::UI::Web::cust_colors(),
59 FS::UI::Web::cust_styles(),
61 'align' => 'r'. FS::UI::Web::cust_aligns(). 'rrrrrr',
64 ( map { $_ ne 'Cust. Status' ? $clink : '' }
65 FS::UI::Web::cust_header(
66 $cgi->param('cust_fields')
74 my $curuser = $FS::CurrentUser::CurrentUser;
77 unless $curuser->access_right('List customers');
79 my($speriod, $eperiod) = FS::UI::Web::parse_beginning_ending($cgi);
80 my $start_date = time2str('%b %o, %Y', $speriod);
81 my $end_date = time2str('%b %o, %Y', $eperiod);
84 if ($cgi->param('agentnum') =~ /^(\d+)$/) {
88 # can't use this directly as it doesn't have any cust_main fields.
89 my $churn = FS::cust_main::Status->churn_sql($speriod, $eperiod);
90 my $select = join(',',
93 FS::UI::Web::cust_sql_fields()
96 my $addl_from = " JOIN ($churn) AS churn USING (custnum) ".
97 FS::UI::Web::join_cust_main('cust_main.custnum') ;
99 'table' => 'cust_main',
101 'addl_from' => $addl_from,
103 my $count_query = "SELECT COUNT(*) FROM cust_main $addl_from";
106 my $status = $cgi->param('status');
108 if ( $status eq 'active' ) {
109 $title = "Customers active on $start_date";
110 push @where, "s_active > 0";
111 } elsif ( $status eq 'started' ) {
112 $title = "Customers starting service, $start_date - $end_date";
113 push @where, "s_active = 0 and e_active > 0";
114 } elsif ( $status eq 'suspended' ) {
115 $title = "Customers suspended, $start_date - $end_date";
116 push @where, "s_active > 0 and e_active = 0 and e_suspended > 0";
117 } elsif ( $status eq 'resumed' ) {
118 $title = "Customers resuming service, $start_date - $end_date";
119 push @where, "s_active = 0 and s_suspended > 0 and e_active > 0";
120 } elsif ( $status eq 'cancelled' ) {
121 $title = "Customers cancelled, $start_date - $end_date";
122 push @where, "s_active > 0 and e_active = 0 and e_suspended = 0";
126 push @where, "agentnum = $agentnum";
130 my $where = " WHERE ". join(' AND ', @where);
131 $query->{extra_sql} = $where;
132 $count_query .= $where;
135 my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];