diff --git a/services/dataProcessor.ts b/services/dataProcessor.ts index 885c031..94afb06 100644 --- a/services/dataProcessor.ts +++ b/services/dataProcessor.ts @@ -346,7 +346,9 @@ export const isRealSale = (record: any): boolean => { // 3. Units check: Real sales must have units. // Records with 0 units or negative units (unless it's a return, but usually returns have an ASIN) - if (!record.units || record.units <= 0) return false; + // Supports both SalesRecord (units) and CombinedKPIs (unitsTotal) + const units = record.units !== undefined ? record.units : record.unitsTotal; + if (units === undefined || units <= 0) return false; return true; }; @@ -1163,6 +1165,7 @@ export const filterData = ( // Apply selected values filter if (condition.selectedValues && condition.selectedValues.length > 0) { result = result.filter(r => { + if (!((key as string) in r)) return true; // Skip if key not in flat record const val = String((r as any)[key] || ''); return condition.selectedValues?.includes(val); }); @@ -1174,6 +1177,7 @@ export const filterData = ( const lowerValue = value.toLowerCase(); result = result.filter(r => { + if (!((key as string) in r)) return true; // Skip if key not in flat record const rowVal = String((r as any)[key] || '').toLowerCase(); switch (operator) { case 'equals': return rowVal === lowerValue;