X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fbrowse%2Fpart_pkg.cgi;h=766806044848ffc3349d7712cc906ea1c9624e1e;hb=5b73387992a96f7b80e40b5ecb2fedabd8a78d6b;hp=5acf17ef2125e878e028c30bb2e078f465707dd4;hpb=0dd05e9ff98263d2d42b419b1e278a5a3bc594b2;p=freeside.git
diff --git a/httemplate/browse/part_pkg.cgi b/httemplate/browse/part_pkg.cgi
index 5acf17ef2..766806044 100755
--- a/httemplate/browse/part_pkg.cgi
+++ b/httemplate/browse/part_pkg.cgi
@@ -1,65 +1,123 @@
<% include( 'elements/browse.html',
- 'title' => 'Package Definitions',
- 'menubar' => [ 'Main Menu' => $p ],
- 'html_init' => $html_init,
- 'html_posttotal' => $posttotal,
- 'name' => 'package definitions',
- 'query' => { 'select' => $select,
- 'table' => 'part_pkg',
- 'hashref' => \%search,
- 'extra_sql' => "ORDER BY $orderby",
- },
- 'count_query' => $count_query,
- 'header' => \@header,
- 'fields' => \@fields,
- 'links' => \@links,
- 'align' => $align,
- 'style' => \@style,
+ 'title' => 'Package Definitions',
+ 'html_init' => $html_init,
+ 'html_posttotal' => $html_posttotal,
+ 'name' => 'package definitions',
+ 'disableable' => 1,
+ 'disabled_statuspos' => 4,
+ 'agent_virt' => 1,
+ 'agent_null_right' => [ $edit, $edit_global ],
+ 'agent_null_right_link' => $edit_global,
+ 'agent_pos' => 6,
+ 'query' => { 'select' => $select,
+ 'table' => 'part_pkg',
+ 'hashref' => \%hash,
+ 'extra_sql' => $extra_sql,
+ 'order_by' => "ORDER BY $orderby"
+ },
+ 'count_query' => $count_query,
+ 'header' => \@header,
+ 'fields' => \@fields,
+ 'links' => \@links,
+ 'align' => $align,
)
%>
<%init>
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+my $edit = 'Edit package definitions';
+my $edit_global = 'Edit global package definitions';
+my $acl_edit = $curuser->access_right($edit);
+my $acl_edit_global = $curuser->access_right($edit_global);
+my $acl_config = $curuser->access_right('Configuration'); #to edit services
+ #and agent types
+ #and bulk change
+
die "access denied"
- unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
-
-#false laziness w/access_user.html
-my %search = ();
-my $search = '';
-unless ( $cgi->param('showdisabled') ) {
- %search = ( 'disabled' => '' );
- $search = "( disabled = '' OR disabled IS NULL )";
-}
+ unless $acl_edit || $acl_edit_global;
+
+my $conf = new FS::Conf;
+my $taxclasses = $conf->exists('enable_taxclasses');
+my $money_char = $conf->config('money_char') || '$';
my $select = '*';
my $orderby = 'pkgpart';
-if ( $cgi->param('active') ) {
+my %hash = ();
+my $extra_count = '';
+if ( $cgi->param('active') ) {
$orderby = 'num_active DESC';
}
- $select = "
- *,
+my @where = ();
+
+#if ( $cgi->param('activeONLY') ) {
+# push @where, ' WHERE num_active > 0 '; #XXX doesn't affect count...
+#}
+
+if ( $cgi->param('recurring') ) {
+ $hash{'freq'} = { op=>'!=', value=>'0' };
+ $extra_count = " freq != '0' ";
+}
+
+my $classnum = '';
+if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
+ $classnum = $1;
+ push @where, $classnum ? "classnum = $classnum"
+ : "classnum IS NULL";
+}
+$cgi->delete('classnum');
+
+if ( $cgi->param('missing_recur_fee') ) {
+ push @where, "0 = ( SELECT COUNT(*) FROM part_pkg_option
+ WHERE optionname = 'recur_fee'
+ AND part_pkg_option.pkgpart = part_pkg.pkgpart
+ AND CAST( optionvalue AS NUMERIC ) > 0
+ )";
+}
- ( 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,
+push @where, FS::part_pkg->curuser_pkgs_sql
+ unless $acl_edit_global;
- ( 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,
+my $extra_sql = scalar(@where)
+ ? ( scalar(keys %hash) ? ' AND ' : ' WHERE ' ).
+ join( 'AND ', @where)
+ : '';
- ( SELECT COUNT(*) FROM cust_pkg WHERE cust_pkg.pkgpart = part_pkg.pkgpart
- AND cancel IS NOT NULL AND cancel != 0
- ) AS num_cancelled
+my $agentnums_sql = $curuser->agentnums_sql( 'table'=>'cust_main' );
+my $count_cust_pkg = "
+ SELECT COUNT(*) FROM cust_pkg LEFT JOIN cust_main USING ( custnum )
+ WHERE cust_pkg.pkgpart = part_pkg.pkgpart
+ AND $agentnums_sql
+";
- ";
+$select = "
-#}
+ *,
-my $conf = new FS::Conf;
-my $taxclasses = $conf->exists('enable_taxclasses');
+ ( $count_cust_pkg
+ AND ( setup IS NULL OR setup = 0 )
+ AND ( cancel IS NULL OR cancel = 0 )
+ AND ( susp IS NULL OR susp = 0 )
+ ) AS num_not_yet_billed,
+
+ ( $count_cust_pkg
+ AND setup IS NOT NULL AND setup != 0
+ AND ( cancel IS NULL OR cancel = 0 )
+ AND ( susp IS NULL OR susp = 0 )
+ ) AS num_active,
+
+ ( $count_cust_pkg
+ AND ( cancel IS NULL OR cancel = 0 )
+ AND susp IS NOT NULL AND susp != 0
+ ) AS num_suspended,
+
+ ( $count_cust_pkg
+ AND cancel IS NOT NULL AND cancel != 0
+ ) AS num_cancelled
+
+";
my $html_init;
#unless ( $cgi->param('active') ) {
@@ -67,45 +125,60 @@ my $html_init;
One or more service definitions are grouped together into a package
definition and given pricing information. Customers purchase packages
rather than purchase services directly.
+