import torrus 1.0.9
[freeside.git] / FS / FS / part_event / Condition / balance.pm
1 package FS::part_event::Condition::balance;
2
3 use strict;
4 use FS::cust_main;
5
6 use base qw( FS::part_event::Condition );
7
8 sub description { 'Customer balance'; }
9
10 sub implicit_flag { 20; }
11
12 sub remove_warning {
13   'Are you sure you want to remove this condition?  Doing so will allow this event to run even if the customer has no outstanding balance.  Perhaps you want to reset "Balance over" to 0 instead of removing the condition entirely?'; #better error msg?
14 }
15
16 sub option_fields {
17   (
18     'balance' => { 'label'      => 'Balance over',
19                    'type'       => 'money',
20                    'value'      => '0.00', #default
21                  },
22   );
23 }
24
25 sub condition {
26   my($self, $object) = @_;
27
28   my $cust_main = $self->cust_main($object);
29
30   my $over = $self->option('balance');
31   $over = 0 unless length($over);
32
33   $cust_main->balance > $over;
34 }
35
36 sub condition_sql {
37   my( $class, $table ) = @_;
38
39   my $over = $class->condition_sql_option('balance');
40
41   my $balance_sql = FS::cust_main->balance_sql;
42
43   "$balance_sql > CAST( $over AS DECIMAL(10,2) )";
44
45 }
46
47 1;
48