61cd8d6d13dc6afc13a8474d6544e419bbf27cbe
[freeside.git] / FS / FS / part_event / Condition / day_of_month.pm
1 package FS::part_event::Condition::day_of_month;
2
3 use strict;
4 use base qw( FS::part_event::Condition );
5
6 sub description {
7   "Run only on a certain day of the month",
8 }
9
10 sub option_fields {
11   (
12     'day'   => { label  => 'Day (1-28, separate multiple days with commas)',
13                  type   => 'text',
14                },
15   );
16 }
17
18 sub condition { # is this even necessary? condition_sql is exact.
19   my( $self, $object, %opt ) = @_;
20
21   my $today = (localtime($opt{'time'}))[3];
22   if (grep { $_ == $today } split(',', $self->option('day'))) {
23     return 1;
24   }
25   '';
26 }
27
28 sub condition_sql {
29   my( $class, $table, %opt ) = @_;
30   my $today = (localtime($opt{'time'}))[3];
31   my $day = $class->condition_sql_option('day');
32   "$today = ANY( string_to_array($day, ',')::integer[] )"
33 }
34
35 1;