7cd74a1f947ff8a3547d617f56e4e4b7016956bb
[freeside.git] / FS / FS / part_event / Condition / billday.pm
1 package FS::part_event::Condition::billday;
2
3 use strict;
4 use Tie::IxHash;
5
6 use base qw( FS::part_event::Condition );
7
8 sub description {
9   "Customer's monthly billing day is before or on current day or customer has no billing day";
10 }
11
12 sub option_fields {
13   (
14     'delay' => { label  => 'Delay additional days',
15                  type   => 'text',
16                  value  => '1',
17                },
18   );
19 }
20
21
22 sub condition {
23   my( $self, $object ) = @_;
24
25   my $cust_main = $self->cust_main($object);
26
27   my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
28   
29   my $delay = $self->option('delay');
30   $delay = 0 unless length($delay);
31
32   (!$cust_main->billday) || ($mday >= $cust_main->billday + $delay);
33 }
34
35 sub condition_sql {
36   my( $class, $table, %opt ) = @_;
37
38   my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
39   
40   my $delay = $class->condition_sql_option_integer('delay', $opt{'driver_name'});
41   
42   "cust_main.billday is null or $mday >= (cust_main.billday + $delay)";
43 }
44
45 1;