X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fbrowse%2Fpart_pkg.cgi;h=0afa54750f89cc29a2edb8886790157b2ff710e3;hp=e6454639f612e7a92066b90bb4b973a0a8e7f1f4;hb=1a033848671cad2cbe7687b37fc718b3b2a68b83;hpb=303cb4ce4b6ce634e108e3b7a0b43086a5e4f184
diff --git a/httemplate/browse/part_pkg.cgi b/httemplate/browse/part_pkg.cgi
index e6454639f..0afa54750 100755
--- a/httemplate/browse/part_pkg.cgi
+++ b/httemplate/browse/part_pkg.cgi
@@ -1,169 +1,236 @@
-
<%
-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';
+
+ $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');
-%>
-<%= include("/elements/header.html","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() %>
-
- >Package |
- Comment |
-<% if ( $cgi->param('active') ) { %>
- Customer packages |
-<% } %>
- Freq. |
-<% if ( $taxclasses ) { %>
- Taxclass |
-<% } %>
- Plan |
- Data |
- Service |
- Quan. |
-<% if ( dbdef->table('pkg_svc')->column('primary_svc') ) { %>
- Primary |
-<% } %>
-
-
+my $html_init;
+unless ( $cgi->param('active') ) {
+ $html_init = qq!
+ 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
+
+ !;
+}
-<%
-foreach my $part_pkg ( sort $sortby @part_pkg ) {
- my @pkg_svc = $part_pkg->pkg_svc;
- my($rowspan)=scalar(@pkg_svc);
- my $plandata;
- if ( $part_pkg->plan ) {
- $plandata = $part_pkg->plandata;
- $plandata =~ s/^(\w+)=/$1 /mg;
- $plandata =~ s/\n/
/g;
- } else {
- $part_pkg->plan('(legacy)');
- $plandata = "Setup ". $part_pkg->setup.
- "
Recur ". $part_pkg->recur;
- }
-%>
-
- ><%= $part_pkg->pkgpart %> |
-
-<% unless ( $cgi->param('showdisabled') ) { %>
- >
- <% if ( $part_pkg->disabled ) { %>
- DISABLED
- <% } %>
- |
-<% } %>
-
- ><%= $part_pkg->pkg %> |
- ><%= $part_pkg->comment %> |
-
-<% if ( $cgi->param('active') ) { %>
- >
- <%= $num_active_cust_pkg{$part_pkg->pkgpart} %> active
-
- <% $suspended_sth->execute( $part_pkg->pkgpart )
- or die $suspended_sth->errstr;
- my $num_suspended = $suspended_sth->fetchrow_arrayref->[0];
- %>
- <%= $num_suspended %> suspended
-
- <% $canceled_sth->execute( $part_pkg->pkgpart )
- or die $canceled_sth->errstr;
- my $num_canceled = $canceled_sth->fetchrow_arrayref->[0];
- %>
- <%= $num_canceled %> canceled
- |
-<% } %>
-
- ><%= $part_pkg->freq_pretty %> |
-
-<% if ( $taxclasses ) { %>
- ><%= $part_pkg->taxclass || ' ' %> |
-<% } %>
-
- ><%= $part_pkg->plan %> |
- ><%= $plandata %> |
+my $posttotal;
+if ( $cgi->param('showdisabled') ) {
+ $cgi->param('showdisabled', 0);
+ $posttotal = '( hide disabled packages )';
+} else {
+ $cgi->param('showdisabled', 1);
+ $posttotal = '( show disabled packages )';
+}
-<%
- my($n)="";
- foreach my $pkg_svc ( @pkg_svc ) {
- my($svcpart)=$pkg_svc->getfield('svcpart');
- my($part_svc) = qsearchs('part_svc',{'svcpart'=> $svcpart });
- print $n,qq!!,
- $part_svc->getfield('svc')," | ",
- $pkg_svc->getfield('quantity')," | ";
- if ( dbdef->table('pkg_svc')->column('primary_svc') ) {
- print '';
- print 'PRIMARY' if $pkg_svc->primary_svc =~ /^Y/i;
- print ' | ';
- }
- print "
\n";
- $n="";
- }
-%>
+# ------
+
+my $link = [ $p.'edit/part_pkg.cgi?', 'pkgpart' ];
+
+my @header = ( '#', 'Package', 'Comment' );
+my @fields = ( 'pkgpart', 'pkg', 'comment' );
+my $align = 'rll';
+my @links = ( $link, $link, '' );
+my @style = ( '', '', '' );
+
+unless ( $cgi->param('showdisabled') ) { #its been reversed already
+ push @header, 'Status';
+ push @fields, sub { shift->disabled
+ ? 'DISABLED'
+ : 'Active'
+ };
+ push @links, '';
+ $align .= 'c';
+ push @style, 'b';
+}
+
+unless ( 0 ) { #already showing only one class or something?
+ push @header, 'Class';
+ push @fields, sub { shift->classname || '(none)'; };
+ $align .= 'l';
+}
+
+if ( $cgi->param('active') ) {
+ push @header, 'Customer
packages';
+ my %col = (
+ 'active' => '00CC00',
+ 'suspended' => 'FF9900',
+ 'cancelled' => 'FF0000',
+ );
+ my $cust_pkg_link = $p. 'search/cust_pkg.cgi?pkgpart=';
+ push @fields, sub { my $part_pkg = shift;
+ [
+ map {
+ [
+ {
+ 'data' => ''.
+ $part_pkg->get("num_$_").
+ '',
+ 'align' => 'right',
+ },
+ {
+ 'data' => $_,
+ 'align' => 'left',
+ 'link' => ( $part_pkg->get("num_$_")
+ ? $cust_pkg_link.
+ $part_pkg->pkgpart.
+ ";magic=$_"
+ : ''
+ ),
+ },
+ ],
+ } (qw( active suspended cancelled ))
+ ]; };
+ $align .= 'r';
+}
-
-<% } %>
+push @header, 'Frequency';
+push @fields, sub { shift->freq_pretty; };
+$align .= 'l';
-
-