Update src/Pages/StockPriceUpdate/StockPriceUpdate.jsx
This commit is contained in:
parent
297afa72d0
commit
6d4d68c475
|
|
@ -36,6 +36,7 @@ import Search from '../../Components/Forms/Search';
|
|||
import { RadioGrpButton } from '../../Components/Forms/RadioGroup.jsx';
|
||||
import { useAuth } from '../../AuthContext.jsx';
|
||||
import '../../Styles/OverAllStyle/OverAllStyle.scss';
|
||||
import './StockPriceUpdate.scss';
|
||||
import { getPreferenceData } from '../../Features/BookingScreen/BookingData/BookingData.js';
|
||||
import { DropDowns } from '../../Components/Forms/DropDown.jsx';
|
||||
import { FiDelete, FiUploadCloud } from 'react-icons/fi';
|
||||
|
|
@ -158,7 +159,10 @@ const StockPriceUpdate = () => {
|
|||
key: 'ProductName',
|
||||
width: 180,
|
||||
render: (value, record, index) => (
|
||||
<p>{`${value} (${record?.Size} ${record?.UOMName})`}</p>
|
||||
<p>
|
||||
{value}{' '}
|
||||
{record?.Size && `(${record?.Size || ''} ${record?.UOMName || ''})`}
|
||||
</p>
|
||||
),
|
||||
},
|
||||
{
|
||||
|
|
@ -807,6 +811,7 @@ const StockPriceUpdate = () => {
|
|||
}
|
||||
|
||||
currentRow[field] = numValue;
|
||||
currentRow.isModified = true;
|
||||
updated[rowIndex] = currentRow;
|
||||
return updated;
|
||||
});
|
||||
|
|
@ -1487,7 +1492,7 @@ const StockPriceUpdate = () => {
|
|||
|
||||
/* ---------------- COLUMN DEFINITIONS ---------------- */
|
||||
const columns = [
|
||||
{ header: 'Product Name', key: 'ProdName', width: 100 },
|
||||
{ header: 'Product Name', key: 'ProdName', width: 20 },
|
||||
...(isStockVariantBased === 'Yes'
|
||||
? [{ header: 'Variant Name', key: 'ProdVariantName', width: 20 }]
|
||||
: []),
|
||||
|
|
@ -1755,7 +1760,34 @@ const StockPriceUpdate = () => {
|
|||
setFileLoading(false);
|
||||
return;
|
||||
}
|
||||
setUploadedData(extractedData);
|
||||
|
||||
// Compare and mark as Old/Modified
|
||||
const comparedData = extractedData
|
||||
.map((uploaded) => {
|
||||
const current = BulkProductData.find(
|
||||
(p) =>
|
||||
p.ProdId === uploaded.ProdId &&
|
||||
(!uploaded.InwardDtlId || p.InwardDtlId === uploaded.InwardDtlId)
|
||||
);
|
||||
|
||||
if (current) {
|
||||
const isModified =
|
||||
Number(current.MRP) !== Number(uploaded.NewMRP) ||
|
||||
Number(current.SellPrice) !== Number(uploaded.NewSellPrice) ||
|
||||
Number(current.WhSalePrice || 0) !==
|
||||
Number(uploaded.NewWholeSalePrice || 0);
|
||||
|
||||
return {
|
||||
...uploaded,
|
||||
isModified,
|
||||
status: isModified ? 'Modified' : 'Old',
|
||||
};
|
||||
}
|
||||
|
||||
return { ...uploaded, isModified: false, status: 'Old' };
|
||||
})
|
||||
.sort((a, b) => Number(b.isModified) - Number(a.isModified));
|
||||
setUploadedData(comparedData);
|
||||
setFileLoading(false);
|
||||
// setFormValuesFromExtractedData(extractedData);
|
||||
};
|
||||
|
|
@ -1929,10 +1961,13 @@ const StockPriceUpdate = () => {
|
|||
const hasMRP = !!data?.NewMRP;
|
||||
const hasSell = !!data?.NewSellPrice;
|
||||
const hasWholesale = !!data?.NewWholeSalePrice;
|
||||
const isModified = data?.isModified === true;
|
||||
|
||||
// valid cases
|
||||
if (hasMRP && hasSell) return true;
|
||||
if (!hasMRP && !hasSell && hasWholesale) return true;
|
||||
if (hasMRP && hasSell && isModified) return true;
|
||||
|
||||
// ✅ Case 2: Only Wholesale changed
|
||||
if (!hasMRP && !hasSell && hasWholesale && isModified) return true;
|
||||
|
||||
return false;
|
||||
})
|
||||
|
|
@ -1954,6 +1989,12 @@ const StockPriceUpdate = () => {
|
|||
CreatedBy: UserId,
|
||||
};
|
||||
|
||||
if (!updatedData || updatedData.length === 0) {
|
||||
setMessageData('Minimum 1 product needs to be changed or added');
|
||||
setMessageType('error');
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await dispatch(bulkPriceUpdate(putData))?.unwrap();
|
||||
|
||||
if (res?.data?.statusCode === 1) {
|
||||
|
|
@ -2046,7 +2087,7 @@ const StockPriceUpdate = () => {
|
|||
onComplete={onComplete}
|
||||
/>
|
||||
|
||||
<div className="formAddNew" style={{justifyContent:"space-between"}}>
|
||||
<div className="formAddNew" style={{ justifyContent: 'space-between' }}>
|
||||
<div>
|
||||
<FormHeader title={'Price Change'} />
|
||||
</div>
|
||||
|
|
@ -2058,9 +2099,7 @@ const StockPriceUpdate = () => {
|
|||
}}
|
||||
>
|
||||
{RadioSelection == 'Bulk' && (
|
||||
<div
|
||||
className='PriChangeUpper'
|
||||
>
|
||||
<div className="PriChangeUpper">
|
||||
<div className="formSearch">
|
||||
<Search
|
||||
value={BulksearchedText}
|
||||
|
|
@ -2360,14 +2399,24 @@ const StockPriceUpdate = () => {
|
|||
<Table
|
||||
columns={columns}
|
||||
rowKey={(record) => record.localId}
|
||||
// components={components}
|
||||
// bordered
|
||||
dataSource={uploadedData}
|
||||
// className="tableExcelUpload"
|
||||
// onChange={handleTableChange}
|
||||
className="price-change-data"
|
||||
rowClassName={(record) =>
|
||||
record.isModified ? 'modified-row' : 'old-row'
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="legend-container">
|
||||
<div className="legend-item">
|
||||
<div className="legend-box old-box"></div>
|
||||
<span className="legend-text">Old</span>
|
||||
</div>
|
||||
<div className="legend-item">
|
||||
<div className="legend-box modified-box"></div>
|
||||
<span className="legend-text">Modified</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="cancel-link"
|
||||
onClick={handleCancelData}
|
||||
|
|
|
|||
Loading…
Reference in New Issue