Fix: Corrected 2026 revenue discrepancy, resolved WeeklyGrid initialization crash, and restored Week Coverage data

This commit is contained in:
Christian Vidal Wolf
2026-04-20 12:54:40 +02:00
parent 11ddcb16c5
commit 1e7c88ffad
5 changed files with 440 additions and 417 deletions
+8 -8
View File
@@ -307,11 +307,10 @@ const isAllowedCustomer = (customer: string): boolean => {
if (!customer) return false;
const normCustomer = customer.trim().toLowerCase();
// Check if the customer string includes any of our allowed market names
// Use strict equality to prevent loose matches (e.g., 'UK' matching 'Amazon UK')
// which incorrectly included ad spend records in sell-out totals.
return ALLOWED_CUSTOMERS.some(allowed =>
normCustomer === allowed.toLowerCase() ||
normCustomer.includes(allowed.toLowerCase()) ||
allowed.toLowerCase().includes(normCustomer)
normCustomer === allowed.toLowerCase()
);
};
@@ -412,8 +411,9 @@ export const processCSV = (fileOrContent: File | string): Promise<SalesRecord[]>
const data: SalesRecord[] = results.data.map((row: any, index: number) => {
return mapRowToRecord(row, index);
})
// Filter: Valid Year >= 2023 (include full historical data) AND Allowed Customer
.filter((r: SalesRecord) => r.year >= 2023 && isAllowedCustomer(r.customer));
// Filter: Valid Year >= 2023 AND Allowed Customer AND non-zero units
// Excluding zero-unit records prevents ad spend or financial adjustments from inflating revenue.
.filter((r: SalesRecord) => r.year >= 2023 && isAllowedCustomer(r.customer) && r.units !== 0);
resolve(data);
} catch (err) {
@@ -440,8 +440,8 @@ export const processExcel = async (file: File): Promise<SalesRecord[]> => {
const data: SalesRecord[] = jsonData.map((row: any, index: number) => {
return mapRowToRecord(row, index);
})
// Filter: Valid Year AND Allowed Customer
.filter((r: SalesRecord) => r.year > 0 && isAllowedCustomer(r.customer));
// Filter: Valid Year AND Allowed Customer AND non-zero units
.filter((r: SalesRecord) => r.year > 0 && isAllowedCustomer(r.customer) && r.units !== 0);
return data;
} catch (error) {