fix(legacy-report): treat accounts with a company name as commercial

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) <noreply@anthropic.com>
This commit is contained in:
louispaulb 2026-06-02 06:33:25 -04:00
parent b01cf19db6
commit c4bf18fdcb

View File

@ -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