summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/part_event.pm9
-rw-r--r--FS/FS/part_event/Condition/signupdate_day.pm54
2 files changed, 59 insertions, 4 deletions
diff --git a/FS/FS/part_event.pm b/FS/FS/part_event.pm
index 31d2afd23..62f16fa1c 100644
--- a/FS/FS/part_event.pm
+++ b/FS/FS/part_event.pm
@@ -253,7 +253,7 @@ sub templatename {
}
}
-=item targets
+=item targets OPTIONS
Returns all objects (of type C<FS::eventtable>, for this object's
C<eventtable>) eligible for processing under this event, as of right now.
@@ -268,7 +268,8 @@ but can be useful when configuring events.
sub targets {
my $self = shift;
- my $time = time; # $opt{'time'}?
+ my %opt = @_;
+ my $time = $opt{'time'} || time;
my $eventpart = $self->eventpart;
$eventpart =~ /^\d+$/ or die "bad eventpart $eventpart";
@@ -305,8 +306,8 @@ sub targets {
});
my @tested_objects;
foreach my $object ( @objects ) {
- my $cust_event = $self->new_cust_event($object, 'time' => $time);
- next unless $cust_event->test_conditions;
+ my $cust_event = $self->new_cust_event($object);
+ next unless $cust_event->test_conditions('time' => $time);
$object->set('cust_event', $cust_event);
push @tested_objects, $object;
diff --git a/FS/FS/part_event/Condition/signupdate_day.pm b/FS/FS/part_event/Condition/signupdate_day.pm
new file mode 100644
index 000000000..dbe9e60a1
--- /dev/null
+++ b/FS/FS/part_event/Condition/signupdate_day.pm
@@ -0,0 +1,54 @@
+package FS::part_event::Condition::signupdate_day;
+
+use strict;
+use Tie::IxHash;
+
+use base qw( FS::part_event::Condition );
+
+sub description {
+ "Customer signed up on the same day of month as today";
+}
+
+sub option_fields {
+ (
+ 'delay' => { label => 'Delay additional days',
+ type => 'text',
+ value => '0',
+ },
+ );
+}
+
+sub condition {
+ my( $self, $object, %opt ) = @_;
+
+ my $cust_main = $self->cust_main($object);
+
+ my ($today) = (localtime($opt{'time'}))[3];
+
+ my $delay = $self->option('delay') || 0;
+ my $signupday = ((localtime($cust_main->signupdate + $delay * 86400))[3] - 1)
+ % 28 + 1;
+
+ $today == $signupday;
+}
+
+sub condition_sql {
+ my( $class, $table, %opt ) = @_;
+ my $mday;
+ if ( $opt{'driver_name'} eq 'Pg' ) {
+ $mday = sub{ "EXTRACT( DAY FROM TO_TIMESTAMP($_[0]) )::INTEGER" };
+ }
+ elsif ( $opt{'driver_name'} eq 'mysql' ) {
+ $mday = sub{ "DAY( FROM_UNIXTIME($_[0]) )" };
+ }
+ else {
+ return 'true';
+ }
+
+ my $delay = $class->condition_sql_option_integer('delay',
+ $opt{'driver_name'}); # returns 0 for null
+ $mday->($opt{'time'}) . ' = '.
+ '(' . $mday->("cust_main.signupdate + $delay * 86400") . ' - 1) % 28 + 1';
+}
+
+1;