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_colors(),
49 FS::UI::Web::cust_styles(),
51 'align' => 'r'. FS::UI::Web::cust_aligns(). 'rrrrrr',
54 ( map { $_ ne 'Cust. Status' ? $clink : '' }
55 FS::UI::Web::cust_header(
56 $cgi->param('cust_fields')
64 my $curuser = $FS::CurrentUser::CurrentUser;
67 unless $curuser->access_right('List customers');
69 my($speriod, $eperiod) = FS::UI::Web::parse_beginning_ending($cgi);
70 my $start_date = time2str('%b %o, %Y', $speriod);
71 my $end_date = time2str('%b %o, %Y', $eperiod);
74 if ($cgi->param('agentnum') =~ /^(\d+)$/) {
78 # can't use this directly as it doesn't have any cust_main fields.
79 my $churn = FS::cust_main::Status->churn_sql($speriod, $eperiod);
82 'table' => 'cust_main',
83 'select' => 'cust_main.*, churn.*',
84 'addl_from' => " JOIN ($churn) AS churn USING (custnum) ",
86 my $count_query = "SELECT COUNT(*) FROM cust_main JOIN ($churn) AS churn USING (custnum)";
89 my $status = $cgi->param('status');
91 if ( $status eq 'active' ) {
92 $title = "Customers active on $start_date";
93 push @where, "s_active > 0";
94 } elsif ( $status eq 'started' ) {
95 $title = "Customers starting service, $start_date - $end_date";
96 push @where, "s_active = 0 and e_active > 0";
97 } elsif ( $status eq 'suspended' ) {
98 $title = "Customers suspended, $start_date - $end_date";
99 push @where, "s_active > 0 and e_active = 0 and e_suspended > 0";
100 } elsif ( $status eq 'resumed' ) {
101 $title = "Customers resuming service, $start_date - $end_date";
102 push @where, "s_active = 0 and s_suspended > 0 and e_active > 0";
103 } elsif ( $status eq 'cancelled' ) {
104 $title = "Customers cancelled, $start_date - $end_date";
105 push @where, "s_active > 0 and e_active = 0 and e_suspended = 0";
109 push @where, "agentnum = $agentnum";
113 my $where = " WHERE ". join(' AND ', @where);
114 $query->{extra_sql} = $where;
115 $count_query .= $where;
118 my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];