X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fbrowse%2Fpart_pkg.cgi;h=48b0ab2b3c80a6ed6f1e76d4d4005586c03ecb5a;hp=ef6a446203f5751fb24f8ae36e0a9bd944a66532;hb=6fe8172b11d0369d0b1274d6825ec0c57afe8001;hpb=3d671921441ba8422650b54435a1959ad1d4c71d diff --git a/httemplate/browse/part_pkg.cgi b/httemplate/browse/part_pkg.cgi index ef6a44620..48b0ab2b3 100755 --- a/httemplate/browse/part_pkg.cgi +++ b/httemplate/browse/part_pkg.cgi @@ -1,59 +1,150 @@ + <% -# - -use strict; -use vars qw( $cgi $p $part_pkg ); -use CGI; -use CGI::Carp qw(fatalsToBrowser); -use FS::UID qw(cgisuidsetup swapuid); -use FS::Record qw(qsearch qsearchs); -use FS::CGI qw(header menubar popurl table); -use FS::part_pkg; -use FS::pkg_svc; -use FS::part_svc; - -$cgi = new CGI; - -&cgisuidsetup($cgi); - -$p = popurl(2); - -print $cgi->header( '-expires' => 'now' ), header("Package Part Listing",menubar( - 'Main Menu' => $p, -)), "One or more services are grouped together into a package and given", - " pricing information. Customers purchase packages, not services.

", - &table(), < + +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 = sub { $a->pkgpart <=> $b->pkgpart; }; +} + +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() %> - Package + >Package Comment - Setup Fee +<% if ( $cgi->param('active') ) { %> + Customer
packages
+<% } %> Freq. - Recur. Fee +<% if ( $taxclasses ) { %> + Taxclass +<% } %> + Plan + Data Service Quan. +<% if ( dbdef->table('pkg_svc')->column('primary_svc') ) { %> + Primary +<% } %> + -END -foreach $part_pkg ( sort { - $a->getfield('pkgpart') <=> $b->getfield('pkgpart') -} qsearch('part_pkg',{}) ) { - my($hashref)=$part_pkg->hashref; +<% +foreach my $part_pkg ( sort $sortby @part_pkg ) { my(@pkg_svc)=grep $_->getfield('quantity'), - qsearch('pkg_svc',{'pkgpart'=> $hashref->{pkgpart} }); + qsearch( 'pkg_svc', { 'pkgpart' => $part_pkg->pkgpart } ); my($rowspan)=scalar(@pkg_svc); - print <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; + } +%> - - $hashref->{pkgpart} - - $hashref->{pkg} - $hashref->{comment} - $hashref->{setup} - $hashref->{freq} - $hashref->{recur} -END + ><%= $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($pkg_svc); my($n)=""; foreach $pkg_svc ( @pkg_svc ) { @@ -61,17 +152,20 @@ END my($part_svc) = qsearchs('part_svc',{'svcpart'=> $svcpart }); print $n,qq!!, $part_svc->getfield('svc'),"", - $pkg_svc->getfield('quantity'),"\n"; + $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 ""; -} + +<% } %> -print <Add new package -END -%>