mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 12:15:23 +02:00
Fix: improve Vendor stock parsing robustness and ASIN extraction for B0D14YBNWB
This commit is contained in:
+27
-10
@@ -2327,15 +2327,21 @@ export const processVendorStockExcel = async (fileOrBuffer: File | ArrayBuffer):
|
||||
|
||||
if (headerRowIndex === -1) {
|
||||
// Fallback: look for ASIN in first row if not found in header scan
|
||||
if (jsonData[0] && (jsonData[0].includes('ASIN') || jsonData[0].includes('asin'))) headerRowIndex = 0;
|
||||
else {
|
||||
headerRowIndex = jsonData.findIndex(row =>
|
||||
row && row.some(cell => String(cell || '').toUpperCase().includes('ASIN'))
|
||||
);
|
||||
|
||||
if (headerRowIndex === -1) {
|
||||
console.warn("Could not find header row in Vendor Stock Excel");
|
||||
return vendorStockMap;
|
||||
}
|
||||
}
|
||||
|
||||
const headers: any[] = jsonData[headerRowIndex];
|
||||
const asinIdx = headers.findIndex(h => String(h || '').toUpperCase() === 'ASIN');
|
||||
const asinIdx = headers.findIndex(h => {
|
||||
const sh = String(h || '').toUpperCase();
|
||||
return sh === 'ASIN' || sh === 'PRODUCT ASIN' || sh === 'IDENTIFIER';
|
||||
});
|
||||
|
||||
// Enhanced marketplace detection - includes 'Store code' for PANEU reports
|
||||
const marketplaceIdx = headers.findIndex(h => {
|
||||
@@ -2396,8 +2402,10 @@ export const processVendorStockExcel = async (fileOrBuffer: File | ArrayBuffer):
|
||||
const row = jsonData[i];
|
||||
if (!row || row.length <= Math.max(finalAsinIdx, finalMarketplaceIdx, finalStockIdx)) continue;
|
||||
|
||||
const asin = String(row[finalAsinIdx] || '').trim().toUpperCase();
|
||||
if (!asin) continue;
|
||||
const asinRaw = String(row[finalAsinIdx] || '').trim().toUpperCase();
|
||||
const asin = (asinRaw.match(/B[A-Z0-9]{9}/) || [asinRaw])[0];
|
||||
if (!asin || asin.length < 10) continue;
|
||||
|
||||
|
||||
const marketplace = String(row[finalMarketplaceIdx] || '').trim().toLowerCase();
|
||||
const stockValue = parseUnits(String(row[finalStockIdx] || '0'));
|
||||
@@ -2409,10 +2417,17 @@ export const processVendorStockExcel = async (fileOrBuffer: File | ArrayBuffer):
|
||||
const current = vendorStockMap.get(asin)!;
|
||||
|
||||
// Map to UK or EU
|
||||
if (marketplace.includes('uk') || marketplace.includes('kingdom') || marketplace === 'gb' || marketplace === 'united kingdom') {
|
||||
const isUK = marketplace.includes('uk') ||
|
||||
marketplace.includes('kingdom') ||
|
||||
marketplace === 'gb' ||
|
||||
marketplace === 'united kingdom' ||
|
||||
marketplace === 'amazon.co.uk';
|
||||
|
||||
if (isUK) {
|
||||
current.uk += stockValue;
|
||||
} else if (marketplace) {
|
||||
// Assume everything else with a marketplace is Pan-EU (DE, IT, FR, ES)
|
||||
} else {
|
||||
// Default to EU for any other marketplace or if marketplace is empty
|
||||
// This ensures we don't lose data if the column detection is slightly off
|
||||
current.eu += stockValue;
|
||||
}
|
||||
}
|
||||
@@ -2485,8 +2500,10 @@ export const processUKInventoryExcel = async (
|
||||
const row = jsonData[i];
|
||||
if (!row || row.length <= Math.max(finalAsinIdx, finalStockIdx)) continue;
|
||||
|
||||
const asin = String(row[finalAsinIdx] || '').trim().toUpperCase();
|
||||
if (!asin) continue;
|
||||
const asinRaw = String(row[finalAsinIdx] || '').trim().toUpperCase();
|
||||
const asin = (asinRaw.match(/B[A-Z0-9]{9}/) || [asinRaw])[0];
|
||||
if (!asin || asin.length < 10) continue;
|
||||
|
||||
|
||||
const stockValue = parseUnits(String(row[finalStockIdx] || '0'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user