1 package FS::part_event::Condition::once_percust_every;
4 use FS::Record qw( qsearch );
8 use base qw( FS::part_event::Condition );
10 sub description { "Don't run this event more than once per customer in the specified interval"; }
12 sub eventtable_hashref {
19 # Runs the event at most "once every X", per customer.
23 'run_delay' => { label=>'Interval', type=>'freq', value=>'1m', },
28 my($self, $object, %opt) = @_;
30 my $obj_pkey = $object->primary_key;
31 my $obj_table = $object->table;
32 my $custnum = $object->custnum;
35 "tablenum IN ( SELECT $obj_pkey FROM $obj_table WHERE custnum = $custnum )"
37 if ( $opt{'cust_event'}->eventnum =~ /^(\d+)$/ ) {
38 push @where, " eventnum != $1 ";
40 my $extra_sql = ' AND '. join(' AND ', @where);
42 my $max_date = $self->option_age_from('run_delay', $opt{'time'});
44 my @existing = qsearch( {
45 'table' => 'cust_event',
47 'eventpart' => $self->eventpart,
48 'status' => { op=>'!=', value=>'failed' },
49 '_date' => { op=>'>', value=>$max_date },
51 'extra_sql' => $extra_sql,