proper fix for signupdate_age that works in customer context too, RT#31213
[freeside.git] / FS / FS / part_event / Condition / signupdate_age.pm
1 package FS::part_event::Condition::signupdate_age;
2 use base qw( FS::part_event::Condition );
3
4 use strict;
5
6 sub description { 'Customer signup age'; }
7
8 #lots of falze laziness w/cust_bill_age, basically just swapped out the field
9
10 sub option_fields {
11   (
12     'age' => { label=>'Age', type=>'freq', },
13   );
14 }
15
16 sub condition {
17   my( $self, $object, %opt ) = @_;
18
19   my $age = $self->option_age_from('age', $opt{'time'} );
20
21   my $cust_main = $self->cust_main($object);
22   ( $cust_main->signupdate - 60 ) <= $age;
23
24 }
25
26 sub condition_sql {
27   my( $class, $table, %opt ) = @_;
28
29   my $age  = $class->condition_sql_option_age_from('age', $opt{'time'} );
30
31   "( cust_main.signupdate - 60 ) <= $age";
32 }
33
34 # i don't think it really matters what order, since we're a customer condition?
35 #  this is for ordering different events for a customer
36 sub order_sql {
37   shift->condition_sql_option_age('age');
38 }
39
40 sub order_sql_weight {
41   -1;
42 }
43
44 1;
45 1;