fix(reports/legacy): include Internet equipment cats to capture all discounts

User flagged Claude Bergeron at 99.95$ "including TV". Investigation: the
report already excludes TV (cat 33/34) — his cat-32 Internet subtotal was
94.95. The real issue was the opposite of what it looked like: a -60$
RAB_FTTH_URBA discount on his account lives in cat 26 ("équipement fibre"),
which the report did NOT count. His true net Internet is 44.95$, so he
should drop off the >90$ list entirely (and now does).

Internet equipment categories (26/29 fibre, 7/8 wireless) carry recurring
items that belong on the Internet bill:
  - modem/router rentals: FTTH_LOCMOD +10, LOC_TPL +5, LOCRTHG8245 +6.95
  - Internet discounts:    RAB_FTTH_URBA (hijacked to -60 for Claude)
Added them to CAT_INTERNET_CORE. The existing price_recurr_type=1 filter
still drops one-time install charges (INSTFIBRE -199, etc.) that share
these categories. Verified HVSECTOUR/INSTTELE (odd high-price items in
cat 7/8) have zero active residential services — no aberrations introduced.

Net effect: the report's "net Internet" is now truly net of every
recurring Internet discount, wherever it's categorized. Residential >90$:
554 → 739 (modem rentals legitimately lift borderline bills; deep
equipment-category discounts like Claude's pull others below the line).
TV and téléphonie remain fully excluded.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
louispaulb 2026-06-01 19:46:58 -04:00
parent 94ebb822db
commit 7413743572

View File

@ -61,8 +61,12 @@
* end date.)
*
* Internet product categories:
* 32 Mensualités fibre, 4 Mensualités sans-fil, 23 Internet camping
* (add-ons) 16 Téléch. supp, 17 IP fixe, 21 Location point-à-point
* monthly: 32 Mensualités fibre, 4 Mensualités sans-fil, 23 camping
* equipment: 26/29 équipement fibre, 7/8 équipement sans-fil
* (recurring modem/router rentals + Internet discounts that
* live here, e.g. RAB_FTTH_URBA). One-time install charges
* in these cats are dropped by the price_recurr_type=1 filter.
* add-ons: 16 Téléch. supp, 17 IP fixe, 21 Location point-à-point
* Excluded entirely: 9 Téléphonie, 33 Télévision, 34 Install télé
*/
@ -72,8 +76,18 @@ const { log, json } = require('./helpers')
let mysql
try { mysql = require('mysql2/promise') } catch { /* optional dep */ }
const CAT_INTERNET_CORE = [32, 4, 23] // fibre, wireless, camping
// Internet category sets. CORE = monthly plans + Internet equipment.
// The equipment categories (26/29 fibre, 7/8 wireless) carry recurring
// modem/router rentals (FTTH_LOCMOD +10, LOC_TPL +5) AND recurring Internet
// discounts (RAB_FTTH_URBA), which are part of the real Internet bill — a
// client's net Internet cost is wrong without them. Example: Claude Bergeron
// shows 94.95 from cat 32 alone, but a -60$ RAB_FTTH_URBA discount lives in
// cat 26, so his true net is 44.95 (and he correctly drops off the report).
// The price_recurr_type=1 filter still excludes one-time install charges
// (INSTFIBRE -199, etc.) that share these equipment categories.
const CAT_INTERNET_CORE = [32, 4, 23, 26, 29, 7, 8]
const CAT_INTERNET_ADDONS = [16, 17, 21] // extra download, static IP, point-to-point
// Always excluded: 9 Téléphonie, 33 Télévision, 34 Installation/équip télé.
// Monthly-normalized effective price expression (see header comment).
const EFF = `((CASE WHEN s.hijack=1 THEN s.hijack_price ELSE p.price END) / (CASE WHEN p.sku LIKE '%ANN' THEN 12 ELSE 1 END))`