summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2011-01-20 09:55:13 +0000
committerivan <ivan>2011-01-20 09:55:13 +0000
commit6f1653f32e2d7bef2b31832a0289482bc40613e5 (patch)
treeef190157487f819665d01d291c3a760353ce01e0
parentdb4098505d7936ff06df667e72626a4e04eba6d5 (diff)
add cust_main-status_module to control how customers with cancelled recurring but un-cancelled one time charges are recognized, RT#10478
-rw-r--r--FS/FS/Conf.pm2
-rw-r--r--FS/FS/cust_main.pm43
-rw-r--r--FS/FS/cust_main/Status.pm118
-rw-r--r--FS/MANIFEST1
4 files changed, 131 insertions, 33 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 610b3a9..d8321b9 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -4273,7 +4273,7 @@ and customer address. Include units.',
{
'key' => 'cust_main-status_module',
'section' => 'UI',
- 'description' => 'Which module to use for customer status display. The "Classic" module (the default) considers accounts with cancelled recurring packages but un-cancelled one-time charges Inactive. The "Recurring" module considers those customers Cancelled.', #other differences?
+ 'description' => 'Which module to use for customer status display. The "Classic" module (the default) considers accounts with cancelled recurring packages but un-cancelled one-time charges Inactive. The "Recurring" module considers those customers Cancelled. Similarly for customers with suspended recurring packages but one-time charges.', #other differences?
'type' => 'select',
'select_enum' => [ 'Classic', 'Recurring' ],
},
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 2cca79d..895f54d 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -3,7 +3,7 @@ package FS::cust_main;
require 5.006;
use strict;
#FS::cust_main:_Marketgear when they're ready to move to 2.1
-use base qw( FS::cust_main::Packages
+use base qw( FS::cust_main::Packages FS::cust_main::Status
FS::cust_main::Billing FS::cust_main::Billing_Realtime
FS::cust_main::Billing_Discount
FS::otaker_Mixin FS::payinfo_Mixin FS::cust_main_Mixin
@@ -3811,6 +3811,9 @@ Returns a status string for this customer, currently:
=back
+Behavior of inactive vs. cancelled edge cases can be adjusted with the
+cust_main-status_module configuration option.
+
=cut
sub status { shift->cust_status(@_); }
@@ -3848,21 +3851,11 @@ Returns a hex triplet color string for this customer's status.
=cut
-use vars qw(%statuscolor);
-tie %statuscolor, 'Tie::IxHash',
- 'prospect' => '7e0079', #'000000', #black? naw, purple
- 'active' => '00CC00', #green
- 'ordered' => '009999', #teal? cyan?
- 'suspended' => 'FF9900', #yellow
- 'cancelled' => 'FF0000', #red
- 'inactive' => '0000CC', #blue
-;
-
sub statuscolor { shift->cust_statuscolor(@_); }
sub cust_statuscolor {
my $self = shift;
- $statuscolor{$self->cust_status};
+ $self->statuscolors->{$self->cust_status};
}
=item tickets
@@ -3958,8 +3951,8 @@ Class method that returns the list of possible status strings for customers
=cut
sub statuses {
- #my $self = shift; #could be class...
- keys %statuscolor;
+ my $self = shift;
+ keys %{ $self->statuscolors };
}
=item cust_status_sql
@@ -4003,13 +3996,14 @@ sub prospect_sql {
=item ordered_sql
Returns an SQL expression identifying ordered cust_main records (customers with
-recurring packages not yet setup).
+no active packages, but recurring packages not yet setup or one time charges
+not yet billed).
=cut
sub ordered_sql {
FS::cust_main->none_active_sql.
- " AND 0 < ( $select_count_pkgs AND ". FS::cust_pkg->ordered_sql. " ) ";
+ " AND 0 < ( $select_count_pkgs AND ". FS::cust_pkg->not_yet_billed_sql. " ) ";
}
=item active_sql
@@ -4068,22 +4062,7 @@ Returns an SQL expression identifying cancelled cust_main records.
=cut
-sub cancelled_sql { cancel_sql(@_); }
-sub cancel_sql {
-
- my $recurring_sql = FS::cust_pkg->recurring_sql;
- my $cancelled_sql = FS::cust_pkg->cancelled_sql;
-
- "
- 0 < ( $select_count_pkgs )
- AND 0 < ( $select_count_pkgs AND $recurring_sql AND $cancelled_sql )
- AND 0 = ( $select_count_pkgs AND $recurring_sql
- AND ( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )
- )
- ";
-# AND 0 = ( $select_count_pkgs AND ". FS::cust_pkg->inactive_sql. " )
-
-}
+sub cancel_sql { shift->cancelled_sql(@_); }
=item uncancel_sql
=item uncancelled_sql
diff --git a/FS/FS/cust_main/Status.pm b/FS/FS/cust_main/Status.pm
new file mode 100644
index 0000000..e5803e0
--- /dev/null
+++ b/FS/FS/cust_main/Status.pm
@@ -0,0 +1,118 @@
+package FS::cust_main::Status;
+
+use strict;
+use vars qw( $conf ); # $module ); #$DEBUG $me );
+use FS::UID;
+use FS::cust_pkg;
+
+#use Tie::IxHash;
+
+use FS::UID qw( getotaker dbh driver_name );
+
+#$DEBUG = 0;
+#$me = '[FS::cust_main::Status]';
+
+install_callback FS::UID sub {
+ $conf = new FS::Conf;
+ #$module = $conf->config('cust_main-status_module') || 'Classic';
+};
+
+=head1 NAME
+
+FS::cust_main::Status - Status mixin for cust_main
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+These methods are available on FS::cust_main objects:
+
+=head1 METHODS
+
+=over 4
+
+=item statuscolors
+
+Returns an (ordered with Tie::IxHash) hash reference of possible status
+names and colors.
+
+=cut
+
+sub statuscolors {
+ #my $self = shift; #i guess i'm a class method
+
+ my %statuscolors;
+
+ my $module = $conf->config('cust_main-status_module') || 'Classic';
+
+ if ( $module eq 'Classic' ) {
+ tie %statuscolors, 'Tie::IxHash',
+ 'prospect' => '7e0079', #'000000', #black? naw, purple
+ 'active' => '00CC00', #green
+ 'ordered' => '009999', #teal? cyan?
+ 'inactive' => '0000CC', #blue
+ 'suspended' => 'FF9900', #yellow
+ 'cancelled' => 'FF0000', #red
+ ;
+ } elsif ( $module eq 'Recurring' ) {
+ tie %statuscolors, 'Tie::IxHash',
+ 'prospect' => '7e0079', #'000000', #black? naw, purple
+ 'active' => '00CC00', #green
+ 'ordered' => '009999', #teal? cyan?
+ 'suspended' => 'FF9900', #yellow
+ 'cancelled' => 'FF0000', #red
+ 'inactive' => '0000CC', #blue
+ ;
+ } else {
+ die "unknown status module $module";
+ }
+
+ \%statuscolors;
+
+}
+
+=item cancelled_sql
+
+=cut
+
+sub cancelled_sql {
+ my $self = shift;
+
+ my $recurring_sql = FS::cust_pkg->recurring_sql;
+ my $cancelled_sql = FS::cust_pkg->cancelled_sql;
+ my $select_count_pkgs = $self->select_count_pkgs_sql;
+
+ my $sql = "
+ 0 < ( $select_count_pkgs )
+ AND 0 = ( $select_count_pkgs AND $recurring_sql
+ AND ( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )
+ )
+ AND 0 < ( $select_count_pkgs AND $cancelled_sql )
+ ";
+
+ my $module = $conf->config('cust_main-status_module') || 'Classic';
+
+ if ( $module eq 'Classic' ) {
+ $sql .=
+ " AND 0 = ( $select_count_pkgs AND ". FS::cust_pkg->inactive_sql. " ) ";
+ #} elsif ( $module eq 'Recurring' ) {
+ #} else {
+ # die "unknown status module $module";
+ }
+
+ $sql;
+
+}
+
+=back
+
+=head1 BUGS
+
+=head1 SEE ALSO
+
+L<FS::cust_main>
+
+=cut
+
+1;
+
diff --git a/FS/MANIFEST b/FS/MANIFEST
index cdb2851..8e75742 100644
--- a/FS/MANIFEST
+++ b/FS/MANIFEST
@@ -556,3 +556,4 @@ FS/svc_port.pm
t/svc_port.t
FS/h_svc_port.pm
t/h_svc_port.t
+FS/cust_main/Status.pm