add cust_main-status_module to control how customers with cancelled recurring but...
authorivan <ivan>
Thu, 20 Jan 2011 09:55:13 +0000 (09:55 +0000)
committerivan <ivan>
Thu, 20 Jan 2011 09:55:13 +0000 (09:55 +0000)
FS/FS/Conf.pm
FS/FS/cust_main.pm
FS/FS/cust_main/Status.pm [new file with mode: 0644]
FS/MANIFEST

index 610b3a9..d8321b9 100644 (file)
@@ -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' ],
   },
index 2cca79d..895f54d 100644 (file)
@@ -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 (file)
index 0000000..e5803e0
--- /dev/null
@@ -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;
+
index cdb2851..8e75742 100644 (file)
@@ -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