summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2012-03-31 17:56:52 -0700
committerMark Wells <mark@freeside.biz>2012-03-31 17:56:52 -0700
commitc2ee6c5c4f274bbf86729cacd2fe011ea71f725d (patch)
tree5e6daaeb6c370ec883ad6d2dd82a64b661900b48 /FS
parentfadc3d69d6a6bceac54fcb52b456222f28c42645 (diff)
add customer referrals to signup graph, #17050
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Report/Table.pm21
1 files changed, 16 insertions, 5 deletions
diff --git a/FS/FS/Report/Table.pm b/FS/FS/Report/Table.pm
index 3942543b5..b0e911f84 100644
--- a/FS/FS/Report/Table.pm
+++ b/FS/FS/Report/Table.pm
@@ -32,21 +32,32 @@ options in %opt.
=over 4
-=item signups: The number of customers signed up.
+=item signups: The number of customers signed up. Options are "refnum"
+(limit by advertising source) and "indirect" (boolean, tells us to limit
+to customers that have a referral_custnum that matches the advertising source).
=cut
sub signups {
my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_;
- my @where = (
- $self->in_time_period_and_agent($speriod, $eperiod, $agentnum, 'signupdate')
+ my @where = ( $self->in_time_period_and_agent($speriod, $eperiod, $agentnum,
+ 'cust_main.signupdate')
);
- if ( $opt{'refnum'} ) {
+ my $join = '';
+ if ( $opt{'indirect'} ) {
+ $join = " JOIN cust_main AS referring_cust_main".
+ " ON (cust_main.referral_custnum = referring_cust_main.custnum)";
+
+ if ( $opt{'refnum'} ) {
+ push @where, "referring_cust_main.refnum = ".$opt{'refnum'};
+ }
+ }
+ elsif ( $opt{'refnum'} ) {
push @where, "refnum = ".$opt{'refnum'};
}
$self->scalar_sql(
- "SELECT COUNT(*) FROM cust_main WHERE ".join(' AND ', @where)
+ "SELECT COUNT(*) FROM cust_main $join WHERE ".join(' AND ', @where)
);
}