edit option for the populated same product

This commit is contained in:
suryacp23 2026-07-29 17:04:00 +05:30
parent 30339b0443
commit d98044692f
3 changed files with 37 additions and 11 deletions

View File

@ -385,11 +385,11 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
if (cat && prod) {
const key = `${cat}::${prod}`;
if (indexMap.has(key)) {
if (indexMap.has(key) && currentBags > 0) {
const targetIdx = indexMap.get(key)!;
const existingRow = merged[targetIdx];
const existingBags = Number(getGridVal(existingRow, ['bags', 'quantity'])) || 0;
const addedBags = currentBags > 0 ? currentBags : 1;
const addedBags = currentBags;
const newBags = existingBags + addedBags;
const skuVal = Number(getGridVal(existingRow, ['sku'], ['code']) || currentSku || 0);
@ -400,7 +400,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
row_kgs: skuVal * newBags,
};
continue;
} else {
} else if (!indexMap.has(key)) {
indexMap.set(key, merged.length);
}
}

View File

@ -78,12 +78,12 @@ export function OrderGrid({
if (cat && prod) {
const key = `${cat}::${prod}`;
if (indexMap.has(key)) {
if (indexMap.has(key) && currentBags > 0) {
const targetIdx = indexMap.get(key)!;
const existingRow = merged[targetIdx];
const existingBags = Number(existingRow[bagsColId] ?? existingRow.bags ?? existingRow.quantity ?? 0);
const addedBags = currentBags > 0 ? currentBags : 1;
const addedBags = currentBags;
const newBags = existingBags + addedBags;
const skuVal = Number(existingRow.sku || r.sku || 0);
@ -97,7 +97,7 @@ export function OrderGrid({
merged[targetIdx] = updatedRow;
continue;
} else {
} else if (!indexMap.has(key)) {
indexMap.set(key, merged.length);
}
}
@ -206,6 +206,7 @@ export function OrderGrid({
const isCatField = isCategoryColumn(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) {
const catVal = String(val ?? '');
@ -222,6 +223,10 @@ export function OrderGrid({
row['br'] = '';
row['sku_code'] = '';
row['skucode'] = '';
row['bags'] = '';
row['quantity'] = '';
if (bagsCol) row[bagsCol.id] = '';
row['row_kgs'] = 0;
} else if (isProdField) {
const currentCat = String(row['category'] || row['product_category'] || (catCol ? row[catCol.id] : '') || '');
const prodOptions = getProductsForCategory(currentCat);
@ -261,6 +266,20 @@ export function OrderGrid({
row['product_category'] = 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 {
row[fieldId] = val;
}
@ -278,7 +297,7 @@ export function OrderGrid({
});
onChange(cleanRows);
}, [rows, columns, visibleColumns, prodNameCol, catCol, getProductsForCategory, onChange]);
}, [rows, columns, visibleColumns, prodNameCol, catCol, bagsCol, getProductsForCategory, onChange]);
const { calculatedBags, calculatedKgs } = useMemo(() => {
let bagsAcc = 0;

View File

@ -66,12 +66,12 @@ export function StorePotentialGrid({
const currentBags = Number(r[bagsColId] ?? r.bags ?? r.quantity ?? 0);
if (cat) {
if (indexMap.has(cat)) {
if (indexMap.has(cat) && currentBags > 0) {
const targetIdx = indexMap.get(cat)!;
const existingRow = merged[targetIdx];
const existingBags = Number(existingRow[bagsColId] ?? existingRow.bags ?? existingRow.quantity ?? 0);
const addedBags = currentBags > 0 ? currentBags : 1;
const addedBags = currentBags;
const newBags = existingBags + addedBags;
const updatedRow: Record<string, unknown> = {
@ -83,7 +83,7 @@ export function StorePotentialGrid({
merged[targetIdx] = updatedRow;
continue;
} else {
} else if (!indexMap.has(cat)) {
indexMap.set(cat, merged.length);
}
}
@ -124,19 +124,26 @@ export function StorePotentialGrid({
const colDef = columns.find((c) => c.id === fieldId);
const colName = colDef?.name || '';
const isCatField = isCategoryColumn(fieldId, colName);
const isBagsField = colDef?.data_type === 'number' || fieldId.includes('bags') || fieldId.includes('quantity') || colName.toLowerCase().includes('bags');
if (isCatField) {
const catVal = String(val ?? '');
row[fieldId] = catVal;
row['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 {
row[fieldId] = val;
}
next[rowIdx] = row;
onChange(next);
}, [rows, columns, onChange]);
}, [rows, columns, bagsCol, onChange]);
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">