2 my $curuser = $FS::CurrentUser::CurrentUser;
3 die 'access denied' unless $curuser->access_right('List packages');
6 'contract_end' => 'Contract end',
7 # We could put any of the date fields in cust_pkg in here, but keep in
9 # - for start_date, setup, and bill, make sure to include rows where
10 # the field is null, as that's effectively "right now".
11 # - for cancel and susp, and maybe expire, adjourn, and resume, add a
12 # column for the cancel or suspend reason.
13 # - for expire, also figure out if there's a future change scheduled.
14 # - for change_date, should probably show what it was changed from.
17 my $col = $cgi->param('date');
18 die "invalid date column" unless $cols{$col};
20 my $title = 'Packages by ' . lc($cols{$col}) . ' date';
21 # second option on the cust_fields_avail list, plus email
22 my $cust_fields = 'Cust# | Customer | Day phone | Night phone | Mobile phone | Invoicing email(s)';
23 my @header = ( $cols{$col},
27 # anything else? package status, maybe?
29 my @fields = ( sub { time2str('%b %d %Y', $_[0]->$col) },
34 my @sort_fields = ( map '', @fields ); # should only ever sort by $col
36 push @header, FS::UI::Web::cust_header($cust_fields);
37 push @fields, \&FS::UI::Web::cust_fields;
39 my $agentnums_sql = $curuser->agentnums_sql('table' => 'cust_main');
42 'table' => 'cust_pkg',
43 'addl_from' => FS::UI::Web::join_cust_main('cust_pkg', 'cust_pkg'),
45 $col => { op => '!=', value => '' },
48 'extra_sql' => ' AND '.$agentnums_sql,
49 'order_by' => "ORDER BY $col",
53 "SELECT COUNT(*) FROM cust_pkg JOIN cust_main USING (custnum) ".
54 "WHERE $col IS NOT NULL AND cancel IS NULL AND $agentnums_sql";
58 my $frag = 'cust_pkg'. $self->pkgnum;
59 [ "${p}view/cust_main.cgi?custnum=".$self->custnum.
60 ";show=packages;fragment=$frag#cust_pkg",
65 my @links = ( '', ($pkg_link) x 3,
66 FS::UI::Web::cust_links() );
68 my $date_color_sub = sub {
71 my $interval = ($self->$col - time) / 86400;
72 if ( $interval > 30 ) {
74 } elsif ( $interval > 0 ) {
79 "background-color: $color";
83 <& elements/search.html,
87 'count_query' => $count_query,
90 'align' => 'rrrl'. FS::UI::Web::cust_aligns(),
92 'cell_style' => [ $date_color_sub ],