This commit was generated by cvs2svn to compensate for changes in r11022,
[freeside.git] / FS / FS / part_event / Condition / balance_age.pm
1 package FS::part_event::Condition::balance_age;
2
3 use strict;
4 use base qw( FS::part_event::Condition );
5
6 sub description { 'Customer balance age'; }
7
8 sub option_fields {
9   (
10     'balance' => { 'label'      => 'Balance over',
11                    'type'       => 'money',
12                    'value'      => '0.00', #default
13                  },
14     'age'     => { 'label'      => 'Age',
15                    'type'       => 'freq',
16                  },
17   );
18 }
19
20 sub condition {
21   my($self, $object, %opt) = @_;
22
23   my $cust_main = $self->cust_main($object);
24
25   my $over = $self->option('balance');
26   $over = 0 unless length($over);
27
28   my $age = $self->option_age_from('age', $opt{'time'} );
29
30   $cust_main->balance_date($age) > $over;
31 }
32
33 sub condition_sql {
34   my( $class, $table, %opt ) = @_;
35
36   my $over    = $class->condition_sql_option('balance');
37   my $age     = $class->condition_sql_option_age_from('age', $opt{'time'});
38
39   my $balance_sql = FS::cust_main->balance_date_sql( $age );
40
41   "$balance_sql > CAST( $over AS DECIMAL(10,2) )";
42 }
43
44 sub order_sql {
45   shift->condition_sql_option_age('age');
46 }
47
48 sub order_sql_weight {
49   10;
50 }
51
52 1;