1 <& elements/search.html,
5 'count_query' => $count_query,
6 'header' => [ emt('#'),
21 #emt('Reason'), # hard to do this right
22 FS::UI::Web::cust_header(
23 $cgi->param('cust_fields')
25 #emt('Services'), # even harder
34 sub { sprintf( $money_char.'%.2f',
35 shift->part_pkg->option('setup_fee'),
39 sprintf( $money_char.'%.2f',
40 $c->part_pkg->base_recur($c)
43 sub { FS::part_pkg::freq_pretty(shift); },
45 ( map { time_or_blank($_) }
46 qw( setup last_bill bill susp change_date cancel ) ),
48 \&FS::UI::Web::cust_fields,
52 ('') x 5, # can use as-is
53 ('') x 3, # can't use at all
54 # use the plain SQL column names
55 qw( setup last_bill bill susp change_date cancel ),
56 # cust_fields can take care of themselves
60 FS::UI::Web::cust_colors(),
62 'style' => [ ('') x 15,
63 FS::UI::Web::cust_styles() ],
64 'size' => [ '', '', '', '', '-1' ],
65 'align' => 'rrlcccrrlrrrrrr'. FS::UI::Web::cust_aligns(). 'r',
71 ( map { $_ ne 'Cust. Status' ? $clink : '' }
72 FS::UI::Web::cust_header(
73 $cgi->param('cust_fields')
80 'active' => 'Active packages as of ',
81 'setup' => 'Packages started between ',
82 'cancel' => 'Packages canceled between ',
83 'susp' => 'Packages suspended between ',
84 'unsusp' => 'Packages unsuspended between ',
89 my $curuser = $FS::CurrentUser::CurrentUser;
92 unless $curuser->access_right('List packages');
94 my $conf = new FS::Conf;
95 my $money_char = $conf->config('money_char') || '$';
99 # pass a very limited set of parameters through
101 for (qw( agentnum zip ))
103 $search_hash{$_} = $cgi->param($_) if length($cgi->param($_));
106 #arrays / comma-separated lists
107 for my $param (qw( pkgpart classnum refnum towernum )) {
108 my @values = map { split(',') } $cgi->param($param);
109 $search_hash{$param} = \@values if scalar(@values);
113 # do not pass dates to FS::cust_pkg->search; use the special churn_fromwhere
117 my $pkg_query = FS::cust_pkg->search(\%search_hash);
118 #warn Dumper $pkg_query;
120 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
121 my $status = $cgi->param('status');
123 my $title = emt($title{$status}) .
124 time2str('%b %o %Y', $beginning);
125 if ($status ne 'active') {
126 $title .= emt(' to ') . time2str('%b %o %Y', $ending);
129 my ($from, @where) = FS::h_cust_pkg->churn_fromwhere_sql($status, $beginning, $ending);
131 push @where, "freq != '0'";
133 # split off the primary table name
134 $from =~ s/^(\w+)(.*)$/$2/s;
137 # merge with $pkg_query
138 $from .= ' ' . $pkg_query->{addl_from};
141 if ($pkg_query->{extra_sql}) {
142 $extra_sql = $pkg_query->{extra_sql} . ' AND ';
144 $extra_sql = 'WHERE ';
146 $extra_sql .= join(' AND ', @where);
150 'addl_from' => $from,
151 'extra_sql' => $extra_sql,
153 warn (Dumper $sql_query) if $cgi->param('debug');
155 my $count_query = "SELECT COUNT(*) FROM $table $from $extra_sql";
157 my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
163 my $frag = 'cust_pkg'. $self->pkgnum; #hack for IE ignoring real #fragment
164 [ "${p}view/cust_main.cgi?custnum=".$self->custnum.
165 "$show;fragment=$frag#cust_pkg",
171 my $cust_pkg = shift;
172 $cust_pkg->cust_main_custnum
173 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
181 my $value = $record->get($column); #mmm closures
182 $value ? time2str('%b %d %Y', $value ) : '';