X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=httemplate%2Fbrowse%2Fpart_pkg.cgi;h=efaa59e00c602e7062c2a2f921525237ca42de6d;hb=bb6dfc07af5c7fee85f2c76ee22a833b41e13c36;hp=c20811491308b11c8697f57262fb441a1a3a6319;hpb=3162b06a6d3be9ddf4daea2c29cd94516ac40f68;p=freeside.git diff --git a/httemplate/browse/part_pkg.cgi b/httemplate/browse/part_pkg.cgi index c20811491..efaa59e00 100755 --- a/httemplate/browse/part_pkg.cgi +++ b/httemplate/browse/part_pkg.cgi @@ -11,13 +11,51 @@ if ( $cgi->param('showdisabled') ) { my @part_pkg = qsearch('part_pkg', \%search ); my $total = scalar(@part_pkg); -print header("Package Definition Listing",menubar( - 'Main Menu' => $p, -)). "One or more services are grouped together into a package and given". - " pricing information. Customers purchase packages". - " rather than purchase services directly.

". - "$total packages "; +my $sortby; +my %num_active_cust_pkg = (); +my( $suspended_sth, $canceled_sth ) = ( '', '' ); +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 = \*pkgpart_sort; +} +%> +<%= 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); print qq!( hide disabled packages )!; @@ -31,6 +69,10 @@ print &table(), < Package Comment +END +print ' Customer
packages
' + if $cgi->param('active'); +print <Freq. Plan Data @@ -39,9 +81,7 @@ print &table(), < END -foreach my $part_pkg ( sort { - $a->getfield('pkgpart') <=> $b->getfield('pkgpart') -} @part_pkg ) { +foreach my $part_pkg ( sort $sortby @part_pkg ) { my($hashref)=$part_pkg->hashref; my(@pkg_svc)=grep $_->getfield('quantity'), qsearch('pkg_svc',{'pkgpart'=> $hashref->{pkgpart} }); @@ -70,6 +110,27 @@ END print <$hashref->{pkg} $hashref->{comment} +END + if ( $cgi->param('active') ) { + print " "; + print ''. + $num_active_cust_pkg{$hashref->{'pkgpart'}}. + qq! active
!; + + $suspended_sth->execute( $part_pkg->pkgpart ) or die $suspended_sth->errstr; + my $num_suspended = $suspended_sth->fetchrow_arrayref->[0]; + print ''. $num_suspended. + qq! suspended
!; + + $canceled_sth->execute( $part_pkg->pkgpart ) or die $canceled_sth->errstr; + my $num_canceled = $canceled_sth->fetchrow_arrayref->[0]; + print ''. $num_canceled. + qq! canceled!; + + + print ''; + } + print <$hashref->{freq} $hashref->{plan} $plandata @@ -91,9 +152,14 @@ END $colspan = $cgi->param('showdisabled') ? 8 : 9; print <Add a new package definition + END + +sub pkgpart_sort { + $a->pkgpart <=> $b->pkgpart; +} + %>