<% my %search; if ( $cgi->param('showdisabled') ) { %search = (); } else { %search = ( 'disabled' => '' ); } my @part_pkg = qsearch('part_pkg', \%search ); my $total = scalar(@part_pkg); 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 )!; } else { $cgi->param('showdisabled', 1); print qq!( show disabled packages )!; } my $colspan = $cgi->param('showdisabled') ? 2 : 3; print &table(), < Package Comment END print ' Customer
packages
' if $cgi->param('active'); print <Freq. Plan Data Service Quan. END print 'Primary' if dbdef->table('pkg_svc')->column('primary_svc'); print ''; 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} }); my($rowspan)=scalar(@pkg_svc); my $plandata; if ( $hashref->{plan} ) { $plandata = $hashref->{plandata}; $plandata =~ s/^(\w+)=/$1 /mg; $plandata =~ s/\n/
/g; } else { $hashref->{plan} = "(legacy)"; $plandata = "Setup ". $hashref->{setup}. "
Recur ". $hashref->{recur}; } print < $hashref->{pkgpart} END unless ( $cgi->param('showdisabled') ) { print ""; print "DISABLED" if $hashref->{disabled}; print ''; } 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 END my($pkg_svc); my($n)=""; foreach $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=""; } print ""; } $colspan = $cgi->param('showdisabled') ? 8 : 9; print < END sub pkgpart_sort { $a->pkgpart <=> $b->pkgpart; } %>