From 6f1653f32e2d7bef2b31832a0289482bc40613e5 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 20 Jan 2011 09:55:13 +0000 Subject: [PATCH] add cust_main-status_module to control how customers with cancelled recurring but un-cancelled one time charges are recognized, RT#10478 --- FS/FS/Conf.pm | 2 +- FS/FS/cust_main.pm | 43 +++++------------ FS/FS/cust_main/Status.pm | 118 ++++++++++++++++++++++++++++++++++++++++++++++ FS/MANIFEST | 1 + 4 files changed, 131 insertions(+), 33 deletions(-) create mode 100644 FS/FS/cust_main/Status.pm diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 610b3a954..d8321b926 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 2cca79d1a..895f54d59 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 000000000..e5803e0db --- /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 + +=cut + +1; + diff --git a/FS/MANIFEST b/FS/MANIFEST index cdb2851b9..8e7574280 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 -- 2.11.0