diff --git a/src/Pages/Product/ProductForm.jsx b/src/Pages/Product/ProductForm.jsx index 5d2393a..9a3add1 100644 --- a/src/Pages/Product/ProductForm.jsx +++ b/src/Pages/Product/ProductForm.jsx @@ -4035,7 +4035,7 @@ const ProductForm = ({ formType }) => { )} -
+
{ const { SadminuserAccess } = useAuth(); let SAAccessCommonMaster = SadminuserAccess?.find( - (e) => e?.MenuName === "Price Change", + (e) => e?.MenuName === 'Price Change' ); const ApplicationPreferenceData = useSelector(ApplicationPreferences); const categoryId = ApplicationPreferenceData?.find( - (p) => p?.PreferredCatName?.toLowerCase() === "price change fields", + (p) => p?.PreferredCatName?.toLowerCase() === 'price change fields' )?.PreferredCatId; const excelCategoryId = ApplicationPreferenceData?.find( - (p) => p?.PreferredCatName?.toLowerCase() === "price change sheet fields", + (p) => p?.PreferredCatName?.toLowerCase() === 'price change sheet fields' )?.PreferredCatId; const fileInputRef = useRef(fileInputRefSelector); @@ -81,8 +81,8 @@ const StockPriceUpdate = () => { const formRef = useRef(null); const allowedExcelTypes = [ - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", // .xlsx - "application/vnd.ms-excel", // .xls + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', // .xlsx + 'application/vnd.ms-excel', // .xls ]; const dispatch = useDispatch(); @@ -90,7 +90,7 @@ const StockPriceUpdate = () => { const [selectedExcelFields, setSelectedExcelFields] = useState([]); const [tableFieldPreferences, setTableFieldPreferences] = useState([]); const [tableExcelFieldPreferences, setTableExcelFieldPreferences] = useState( - [], + [] ); const [messageType, setMessageType] = useState(null); const [messageData, setMessageData] = useState(null); @@ -103,8 +103,8 @@ const StockPriceUpdate = () => { const [dataSource, setDataSource] = useState([]); const [sortedInfo, setSortedInfo] = useState({}); const [BulksortedInfo, setBulksortedInfo] = useState({}); - const [searchedText, setSearchedText] = useState(""); - const [BulksearchedText, setBulksearchedText] = useState(""); + const [searchedText, setSearchedText] = useState(''); + const [BulksearchedText, setBulksearchedText] = useState(''); const [filteredInfo, setFilteredInfo] = useState({}); const [page, setpage] = useState(1); const [Bulkchangepage, setBulkchangepage] = useState(1); @@ -114,35 +114,35 @@ const StockPriceUpdate = () => { const [open, setOpen] = useState(false); const [excelModalOpen, setExcelModalOpen] = useState(false); const [priceChangeModalOpen, setPriceChangeModalOpen] = useState(false); - const [stockVariantBased, setStockVariantBased] = useState("Yes"); + const [stockVariantBased, setStockVariantBased] = useState('Yes'); const [exportLoading, setExportLoading] = useState(false); const [fileLoading, setFileLoading] = useState(false); const [loading, setLoading] = useState(false); const [headers, setHeaders] = useState([]); const [uploadedData, setUploadedData] = useState([]); - const CompId = getSession("CompId"); - const BranchId = getSession("BranchId"); - const AppId = getSession("AppId"); - const UserId = getSession("UserId"); - const UserType = getSession("UserType"); + const CompId = getSession('CompId'); + const BranchId = getSession('BranchId'); + const AppId = getSession('AppId'); + const UserId = getSession('UserId'); + const UserType = getSession('UserType'); const [empData, setEmpData] = useState(); const [addnewAccess, setaddnewAccess] = useState(true); - const [RadioSelection, setRadioSelection] = useState("Single"); + const [RadioSelection, setRadioSelection] = useState('Single'); const [BulkProductData, setBulkProductData] = useState([]); const [allowDecimal, setAllowDecimal] = useState(false); const hasFieldExists = (label) => headers.some((h) => h.toLowerCase() === label.toLowerCase()); const hasField = (label) => - tableFieldPreferences?.some((f) => f.label === label && f.access === "Y"); + tableFieldPreferences?.some((f) => f.label === label && f.access === 'Y'); const hasExcelField = (label) => tableExcelFieldPreferences?.some( - (f) => f.label === label && f.access === "Y", + (f) => f.label === label && f.access === 'Y' ); const items = [ { - name: "Home", + name: 'Home', link: `${subDirectory}app-page/home`, }, ]; @@ -153,82 +153,82 @@ const StockPriceUpdate = () => { const columns = [ { - title: "Product Name", - dataIndex: "ProductName", - key: "ProductName", + title: 'Product Name', + dataIndex: 'ProductName', + key: 'ProductName', width: 180, render: (value, record, index) => (

{`${value} (${record?.Size} ${record?.UOMName})`}

), }, { - title: "Variant Name", - dataIndex: "VariantName", - key: "VariantName", + title: 'Variant Name', + dataIndex: 'VariantName', + key: 'VariantName', width: 180, }, { - title: "Batch No", - dataIndex: "BatchRef", - key: "BatchRef", + title: 'Batch No', + dataIndex: 'BatchRef', + key: 'BatchRef', width: 180, }, - ...(hasFieldExists("Stock") + ...(hasFieldExists('Stock') ? [ - { - title: "Stock", - dataIndex: "Stock", - key: "Stock", - width: 80, - }, - ] + { + title: 'Stock', + dataIndex: 'Stock', + key: 'Stock', + width: 80, + }, + ] : []), - ...(hasFieldExists("Stock Date") + ...(hasFieldExists('Stock Date') ? [ - { - title: "Stock Date", - dataIndex: "StockDate", - key: "StockDate", - width: 80, - }, - ] + { + title: 'Stock Date', + dataIndex: 'StockDate', + key: 'StockDate', + width: 80, + }, + ] : []), - ...(hasFieldExists("Old MRP") + ...(hasFieldExists('Old MRP') ? [ - { - title: "Old MRP", - dataIndex: "OldMRP", - key: "OldMRP", - width: 100, - }, - ] + { + title: 'Old MRP', + dataIndex: 'OldMRP', + key: 'OldMRP', + width: 100, + }, + ] : []), - ...(hasFieldExists("Old SP") + ...(hasFieldExists('Old SP') ? [ - { - title: "Old SP", - dataIndex: "OldSP", - key: "OldSP", - width: 100, - }, - ] + { + title: 'Old SP', + dataIndex: 'OldSP', + key: 'OldSP', + width: 100, + }, + ] : []), - ...(hasFieldExists("Old Wholesale Price") + ...(hasFieldExists('Old Wholesale Price') ? [ - { - title: "Old Wholesale Price", - dataIndex: "OldWholeSalePrice", - key: "OldWholeSalePrice", - width: 140, - }, - ] + { + title: 'Old Wholesale Price', + dataIndex: 'OldWholeSalePrice', + key: 'OldWholeSalePrice', + width: 140, + }, + ] : []), // ✅ EDITABLE { - title: "New MRP", - dataIndex: "NewMRP", - key: "NewMRP", + title: 'New MRP', + dataIndex: 'NewMRP', + key: 'NewMRP', width: 120, render: (_, record, index) => ( @@ -236,17 +236,17 @@ const StockPriceUpdate = () => { placeholder="New MRP" inputMode="decimal" onChange={(e) => - handlePriceChange(index, "NewMRP", e.target.value, record.localId) + handlePriceChange(index, 'NewMRP', e.target.value, record.localId) } onInput={(e) => { - let cleanedValue = e.target.value.replace(/[^0-9.]/g, ""); - if (cleanedValue.startsWith(".")) { - cleanedValue = "0" + cleanedValue; + let cleanedValue = e.target.value.replace(/[^0-9.]/g, ''); + if (cleanedValue.startsWith('.')) { + cleanedValue = '0' + cleanedValue; } - const parts = cleanedValue.split("."); + const parts = cleanedValue.split('.'); e.target.value = parts.length > 2 - ? `${parts[0]}.${parts.slice(1).join("")}` + ? `${parts[0]}.${parts.slice(1).join('')}` : cleanedValue; }} /> @@ -254,38 +254,38 @@ const StockPriceUpdate = () => { ), }, { - title: "New SP", - dataIndex: "NewSellPrice", - key: "NewSellPrice", + title: 'New SP', + dataIndex: 'NewSellPrice', + key: 'NewSellPrice', width: 120, render: (_, record, index) => ( ({ validator(_, value) { const mrp = getFieldValue(`NewMRP${record.localId}`); - if (mrp === undefined || mrp === null || mrp === "") { + if (mrp === undefined || mrp === null || mrp === '') { return Promise.resolve(); } const numMRP = Number(mrp); const numSP = - value === undefined || value === null || value === "" + value === undefined || value === null || value === '' ? null : Number(value); if (numSP === null) { return Promise.reject( - new Error("New SP is required when New MRP is provided"), + new Error('New SP is required when New MRP is provided') ); } if (numSP > numMRP) { return Promise.reject( - new Error("New SP cannot be greater than New MRP"), + new Error('New SP cannot be greater than New MRP') ); } @@ -298,80 +298,80 @@ const StockPriceUpdate = () => { placeholder="New SP" inputMode="decimal" onInput={(e) => { - let cleanedValue = e.target.value.replace(/[^0-9.]/g, ""); - const parts = cleanedValue.split("."); - if (cleanedValue.startsWith(".")) { - cleanedValue = "0" + cleanedValue; + let cleanedValue = e.target.value.replace(/[^0-9.]/g, ''); + const parts = cleanedValue.split('.'); + if (cleanedValue.startsWith('.')) { + cleanedValue = '0' + cleanedValue; } e.target.value = parts.length > 2 - ? `${parts[0]}.${parts.slice(1).join("")}` + ? `${parts[0]}.${parts.slice(1).join('')}` : cleanedValue; }} onChange={(e) => { { handlePriceChange( index, - "NewSellPrice", + 'NewSellPrice', e.target.value, - record.localId, + record.localId ); excelDataRef.current ?.validateFields([`NewSellPrice${record.localId}`]) - .catch(() => { }); + .catch(() => {}); } }} /> ), }, - ...(hasFieldExists("New Wholesale Price") + ...(hasFieldExists('New Wholesale Price') ? [ - { - title: "New Wholesale Price", - dataIndex: "NewWholeSalePrice", - key: "NewWholeSalePrice", - width: 160, - render: (value, record, index) => ( - - - handlePriceChange( - index, - "NewWholeSalePrice", - e.target.value, - record.localId, - ) - } - placeholder="New Wholesale" - inputMode="decimal" - onInput={(e) => { - let cleanedValue = e.target.value.replace(/[^0-9.]/g, ""); - const parts = cleanedValue.split("."); - if (cleanedValue.startsWith(".")) { - cleanedValue = "0" + cleanedValue; + { + title: 'New Wholesale Price', + dataIndex: 'NewWholeSalePrice', + key: 'NewWholeSalePrice', + width: 160, + render: (value, record, index) => ( + + + handlePriceChange( + index, + 'NewWholeSalePrice', + e.target.value, + record.localId + ) } - e.target.value = - parts.length > 2 - ? `${parts[0]}.${parts.slice(1).join("")}` - : cleanedValue; - }} - /> - - ), - }, - ] + placeholder="New Wholesale" + inputMode="decimal" + onInput={(e) => { + let cleanedValue = e.target.value.replace(/[^0-9.]/g, ''); + const parts = cleanedValue.split('.'); + if (cleanedValue.startsWith('.')) { + cleanedValue = '0' + cleanedValue; + } + e.target.value = + parts.length > 2 + ? `${parts[0]}.${parts.slice(1).join('')}` + : cleanedValue; + }} + /> + + ), + }, + ] : []), { - title: "Action", - key: "action", + title: 'Action', + key: 'action', width: 80, - align: "center", + align: 'center', render: (_, record, index) => ( handleRemoveRecord(index)} /> @@ -390,7 +390,7 @@ const StockPriceUpdate = () => { dispatch(getCommonAppPreference(AppId)); }, [AppId, dispatch]); useEffect(() => { - if (UserType === "Employee") { + if (UserType === 'Employee') { fetchApi(); } }, [UserType]); @@ -406,25 +406,25 @@ const StockPriceUpdate = () => { const getFieldSetup = async () => { try { const response = await dispatch( - getFieldSetupData({ AppId, CompId, BranchId, categoryId, Type: "GB" }), + getFieldSetupData({ AppId, CompId, BranchId, categoryId, Type: 'GB' }) ).unwrap(); if (response?.data?.statusCode === 1) { - console.log(response?.data?.data?.[0]?.ConfigDtl, "Field Setup Data"); + console.log(response?.data?.data?.[0]?.ConfigDtl, 'Field Setup Data'); setSelectedFields( response?.data?.data?.[0]?.ConfigDtl?.filter( - (c) => c.ConfigId && c.Access === "Y", - )?.map((c) => c.ConfigId) || [], + (c) => c.ConfigId && c.Access === 'Y' + )?.map((c) => c.ConfigId) || [] ); setTableFieldPreferences( response?.data?.data?.[0]?.ConfigDtl?.map((c) => ({ value: c.ConfigId, label: c.ConfigName, access: c.Access, - })) || [], + })) || [] ); } } catch (error) { - console.error("Error fetching field setup:", error); + console.error('Error fetching field setup:', error); } }; @@ -436,38 +436,38 @@ const StockPriceUpdate = () => { CompId, BranchId, categoryId: excelCategoryId, - Type: "GB", - }), + Type: 'GB', + }) ).unwrap(); if (response?.data?.statusCode === 1) { - console.log(response?.data?.data?.[0]?.ConfigDtl, "Field Setup Data"); + console.log(response?.data?.data?.[0]?.ConfigDtl, 'Field Setup Data'); setSelectedExcelFields( response?.data?.data?.[0]?.ConfigDtl?.filter( - (c) => c.ConfigId && c.Access === "Y", - )?.map((c) => c.ConfigId) || [], + (c) => c.ConfigId && c.Access === 'Y' + )?.map((c) => c.ConfigId) || [] ); setTableExcelFieldPreferences( response?.data?.data?.[0]?.ConfigDtl?.map((c) => ({ value: c.ConfigId, label: c.ConfigName, access: c.Access, - })) || [], + })) || [] ); } } catch (error) { - console.error("Error fetching field setup:", error); + console.error('Error fetching field setup:', error); } }; useEffect(() => { let hasAccess = false; - if (UserType === "Admin" || UserType === "Super Admin") { + if (UserType === 'Admin' || UserType === 'Super Admin') { hasAccess = true; - } else if (UserType === "Employee") { - hasAccess = empData?.AddAccess === "Y"; - } else if (UserType === "Super Admin User") { - hasAccess = SAAccessCommonMaster?.AddAccess === "Y"; + } else if (UserType === 'Employee') { + hasAccess = empData?.AddAccess === 'Y'; + } else if (UserType === 'Super Admin User') { + hasAccess = SAAccessCommonMaster?.AddAccess === 'Y'; } setaddnewAccess(!hasAccess); @@ -490,7 +490,7 @@ const StockPriceUpdate = () => { }; let response = await dispatch(getEmpAccess(data)).unwrap(); let datas = response?.data?.data?.[0]?.EmpAccessDetails?.filter( - (item) => item.ConfigName === "Price Change", + (item) => item.ConfigName === 'Price Change' ); setEmpData(datas?.[0]); }; @@ -553,7 +553,7 @@ const StockPriceUpdate = () => { ...values, }); } catch (errInfo) { - console.log("Save failed:", errInfo); + console.log('Save failed:', errInfo); } }; @@ -569,12 +569,12 @@ const StockPriceUpdate = () => { rules={[ { pattern: /^(?!0$)(\d+)(\.\d{1,2})?$/, - message: "Invalid format (Max 2 decimals, No zero)", + message: 'Invalid format (Max 2 decimals, No zero)', }, { validator: (_, value) => value?.length > 10 - ? Promise.reject("Max 10 characters allowed") + ? Promise.reject('Max 10 characters allowed') : Promise.resolve(), }, ]} @@ -590,11 +590,11 @@ const StockPriceUpdate = () => { } inputMode="decimal" onInput={(e) => { - const cleanedValue = e.target.value.replace(/[^0-9.]/g, ""); - const parts = cleanedValue.split("."); + const cleanedValue = e.target.value.replace(/[^0-9.]/g, ''); + const parts = cleanedValue.split('.'); e.target.value = parts.length > 2 - ? `${parts[0]}.${parts.slice(1).join("")}` + ? `${parts[0]}.${parts.slice(1).join('')}` : cleanedValue; }} /> @@ -660,7 +660,7 @@ const StockPriceUpdate = () => { ...values, }); } catch (errInfo) { - console.log("Save failed:", errInfo); + console.log('Save failed:', errInfo); } }; @@ -676,12 +676,12 @@ const StockPriceUpdate = () => { rules={[ { pattern: /^(?!0$)(\d+)(\.\d{1,2})?$/, - message: "Invalid format (Max 2 decimals, No zero)", + message: 'Invalid format (Max 2 decimals, No zero)', }, { validator: (_, value) => value?.length > 10 - ? Promise.reject("Max 10 characters allowed") + ? Promise.reject('Max 10 characters allowed') : Promise.resolve(), }, ]} @@ -696,11 +696,11 @@ const StockPriceUpdate = () => { } inputMode="decimal" onInput={(e) => { - const cleanedValue = e.target.value.replace(/[^0-9.]/g, ""); - const parts = cleanedValue.split("."); + const cleanedValue = e.target.value.replace(/[^0-9.]/g, ''); + const parts = cleanedValue.split('.'); e.target.value = parts.length > 2 - ? `${parts[0]}.${parts.slice(1).join("")}` + ? `${parts[0]}.${parts.slice(1).join('')}` : cleanedValue; }} /> @@ -736,8 +736,8 @@ const StockPriceUpdate = () => { const { data: res } = await dispatch(getPreferenceData(data)).unwrap(); const decimalSetting = res?.data?.[0]?.SettingDtlDetails?.find( (setting) => - setting?.SettingIdName?.toLowerCase() === "decimal" && - setting?.SettingValue === "Y", + setting?.SettingIdName?.toLowerCase() === 'decimal' && + setting?.SettingValue === 'Y' ); if (decimalSetting) { setAllowDecimal(true); @@ -781,7 +781,7 @@ const StockPriceUpdate = () => { ProdVariantName: detail?.ProdVariantName, BatchRef: detail?.BatchRef, key: `${product.ProdId}_${detail.InwardDtlId}`, - })), + })) ); setBulkProductData(flattenedArray); }; @@ -799,7 +799,7 @@ const StockPriceUpdate = () => { const currentRow = { ...updated[rowIndex] }; // If changing New MRP, clear New SP - if (field === "NewMRP") { + if (field === 'NewMRP') { currentRow.NewSellPrice = null; excelDataRef.current?.setFieldsValue({ [`NewSellPrice${localId}`]: null, @@ -812,13 +812,13 @@ const StockPriceUpdate = () => { }); // Validate New SP against New MRP - if (field === "NewSellPrice" && numValue) { + if (field === 'NewSellPrice' && numValue) { const currentRow = uploadedData[rowIndex]; const newMRP = currentRow?.NewMRP; if (newMRP && numValue > newMRP) { - setMessageType("error"); - setMessageData("New SP cannot be greater than New MRP"); + setMessageType('error'); + setMessageData('New SP cannot be greater than New MRP'); return; } } @@ -830,7 +830,7 @@ const StockPriceUpdate = () => { const statusFormatter = async (row) => { const updatedData = StockDetails?.filter( - (item) => item?.InwardDtlId !== row?.InwardDtlId, + (item) => item?.InwardDtlId !== row?.InwardDtlId ); setStockDetails(updatedData); }; @@ -838,7 +838,7 @@ const StockPriceUpdate = () => { let tableValue = StockNames?.[0]?.stockDetails; let DataSource = StockNames?.map((name, index) => ({ value: index + 1, - label: name?.ProdName + "(" + (name?.Size + " " + name?.UOMName) + ")", + label: name?.ProdName + '(' + (name?.Size + ' ' + name?.UOMName) + ')', ProdId: name?.ProdId, stockDetails: name?.stockDetails, Quantity: name?.Size, @@ -864,8 +864,8 @@ const StockPriceUpdate = () => { }); setStockDetails(newData); } else { - setMessageType("error"); - setMessageData("MRP is must be greater than or equal to selling price"); + setMessageType('error'); + setMessageData('MRP is must be greater than or equal to selling price'); } } else { const newData = StockDetails?.map((item) => { @@ -894,9 +894,9 @@ const StockPriceUpdate = () => { }); setBulkProductData(newData); } else { - setMessageType("error"); + setMessageType('error'); setMessageData( - "MRP is must be greater than or equal to selling price", + 'MRP is must be greater than or equal to selling price' ); } } else { @@ -926,31 +926,31 @@ const StockPriceUpdate = () => { }; function safeRound(amountStr) { - if (amountStr == null) return allowDecimal ? "0.00" : "0"; + if (amountStr == null) return allowDecimal ? '0.00' : '0'; - const cleaned = String(amountStr).replace(/[^0-9.-]+/g, ""); + const cleaned = String(amountStr).replace(/[^0-9.-]+/g, ''); const num = Number(cleaned); - if (isNaN(num)) return allowDecimal ? "0.00" : "0"; + if (isNaN(num)) return allowDecimal ? '0.00' : '0'; return allowDecimal ? num.toFixed(2) : Math.round(num).toString(); } const columns2 = [ { - title: "Sl.No", - align: "center", - key: "sno", - width: "60px", + title: 'Sl.No', + align: 'center', + key: 'sno', + width: '60px', render: (text, object, index) => ( - {index + 1} + {index + 1} ), }, { - title: "Product Name", - dataIndex: "ProdName", - key: "ProdName", - width: "20%", + title: 'Product Name', + dataIndex: 'ProdName', + key: 'ProdName', + width: '20%', filteredValue: [searchedText], onFilter: (value, record) => { return String(record.ProdName) @@ -958,7 +958,7 @@ const StockPriceUpdate = () => { .includes(value?.toLowerCase()); }, sorter: (a, b) => a?.ProdName?.localeCompare(b.ProdName), - sortOrder: sortedInfo.columnKey === "ProdName" ? sortedInfo.order : null, + sortOrder: sortedInfo.columnKey === 'ProdName' ? sortedInfo.order : null, ellipsis: true, render: (_, record) => ( @@ -968,65 +968,65 @@ const StockPriceUpdate = () => { ), }, { - title: "stock Date", - dataIndex: "InwardDate", - key: "InwardDate", - align: "right", - width: "150px", + title: 'stock Date', + dataIndex: 'InwardDate', + key: 'InwardDate', + align: 'right', + width: '150px', render: (InwardDate) => - InwardDate !== null ? ExtractDateFormate(InwardDate) : "-", + InwardDate !== null ? ExtractDateFormate(InwardDate) : '-', }, { - title: "Old MRP", - dataIndex: "MRP", - key: "MRP", - align: "right", - render: (MRP) => (safeRound(MRP) !== null ? safeRound(MRP) : "-"), + title: 'Old MRP', + dataIndex: 'MRP', + key: 'MRP', + align: 'right', + render: (MRP) => (safeRound(MRP) !== null ? safeRound(MRP) : '-'), }, { - title: "Old Price", - dataIndex: "SellPrice", - key: "SellPrice", - align: "right", + title: 'Old Price', + dataIndex: 'SellPrice', + key: 'SellPrice', + align: 'right', render: (SellPrice) => - safeRound(SellPrice) !== null ? safeRound(SellPrice) : "-", + safeRound(SellPrice) !== null ? safeRound(SellPrice) : '-', }, { - title: "New MRP", - dataIndex: "CurrentMRP", - key: "CurrentMRP", - align: "right", + title: 'New MRP', + dataIndex: 'CurrentMRP', + key: 'CurrentMRP', + align: 'right', editable: true, - render: (text, record) =>

{text ? text : "Enter MRP"}

, + render: (text, record) =>

{text ? text : 'Enter MRP'}

, width: 100, }, { - title: "New SP", - dataIndex: "CurrentAmt", - key: "CurrentAmt", - align: "right", + title: 'New SP', + dataIndex: 'CurrentAmt', + key: 'CurrentAmt', + align: 'right', editable: true, - render: (text, record) =>

{text ? text : "Enter Price"}

, + render: (text, record) =>

{text ? text : 'Enter Price'}

, width: 100, }, { - title: "Action", - dataIndex: "SellPrice", - key: "SellPrice", - align: "center", - width: "100px", + title: 'Action', + dataIndex: 'SellPrice', + key: 'SellPrice', + align: 'center', + width: '100px', render: (_, record, index) => (
statusFormatter(record, index)} />
@@ -1035,21 +1035,21 @@ const StockPriceUpdate = () => { ]; const BulkPricechangeColumns = [ { - title: "Sl.No", - align: "center", - key: "sno", - width: "50px", + title: 'Sl.No', + align: 'center', + key: 'sno', + width: '50px', render: (text, object, index) => ( - + {(Bulkchangepage - 1) * 10 + index + 1} ), }, { - title: "Name", - dataIndex: "ProdName", - key: "ProdName", - width: "20%", + title: 'Name', + dataIndex: 'ProdName', + key: 'ProdName', + width: 150, filteredValue: [BulksearchedText], onFilter: (value, record) => { return String(record.ProdName) @@ -1058,7 +1058,7 @@ const StockPriceUpdate = () => { }, sorter: (a, b) => a?.ProdName?.localeCompare(b.ProdName), sortOrder: - BulksortedInfo.columnKey === "ProdName" ? BulksortedInfo.order : null, + BulksortedInfo.columnKey === 'ProdName' ? BulksortedInfo.order : null, ellipsis: true, render: (_, record) => ( @@ -1067,131 +1067,130 @@ const StockPriceUpdate = () => { ), }, { - title: "Variant Name", - dataIndex: "ProdVariantName", - key: "ProdVariantName", - align: "left", - width: "120px", + title: 'Variant Name', + dataIndex: 'ProdVariantName', + key: 'ProdVariantName', + align: 'left', + width: 120, }, { - title: "Batch No", - dataIndex: "BatchRef", - key: "BatchRef", - align: "left", - width: "120px", + title: 'Batch No', + dataIndex: 'BatchRef', + key: 'BatchRef', + align: 'left', + width: 120, }, - ...(hasField("Stock Date") + ...(hasField('Stock Date') ? [ - { - title: "stock Date", - dataIndex: "InwardDate", - key: "InwardDate", - align: "center", - width: "100px", - render: (InwardDate) => - InwardDate !== null ? ExtractDateFormate(InwardDate) : "-", - }, - ] + { + title: 'stock Date', + dataIndex: 'InwardDate', + key: 'InwardDate', + align: 'center', + width: 120, + render: (InwardDate) => + InwardDate !== null ? ExtractDateFormate(InwardDate) : '-', + }, + ] : []), - ...(hasField("Expiry Date") + ...(hasField('Expiry Date') ? [ - { - title: "Exp date", - dataIndex: "ExpDate", - key: "ExpDate", - align: "center", - width: "100px", - render: (ExpDate) => - ExpDate !== null ? ExtractDateFormate(ExpDate) : "-", - }, - ] + { + title: 'Exp date', + dataIndex: 'ExpDate', + key: 'ExpDate', + align: 'center', + width: 100, + render: (ExpDate) => + ExpDate !== null ? ExtractDateFormate(ExpDate) : '-', + }, + ] : []), - ...(hasField("Stock") + ...(hasField('Stock') ? [ - - { - title: "stock", - dataIndex: "BalanceQty", - key: "BalanceQty", - align: "right", - width: "60px", - render: (BalanceQty) => (BalanceQty !== null ? BalanceQty : "-"), - }, - ] + { + title: 'stock', + dataIndex: 'BalanceQty', + key: 'BalanceQty', + align: 'right', + width: '60px', + render: (BalanceQty) => (BalanceQty !== null ? BalanceQty : '-'), + }, + ] : []), - ...(hasField("Old MRP") + ...(hasField('Old MRP') ? [ - { - title: "Old MRP", - dataIndex: "MRP", - key: "MRP", - align: "right", - width: "70px", - render: (MRP) => (safeRound(MRP) !== null ? safeRound(MRP) : "-"), - }, - ] + { + title: 'Old MRP', + dataIndex: 'MRP', + key: 'MRP', + align: 'right', + width: '70px', + render: (MRP) => (safeRound(MRP) !== null ? safeRound(MRP) : '-'), + }, + ] : []), - ...(hasField("Old SP") + ...(hasField('Old SP') ? [ - { - title: "Old SP", - dataIndex: "SellPrice", - key: "SellPrice", - align: "right", - width: "70px", - render: (SellPrice) => - safeRound(SellPrice) !== null ? safeRound(SellPrice) : "-", - }, - ] + { + title: 'Old SP', + dataIndex: 'SellPrice', + key: 'SellPrice', + align: 'right', + width: '70px', + render: (SellPrice) => + safeRound(SellPrice) !== null ? safeRound(SellPrice) : '-', + }, + ] : []), - ...(hasField("Old Wholesale Price") + ...(hasField('Old Wholesale Price') ? [ - { - title: "Old Wholesale Price", - dataIndex: "WhSalePrice", - key: "WhSalePrice", - align: "right", - width: "120px", - render: (WhSalePrice) => - safeRound(WhSalePrice) !== null ? safeRound(WhSalePrice) : "-", - }, - ] + { + title: 'Old Wholesale Price', + dataIndex: 'WhSalePrice', + key: 'WhSalePrice', + align: 'right', + width: '120px', + render: (WhSalePrice) => + safeRound(WhSalePrice) !== null ? safeRound(WhSalePrice) : '-', + }, + ] : []), { - title: "New MRP", - dataIndex: "CurrentMRP", - key: "CurrentMRP", - align: "center", - with: "4rem", + title: 'New MRP', + dataIndex: 'CurrentMRP', + key: 'CurrentMRP', + align: 'center', + with: '4rem', editable: true, - render: (text, record) =>

{text ? text : "Enter MRP"}

, + render: (text, record) =>

{text ? text : 'Enter MRP'}

, width: 100, }, { - title: "New SP", - dataIndex: "CurrentAmt", - key: "CurrentAmt", - align: "center", - with: "4rem", + title: 'New SP', + dataIndex: 'CurrentAmt', + key: 'CurrentAmt', + align: 'center', + with: '4rem', editable: true, - render: (text, record) =>

{text ? text : "Enter Price"}

, + render: (text, record) =>

{text ? text : 'Enter Price'}

, width: 100, }, - ...(hasField("New Wholesale Price") + ...(hasField('New Wholesale Price') ? [ - { - title: "New Wholesale Price", - dataIndex: "CurrentWhAmt", - key: "CurrentWhAmt", - align: "center", - with: "4rem", - editable: true, - render: (text, record) => ( -

{text ? text : "Enter Wholesale Price"}

- ), - width: 120, - }, - ] + { + title: 'New Wholesale Price', + dataIndex: 'CurrentWhAmt', + key: 'CurrentWhAmt', + align: 'center', + with: '4rem', + editable: true, + render: (text, record) => ( +

{text ? text : 'Enter Wholesale Price'}

+ ), + width: 120, + }, + ] : []), ]; @@ -1200,7 +1199,7 @@ const StockPriceUpdate = () => { // Check if any of the new products already exist in StockDetails setStockDetails((prevStockDetails) => { const existingInwardDtlIds = new Set( - prevStockDetails?.map((item) => item.InwardDtlId), + prevStockDetails?.map((item) => item.InwardDtlId) ); const uniqueNewStockDetails = newStockDetails @@ -1255,18 +1254,18 @@ const StockPriceUpdate = () => { // }; const HandlePutData = async () => { - if (RadioSelection == "Bulk") { + if (RadioSelection == 'Bulk') { const filteredCurrentAmtData = BulkProductData?.filter( (item) => (item.CurrentAmt !== undefined && item.CurrentAmt !== null && - item.CurrentAmt !== "" && + item.CurrentAmt !== '' && item.CurrentMRP !== undefined && item.CurrentMRP !== null && - item.CurrentMRP !== "") || + item.CurrentMRP !== '') || (item.CurrentWhAmt !== undefined && item.CurrentWhAmt !== null && - item.CurrentWhAmt !== ""), + item.CurrentWhAmt !== '') ); const hasInvalidData = BulkProductData.every((item) => { const isAbsent = item.CurrentAmt == null && item.CurrentMRP == null; @@ -1280,12 +1279,12 @@ const StockPriceUpdate = () => { let Postdata = { CompId: CompId, BranchId: BranchId, - Type: "Variant", + Type: 'Variant', ProductDetails: filteredCurrentAmtData?.map((item) => ({ ProdId: item?.ProdId, NewMRP: item?.CurrentMRP, NewSellPrice: item?.CurrentAmt, - AdjComment: "string", + AdjComment: 'string', InwardDtlId: item?.InwardDtlId, NewWholeSalePrice: item.CurrentWhAmt, })), @@ -1295,32 +1294,32 @@ const StockPriceUpdate = () => { if (response?.data?.statusCode == 1) { setProductName(); - setMessageType("success"); + setMessageType('success'); setMessageData(response?.data?.response); fetchData(); - setBulksearchedText(""); + setBulksearchedText(''); setStockDetails([]); setBulkProductData([]); } else { - setMessageType("error"); + setMessageType('error'); setMessageData(response?.data?.response); } } else { - setMessageType("error"); - setMessageData("Please give all details"); + setMessageType('error'); + setMessageData('Please give all details'); } } else { const filteredStockDetails = StockDetails?.filter( (item) => item?.CurrentMRP && - item?.CurrentMRP !== "" && + item?.CurrentMRP !== '' && item?.CurrentAmt && - item?.CurrentAmt !== "", + item?.CurrentAmt !== '' ); if (filteredStockDetails?.length === 0) { - setMessageType("error"); - setMessageData("Please enter price details for at least one product"); + setMessageType('error'); + setMessageData('Please enter price details for at least one product'); return; } @@ -1331,7 +1330,7 @@ const StockPriceUpdate = () => { ProdId: item?.ProdId, MRP: item?.CurrentMRP, SellPrice: item?.CurrentAmt, - AdjComment: "string", + AdjComment: 'string', InwardDtlId: item?.InwardDtlId, })), UpdatedBy: 1, @@ -1343,11 +1342,11 @@ const StockPriceUpdate = () => { setStockNames(res?.data?.data); if (response?.data?.statusCode == 1) { setProductName(); - setMessageType("success"); + setMessageType('success'); setMessageData(response?.data?.response); fetchData(); } else { - setMessageType("error"); + setMessageType('error'); setMessageData(response?.data?.response); } setStockDetails([]); @@ -1464,94 +1463,94 @@ const StockPriceUpdate = () => { setPriceChangeModalOpen(true); }; - const handleExport = async (isStockVariantBased = "Yes") => { + const handleExport = async (isStockVariantBased = 'Yes') => { setExportLoading(true); setPriceChangeModalOpen(false); const uniqueBulkProductData = - isStockVariantBased === "Yes" + isStockVariantBased === 'Yes' ? BulkProductData || [] : (BulkProductData || [])?.filter( - (item, index, self) => - index === self.findIndex((p) => p.ProdId === item.ProdId), - ); + (item, index, self) => + index === self.findIndex((p) => p.ProdId === item.ProdId) + ); if (!uniqueBulkProductData?.length) { - setMessageType("error"); - setMessageData("No data available to export"); + setMessageType('error'); + setMessageData('No data available to export'); setExportLoading(false); return; } const workbook = new ExcelJS.Workbook(); - const worksheet = workbook.addWorksheet("Products"); + const worksheet = workbook.addWorksheet('Products'); /* ---------------- COLUMN DEFINITIONS ---------------- */ const columns = [ - { header: "Product Name", key: "ProdName", width: 20 }, - ...(isStockVariantBased === "Yes" - ? [{ header: "Variant Name", key: "ProdVariantName", width: 20 }] + { header: 'Product Name', key: 'ProdName', width: 100 }, + ...(isStockVariantBased === 'Yes' + ? [{ header: 'Variant Name', key: 'ProdVariantName', width: 20 }] : []), - ...(isStockVariantBased === "Yes" - ? [{ header: "Batch No", key: "BatchRef", width: 20 }] + ...(isStockVariantBased === 'Yes' + ? [{ header: 'Batch No', key: 'BatchRef', width: 20 }] : []), - ...(hasExcelField("Stock Date") - ? [{ header: "Stock Date", key: "StockDate", width: 15 }] + ...(hasExcelField('Stock Date') + ? [{ header: 'Stock Date', key: 'StockDate', width: 15 }] : []), - ...(hasExcelField("Expiry Date") - ? [{ header: "Exp Date", key: "ExpDate", width: 15 }] + ...(hasExcelField('Expiry Date') + ? [{ header: 'Exp Date', key: 'ExpDate', width: 15 }] : []), - ...(hasExcelField("Stock") - ? [{ header: "Stock", key: "Stock", width: 10 }] + ...(hasExcelField('Stock') + ? [{ header: 'Stock', key: 'Stock', width: 10 }] : []), - ...(hasExcelField("Old MRP") - ? [{ header: "Old MRP", key: "OldMRP", width: 10 }] + ...(hasExcelField('Old MRP') + ? [{ header: 'Old MRP', key: 'OldMRP', width: 10 }] : []), - ...(hasExcelField("Old SP") - ? [{ header: "Old SP", key: "OldSP", width: 10 }] + ...(hasExcelField('Old SP') + ? [{ header: 'Old SP', key: 'OldSP', width: 10 }] : []), - ...(hasExcelField("Old Wholesale Price") - ? [{ header: "Old Wholesale Price", key: "WhSalePrice", width: 14 }] + ...(hasExcelField('Old Wholesale Price') + ? [{ header: 'Old Wholesale Price', key: 'WhSalePrice', width: 14 }] : []), - ...(hasExcelField("Size") - ? [{ header: "Size", key: "Size", width: 10 }] + ...(hasExcelField('Size') + ? [{ header: 'Size', key: 'Size', width: 10 }] : []), - ...(hasExcelField("Stock Maintainence") - ? [{ header: "Stock Maintainence", key: "StockAvailable", width: 18 }] + ...(hasExcelField('Stock Maintainence') + ? [{ header: 'Stock Maintainence', key: 'StockAvailable', width: 18 }] : []), - ...(hasExcelField("UOM Name") - ? [{ header: "UOMName", key: "UOMName", width: 15 }] + ...(hasExcelField('UOM Name') + ? [{ header: 'UOMName', key: 'UOMName', width: 15 }] : []), // ...(hasExcelField("New MRP & New SP") // ? [ - { header: "New MRP", key: "NewMRP", width: 12 }, - { header: "New SP", key: "NewSP", width: 12 }, + { header: 'New MRP', key: 'NewMRP', width: 12 }, + { header: 'New SP', key: 'NewSP', width: 12 }, // ] // : []), - ...(hasExcelField("New Wholesale Price") - ? [{ header: "New Wholesale Price", key: "NewWhSalePrice", width: 14 }] + ...(hasExcelField('New Wholesale Price') + ? [{ header: 'New Wholesale Price', key: 'NewWhSalePrice', width: 14 }] : []), // --- Hidden system columns (always included) --- - { header: "ProdId", key: "ProdId", width: 1 }, + { header: 'ProdId', key: 'ProdId', width: 1 }, - ...(isStockVariantBased === "Yes" - ? [{ header: "InwardDtlId", key: "InwardDtlId", width: 1 }] + ...(isStockVariantBased === 'Yes' + ? [{ header: 'InwardDtlId', key: 'InwardDtlId', width: 1 }] : []), - { header: "key", key: "key", width: 1 }, - { header: "downloadType", key: "downloadType", width: 1 }, + { header: 'key', key: 'key', width: 1 }, + { header: 'downloadType', key: 'downloadType', width: 1 }, ]; worksheet.columns = columns; - worksheet.views = [{ state: "frozen", xSplit: 1, ySplit: 1 }]; + worksheet.views = [{ state: 'frozen', xSplit: 1, ySplit: 1 }]; const headerRow = worksheet.getRow(1); - const newMRPCol = headerRow.values.indexOf("New MRP"); - const newSPCol = headerRow.values.indexOf("New SP"); + const newMRPCol = headerRow.values.indexOf('New MRP'); + const newSPCol = headerRow.values.indexOf('New SP'); const hasNewMRPAndSP = newMRPCol > 0 && newSPCol > 0; /* ---------------- HEADER STYLE ---------------- */ @@ -1559,37 +1558,37 @@ const StockPriceUpdate = () => { const header = cell.value; const isHiddenCol = - header === "key" || - header === "ProdId" || - header === "InwardDtlId" || - header === "downloadType"; + header === 'key' || + header === 'ProdId' || + header === 'InwardDtlId' || + header === 'downloadType'; cell.font = { bold: true, size: isHiddenCol ? 1 : 11, - color: { argb: isHiddenCol ? "FFFFFFFF" : "FF000000" }, + color: { argb: isHiddenCol ? 'FFFFFFFF' : 'FF000000' }, }; cell.alignment = { - horizontal: "center", - vertical: "middle", + horizontal: 'center', + vertical: 'middle', wrapText: true, // ✅ prevents overflow in header }; cell.fill = { - type: "pattern", - pattern: "solid", + type: 'pattern', + pattern: 'solid', fgColor: { - argb: isHiddenCol ? "FFFFFFFF" : "FF52C41A", + argb: isHiddenCol ? 'FFFFFFFF' : 'FF52C41A', }, }; cell.border = isHiddenCol ? undefined : { - right: { style: "thin", color: { argb: "FF000000" } }, - bottom: { style: "thin", color: { argb: "FF000000" } }, - }; + right: { style: 'thin', color: { argb: 'FF000000' } }, + bottom: { style: 'thin', color: { argb: 'FF000000' } }, + }; }); /* ---------------- ADD DATA ---------------- */ @@ -1599,7 +1598,7 @@ const StockPriceUpdate = () => { ProdVariantName: product?.ProdVariantName, BatchRef: product?.BatchRef, StockDate: product?.InwardDate, - ExpDate: product?.ExpDate || "-", + ExpDate: product?.ExpDate || '-', Stock: product?.BalanceQty, OldMRP: product?.MRP, OldSP: product?.SellPrice, @@ -1608,13 +1607,13 @@ const StockPriceUpdate = () => { StockAvailable: product?.StockAvailable, UOMName: product?.UOMName, key: product?.key, - downloadType: isStockVariantBased === "Yes" ? "Variant" : "Product", - NewMRP: "", - NewSP: "", - NewWhSalePrice: "", + downloadType: isStockVariantBased === 'Yes' ? 'Variant' : 'Product', + NewMRP: '', + NewSP: '', + NewWhSalePrice: '', ProdId: product?.ProdId, InwardDtlId: - isStockVariantBased === "Yes" ? product?.InwardDtlId : undefined, + isStockVariantBased === 'Yes' ? product?.InwardDtlId : undefined, }); }); @@ -1627,15 +1626,15 @@ const StockPriceUpdate = () => { const newSPCell = row.getCell(newSPCol); newSPCell.dataValidation = { - type: "custom", + type: 'custom', allowBlank: true, formulae: [ `IFERROR(VALUE(${newSPCell.address}),0) <= IFERROR(VALUE(${newMRPCell.address}),0)`, ], showErrorMessage: true, - errorStyle: "stop", - errorTitle: "Invalid Selling Price", - error: "New SP cannot be greater than New MRP", + errorStyle: 'stop', + errorTitle: 'Invalid Selling Price', + error: 'New SP cannot be greater than New MRP', }; }); } @@ -1662,38 +1661,38 @@ const StockPriceUpdate = () => { const header = worksheet.getRow(1).getCell(colNumber).value; const isHiddenCol = - header === "key" || - header === "ProdId" || - header === "InwardDtlId" || - header === "downloadType"; + header === 'key' || + header === 'ProdId' || + header === 'InwardDtlId' || + header === 'downloadType'; const isEditable = - header === "New MRP" || - header === "New SP" || - header === "New Wholesale Price"; + header === 'New MRP' || + header === 'New SP' || + header === 'New Wholesale Price'; cell.protection = { locked: !isEditable }; cell.alignment = { - vertical: "middle", + vertical: 'middle', wrapText: true, }; if (isHiddenCol) { cell.font = { size: 1, - color: { argb: "FFFFFFFF" }, + color: { argb: 'FFFFFFFF' }, }; cell.fill = { - type: "pattern", - pattern: "solid", - fgColor: { argb: "FFFFFFFF" }, + type: 'pattern', + pattern: 'solid', + fgColor: { argb: 'FFFFFFFF' }, }; } }); }); /* ---------------- PROTECT SHEET ---------------- */ - await worksheet.protect("", { + await worksheet.protect('', { selectLockedCells: false, selectUnlockedCells: true, formatCells: false, @@ -1705,12 +1704,12 @@ const StockPriceUpdate = () => { /* ---------------- DOWNLOAD ---------------- */ const buffer = await workbook.xlsx.writeBuffer(); const blob = new Blob([buffer], { - type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', }); - const link = document.createElement("a"); + const link = document.createElement('a'); link.href = URL.createObjectURL(blob); - link.download = "PriceChange_Data.xlsx"; + link.download = 'PriceChange_Data.xlsx'; link.click(); setExportLoading(false); @@ -1733,8 +1732,8 @@ const StockPriceUpdate = () => { const isAllowed = allowedExcelTypes?.includes(file.type); if (!isAllowed) { Modal.error({ - title: "Invalid File Type", - content: "Only Excel files (.xls, .xlsx) are allowed.", + title: 'Invalid File Type', + content: 'Only Excel files (.xls, .xlsx) are allowed.', }); handleCancelData(); setFileLoading(false); @@ -1748,10 +1747,10 @@ const StockPriceUpdate = () => { const extractedData = extractPriceChangeDataFromExcel(arrayBuffer); - console.log(extractedData, "extractedData"); + console.log(extractedData, 'extractedData'); if ((extractedData || [])?.length === 0) { - setMessageData("No Data Found in Uploaded Sheet"); - setMessageType("error"); + setMessageData('No Data Found in Uploaded Sheet'); + setMessageType('error'); handleCancelData(); setFileLoading(false); return; @@ -1790,13 +1789,13 @@ const StockPriceUpdate = () => { }; const extractPriceChangeDataFromExcel = (arrayBuffer) => { - const workbook = read(arrayBuffer, { type: "array" }); + const workbook = read(arrayBuffer, { type: 'array' }); const worksheet = workbook.Sheets[workbook.SheetNames[0]]; const rows = utils.sheet_to_json(worksheet, { header: 1, raw: false, - defval: "", + defval: '', }); if (!rows.length) return []; @@ -1808,23 +1807,23 @@ const StockPriceUpdate = () => { // Helper to safely get column value const getVal = (row, colName) => { const idx = header.indexOf(colName); - return idx !== -1 ? row[idx] : ""; + return idx !== -1 ? row[idx] : ''; }; const result = dataRows .map((row) => { - const prodId = getVal(row, "ProdId")?.toString().trim(); + const prodId = getVal(row, 'ProdId')?.toString().trim(); if (!prodId) return null; const newMRP = - getVal(row, "New MRP") !== "" ? Number(getVal(row, "New MRP")) : null; + getVal(row, 'New MRP') !== '' ? Number(getVal(row, 'New MRP')) : null; const newSP = - getVal(row, "New SP") !== "" ? Number(getVal(row, "New SP")) : null; + getVal(row, 'New SP') !== '' ? Number(getVal(row, 'New SP')) : null; const newWholesale = - getVal(row, "New Wholesale Price") !== "" - ? Number(getVal(row, "New Wholesale Price")) + getVal(row, 'New Wholesale Price') !== '' + ? Number(getVal(row, 'New Wholesale Price')) : null; // ❌ Must have at least one change @@ -1836,37 +1835,37 @@ const StockPriceUpdate = () => { // 🔹 Product identity localId: uuidv4(), ProdId: prodId, - InwardDtlId: getVal(row, "InwardDtlId") - ? getVal(row, "InwardDtlId").toString() + InwardDtlId: getVal(row, 'InwardDtlId') + ? getVal(row, 'InwardDtlId').toString() : null, // 🔹 Product info - VariantName: getVal(row, "Variant Name") || null, - BatchRef: getVal(row, "Batch No") || null, - ProductName: getVal(row, "Product Name") || null, - Size: getVal(row, "Size") || null, - UOMName: getVal(row, "UOMName") || null, - StockMaintainence: getVal(row, "Stock Maintainence") || null, + VariantName: getVal(row, 'Variant Name') || null, + BatchRef: getVal(row, 'Batch No') || null, + ProductName: getVal(row, 'Product Name') || null, + Size: getVal(row, 'Size') || null, + UOMName: getVal(row, 'UOMName') || null, + StockMaintainence: getVal(row, 'Stock Maintainence') || null, // 🔹 Stock / dates - StockDate: getVal(row, "Stock Date") || null, - ExpDate: getVal(row, "Exp Date") || null, - downloadType: getVal(row, "downloadType") || null, + StockDate: getVal(row, 'Stock Date') || null, + ExpDate: getVal(row, 'Exp Date') || null, + downloadType: getVal(row, 'downloadType') || null, Stock: - getVal(row, "Stock") !== "" ? Number(getVal(row, "Stock")) : null, + getVal(row, 'Stock') !== '' ? Number(getVal(row, 'Stock')) : null, // 🔹 Old prices OldMRP: - getVal(row, "Old MRP") !== "" - ? Number(getVal(row, "Old MRP")) + getVal(row, 'Old MRP') !== '' + ? Number(getVal(row, 'Old MRP')) : null, OldSP: - getVal(row, "Old SP") !== "" ? Number(getVal(row, "Old SP")) : null, + getVal(row, 'Old SP') !== '' ? Number(getVal(row, 'Old SP')) : null, OldWholeSalePrice: - getVal(row, "Old Wholesale Price") !== "" - ? Number(getVal(row, "Old Wholesale Price")) + getVal(row, 'Old Wholesale Price') !== '' + ? Number(getVal(row, 'Old Wholesale Price')) : null, // 🔹 New prices (normalized) @@ -1883,7 +1882,7 @@ const StockPriceUpdate = () => { const handleCancelData = () => { dispatch(emptyExcelData()); if (fileInputRef.current) { - fileInputRef.current.value = ""; + fileInputRef.current.value = ''; } setUploadedData([]); }; @@ -1901,26 +1900,26 @@ const StockPriceUpdate = () => { // If MRP is present, SP must also be present if (newMRP && !newSP) { - setMessageType("error"); + setMessageType('error'); setMessageData( - "If New MRP is provided, New SP must also be provided", + 'If New MRP is provided, New SP must also be provided' ); return; } // If SP is present, MRP must also be present if (newSP && !newMRP) { - setMessageType("error"); + setMessageType('error'); setMessageData( - "If New SP is provided, New MRP must also be provided", + 'If New SP is provided, New MRP must also be provided' ); return; } // New SP cannot be greater than New MRP if (newMRP && newSP && parseFloat(newSP) > parseFloat(newMRP)) { - setMessageType("error"); - setMessageData("New SP cannot be greater than New MRP"); + setMessageType('error'); + setMessageData('New SP cannot be greater than New MRP'); return; } } @@ -1943,7 +1942,7 @@ const StockPriceUpdate = () => { NewSellPrice: data?.NewSellPrice, NewMRP: data?.NewMRP, NewWholeSalePrice: data?.NewWholeSalePrice, - AdjComment: "string", + AdjComment: 'string', })); const putData = { @@ -1958,22 +1957,22 @@ const StockPriceUpdate = () => { const res = await dispatch(bulkPriceUpdate(putData))?.unwrap(); if (res?.data?.statusCode === 1) { - setMessageData(res?.data?.response || "Price Updated Successfully"); - setMessageType("success"); + setMessageData(res?.data?.response || 'Price Updated Successfully'); + setMessageType('success'); setUploadedData([]); handleCancelData(); setExcelModalOpen(false); await fetchData(); } else { setMessageData(res?.data?.response); - setMessageType("error"); + setMessageType('error'); } // If validation passes, proceed with submission - console.log("Form validation passed", updatedData); + console.log('Form validation passed', updatedData); } catch (error) { - setMessageType("error"); - setMessageData("Please check all fields and try again"); + setMessageType('error'); + setMessageData('Please check all fields and try again'); } finally { setLoading(false); } @@ -1984,14 +1983,14 @@ const StockPriceUpdate = () => { AppId: AppId, CompId: CompId, BranchId: BranchId, - Type: "GB", - FormType: fieldSetup ? "Price Change" : "Price Change Sheet", + Type: 'GB', + FormType: fieldSetup ? 'Price Change' : 'Price Change Sheet', TypeId: fieldSetup ? categoryId : excelCategoryId, ConfigDtl: (fieldSetup ? selectedFields : selectedExcelFields)?.map( (field) => ({ ConfigId: field, - Access: "Y", - }), + Access: 'Y', + }) ), CreatedBy: UserId, }; @@ -1999,7 +1998,7 @@ const StockPriceUpdate = () => { const response = await dispatch(postFieldSetup(postData))?.unwrap(); if (response?.data?.statusCode === 1) { - setMessageType("success"); + setMessageType('success'); setMessageData(response?.data?.response); if (fieldSetup) { await getFieldSetup(); @@ -2007,8 +2006,8 @@ const StockPriceUpdate = () => { await getExcelFieldSetup(); } } else { - setMessageType("error"); - setMessageData("Failed to set up fields"); + setMessageType('error'); + setMessageData('Failed to set up fields'); } }; @@ -2047,27 +2046,20 @@ const StockPriceUpdate = () => { onComplete={onComplete} /> -
+
- +
- {RadioSelection == "Bulk" && ( + {RadioSelection == 'Bulk' && (
{ />
-
+
)}
- {RadioSelection == "Single" && ( + {RadioSelection == 'Single' && (
-
+
@@ -2119,7 +2111,7 @@ const StockPriceUpdate = () => { onChangeFunction={(value, option) => HandleStockNames(value, option) } - style={{ width: "240px" }} + style={{ width: '240px' }} options={DataSource} isOnchanges={ProductName ? true : false} /> @@ -2148,17 +2140,17 @@ const StockPriceUpdate = () => {
{
- {(RadioSelection == "Bulk" || - (RadioSelection == "Single" && StockDetails.length > 0)) && ( -
- } - disabled={addnewAccess} - > -
- )} + {(RadioSelection == 'Bulk' || + (RadioSelection == 'Single' && StockDetails.length > 0)) && ( +
+ } + disabled={addnewAccess} + > +
+ )}
- {RadioSelection == "Single" && ( + {RadioSelection == 'Single' && (
{ StockDetails?.length < 11 ? false : { - current: page, - pageSize: pageSize, - onChange: handlePageChange, - } + current: page, + pageSize: pageSize, + onChange: handlePageChange, + } } onChange={handleChange} >
)} - {RadioSelection == "Bulk" && ( -
+ {RadioSelection == 'Bulk' && ( +
{ pagination={{ current: Bulkchangepage, pageSize: pageSize, - pageSizeOptions: ["10", "20", "30"], + pageSizeOptions: ['10', '20', '30'], onChange: handlePageChangeBulk, showSizeChanger: false, }} @@ -2232,7 +2221,7 @@ const StockPriceUpdate = () => { open={excelModalOpen} title="Bulk Upload" footer={false} - className={"bulkuploadmodal padding-less-modal"} + className={'bulkuploadmodal padding-less-modal'} handleCancel={() => { setExcelModalOpen(false); handleCancelData(); @@ -2243,24 +2232,24 @@ const StockPriceUpdate = () => { {uploadedData?.length === 0 && (
@@ -2268,15 +2257,15 @@ const StockPriceUpdate = () => {
{ } : () => showPriceChangeModal() + exportLoading ? () => {} : () => showPriceChangeModal() } >
-
+
Export Excel
@@ -2287,29 +2276,29 @@ const StockPriceUpdate = () => { {!fileLoading && (
{/* */}
{ onChange={handleFileUpload} ref={fileInputRef} style={{ - position: "absolute", + position: 'absolute', top: 0, left: 0, - width: "100%", - height: "100%", + width: '100%', + height: '100%', opacity: 0, - cursor: "pointer", + cursor: 'pointer', }} /> - - {" "} - Upload Sheet{" "} + + {' '} + Upload Sheet{' '}
)} {fileLoading && ( -
+
-

+

Processing file...