performed field check fix
This commit is contained in:
parent
d98044692f
commit
b6f2872703
@ -18,6 +18,7 @@ import {
|
|||||||
RadioField,
|
RadioField,
|
||||||
} from './fields';
|
} from './fields';
|
||||||
import { ORDER_BOOKING, STORE, DAILY_REPORTS, PIPELINE } from '../../api/config';
|
import { ORDER_BOOKING, STORE, DAILY_REPORTS, PIPELINE } from '../../api/config';
|
||||||
|
import { isCategoryColumn, isProductColumn } from './fields/gridUtils';
|
||||||
|
|
||||||
export interface DynamicFormProps {
|
export interface DynamicFormProps {
|
||||||
client: ZinoClient;
|
client: ZinoClient;
|
||||||
@ -597,13 +598,113 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
|||||||
payload[f.id] = [fileMeta];
|
payload[f.id] = [fileMeta];
|
||||||
} else if (f.data_type.startsWith('grid') || f.data_type === 'smart_grid') {
|
} else if (f.data_type.startsWith('grid') || f.data_type === 'smart_grid') {
|
||||||
const gridRows = Array.isArray(val) ? val : [];
|
const gridRows = Array.isArray(val) ? val : [];
|
||||||
const cleanRows = gridRows.filter(r => {
|
const getFormattedGridVal = (colKey: string, rawVal: unknown, colDef?: FormScreenField) => {
|
||||||
return Object.keys(r).some(k => {
|
if (rawVal === undefined || rawVal === null || String(rawVal).trim() === '') return undefined;
|
||||||
const v = r[k];
|
|
||||||
return v !== undefined && v !== null && String(v).trim() !== '';
|
const keyLower = colKey.toLowerCase();
|
||||||
|
const colNameLower = (colDef?.name || '').toLowerCase();
|
||||||
|
const dataType = colDef?.data_type;
|
||||||
|
|
||||||
|
// 1. Explicit number data_type from form screen API
|
||||||
|
if (dataType === 'number') {
|
||||||
|
const num = Number(rawVal);
|
||||||
|
return !isNaN(num) ? num : rawVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Explicit string/select/id_gen data_type from API or SKU/code identifier columns
|
||||||
|
const isStringCol = dataType === 'select' ||
|
||||||
|
dataType === 'text' ||
|
||||||
|
dataType === 'string' ||
|
||||||
|
dataType === 'id_gen' ||
|
||||||
|
keyLower.includes('sku') ||
|
||||||
|
keyLower.includes('code') ||
|
||||||
|
keyLower.includes('br_code') ||
|
||||||
|
keyLower === 'br' ||
|
||||||
|
colNameLower.includes('sku') ||
|
||||||
|
colNameLower.includes('code');
|
||||||
|
|
||||||
|
if (isStringCol) {
|
||||||
|
return String(rawVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Bags / Quantity / Row Kgs quantity columns without explicit text colDef
|
||||||
|
const isNumericQuantity = keyLower === 'bags' ||
|
||||||
|
keyLower === 'quantity' ||
|
||||||
|
keyLower === 'row_kgs' ||
|
||||||
|
colNameLower === 'bags' ||
|
||||||
|
colNameLower === 'quantity';
|
||||||
|
|
||||||
|
if (isNumericQuantity) {
|
||||||
|
const num = Number(rawVal);
|
||||||
|
return !isNaN(num) ? num : rawVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rawVal;
|
||||||
|
};
|
||||||
|
|
||||||
|
const cleanRows = gridRows
|
||||||
|
.filter(r => {
|
||||||
|
return Object.keys(r).some(k => {
|
||||||
|
const v = r[k];
|
||||||
|
return v !== undefined && v !== null && String(v).trim() !== '';
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.map(r => {
|
||||||
|
const formattedRow: Record<string, unknown> = {};
|
||||||
|
|
||||||
|
// 1. Process all existing keys in row r
|
||||||
|
for (const [k, v] of Object.entries(r)) {
|
||||||
|
if (v === undefined || v === null || String(v).trim() === '') continue;
|
||||||
|
|
||||||
|
const colDef = f.columns?.find(c =>
|
||||||
|
c.id === k ||
|
||||||
|
(c.name || '').toLowerCase() === k.toLowerCase() ||
|
||||||
|
c.mapped_workflow_field === k
|
||||||
|
);
|
||||||
|
|
||||||
|
const formattedVal = getFormattedGridVal(k, v, colDef);
|
||||||
|
if (formattedVal !== undefined) {
|
||||||
|
formattedRow[k] = formattedVal;
|
||||||
|
|
||||||
|
if (colDef && colDef.id && colDef.id !== k) {
|
||||||
|
formattedRow[colDef.id] = formattedVal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Also map any schema defined columns from f.columns
|
||||||
|
if (f.columns && f.columns.length > 0) {
|
||||||
|
for (const col of f.columns) {
|
||||||
|
if (formattedRow[col.id] === undefined) {
|
||||||
|
const matchKey = Object.keys(r).find(rk =>
|
||||||
|
rk.toLowerCase() === col.id.toLowerCase() ||
|
||||||
|
rk.toLowerCase() === (col.name || '').toLowerCase() ||
|
||||||
|
(col.mapped_workflow_field && rk.toLowerCase() === col.mapped_workflow_field.toLowerCase()) ||
|
||||||
|
(isCategoryColumn(col.id, col.name) && (rk.toLowerCase().includes('category') || rk === 'cat')) ||
|
||||||
|
(isProductColumn(col.id, col.name) && (rk.toLowerCase().includes('product') || rk === 'productName')) ||
|
||||||
|
(col.name?.toLowerCase().includes('bags') && (rk.toLowerCase().includes('bags') || rk.toLowerCase().includes('quantity')))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (matchKey && r[matchKey] !== undefined && r[matchKey] !== null && String(r[matchKey]).trim() !== '') {
|
||||||
|
const formattedVal = getFormattedGridVal(matchKey, r[matchKey], col);
|
||||||
|
if (formattedVal !== undefined) {
|
||||||
|
formattedRow[col.id] = formattedVal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedRow;
|
||||||
});
|
});
|
||||||
});
|
|
||||||
payload[f.id] = cleanRows;
|
payload[f.id] = cleanRows;
|
||||||
|
} else if (f.data_type === 'number') {
|
||||||
|
if (val !== undefined && val !== null && val !== '') {
|
||||||
|
const num = Number(val);
|
||||||
|
payload[f.id] = !isNaN(num) ? num : val;
|
||||||
|
} else {
|
||||||
|
payload[f.id] = val;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
payload[f.id] = val;
|
payload[f.id] = val;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -247,19 +247,19 @@ export function OrderGrid({
|
|||||||
row['productName'] = selectedName;
|
row['productName'] = selectedName;
|
||||||
if (prodNameCol) row[prodNameCol.id] = setVal;
|
if (prodNameCol) row[prodNameCol.id] = setVal;
|
||||||
|
|
||||||
row['sku'] = sku;
|
row['sku'] = String(sku ?? '');
|
||||||
const skuCol = findColumn(columns, 'sku');
|
const skuCol = findColumn(columns, 'sku');
|
||||||
if (skuCol) row[skuCol.id] = sku;
|
if (skuCol) row[skuCol.id] = String(sku ?? '');
|
||||||
|
|
||||||
row['br'] = br;
|
row['br'] = String(br ?? '');
|
||||||
row['br_code'] = br;
|
row['br_code'] = String(br ?? '');
|
||||||
const brCol = findColumn(columns, 'br_code', 'br');
|
const brCol = findColumn(columns, 'br_code', 'br');
|
||||||
if (brCol) row[brCol.id] = br;
|
if (brCol) row[brCol.id] = String(br ?? '');
|
||||||
|
|
||||||
row['skucode'] = skucode;
|
row['skucode'] = String(skucode ?? '');
|
||||||
row['sku_code'] = skucode;
|
row['sku_code'] = String(skucode ?? '');
|
||||||
const skuCodeCol = findColumn(columns, 'sku_code', 'skucode');
|
const skuCodeCol = findColumn(columns, 'sku_code', 'skucode');
|
||||||
if (skuCodeCol) row[skuCodeCol.id] = skucode;
|
if (skuCodeCol) row[skuCodeCol.id] = String(skucode ?? '');
|
||||||
|
|
||||||
if (cat) {
|
if (cat) {
|
||||||
row['category'] = cat;
|
row['category'] = cat;
|
||||||
@ -270,16 +270,17 @@ export function OrderGrid({
|
|||||||
const bagsVal = Number(row.bags ?? row.quantity ?? (bagsCol ? row[bagsCol.id] : 0)) || 0;
|
const bagsVal = Number(row.bags ?? row.quantity ?? (bagsCol ? row[bagsCol.id] : 0)) || 0;
|
||||||
row['row_kgs'] = Number(sku || 0) * bagsVal;
|
row['row_kgs'] = Number(sku || 0) * bagsVal;
|
||||||
} else if (isBagsField) {
|
} else if (isBagsField) {
|
||||||
const parsedVal = val !== '' && val !== null && val !== undefined ? val : '';
|
const numericVal = val !== '' && val !== null && val !== undefined ? Number(val) : 0;
|
||||||
const numericVal = Number(val) || 0;
|
const isNumValid = !isNaN(numericVal);
|
||||||
|
const valToSave = isNumValid ? numericVal : 0;
|
||||||
|
|
||||||
row[fieldId] = parsedVal;
|
row[fieldId] = valToSave;
|
||||||
row['bags'] = parsedVal;
|
row['bags'] = valToSave;
|
||||||
row['quantity'] = parsedVal;
|
row['quantity'] = valToSave;
|
||||||
if (bagsCol) row[bagsCol.id] = parsedVal;
|
if (bagsCol) row[bagsCol.id] = valToSave;
|
||||||
|
|
||||||
const skuVal = Number(row.sku || 0);
|
const skuVal = Number(row.sku || 0);
|
||||||
row['row_kgs'] = skuVal * numericVal;
|
row['row_kgs'] = skuVal * valToSave;
|
||||||
} else {
|
} else {
|
||||||
row[fieldId] = val;
|
row[fieldId] = val;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -132,11 +132,12 @@ export function StorePotentialGrid({
|
|||||||
row['category'] = catVal;
|
row['category'] = catVal;
|
||||||
row['product_category'] = catVal;
|
row['product_category'] = catVal;
|
||||||
} else if (isBagsField) {
|
} else if (isBagsField) {
|
||||||
const parsedVal = val !== '' && val !== null && val !== undefined ? val : '';
|
const numericVal = val !== '' && val !== null && val !== undefined ? Number(val) : 0;
|
||||||
row[fieldId] = parsedVal;
|
const valToSave = !isNaN(numericVal) ? numericVal : 0;
|
||||||
row['bags'] = parsedVal;
|
row[fieldId] = valToSave;
|
||||||
row['quantity'] = parsedVal;
|
row['bags'] = valToSave;
|
||||||
if (bagsCol) row[bagsCol.id] = parsedVal;
|
row['quantity'] = valToSave;
|
||||||
|
if (bagsCol) row[bagsCol.id] = valToSave;
|
||||||
} else {
|
} else {
|
||||||
row[fieldId] = val;
|
row[fieldId] = val;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user