enable package class condition for invoices, #14499
[freeside.git] / FS / FS / part_event / Condition / cust_paydate_within.pm
1 package FS::part_event::Condition::cust_paydate_within;
2
3 use strict;
4 use base qw( FS::part_event::Condition );
5 use FS::Record qw( str2time_sql str2time_sql_closing );
6 use Time::Local 'timelocal';
7
8 sub description {
9   'Credit card expires within upcoming interval';
10 }
11
12 # Run the event when the customer's credit card expiration 
13 # date is less than X days in the future.
14 # Combine this with a "once_every" condition so that the event
15 # won't repeat every day until the expiration date.
16
17 sub eventtable_hashref {
18     { 'cust_main' => 1,
19       'cust_bill' => 0,
20       'cust_pkg'  => 0,
21     };
22 }
23
24 sub option_fields {
25   (
26     'within'  =>  { 'label'   => 'Expiration date within',
27                     'type'    => 'freq',
28                   },
29   );
30 }
31
32 sub condition {
33   my( $self, $cust_main, %opt ) = @_;
34   my $expire_time = $cust_main->paydate_epoch or return 0;
35   $opt{'time'} >= $self->option_age_from('within', $expire_time);
36 }
37
38 sub condition_sql {
39   my ($self, $table, %opt) = @_;
40   my $expire_time = FS::cust_main->paydate_epoch_sql or return 'true';
41   $opt{'time'} . ' >= ' .  
42     $self->condition_sql_option_age_from('within', $expire_time);
43 }
44
45 1;
46