X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fbrowse%2Fpart_pkg.cgi;h=b67a5e55f96d3a8d5ed43550c77eb1afc87aa423;hb=8af88c7428552043516f529007645ab489b32063;hp=48b0ab2b3c80a6ed6f1e76d4d4005586c03ecb5a;hpb=6fe8172b11d0369d0b1274d6825ec0c57afe8001;p=freeside.git
diff --git a/httemplate/browse/part_pkg.cgi b/httemplate/browse/part_pkg.cgi
index 48b0ab2b3..b67a5e55f 100755
--- a/httemplate/browse/part_pkg.cgi
+++ b/httemplate/browse/part_pkg.cgi
@@ -1,171 +1,240 @@
-
<%
-my %search;
-if ( $cgi->param('showdisabled') ) {
- %search = ();
-} else {
+my %search = ();
+my $search = '';
+unless ( $cgi->param('showdisabled') ) {
%search = ( 'disabled' => '' );
+ $search = "( disabled = '' OR disabled IS NULL )";
}
-my @part_pkg = qsearch('part_pkg', \%search );
-my $total = scalar(@part_pkg);
-
-my $sortby;
-my %num_active_cust_pkg = ();
-my( $suspended_sth, $canceled_sth ) = ( '', '' );
+my $select = '*';
+my $orderby = 'pkgpart';
if ( $cgi->param('active') ) {
- my $active_sth = dbh->prepare(
- 'SELECT COUNT(*) FROM cust_pkg WHERE pkgpart = ?'.
- ' AND ( cancel IS NULL OR cancel = 0 )'.
- ' AND ( susp IS NULL OR susp = 0 )'
- ) or die dbh->errstr;
- foreach my $part_pkg ( @part_pkg ) {
- $active_sth->execute($part_pkg->pkgpart) or die $active_sth->errstr;
- $num_active_cust_pkg{$part_pkg->pkgpart} =
- $active_sth->fetchrow_arrayref->[0];
- }
- $sortby = sub {
- $num_active_cust_pkg{$b->pkgpart} <=> $num_active_cust_pkg{$a->pkgpart};
- };
-
- $suspended_sth = dbh->prepare(
- 'SELECT COUNT(*) FROM cust_pkg WHERE pkgpart = ?'.
- ' AND ( cancel IS NULL OR cancel = 0 )'.
- ' AND susp IS NOT NULL AND susp != 0'
- ) or die dbh->errstr;
-
- $canceled_sth = dbh->prepare(
- 'SELECT COUNT(*) FROM cust_pkg WHERE pkgpart = ?'.
- ' AND cancel IS NOT NULL AND cancel != 0'
- ) or die dbh->errstr;
-} else {
- $sortby = sub { $a->pkgpart <=> $b->pkgpart; };
+ $orderby = 'num_active DESC';
}
+ $select = "
+
+ *,
+
+ ( SELECT COUNT(*) FROM cust_pkg WHERE cust_pkg.pkgpart = part_pkg.pkgpart
+ AND ( cancel IS NULL OR cancel = 0 )
+ AND ( susp IS NULL OR susp = 0 )
+ ) AS num_active,
+
+ ( SELECT COUNT(*) FROM cust_pkg WHERE cust_pkg.pkgpart = part_pkg.pkgpart
+ AND ( cancel IS NULL OR cancel = 0 )
+ AND susp IS NOT NULL AND susp != 0
+ ) AS num_suspended,
+
+ ( SELECT COUNT(*) FROM cust_pkg WHERE cust_pkg.pkgpart = part_pkg.pkgpart
+ AND cancel IS NOT NULL AND cancel != 0
+ ) AS num_cancelled
+
+ ";
+
+#}
my $conf = new FS::Conf;
my $taxclasses = $conf->exists('enable_taxclasses');
-%>
-<%= header("Package Definition Listing",menubar( 'Main Menu' => $p )) %>
-<% unless ( $cgi->param('active') ) { %>
- One or more service definitions are grouped together into a package
- definition and given pricing information. Customers purchase packages
- rather than purchase services directly.
- Add a new package definition
-
-<% } %>
-
-<%= $total %> package definitions
-<% if ( $cgi->param('showdisabled') ) { $cgi->param('showdisabled', 0); %>
- ( hide disabled packages )
-<% } else { $cgi->param('showdisabled', 1); %>
- ( show disabled packages )
-<% } %>
-
-<% my $colspan = $cgi->param('showdisabled') ? 2 : 3; %>
-
-<%= &table() %>
-