mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 11:35:24 +02:00
feat(bc): sync categorization code
This commit is contained in:
@@ -8,6 +8,17 @@ function findHeaderIndex(headers, patterns) {
|
||||
);
|
||||
}
|
||||
|
||||
function findCategorizationCodeIndex(headers) {
|
||||
const normalized = headers.map(h => String(h || '').toLowerCase().trim());
|
||||
const categorizationIdx = normalized.findIndex(header => header.replace(/[\s_-]+/g, '') === 'categorizationcode');
|
||||
if (categorizationIdx >= 0) return categorizationIdx;
|
||||
|
||||
const typeIdx = normalized.findIndex(header => header === 'type');
|
||||
if (typeIdx >= 0) return typeIdx;
|
||||
|
||||
return normalized.findIndex(header => header.includes('product') && header.includes('type'));
|
||||
}
|
||||
|
||||
function formatDateForBc(value) {
|
||||
if (value === null || value === undefined || value === '') return null;
|
||||
|
||||
@@ -60,6 +71,7 @@ export function buildBusinessCentralMappingPreview(headers, row) {
|
||||
const shortDeIdx = findHeaderIndex(headers, ['short', 'description', 'german']);
|
||||
const shortEnIdx = findHeaderIndex(headers, ['short', 'description', 'english']);
|
||||
const cpnpIdx = findHeaderIndex(headers, ['cpnp']);
|
||||
const categorizationCodeIdx = findCategorizationCodeIndex(headers);
|
||||
|
||||
const unitsOuterIdx = findHeaderIndex(headers, ['units', 'outer']);
|
||||
const units40HqIdx = (() => {
|
||||
@@ -76,6 +88,9 @@ export function buildBusinessCentralMappingPreview(headers, row) {
|
||||
|
||||
const articleNo = String(getValue(row, articleNoIdx) ?? '');
|
||||
|
||||
const categorizationCode = getValue(row, categorizationCodeIdx);
|
||||
const hasCategorizationCode = String(categorizationCode ?? '').trim() !== '';
|
||||
|
||||
const itemsPayload = {
|
||||
no: getValue(row, articleNoIdx),
|
||||
articleDetailsEnglish: getValue(row, articleDetailsEnIdx),
|
||||
@@ -88,6 +103,10 @@ export function buildBusinessCentralMappingPreview(headers, row) {
|
||||
cpnpNo: getValue(row, cpnpIdx),
|
||||
};
|
||||
|
||||
if (hasCategorizationCode) {
|
||||
itemsPayload.categorizationCode = String(categorizationCode).trim();
|
||||
}
|
||||
|
||||
const itemUnitsOfMeasurePayload = {
|
||||
itemNo: getValue(row, articleNoIdx),
|
||||
code: 'OUTER',
|
||||
@@ -118,6 +137,9 @@ export function buildBusinessCentralMappingPreview(headers, row) {
|
||||
makeFieldPreview('Short Description - German', shortDeIdx, 'shortDescriptionInGerman', itemsPayload.shortDescriptionInGerman),
|
||||
makeFieldPreview('Short Description - English', shortEnIdx, 'shortDescriptionInEnglish', itemsPayload.shortDescriptionInEnglish),
|
||||
makeFieldPreview('CPNP', cpnpIdx, 'cpnpNo', itemsPayload.cpnpNo),
|
||||
...(hasCategorizationCode
|
||||
? [makeFieldPreview('CategorizationCode', categorizationCodeIdx, 'categorizationCode', itemsPayload.categorizationCode)]
|
||||
: []),
|
||||
],
|
||||
itemUnitsFields: [
|
||||
makeFieldPreview('Article No.', articleNoIdx, 'itemNo', itemUnitsOfMeasurePayload.itemNo),
|
||||
@@ -239,6 +261,7 @@ function getItemsSelect() {
|
||||
'shortDescriptionInGerman',
|
||||
'shortDescriptionInEnglish',
|
||||
'cpnpNo',
|
||||
'categorizationCode',
|
||||
].join(',');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user