summaryrefslogtreecommitdiff
path: root/FS/FS/part_event/Condition/balance_under.pm
diff options
context:
space:
mode:
Diffstat (limited to 'FS/FS/part_event/Condition/balance_under.pm')
-rw-r--r--FS/FS/part_event/Condition/balance_under.pm42
1 files changed, 42 insertions, 0 deletions
diff --git a/FS/FS/part_event/Condition/balance_under.pm b/FS/FS/part_event/Condition/balance_under.pm
new file mode 100644
index 0000000..2002c70
--- /dev/null
+++ b/FS/FS/part_event/Condition/balance_under.pm
@@ -0,0 +1,42 @@
+package FS::part_event::Condition::balance_under;
+
+use strict;
+use FS::cust_main;
+
+use base qw( FS::part_event::Condition );
+
+sub description { 'Customer balance (under)'; }
+
+sub option_fields {
+ (
+ 'balance' => { 'label' => 'Balance under (or equal to)',
+ 'type' => 'money',
+ 'value' => '0.00', #default
+ },
+ );
+}
+
+sub condition {
+ my($self, $object) = @_;
+
+ my $cust_main = $self->cust_main($object);
+
+ my $under = $self->option('balance');
+ $under = 0 unless length($under);
+
+ $cust_main->balance <= $under;
+}
+
+sub condition_sql {
+ my( $class, $table ) = @_;
+
+ my $under = $class->condition_sql_option('balance');
+
+ my $balance_sql = FS::cust_main->balance_sql;
+
+ "$balance_sql <= CAST( $under AS DECIMAL(10,2) )";
+
+}
+
+1;
+