From 910e6d2a4d6f826dc348c58da6b591ab234abf83 Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Thu, 12 Mar 2026 16:44:36 +0100 Subject: [PATCH] fix: include empty-ASIN ad records so MKT total matches ADs Weekly Removed the `if (asin)` guard so records without a product ASIN (e.g. campaign-level rows) accumulate in adsSpendMap and appear as an 'Unassigned Ad Spend' row, ensuring the total PPC spend is the same as in the ADs Weekly tab. Co-Authored-By: Claude Sonnet 4.6 --- components/mkt/MktDataView.tsx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/components/mkt/MktDataView.tsx b/components/mkt/MktDataView.tsx index 1bcd8ec..b482808 100644 --- a/components/mkt/MktDataView.tsx +++ b/components/mkt/MktDataView.tsx @@ -169,10 +169,11 @@ export default function MktDataView({ rawData, adsData }: MktDataViewProps) { }); // ASIN → global ad spend (all filtered data, no hardcoded year) + // Include ALL records (even empty ASIN) so total matches ADs Weekly tab const adsSpendMap = new Map(); adsData.forEach(r => { const asin = r.asin.trim().toUpperCase(); - if (asin) adsSpendMap.set(asin, (adsSpendMap.get(asin) || 0) + r.cost); + adsSpendMap.set(asin, (adsSpendMap.get(asin) || 0) + r.cost); }); // Deals/Promos/Chargebacks are 2025-only data — only apply when 2025 is in scope @@ -201,23 +202,23 @@ export default function MktDataView({ rawData, adsData }: MktDataViewProps) { cogs: 0, })); - // Add ASINs that have ad spend but no sales records (so total matches ADs tab) + // Add ASINs (or unassigned spend) that have ad spend but no sales records adsSpendMap.forEach((spend, asin) => { if (!metaMap.has(asin) && spend > 0) { products.push({ - id: asin, - asin, + id: asin || '__unassigned__', + asin: asin || '—', sku: '', - name: asin, + name: asin ? asin : 'Unassigned Ad Spend', image: '', category: 'Other', brand: '', grossSales: 0, unitsSold: 0, ppcSpend: spend, - deals: getDeals(asin), - promos: getPromos(asin), - chargebacks: getChargebacks(asin), + deals: asin ? getDeals(asin) : 0, + promos: asin ? getPromos(asin) : 0, + chargebacks: asin ? getChargebacks(asin) : 0, chargebacksPrevMonth: 0, cogs: 0, });