" 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
}
-#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;
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;