mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 12:15:23 +02:00
Fix: Corrected 2026 revenue discrepancy, resolved WeeklyGrid initialization crash, and restored Week Coverage data
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user