summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2009-03-29 23:44:12 +0000
committerivan <ivan>2009-03-29 23:44:12 +0000
commit75989a32bd20f0ab3d38d2cd2c05795ea9b7590d (patch)
tree077c9fd2771e1271f71daf7b1787adb4a9ee6cb5
parent35e195cdee48f99ca9b6406491696c7cdccb7814 (diff)
hide over 2 (or configured) cancelled and one-time charge packages, RT#5083
-rw-r--r--FS/FS/Conf.pm7
-rwxr-xr-xhttemplate/view/cust_main/packages.html33
2 files changed, 36 insertions, 4 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index b6fea5413..17da9def9 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -2198,6 +2198,13 @@ worry that config_items is freeside-specific and icky.
},
{
+ 'key' => 'cust_main-packages-years',
+ 'section' => 'UI',
+ 'description' => 'Number of years to show old (cancelled and one-time charge) packages by default. Currently defaults to 2.',
+ 'type' => 'text',
+ },
+
+ {
'key' => 'cust_main-use_comments',
'section' => 'UI',
'description' => 'Display free form comments on the customer edit screen. Useful as a scratch pad.',
diff --git a/httemplate/view/cust_main/packages.html b/httemplate/view/cust_main/packages.html
index 72846b8ec..7643e3efd 100755
--- a/httemplate/view/cust_main/packages.html
+++ b/httemplate/view/cust_main/packages.html
@@ -53,6 +53,13 @@ Current packages
cancelled packages</a> )
% }
+% if ( $num_old_packages ) {
+% $cgi->param('showoldpackages', 1);
+ ( <a href="<% $cgi->self_url %>">show old packages</a> )
+% } elsif ( $cgi->param('showoldpackages') ) {
+% $cgi->param('showoldpackages', 0);
+ ( <a href="<% $cgi->self_url %>">hide old packages</a> )
+% }
% if ( @$packages ) {
<% include('/elements/table-grid.html') %>
@@ -119,7 +126,7 @@ my $conf = new FS::Conf;
my $curuser = $FS::CurrentUser::CurrentUser;
-my $packages = get_packages($cust_main, $conf);
+my( $packages, $num_old_packages ) = get_packages($cust_main, $conf);
my $show_location = $conf->exists('cust_pkg-always_show_location')
|| ( grep $_->locationnum, @$packages ); # ? '1' : '0';
@@ -146,8 +153,7 @@ my %conf_opt = (
sub get_packages {
my $cust_main = shift or return undef;
my $conf = shift;
-
- my @packages = ();
+
my $method;
if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
|| ( $conf->exists('hidecancelledpackages')
@@ -159,7 +165,26 @@ sub get_packages {
$method = 'all_pkgs';
}
- [ $cust_main->$method() ];
+ my @packages = $cust_main->$method();
+ my $num_old_packages = scalar(@packages);
+
+ unless ( $cgi->param('showoldpackages') ) {
+ my $years = $conf->config('cust_main-packages-years') || 2;
+ my $seconds = 31556926; #60*60*24*365.2422 is close enough
+ my $then = time - $seconds;
+
+ my %hide = ( 'cancelled' => 'cancel',
+ 'one-time charge' => 'setup',
+ );
+
+ @packages =
+ grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then }
+ @packages;
+ }
+
+ $num_old_packages -= scalar(@packages);
+
+ ( \@packages, $num_old_packages );
}
</%init>