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 if ( $module eq 'Classic' ) {
44 tie %statuscolors, 'Tie::IxHash',
45 'prospect' => 'FF00F5', #'000000', #black? naw, purple
46 'active' => '00CC00', #green
47 'ordered' => '009999', #teal? cyan?
48 'inactive' => '0000CC', #blue
49 'suspended' => 'FF9900', #yellow
50 'cancelled' => 'FF0000', #red
52 } elsif ( $module eq 'Recurring' ) {
53 tie %statuscolors, 'Tie::IxHash',
54 'prospect' => 'FF00F5', #'000000', #black? naw, purple
55 'active' => '00CC00', #green
56 'ordered' => '009999', #teal? cyan?
57 'suspended' => 'FF9900', #yellow
58 'cancelled' => 'FF0000', #red
59 'inactive' => '0000CC', #blue
62 die "unknown status module $module";
76 my $recurring_sql = FS::cust_pkg->recurring_sql;
77 my $cancelled_sql = FS::cust_pkg->cancelled_sql;
78 my $select_count_pkgs = $self->select_count_pkgs_sql;
81 0 < ( $select_count_pkgs )
82 AND 0 = ( $select_count_pkgs AND $recurring_sql
83 AND ( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )
85 AND 0 < ( $select_count_pkgs AND $cancelled_sql )
88 if ( $module eq 'Classic' ) {
90 " AND 0 = ( $select_count_pkgs AND ". FS::cust_pkg->inactive_sql. " ) ";
91 #} elsif ( $module eq 'Recurring' ) {
93 # die "unknown status module $module";
106 =item churn_sql START, END
108 Returns an SQL statement for the customer churn status query. The columns
109 returned are the custnum and the number of active, suspended, and cancelled
110 packages (excluding one-time packages) at the start date ("s_active",
111 "s_suspended", and "s_cancelled") and the end date ("e_active", etc.).
115 # not sure this belongs here...FS::cust_main::Packages?
119 my ($speriod, $eperiod) = @_;
121 my $s_sql = FS::h_cust_pkg->status_as_of_sql($speriod);
122 my $e_sql = FS::h_cust_pkg->status_as_of_sql($eperiod);
126 'COALESCE(SUM(s.is_active::int),0) as s_active',
127 'COALESCE(SUM(s.is_suspended::int),0) as s_suspended',
128 'COALESCE(SUM(s.is_cancelled::int),0) as s_cancelled',
129 'COALESCE(SUM(e.is_active::int),0) as e_active',
130 'COALESCE(SUM(e.is_suspended::int),0) as e_suspended',
131 'COALESCE(SUM(e.is_cancelled::int),0) as e_cancelled',
133 my $from = "($s_sql) AS s FULL JOIN ($e_sql) AS e USING (custnum)";
135 return "SELECT ".join(',', @select)." FROM $from GROUP BY custnum";