X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FBilling_Discount.pm;h=ec2bf077eaa93eddf77afb9fd90288511f59420f;hb=4fd1280540e2c9b90fa59c0c32d691f5222f65d4;hp=9dda389f6a88f6fd3f82488ded9ca4bdf08a820d;hpb=337323718878fdfe98801193b0dbecffdc8dffc8;p=freeside.git diff --git a/FS/FS/cust_main/Billing_Discount.pm b/FS/FS/cust_main/Billing_Discount.pm index 9dda389f6..ec2bf077e 100644 --- a/FS/FS/cust_main/Billing_Discount.pm +++ b/FS/FS/cust_main/Billing_Discount.pm @@ -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); @@ -90,8 +92,11 @@ sub discount_terms { my @discount_pkgs = $self->_discount_pkgs_and_bill; shift @discount_pkgs; #discard bill; - - map { $terms{$_->months} = 1 } + + # convert @discount_pkgs (the list of packages that have available discounts) + # to a list of distinct term lengths in months, and strip any decimal places + # from the number of months, not that it should have any + map { $terms{sprintf('%.0f', $_->months)} = 1 } grep { $_->months && $_->months > 1 } map { $_->discount } map { $_->part_pkg->part_pkg_discount } @@ -108,6 +113,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;