edit option for the populated same product
This commit is contained in:
parent
30339b0443
commit
d98044692f
@ -385,11 +385,11 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
|||||||
|
|
||||||
if (cat && prod) {
|
if (cat && prod) {
|
||||||
const key = `${cat}::${prod}`;
|
const key = `${cat}::${prod}`;
|
||||||
if (indexMap.has(key)) {
|
if (indexMap.has(key) && currentBags > 0) {
|
||||||
const targetIdx = indexMap.get(key)!;
|
const targetIdx = indexMap.get(key)!;
|
||||||
const existingRow = merged[targetIdx];
|
const existingRow = merged[targetIdx];
|
||||||
const existingBags = Number(getGridVal(existingRow, ['bags', 'quantity'])) || 0;
|
const existingBags = Number(getGridVal(existingRow, ['bags', 'quantity'])) || 0;
|
||||||
const addedBags = currentBags > 0 ? currentBags : 1;
|
const addedBags = currentBags;
|
||||||
const newBags = existingBags + addedBags;
|
const newBags = existingBags + addedBags;
|
||||||
const skuVal = Number(getGridVal(existingRow, ['sku'], ['code']) || currentSku || 0);
|
const skuVal = Number(getGridVal(existingRow, ['sku'], ['code']) || currentSku || 0);
|
||||||
|
|
||||||
@ -400,7 +400,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
|||||||
row_kgs: skuVal * newBags,
|
row_kgs: skuVal * newBags,
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else if (!indexMap.has(key)) {
|
||||||
indexMap.set(key, merged.length);
|
indexMap.set(key, merged.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,12 +78,12 @@ export function OrderGrid({
|
|||||||
|
|
||||||
if (cat && prod) {
|
if (cat && prod) {
|
||||||
const key = `${cat}::${prod}`;
|
const key = `${cat}::${prod}`;
|
||||||
if (indexMap.has(key)) {
|
if (indexMap.has(key) && currentBags > 0) {
|
||||||
const targetIdx = indexMap.get(key)!;
|
const targetIdx = indexMap.get(key)!;
|
||||||
const existingRow = merged[targetIdx];
|
const existingRow = merged[targetIdx];
|
||||||
|
|
||||||
const existingBags = Number(existingRow[bagsColId] ?? existingRow.bags ?? existingRow.quantity ?? 0);
|
const existingBags = Number(existingRow[bagsColId] ?? existingRow.bags ?? existingRow.quantity ?? 0);
|
||||||
const addedBags = currentBags > 0 ? currentBags : 1;
|
const addedBags = currentBags;
|
||||||
const newBags = existingBags + addedBags;
|
const newBags = existingBags + addedBags;
|
||||||
const skuVal = Number(existingRow.sku || r.sku || 0);
|
const skuVal = Number(existingRow.sku || r.sku || 0);
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ export function OrderGrid({
|
|||||||
|
|
||||||
merged[targetIdx] = updatedRow;
|
merged[targetIdx] = updatedRow;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else if (!indexMap.has(key)) {
|
||||||
indexMap.set(key, merged.length);
|
indexMap.set(key, merged.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,6 +206,7 @@ export function OrderGrid({
|
|||||||
|
|
||||||
const isCatField = isCategoryColumn(fieldId, colName);
|
const isCatField = isCategoryColumn(fieldId, colName);
|
||||||
const isProdField = isProductColumn(fieldId, colName);
|
const isProdField = isProductColumn(fieldId, colName);
|
||||||
|
const isBagsField = colDef?.data_type === 'number' || fieldId.includes('bags') || fieldId.includes('quantity') || colName.toLowerCase().includes('bags');
|
||||||
|
|
||||||
if (isCatField) {
|
if (isCatField) {
|
||||||
const catVal = String(val ?? '');
|
const catVal = String(val ?? '');
|
||||||
@ -222,6 +223,10 @@ export function OrderGrid({
|
|||||||
row['br'] = '';
|
row['br'] = '';
|
||||||
row['sku_code'] = '';
|
row['sku_code'] = '';
|
||||||
row['skucode'] = '';
|
row['skucode'] = '';
|
||||||
|
row['bags'] = '';
|
||||||
|
row['quantity'] = '';
|
||||||
|
if (bagsCol) row[bagsCol.id] = '';
|
||||||
|
row['row_kgs'] = 0;
|
||||||
} else if (isProdField) {
|
} else if (isProdField) {
|
||||||
const currentCat = String(row['category'] || row['product_category'] || (catCol ? row[catCol.id] : '') || '');
|
const currentCat = String(row['category'] || row['product_category'] || (catCol ? row[catCol.id] : '') || '');
|
||||||
const prodOptions = getProductsForCategory(currentCat);
|
const prodOptions = getProductsForCategory(currentCat);
|
||||||
@ -261,6 +266,20 @@ export function OrderGrid({
|
|||||||
row['product_category'] = cat;
|
row['product_category'] = cat;
|
||||||
if (catCol) row[catCol.id] = cat;
|
if (catCol) row[catCol.id] = cat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bagsVal = Number(row.bags ?? row.quantity ?? (bagsCol ? row[bagsCol.id] : 0)) || 0;
|
||||||
|
row['row_kgs'] = Number(sku || 0) * bagsVal;
|
||||||
|
} else if (isBagsField) {
|
||||||
|
const parsedVal = val !== '' && val !== null && val !== undefined ? val : '';
|
||||||
|
const numericVal = Number(val) || 0;
|
||||||
|
|
||||||
|
row[fieldId] = parsedVal;
|
||||||
|
row['bags'] = parsedVal;
|
||||||
|
row['quantity'] = parsedVal;
|
||||||
|
if (bagsCol) row[bagsCol.id] = parsedVal;
|
||||||
|
|
||||||
|
const skuVal = Number(row.sku || 0);
|
||||||
|
row['row_kgs'] = skuVal * numericVal;
|
||||||
} else {
|
} else {
|
||||||
row[fieldId] = val;
|
row[fieldId] = val;
|
||||||
}
|
}
|
||||||
@ -278,7 +297,7 @@ export function OrderGrid({
|
|||||||
});
|
});
|
||||||
|
|
||||||
onChange(cleanRows);
|
onChange(cleanRows);
|
||||||
}, [rows, columns, visibleColumns, prodNameCol, catCol, getProductsForCategory, onChange]);
|
}, [rows, columns, visibleColumns, prodNameCol, catCol, bagsCol, getProductsForCategory, onChange]);
|
||||||
|
|
||||||
const { calculatedBags, calculatedKgs } = useMemo(() => {
|
const { calculatedBags, calculatedKgs } = useMemo(() => {
|
||||||
let bagsAcc = 0;
|
let bagsAcc = 0;
|
||||||
|
|||||||
@ -66,12 +66,12 @@ export function StorePotentialGrid({
|
|||||||
const currentBags = Number(r[bagsColId] ?? r.bags ?? r.quantity ?? 0);
|
const currentBags = Number(r[bagsColId] ?? r.bags ?? r.quantity ?? 0);
|
||||||
|
|
||||||
if (cat) {
|
if (cat) {
|
||||||
if (indexMap.has(cat)) {
|
if (indexMap.has(cat) && currentBags > 0) {
|
||||||
const targetIdx = indexMap.get(cat)!;
|
const targetIdx = indexMap.get(cat)!;
|
||||||
const existingRow = merged[targetIdx];
|
const existingRow = merged[targetIdx];
|
||||||
|
|
||||||
const existingBags = Number(existingRow[bagsColId] ?? existingRow.bags ?? existingRow.quantity ?? 0);
|
const existingBags = Number(existingRow[bagsColId] ?? existingRow.bags ?? existingRow.quantity ?? 0);
|
||||||
const addedBags = currentBags > 0 ? currentBags : 1;
|
const addedBags = currentBags;
|
||||||
const newBags = existingBags + addedBags;
|
const newBags = existingBags + addedBags;
|
||||||
|
|
||||||
const updatedRow: Record<string, unknown> = {
|
const updatedRow: Record<string, unknown> = {
|
||||||
@ -83,7 +83,7 @@ export function StorePotentialGrid({
|
|||||||
|
|
||||||
merged[targetIdx] = updatedRow;
|
merged[targetIdx] = updatedRow;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else if (!indexMap.has(cat)) {
|
||||||
indexMap.set(cat, merged.length);
|
indexMap.set(cat, merged.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,19 +124,26 @@ export function StorePotentialGrid({
|
|||||||
const colDef = columns.find((c) => c.id === fieldId);
|
const colDef = columns.find((c) => c.id === fieldId);
|
||||||
const colName = colDef?.name || '';
|
const colName = colDef?.name || '';
|
||||||
const isCatField = isCategoryColumn(fieldId, colName);
|
const isCatField = isCategoryColumn(fieldId, colName);
|
||||||
|
const isBagsField = colDef?.data_type === 'number' || fieldId.includes('bags') || fieldId.includes('quantity') || colName.toLowerCase().includes('bags');
|
||||||
|
|
||||||
if (isCatField) {
|
if (isCatField) {
|
||||||
const catVal = String(val ?? '');
|
const catVal = String(val ?? '');
|
||||||
row[fieldId] = catVal;
|
row[fieldId] = catVal;
|
||||||
row['category'] = catVal;
|
row['category'] = catVal;
|
||||||
row['product_category'] = catVal;
|
row['product_category'] = catVal;
|
||||||
|
} else if (isBagsField) {
|
||||||
|
const parsedVal = val !== '' && val !== null && val !== undefined ? val : '';
|
||||||
|
row[fieldId] = parsedVal;
|
||||||
|
row['bags'] = parsedVal;
|
||||||
|
row['quantity'] = parsedVal;
|
||||||
|
if (bagsCol) row[bagsCol.id] = parsedVal;
|
||||||
} else {
|
} else {
|
||||||
row[fieldId] = val;
|
row[fieldId] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
next[rowIdx] = row;
|
next[rowIdx] = row;
|
||||||
onChange(next);
|
onChange(next);
|
||||||
}, [rows, columns, onChange]);
|
}, [rows, columns, bagsCol, onChange]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="max-w-full bg-[var(--tiles-card-bg)] rounded-xl border border-border-default p-6 space-y-6 shadow-sm font-sans">
|
<div className="max-w-full bg-[var(--tiles-card-bg)] rounded-xl border border-border-default p-6 space-y-6 shadow-sm font-sans">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user