event refactor, landing on HEAD!
[freeside.git] / FS / FS / part_event / Condition / balance_under.pm
1 package FS::part_event::Condition::balance_under;
2
3 use strict;
4 use FS::cust_main;
5
6 use base qw( FS::part_event::Condition );
7
8 sub description { 'Customer balance (under)'; }
9
10 sub option_fields {
11   (
12     'balance' => { 'label'      => 'Balance under (or equal to)',
13                    'type'       => 'money',
14                    'value'      => '0.00', #default
15                  },
16   );
17 }
18
19 sub condition {
20   my($self, $object) = @_;
21
22   my $cust_main = $self->cust_main($object);
23
24   my $under = $self->option('balance');
25   $under = 0 unless length($under);
26
27   $cust_main->balance <= $under;
28 }
29
30 sub condition_sql {
31   my( $class, $table ) = @_;
32
33   my $under = $class->condition_sql_option('balance');
34
35   my $balance_sql = FS::cust_main->balance_sql;
36
37   "$balance_sql <= $under";
38
39 }
40
41 1;
42