Don't renew if there is a future plan

Stephen Paul Weber created

Note this means if there is a big hole between the end of current plan
and the future plan that they won't renew properly.

Change summary

bin/billing_monthly_cronjob | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

Detailed changes

bin/billing_monthly_cronjob 🔗

@@ -88,7 +88,13 @@ EM::Iterator.new(db.exec(
 	FROM customer_plans
 	WHERE
 		expires_at <= LOCALTIMESTAMP + '4 days' AND
-		expires_at > LOCALTIMESTAMP - INTERVAL '1 month'
+		expires_at > LOCALTIMESTAMP - INTERVAL '1 month' AND (
+			SELECT COUNT(*)
+			FROM plan_log
+			WHERE
+				customer_id=customer_plans.customer_id AND
+				UPPER(date_range) > LOCALTIMESTAMP + '4 days'
+		) < 1;
 	SQL
 ), 3).each(nil, -> { one << :done }) do |row, iter|
 	customer = ExpiringCustomer.new(row["customer_id"])