diff options
author | Christopher Burger <burgerc@freeside.biz> | 2018-09-13 17:56:51 -0400 |
---|---|---|
committer | Christopher Burger <burgerc@freeside.biz> | 2018-09-13 17:56:51 -0400 |
commit | 167c830485a305064fb18bb7d91322857e5b5182 (patch) | |
tree | 73146a8e0d5fb137b643038a52df0ec9e2b113e9 | |
parent | 55e25606b4df2ac531cec49d219cfd53ffae8a2f (diff) | |
parent | 5a1c7ce42856c68811fca96c7597efebdab48434 (diff) |
Merge branch 'FREESIDE_3_BRANCH' of ssh://git.freeside.biz/home/git/freeside into FREESIDE_3_BRANCH
-rw-r--r-- | FS/FS/part_event/Condition.pm | 16 | ||||
-rw-r--r-- | FS/FS/part_event/Condition/has_referral_custnum.pm | 23 | ||||
-rw-r--r-- | FS/FS/part_event/Condition/pkg_pkgpart.pm | 11 |
3 files changed, 37 insertions, 13 deletions
diff --git a/FS/FS/part_event/Condition.pm b/FS/FS/part_event/Condition.pm index d1d5196..9900aca 100644 --- a/FS/FS/part_event/Condition.pm +++ b/FS/FS/part_event/Condition.pm @@ -533,6 +533,22 @@ sub condition_sql_option_integer { " AS $integer )"; } +=item condition_sql_option_money OPTION + +As I<condition_sql_option>, but cast the option value to DECIMAL so that +comparison to other monetary values is type-correct. + +=cut + +sub condition_sql_option_money { + my ($class, $option ) = @_; + + 'CAST( + COALESCE('. $class->condition_sql_option($option). + " ,'0') ". + " AS DECIMAL(10,2) )"; +} + =head1 NEW CONDITION CLASSES A module should be added in FS/FS/part_event/Condition/ which implements the diff --git a/FS/FS/part_event/Condition/has_referral_custnum.pm b/FS/FS/part_event/Condition/has_referral_custnum.pm index f8a2b82..a56e3fa 100644 --- a/FS/FS/part_event/Condition/has_referral_custnum.pm +++ b/FS/FS/part_event/Condition/has_referral_custnum.pm @@ -57,16 +57,23 @@ sub condition { } -#this is incomplete wrt checking referring customer balances, but that's okay. -# false positives are acceptable here, its just an optimizaiton sub condition_sql { - my( $class, $table ) = @_; + my( $class, $table, %opt ) = @_; - my $sql = FS::cust_main->active_sql; - $sql =~ s/cust_main.custnum/cust_main.referral_custnum/; - $sql = 'cust_main.referral_custnum IS NOT NULL AND ('. - $class->condition_sql_option('active') . ' IS NULL OR '.$sql.')'; - return $sql; + my $active_sql = FS::cust_main->active_sql; + $active_sql =~ s/cust_main.custnum/cust_main.referral_custnum/; + + my $under = $class->condition_sql_option_money('balance'); + + my $age = $class->condition_sql_option_age_from('age', $opt{'time'}); + my $balance_date_sql = FS::cust_main->balance_date_sql($age); + $balance_date_sql =~ s/cust_main.custnum/cust_main.referral_custnum/; + my $bal_sql = "$balance_date_sql <= $under"; + + "cust_main.referral_custnum IS NOT NULL + AND (". $class->condition_sql_option('active'). " IS NULL OR $active_sql) + AND (". $class->condition_sql_option('check_bal'). " IS NULL OR $bal_sql ) + "; } 1; diff --git a/FS/FS/part_event/Condition/pkg_pkgpart.pm b/FS/FS/part_event/Condition/pkg_pkgpart.pm index 6adef8e..d5b5c8d 100644 --- a/FS/FS/part_event/Condition/pkg_pkgpart.pm +++ b/FS/FS/part_event/Condition/pkg_pkgpart.pm @@ -25,15 +25,16 @@ sub option_fields { sub condition { my( $self, $cust_pkg) = @_; - #XXX test my $if_pkgpart = $self->option('if_pkgpart') || {}; $if_pkgpart->{ $cust_pkg->pkgpart }; } -#XXX -#sub condition_sql { -# -#} +sub condition_sql { + my( $self, $table ) = @_; + + 'cust_pkg.pkgpart IN '. + $self->condition_sql_option_option_integer('if_pkgpart'); +} 1; |