X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_event%2FCondition%2Fcust_bill_hasnt_noauto.pm;h=027625569d1d439f8e844ce2774d1f3a1aea0057;hb=4924d635301e5c365d55b0c008f12e9cff40350f;hp=78a6d51d41a67289e0c689cc8d2ddf76f58f4778;hpb=0fb307c305e4bc2c9c27dc25a3308beae3a4d33c;p=freeside.git 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..027625569 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,36 @@ sub condition { ! $cust_bill->no_auto; } -#sub condition_sql { -# my( $class, $table ) = @_; -# -# my $sql = qq| |; -# return $sql; -#} +sub condition_sql { + my( $class, $table, %opt ) = @_; + + # XXX: can be made faster with optimizations? + # -remove some/all sub-selects? + # -remove the two main separate selects? + + "0 = (select count(1) from cust_pkg + where cust_pkg.no_auto = 'Y' and cust_pkg.pkgnum in + (select distinct cust_bill_pkg.pkgnum + from cust_bill_pkg, cust_pkg + where cust_bill_pkg.pkgnum = cust_pkg.pkgnum + and cust_bill_pkg.invnum = cust_bill.invnum + and cust_bill_pkg.pkgnum > 0 + ) + ) + AND + 0 = (select count(1) from part_pkg + where part_pkg.no_auto = 'Y' and part_pkg.pkgpart in + (select cust_pkg.pkgpart from cust_pkg + where pkgnum in + (select distinct cust_bill_pkg.pkgnum + from cust_bill_pkg, cust_pkg + where cust_bill_pkg.pkgnum = cust_pkg.pkgnum + and cust_bill_pkg.invnum = cust_bill.invnum + and cust_bill_pkg.pkgnum > 0 + ) + ) + ) + "; +} 1;