diff options
author | levinse <levinse> | 2011-05-08 05:44:40 +0000 |
---|---|---|
committer | levinse <levinse> | 2011-05-08 05:44:40 +0000 |
commit | 8a4f7ef5401e2ae6c1c05269458084fe399361f8 (patch) | |
tree | a9ff1ac559357d585b14320325c41b7eb31422f8 | |
parent | 487671e2fe08e63485dc71363a908295027516b5 (diff) |
implement condition_sql for FS::part_event::Condition::cust_bill_hasnt_noauto, RT12714
-rw-r--r-- | FS/FS/part_event/Condition/cust_bill_hasnt_noauto.pm | 38 |
1 files changed, 32 insertions, 6 deletions
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..bb0f3d04a 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,37 @@ 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? + # -add indices on cust_pkg.no_auto and part_pkg.no_auto and others? + + "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; |