diff --git a/components/mkt/MktDataView.tsx b/components/mkt/MktDataView.tsx index 993ce8e..8334ebe 100644 --- a/components/mkt/MktDataView.tsx +++ b/components/mkt/MktDataView.tsx @@ -159,25 +159,24 @@ export default function MktDataView({ rawData, adsData }: MktDataViewProps) { } }); - // ASIN → global sell-out and units (only for 2025) + // ASIN → global sell-out and units const sellOutMap = new Map(); const unitsMap = new Map(); - const rawData2025 = rawData.filter(r => r.year === 2025); - rawData2025.forEach(r => { + rawData.forEach(r => { const asin = r.asin.trim().toUpperCase(); sellOutMap.set(asin, (sellOutMap.get(asin) || 0) + r.sellOut); unitsMap.set(asin, (unitsMap.get(asin) || 0) + r.units); }); - // ASIN → global ad spend (only for 2025) + // ASIN → global ad spend (all filtered data, no hardcoded year) const adsSpendMap = new Map(); - const adsData2025 = adsData.filter(r => r.year === 2025); - adsData2025.forEach(r => { + adsData.forEach(r => { const asin = r.asin.trim().toUpperCase(); - adsSpendMap.set(asin, (adsSpendMap.get(asin) || 0) + r.cost); + if (asin) adsSpendMap.set(asin, (adsSpendMap.get(asin) || 0) + r.cost); }); - return Array.from(metaMap.entries()) + // Build products from sales ASINs + const products = Array.from(metaMap.entries()) .map(([asin, meta]): Product => ({ id: asin, asin, @@ -195,6 +194,31 @@ export default function MktDataView({ rawData, adsData }: MktDataViewProps) { chargebacksPrevMonth: 0, cogs: 0, })); + + // Add ASINs that have ad spend but no sales records (so total matches ADs tab) + adsSpendMap.forEach((spend, asin) => { + if (!metaMap.has(asin) && spend > 0) { + products.push({ + id: asin, + asin, + sku: '', + name: asin, + image: '', + category: 'Other', + brand: '', + grossSales: 0, + unitsSold: 0, + ppcSpend: spend, + deals: dealsMap.get(asin) || 0, + promos: promosMap.get(asin) || 0, + chargebacks: chargebacksMap.get(asin) || 0, + chargebacksPrevMonth: 0, + cogs: 0, + }); + } + }); + + return products; }, [rawData, adsData, dealsMap, promosMap, chargebacksMap]); const filteredProducts = allProducts;