diff --git a/services/targo-hub/lib/legacy-reports.js b/services/targo-hub/lib/legacy-reports.js index 179dc26..590d944 100644 --- a/services/targo-hub/lib/legacy-reports.js +++ b/services/targo-hub/lib/legacy-reports.js @@ -22,15 +22,26 @@ * * Effective monthly price of a service line: * base = service.hijack=1 ? service.hijack_price : product.price - * // Annual plans (SKU ends in "ANN", e.g. FTTH_ANN @ 480$/yr) are - * // normalized to a monthly equivalent so the threshold compares apples - * // to apples — otherwise a $480/yr (=$40/mo) plan falsely shows as $480. + * // product.price is ALREADY the monthly unit price regardless of the + * // service's billing frequency — a semestrial FTTH1500I has price + * // 109.95 (same as the monthly one) and is billed 6×109.95 every 6 + * // months. Verified against the legacy billing logic (LEGACY- + * // ACCOUNTING-ANALYSIS.md §6.1: "prix = quantité × prix_unitaire"). + * // So we do NOT divide by service.payment_recurrence. + * // The one exception: true annual plans (SKU ends in "ANN", e.g. + * // FTTH_ANN @ 480$/yr where price IS the yearly amount) → normalize /12. * monthly = base / (sku LIKE '%ANN' ? 12 : 1) * * Only recurring lines count: product.price_recurr_type = 1. Type 0 is * one-time charges (equipment, installation) which don't belong on a * recurring monthly bill. * + * Expired credits excluded: a discount line (price<0) whose service + * actif_until is in the past no longer reduces the real bill — counting + * it would understate what the client actually pays today. (Per + * LEGACY-ACCOUNTING-ANALYSIS.md §10: promo credits carry an actif_until + * 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 @@ -106,6 +117,7 @@ function buildQuery (url) { JOIN product p ON p.id = s.product_id WHERE p.category IN (${catPlaceholders}) AND p.price_recurr_type = 1 + AND NOT (p.price < 0 AND s.actif_until IS NOT NULL AND s.actif_until > 0 AND s.actif_until < UNIX_TIMESTAMP()) ${commercialClause} GROUP BY d.id HAVING net_internet > ?