1 package FS::part_event::Condition::once_percust;
4 use FS::Record qw( qsearch );
8 use base qw( FS::part_event::Condition );
10 sub description { "Don't run more than once per customer"; }
12 sub eventtable_hashref {
20 my($self, $object, %opt) = @_;
22 my $obj_pkey = $object->primary_key;
23 my $obj_table = $object->table;
24 my $custnum = $object->custnum;
27 "tablenum IN ( SELECT $obj_pkey FROM $obj_table WHERE custnum = $custnum )"
29 if ( $opt{'cust_event'}->eventnum =~ /^(\d+)$/ ) {
30 push @where, " eventnum != $1 ";
32 my $extra_sql = ' AND '. join(' AND ', @where);
34 my @existing = qsearch( {
35 'table' => 'cust_event',
37 'eventpart' => $self->eventpart,
38 #'tablenum' => $tablenum,
39 'status' => { op=>'!=', value=>'failed' },
41 'extra_sql' => $extra_sql,
49 my( $self, $table ) = @_;
51 my %pkey = %{ FS::part_event->eventtable_pkey };
53 my $pkey = $pkey{$table};
55 "NOT EXISTS ( SELECT 1 FROM cust_event
56 WHERE cust_event.eventpart = part_event.eventpart
57 AND cust_event.tablenum IN (
58 SELECT $pkey FROM $table AS once_percust
59 WHERE once_percust.custnum = cust_main.custnum )
60 AND status != 'failed'