1 package FS::cust_main::Status;
4 use vars qw( $conf ); # $module ); #$DEBUG $me );
10 #$me = '[FS::cust_main::Status]';
12 install_callback FS::UID sub {
14 #$module = $conf->config('cust_main-status_module') || 'Classic';
19 FS::cust_main::Status - Status mixin for cust_main
25 These methods are available on FS::cust_main objects:
33 Returns an (ordered with Tie::IxHash) hash reference of possible status
39 #my $self = shift; #i guess i'm a class method
43 my $module = $conf->config('cust_main-status_module') || 'Classic';
45 if ( $module eq 'Classic' ) {
46 tie %statuscolors, 'Tie::IxHash',
47 'prospect' => '7e0079', #'000000', #black? naw, purple
48 'active' => '00CC00', #green
49 'ordered' => '009999', #teal? cyan?
50 'inactive' => '0000CC', #blue
51 'suspended' => 'FF9900', #yellow
52 'cancelled' => 'FF0000', #red
54 } elsif ( $module eq 'Recurring' ) {
55 tie %statuscolors, 'Tie::IxHash',
56 'prospect' => '7e0079', #'000000', #black? naw, purple
57 'active' => '00CC00', #green
58 'ordered' => '009999', #teal? cyan?
59 'suspended' => 'FF9900', #yellow
60 'cancelled' => 'FF0000', #red
61 'inactive' => '0000CC', #blue
64 die "unknown status module $module";
72 #my $self = shift; #i guess i'm a class method
75 'prospect' => 'No packages',
77 'ordered' => 'Ordered',
78 'inactive' => 'Inactive',
79 'suspended' => 'Suspended',
80 'cancelled' => 'Cancelled',
93 my $recurring_sql = FS::cust_pkg->recurring_sql;
94 my $cancelled_sql = FS::cust_pkg->cancelled_sql;
95 my $select_count_pkgs = $self->select_count_pkgs_sql;
98 0 < ( $select_count_pkgs )
99 AND 0 = ( $select_count_pkgs AND $recurring_sql
100 AND ( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )
102 AND 0 < ( $select_count_pkgs AND $cancelled_sql )
105 my $module = $conf->config('cust_main-status_module') || 'Classic';
107 if ( $module eq 'Classic' ) {
109 " AND 0 = ( $select_count_pkgs AND ". FS::cust_pkg->inactive_sql. " ) ";
110 #} elsif ( $module eq 'Recurring' ) {
112 # die "unknown status module $module";
125 =item churn_sql START, END
127 Returns an SQL statement for the customer churn status query. The columns
128 returned are the custnum and the number of active, suspended, and cancelled
129 packages (excluding one-time packages) at the start date ("s_active",
130 "s_suspended", and "s_cancelled") and the end date ("e_active", etc.).
134 # not sure this belongs here...FS::cust_main::Packages?
138 my ($speriod, $eperiod) = @_;
140 my $s_sql = FS::h_cust_pkg->status_as_of_sql($speriod);
141 my $e_sql = FS::h_cust_pkg->status_as_of_sql($eperiod);
145 'COALESCE(SUM(s.is_active::int),0) as s_active',
146 'COALESCE(SUM(s.is_suspended::int),0) as s_suspended',
147 'COALESCE(SUM(s.is_cancelled::int),0) as s_cancelled',
148 'COALESCE(SUM(e.is_active::int),0) as e_active',
149 'COALESCE(SUM(e.is_suspended::int),0) as e_suspended',
150 'COALESCE(SUM(e.is_cancelled::int),0) as e_cancelled',
152 my $from = "($s_sql) AS s FULL JOIN ($e_sql) AS e USING (custnum)";
154 return "SELECT ".join(',', @select)." FROM $from GROUP BY custnum";