1 package FS::part_event::Condition::once_perinv;
4 use FS::Record qw( qsearch );
8 use base qw( FS::part_event::Condition );
10 sub description { "Run only once for each time the package has been billed"; }
12 # Run the event, at most, a number of times equal to the number of
13 # distinct invoices that contain line items from this package.
15 sub eventtable_hashref {
23 my($self, $cust_pkg, %opt) = @_;
26 $invnum{$_->invnum} = 1
27 foreach ( qsearch('cust_bill_pkg', { 'pkgnum' => $cust_pkg->pkgnum }) );
28 my @events = qsearch( {
29 'table' => 'cust_event',
30 'hashref' => { 'eventpart' => $self->eventpart,
31 'status' => { op=>'!=', value=>'failed' },
32 'tablenum' => $cust_pkg->pkgnum,
34 'extra_sql' => ( $opt{'cust_event'}->eventnum =~ /^(\d+)$/
35 ? " AND eventnum != $1 " : '' ),
37 scalar(@events) < scalar(keys %invnum);
41 my( $self, $table ) = @_;
44 ( SELECT COUNT(distinct(invnum))
46 WHERE cust_bill_pkg.pkgnum = cust_pkg.pkgnum )
50 WHERE cust_event.eventpart = part_event.eventpart
51 AND cust_event.tablenum = cust_pkg.pkgnum
52 AND status != 'failed' )