mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 11:45:23 +02:00
fix: include all ad-spend ASINs in MKT tab to match ADs Weekly total
Two bugs fixed: 1. Removed hardcoded year===2025 filter (data is already pre-filtered) 2. ASINs with ad spend but no sales records were silently dropped — now appended as extra rows so the total PPC spend matches ADs Weekly Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
657009a7ba
commit
0eda5551d8
@@ -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<string, number>();
|
const sellOutMap = new Map<string, number>();
|
||||||
const unitsMap = new Map<string, number>();
|
const unitsMap = new Map<string, number>();
|
||||||
const rawData2025 = rawData.filter(r => r.year === 2025);
|
rawData.forEach(r => {
|
||||||
rawData2025.forEach(r => {
|
|
||||||
const asin = r.asin.trim().toUpperCase();
|
const asin = r.asin.trim().toUpperCase();
|
||||||
sellOutMap.set(asin, (sellOutMap.get(asin) || 0) + r.sellOut);
|
sellOutMap.set(asin, (sellOutMap.get(asin) || 0) + r.sellOut);
|
||||||
unitsMap.set(asin, (unitsMap.get(asin) || 0) + r.units);
|
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<string, number>();
|
const adsSpendMap = new Map<string, number>();
|
||||||
const adsData2025 = adsData.filter(r => r.year === 2025);
|
adsData.forEach(r => {
|
||||||
adsData2025.forEach(r => {
|
|
||||||
const asin = r.asin.trim().toUpperCase();
|
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 => ({
|
.map(([asin, meta]): Product => ({
|
||||||
id: asin,
|
id: asin,
|
||||||
asin,
|
asin,
|
||||||
@@ -195,6 +194,31 @@ export default function MktDataView({ rawData, adsData }: MktDataViewProps) {
|
|||||||
chargebacksPrevMonth: 0,
|
chargebacksPrevMonth: 0,
|
||||||
cogs: 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]);
|
}, [rawData, adsData, dealsMap, promosMap, chargebacksMap]);
|
||||||
|
|
||||||
const filteredProducts = allProducts;
|
const filteredProducts = allProducts;
|
||||||
|
|||||||
Reference in New Issue
Block a user