summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2014-04-27 14:21:22 -0700
committerIvan Kohler <ivan@freeside.biz>2014-04-27 14:21:22 -0700
commit729956733bf21293c801358c3e711c81d7df5b4f (patch)
tree6731dfbef39cdc6225026ec1c38b283887dc16dd /FS
parentdc54c9e83f5cc315e9e2823e61a9f861f842da48 (diff)
"on hold" package ordering and status, RT#28508
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/cust_main/Billing.pm14
-rw-r--r--FS/FS/cust_pkg.pm37
2 files changed, 44 insertions, 7 deletions
diff --git a/FS/FS/cust_main/Billing.pm b/FS/FS/cust_main/Billing.pm
index d0fd12cfa..fff0cb076 100644
--- a/FS/FS/cust_main/Billing.pm
+++ b/FS/FS/cust_main/Billing.pm
@@ -1117,10 +1117,16 @@ sub _make_lines {
my @recur_discounts = ();
my $sdate;
if ( ! $cust_pkg->start_date
- and ( ! $cust_pkg->susp || $cust_pkg->option('suspend_bill',1)
- || ( $part_pkg->option('suspend_bill', 1) )
- && ! $cust_pkg->option('no_suspend_bill',1)
- )
+ and
+ ( ! $cust_pkg->susp
+ || ( $cust_pkg->susp != $cust_pkg->order_date
+ && ( $cust_pkg->option('suspend_bill',1)
+ || ( $part_pkg->option('suspend_bill', 1)
+ && ! $cust_pkg->option('no_suspend_bill',1)
+ )
+ )
+ )
+ )
and
( $part_pkg->freq ne '0' && ( $cust_pkg->bill || 0 ) <= $cmp_time )
|| ( $part_pkg->plan eq 'voip_cdr'
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 098baf2cd..f0b445f08 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -343,6 +343,8 @@ sub insert {
local $SIG{TSTP} = 'IGNORE';
local $SIG{PIPE} = 'IGNORE';
+ $self->susp( $self->order_date ) if $self->susp eq 'now';
+
my $oldAutoCommit = $FS::UID::AutoCommit;
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
@@ -1576,7 +1578,9 @@ sub unsuspend {
&& ! $self->option('suspend_bill',1)
&& ( ! $self->part_pkg->option('suspend_bill',1)
|| $self->option('no_suspend_bill',1)
- );
+ )
+ && $hash{'order_date'} != $hash{'susp'}
+ ;
$hash{'susp'} = '';
$hash{'adjourn'} = '' if $hash{'adjourn'} and $hash{'adjourn'} < time;
@@ -3107,6 +3111,8 @@ Returns a short status string for this package, currently:
=over 4
+=item on hold
+
=item not yet billed
=item one-time charge
@@ -3127,6 +3133,7 @@ sub status {
my $freq = length($self->freq) ? $self->freq : $self->part_pkg->freq;
return 'cancelled' if $self->get('cancel');
+ return 'on hold' if $self->susp && ! $self->setup;
return 'suspended' if $self->susp;
return 'not yet billed' unless $self->setup;
return 'one-time charge' if $freq =~ /^(0|$)/;
@@ -3153,6 +3160,7 @@ Class method that returns the list of possible status strings for packages
=cut
tie my %statuscolor, 'Tie::IxHash',
+ 'on hold' => '7E0079', #purple!
'not yet billed' => '009999', #teal? cyan?
'one-time charge' => '000000',
'active' => '00CC00',
@@ -4215,6 +4223,21 @@ sub inactive_sql { "
AND ( cust_pkg.susp IS NULL OR cust_pkg.susp = 0 )
"; }
+=item on_hold_sql
+
+Returns an SQL expression identifying on-hold packages.
+
+=cut
+
+sub on_hold_sql {
+ #$_[0]->recurring_sql(). ' AND '.
+ "
+ ( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )
+ AND cust_pkg.susp IS NOT NULL AND cust_pkg.susp != 0
+ AND ( cust_pkg.setup IS NULL OR cust_pkg.setup = 0 )
+ ";
+}
+
=item susp_sql
=item suspended_sql
@@ -4228,6 +4251,7 @@ sub susp_sql {
"
( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )
AND cust_pkg.susp IS NOT NULL AND cust_pkg.susp != 0
+ AND cust_pkg.setup IS NOT NULL AND cust_pkg.setup != 0
";
}
@@ -4253,6 +4277,7 @@ Returns an SQL expression to give the package status as a string.
sub status_sql {
"CASE
WHEN cust_pkg.cancel IS NOT NULL THEN 'cancelled'
+ WHEN ( cust_pkg.susp IS NOT NULL AND cust_pkg.setup IS NULL ) THEN 'on hold'
WHEN cust_pkg.susp IS NOT NULL THEN 'suspended'
WHEN cust_pkg.setup IS NULL THEN 'not yet billed'
WHEN ".onetime_sql()." THEN 'one-time charge'
@@ -4273,11 +4298,11 @@ Valid parameters are
=item magic
-active, inactive, suspended, cancel (or cancelled)
+on hold, active, inactive (or one-time charge), suspended, cancel (or cancelled)
=item status
-active, inactive, suspended, one-time charge, inactive, cancel (or cancelled)
+on hold, active, inactive (or one-time charge), suspended, cancel (or cancelled)
=item custom
@@ -4445,6 +4470,12 @@ sub search {
push @where, FS::cust_pkg->inactive_sql();
+ } elsif ( $params->{'magic'} =~ /^on[ _]hold$/
+ || $params->{'status'} =~ /^on[ _]hold$/ ) {
+
+ push @where, FS::cust_pkg->on_hold_sql();
+
+
} elsif ( $params->{'magic'} eq 'suspended'
|| $params->{'status'} eq 'suspended' ) {