RT#33484 [actually a bug fix to d4b8e45c3589f3c6489442798f5fba439d5a29c9]
[freeside.git] / FS / FS / cust_main / Billing_Discount.pm
index 9dda389..117bf31 100644 (file)
@@ -42,11 +42,13 @@ sub _discount_pkgs_and_bill {
   push @where, "part_pkg.freq = '1'";
   push @where, "(cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0)";
   push @where, "(cust_pkg.susp   IS NULL OR cust_pkg.susp   = 0)";
-  push @where, "0<(SELECT count(*) FROM part_pkg_discount
-                  WHERE part_pkg.pkgpart = part_pkg_discount.pkgpart)";
+  push @where, "EXISTS( SELECT 1 FROM part_pkg_discount
+                          WHERE part_pkg.pkgpart = part_pkg_discount.pkgpart )";
   push @where,
-    "0=(SELECT count(*) FROM cust_bill_pkg_discount
-         WHERE cust_bill_pkg.billpkgnum = cust_bill_pkg_discount.billpkgnum)";
+    "NOT EXISTS (
+       SELECT 1 FROM cust_bill_pkg_discount
+         WHERE cust_bill_pkg.billpkgnum = cust_bill_pkg_discount.billpkgnum
+    )";
 
   my $extra_sql = 'WHERE '. join(' AND ', @where);
 
@@ -108,6 +110,9 @@ by prepaying the most recent invoice for MONTHS.
 
 =cut
 
+# XXX this should work by creating a quotation; then we can finally retire
+# the "no_commit" option, which doesn't work with modern tax calculation
+
 sub discount_term_values {
   my $self = shift;
   my $term = shift;