X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpart_event%2FCondition%2Fcust_bill_hasnt_noauto.pm;h=d782c12c15f0b03c6ba349c62433d5cde78f27db;hp=78a6d51d41a67289e0c689cc8d2ddf76f58f4778;hb=18af4f3316291938fa8f0a74e083209f62eac4fa;hpb=0fb307c305e4bc2c9c27dc25a3308beae3a4d33c diff --git a/FS/FS/part_event/Condition/cust_bill_hasnt_noauto.pm b/FS/FS/part_event/Condition/cust_bill_hasnt_noauto.pm index 78a6d51d4..d782c12c1 100644 --- a/FS/FS/part_event/Condition/cust_bill_hasnt_noauto.pm +++ b/FS/FS/part_event/Condition/cust_bill_hasnt_noauto.pm @@ -23,11 +23,22 @@ sub condition { ! $cust_bill->no_auto; } -#sub condition_sql { -# my( $class, $table ) = @_; -# -# my $sql = qq| |; -# return $sql; -#} +sub condition_sql { + my( $class, $table, %opt ) = @_; + + # can be made still faster with optimizations? + + "NOT EXISTS ( SELECT 1 FROM cust_pkg + LEFT JOIN part_pkg USING (pkgpart) + WHERE ( cust_pkg.no_auto = 'Y' OR part_pkg.no_auto = 'Y' ) + AND cust_pkg.pkgnum IN + ( SELECT DISTINCT cust_bill_pkg.pkgnum + FROM cust_bill_pkg + WHERE cust_bill_pkg.invnum = cust_bill.invnum + AND cust_bill_pkg.pkgnum > 0 + ) + ) + "; +} 1;