diff options
author | Mark Wells <mark@freeside.biz> | 2014-05-08 15:44:19 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2014-05-08 15:44:19 -0700 |
commit | fb603cbe0bf8cda2eb139bf2e867d23d636db7ad (patch) | |
tree | 9ccc4562224bc9893d27ca05ca22aa3c9220efb9 | |
parent | 3797296c49485eb48aea3cafe9d4a3323752ef34 (diff) |
current day of month condition, #25899
-rw-r--r-- | FS/FS/part_event/Condition/day_of_month.pm | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/FS/FS/part_event/Condition/day_of_month.pm b/FS/FS/part_event/Condition/day_of_month.pm new file mode 100644 index 000000000..61cd8d6d1 --- /dev/null +++ b/FS/FS/part_event/Condition/day_of_month.pm @@ -0,0 +1,35 @@ +package FS::part_event::Condition::day_of_month; + +use strict; +use base qw( FS::part_event::Condition ); + +sub description { + "Run only on a certain day of the month", +} + +sub option_fields { + ( + 'day' => { label => 'Day (1-28, separate multiple days with commas)', + type => 'text', + }, + ); +} + +sub condition { # is this even necessary? condition_sql is exact. + my( $self, $object, %opt ) = @_; + + my $today = (localtime($opt{'time'}))[3]; + if (grep { $_ == $today } split(',', $self->option('day'))) { + return 1; + } + ''; +} + +sub condition_sql { + my( $class, $table, %opt ) = @_; + my $today = (localtime($opt{'time'}))[3]; + my $day = $class->condition_sql_option('day'); + "$today = ANY( string_to_array($day, ',')::integer[] )" +} + +1; |