1 package FS::part_event::Condition::times;
4 use FS::Record qw( qsearch );
8 use base qw( FS::part_event::Condition );
10 sub description { "Run this event the specified number of times"; }
14 'run_times' => { label=>'Number of times', type=>'text', value=>'1', },
19 my($self, $object, %opt) = @_;
21 my $obj_pkey = $object->primary_key;
22 my $tablenum = $object->$obj_pkey();
24 my @existing = qsearch( {
25 'table' => 'cust_event',
27 'eventpart' => $self->eventpart,
28 'tablenum' => $tablenum,
29 'status' => { op=>'!=', value=>'failed' },
31 'extra_sql' => ( $opt{'cust_event'}->eventnum =~ /^(\d+)$/
32 ? " AND eventnum != $1 "
37 scalar(@existing) < $self->option('run_times');
42 my( $class, $table, %opt ) = @_;
44 my %tablenum = %{ FS::part_event->eventtable_pkey_sql };
47 $class->condition_sql_option_integer('run_times', $opt{'driver_name'});
49 my $existing = "( SELECT COUNT(*) FROM cust_event
50 WHERE cust_event.eventpart = part_event.eventpart
51 AND cust_event.tablenum = $tablenum{$table}
52 AND status != 'failed'
55 "$existing < $run_times";