From c4bf18fdcbfdcbe83076b6f1c74dc490b9a198a7 Mon Sep 17 00:00:00 2001 From: louispaulb Date: Tue, 2 Jun 2026 06:33:25 -0400 Subject: [PATCH] fix(legacy-report): treat accounts with a company name as commercial MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 98 business accounts had commercial=0 but a company name (Ferme X Inc., Ville de Farnham, Les Jardins Sorel…), leaking into the residential report. Rule is now: commercial = (commercial flag) OR (company present). Residential @90$ drops 739→654 (0 company-bearing rows left); commercial 244→276. Co-Authored-By: Claude Opus 4.8 (1M context) --- services/targo-hub/lib/legacy-reports.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/services/targo-hub/lib/legacy-reports.js b/services/targo-hub/lib/legacy-reports.js index 7c817ac..b6f0af2 100644 --- a/services/targo-hub/lib/legacy-reports.js +++ b/services/targo-hub/lib/legacy-reports.js @@ -117,9 +117,15 @@ function buildQuery (url) { const cats = includeAddons ? [...CAT_INTERNET_CORE, ...CAT_INTERNET_ADDONS] : CAT_INTERNET_CORE const catPlaceholders = cats.map(() => '?').join(',') + // A non-empty company name means a business even when the legacy `commercial` + // flag wasn't set — 98 such accounts (Ferme X Inc., Assurances …, Ville de + // Farnham, Les Jardins Sorel) leaked into "residential". So the rule is: + // commercial = (commercial flag set) OR (company name present). Residential + // therefore excludes any account carrying a company name. + const HAS_COMPANY = "(a.company IS NOT NULL AND TRIM(a.company) <> '')" let commercialClause = '' - if (segment === 'residential') commercialClause = 'AND a.commercial = 0' - else if (segment === 'commercial') commercialClause = 'AND a.commercial = 1' + if (segment === 'residential') commercialClause = `AND a.commercial = 0 AND NOT ${HAS_COMPANY}` + else if (segment === 'commercial') commercialClause = `AND (a.commercial = 1 OR ${HAS_COMPANY})` const sql = ` SELECT