1 <% include('/elements/header.html', $title) %>
2 <% include('/elements/table-grid.html') %>
5 <TH CLASS="grid" BGCOLOR="#cccccc"><% $_ %></TH>
9 % foreach my $row (@rows) {
12 <TD CLASS="grid" ALIGN="right" BGCOLOR="<% $r % 2 ? '#ffffff' : '#eeeeee' %>"><% $_ %></TD>
19 <TD CLASS="grid" ALIGN="right" BGCOLOR="<% $r % 2 ? '#ffffff' : '#eeeeee' %>"><B><% $_ %></B></TD>
25 unless $FS::CurrentUser::CurrentUser->access_right('List packages');
27 my $title = 'Package Summary Report';
28 my ($begin, $end) = FS::UI::Web::parse_beginning_ending($cgi);
31 $cgi->param('beginning').' - '.$cgi->param('ending').')';
34 my @h_sql = FS::h_cust_pkg->sql_h_search($end);
36 my ($end_sql, $addl_from) = @h_sql[1,3];
37 $end_sql =~ s/ORDER BY.*//; # breaks aggregate queries
39 my $begin_sql = $end_sql;
40 $begin_sql =~ s/$end/$begin/g;
42 my $active_sql = FS::cust_pkg->active_sql;
43 my $suspended_sql = FS::cust_pkg->suspended_sql;
45 # SQL WHERE clauses for each column of the table.
46 " $begin_sql AND ($active_sql OR $suspended_sql)",
48 " $end_sql AND ($active_sql OR $suspended_sql)",
49 " $end_sql AND $active_sql",
50 " $end_sql AND $suspended_sql",
53 $_ =~ s/\bcust_pkg/maintable/g foreach @conds;
55 my @head = ('Package', 'Before Period', 'Sales', 'Total', 'Active', 'Suspended');
57 my @totals = ('Total', 0, 0, 0, 0, 0);
64 foreach my $part_pkg (qsearch('part_pkg', {} )) {
66 next if !$part_pkg->freq; # exclude one-time packages
67 push @row, $part_pkg->pkg;
69 foreach my $cond (@conds) {
71 my $result = qsearchs({
72 'table' => 'h_cust_pkg',
74 'select' => 'count(*)',
75 'addl_from' => $addl_from,
76 'extra_sql' => 'WHERE pkgpart = '.$part_pkg->pkgpart.$cond,
78 $row[$i] = $result->getfield('count');
79 $totals[$i] += $row[$i];
83 $row[2] = $row[3]-$row[1];
84 $totals[2] += $row[2];