This commit was generated by cvs2svn to compensate for changes in r11022,
[freeside.git] / FS / FS / part_event / Condition / has_referral_custnum.pm
1 package FS::part_event::Condition::has_referral_custnum;
2
3 use strict;
4 use FS::cust_main;
5
6 use base qw( FS::part_event::Condition );
7
8 sub description { 'Customer has a referring customer'; }
9
10 sub option_fields {
11   (
12     'active' => { 'label' => 'Referring customer is active',
13                   'type'  => 'checkbox',
14                   'value' => 'Y',
15                 },
16   );
17 }
18
19 sub condition {
20   my($self, $object) = @_;
21
22   my $cust_main = $self->cust_main($object);
23
24   if ( $self->option('active') ) {
25
26     return 0 unless $cust_main->referral_custnum;
27
28     #check for no cust_main for referral_custnum? (deleted?)
29
30     $cust_main->referral_custnum_cust_main->status eq 'active';
31
32   } else {
33
34     $cust_main->referral_custnum; # ? 1 : 0;
35
36   }
37
38 }
39
40 sub condition_sql {
41   my( $class, $table ) = @_;
42
43   my $sql = FS::cust_main->active_sql;
44   $sql =~ s/cust_main.custnum/cust_main.referral_custnum/;
45   $sql = 'cust_main.referral_custnum IS NOT NULL AND ('.
46           $class->condition_sql_option('active') . ' IS NULL OR '.$sql.')';
47   return $sql;
48 }
49
50 1;