RT#37544 Prevent billing events from running on weekends
[freeside.git] / FS / FS / part_event / Condition / day_of_week.pm
1 package FS::part_event::Condition::day_of_week;
2
3 use strict;
4 use base qw( FS::part_event::Condition );
5 use FS::Record qw( dbh );
6
7 tie my %dayofweek, 'Tie::IxHash', 
8   0 => 'Sunday',
9   1 => 'Monday',
10   2 => 'Tuesday',
11   3 => 'Wednesday',
12   4 => 'Thursday',
13   5 => 'Friday',
14   6 => 'Saturday',
15 ;
16
17 sub description {
18   "Run only on certain days of the week",
19 }
20
21 sub option_fields {
22   (
23     'dayofweek' => {
24        label         => 'Days to run',
25        type          => 'checkbox-multiple',
26        options       => [ values %dayofweek ],
27        option_labels => { map { $_ => $_ } values %dayofweek },
28     },
29   );
30 }
31
32 sub condition { # is this even necessary? condition_sql is exact.
33   my( $self, $object, %opt ) = @_;
34
35   my $today = $dayofweek{(localtime($opt{'time'}))[6]};
36   if (grep { $_ eq $today } (keys %{$self->option('dayofweek')})) {
37     return 1;
38   }
39   '';
40 }
41
42 sub condition_sql {
43   my( $class, $table, %opt ) = @_;
44   my $today = $dayofweek{(localtime($opt{'time'}))[6]};
45   my $day = $class->condition_sql_option_option('dayofweek');
46   return dbh->quote($today) . " IN $day";
47 }
48
49 1;