Reviewed-on: Pozomind/pozo-retail-app#52
This commit is contained in:
commit
441aab2d70
|
|
@ -101,7 +101,7 @@ export const getPurProdvaraiantdata = createAsyncThunk(
|
||||||
data?.prodName !== undefined
|
data?.prodName !== undefined
|
||||||
) {
|
) {
|
||||||
return await axiosRetailInstanceData.get(
|
return await axiosRetailInstanceData.get(
|
||||||
`/ProductCardList?CompId=${data?.CompId}&BranchId=${data?.BranchId}&AppId=${data?.AppId}&prodName=${encodeURIComponent(data?.prodName)}`
|
`/ProductCardList?CompId=${data?.CompId}&BranchId=${data?.BranchId}&AppId=${data?.AppId}&prodName=${encodeURIComponent(data?.prodName)}&type=S`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -327,7 +327,10 @@ const BSC1Payment = (props) => {
|
||||||
)?.PreferenceCatDetails;
|
)?.PreferenceCatDetails;
|
||||||
const sportsAppPreference = commonModulePreference?.find(
|
const sportsAppPreference = commonModulePreference?.find(
|
||||||
(preference) => preference?.PreferredSubCatName === 'SportsApp'
|
(preference) => preference?.PreferredSubCatName === 'SportsApp'
|
||||||
|
&&
|
||||||
|
preference?.PreferredStatus == 'Y'
|
||||||
);
|
);
|
||||||
|
console.log(sportsAppPreference,commonModulePreference,"sportsAppPreference")
|
||||||
const bookingTypePreference = appPreferences?.find(
|
const bookingTypePreference = appPreferences?.find(
|
||||||
(preference) => preference?.PreferredCatName === 'Booking Type'
|
(preference) => preference?.PreferredCatName === 'Booking Type'
|
||||||
)?.PreferenceCatDetails;
|
)?.PreferenceCatDetails;
|
||||||
|
|
|
||||||
|
|
@ -1,449 +1,517 @@
|
||||||
import { shallowEqual, useSelector } from "react-redux";
|
import { shallowEqual, useSelector } from 'react-redux';
|
||||||
import { GlobalAccessForOthers, GlobalCardAccess, GlobalCombosearch, GlobalItemCard, GlobalProductCategorie, GlobalSelectedDatas, GlobalWithoutSubCatItemCard, triggerProductCard } from "../../../../Features/BookingScreen/BookingData/BookingData";
|
import {
|
||||||
import { DefaultModal } from "../../../../Components/Modal/DefaultModal";
|
GlobalAccessForOthers,
|
||||||
import { useCallback, useEffect, useRef, useState } from "react";
|
GlobalCardAccess,
|
||||||
import { Tables } from "../../../../Components/Tables/Table";
|
GlobalCombosearch,
|
||||||
import { InputField } from "../../../../Components/Forms/InputField";
|
GlobalItemCard,
|
||||||
import { Form, Pagination, Tooltip } from "antd";
|
GlobalProductCategorie,
|
||||||
import { getSession } from "../../../../Services/Others";
|
GlobalSelectedDatas,
|
||||||
import { Messages } from "../../../../Components/Notifications/Messages";
|
GlobalWithoutSubCatItemCard,
|
||||||
import { useDispatch } from "react-redux";
|
triggerProductCard,
|
||||||
import { PutStockPrice } from "../../../../Features/StockPriceUpdate/StockPriceUpdateMaster";
|
} from '../../../../Features/BookingScreen/BookingData/BookingData';
|
||||||
import PriceChange from "../../../../Images/PayOptImgs/PriceChange.svg"
|
import { DefaultModal } from '../../../../Components/Modal/DefaultModal';
|
||||||
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
|
import { Tables } from '../../../../Components/Tables/Table';
|
||||||
|
import { InputField } from '../../../../Components/Forms/InputField';
|
||||||
|
import { Form, Pagination, Tooltip } from 'antd';
|
||||||
|
import { getSession } from '../../../../Services/Others';
|
||||||
|
import { Messages } from '../../../../Components/Notifications/Messages';
|
||||||
|
import { useDispatch } from 'react-redux';
|
||||||
|
import { PutStockPrice } from '../../../../Features/StockPriceUpdate/StockPriceUpdateMaster';
|
||||||
|
import PriceChange from '../../../../Images/PayOptImgs/PriceChange.svg';
|
||||||
|
|
||||||
const ProductPriceChange = ({ showButton = true, priceChangeProduct = null, productPriceChange = false, setProductPriceChange = () => { }, setPriceChangeProduct = () => { } }) => {
|
const ProductPriceChange = ({
|
||||||
|
showButton = true,
|
||||||
|
priceChangeProduct = [],
|
||||||
|
productPriceChange = false,
|
||||||
|
setProductPriceChange = () => {},
|
||||||
|
setPriceChangeProduct = () => {},
|
||||||
|
}) => {
|
||||||
|
const formRef = useRef(null);
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
const formRef = useRef(null);
|
const AppId = getSession('AppId');
|
||||||
const dispatch = useDispatch();
|
const CompId = getSession('CompId');
|
||||||
|
const BranchId = getSession('BranchId');
|
||||||
|
const UserId = getSession('UserId');
|
||||||
|
|
||||||
const AppId = getSession('AppId');
|
const [messageData, setMessageData] = useState(null);
|
||||||
const CompId = getSession('CompId');
|
const [messageType, setMessageType] = useState(null);
|
||||||
const BranchId = getSession('BranchId');
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const UserId = getSession('UserId');
|
const [pageSize] = useState(10);
|
||||||
|
|
||||||
const [messageData, setMessageData] = useState(null);
|
const [noSubcatCardData, setNoSubcatCardData] = useState();
|
||||||
const [messageType, setMessageType] = useState(null);
|
const [priceChangeModal, setPriceChangeModal] = useState(false);
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
|
||||||
const [pageSize] = useState(10);
|
|
||||||
|
|
||||||
const [noSubcatCardData, setNoSubcatCardData] = useState();
|
const comboSearch = useSelector(GlobalCombosearch);
|
||||||
const [priceChangeModal, setPriceChangeModal] = useState(false);
|
const ProdCat = useSelector(GlobalProductCategorie, shallowEqual);
|
||||||
|
const ItemCard = useSelector(GlobalItemCard, shallowEqual);
|
||||||
|
const withoutSubCatItemCard = useSelector(
|
||||||
|
GlobalWithoutSubCatItemCard,
|
||||||
|
shallowEqual
|
||||||
|
);
|
||||||
|
const CardAccess = useSelector(GlobalCardAccess, shallowEqual);
|
||||||
|
const globalAccessForOthers = useSelector(
|
||||||
|
GlobalAccessForOthers,
|
||||||
|
shallowEqual
|
||||||
|
);
|
||||||
|
const SelectedDatas = useSelector(GlobalSelectedDatas, shallowEqual);
|
||||||
|
const [tableData, setTableData] = useState([]);
|
||||||
|
const [editingKey, setEditingKey] = useState(null);
|
||||||
|
const [priceChangedProducts, setPriceChangedProducts] = useState([]);
|
||||||
|
console.log(comboSearch, 'comboSearch');
|
||||||
|
|
||||||
const comboSearch = useSelector(GlobalCombosearch);
|
// console.log(noSubcatCardData, "noSubcatCardData")
|
||||||
const ProdCat = useSelector(GlobalProductCategorie, shallowEqual);
|
|
||||||
const ItemCard = useSelector(GlobalItemCard, shallowEqual);
|
|
||||||
const withoutSubCatItemCard = useSelector(GlobalWithoutSubCatItemCard, shallowEqual);
|
|
||||||
const CardAccess = useSelector(GlobalCardAccess, shallowEqual);
|
|
||||||
const globalAccessForOthers = useSelector(GlobalAccessForOthers, shallowEqual);
|
|
||||||
const SelectedDatas = useSelector(GlobalSelectedDatas, shallowEqual);
|
|
||||||
const [tableData, setTableData] = useState([]);
|
|
||||||
const [editingKey, setEditingKey] = useState(null);
|
|
||||||
const [priceChangedProducts, setPriceChangedProducts] = useState([]);
|
|
||||||
console.log(comboSearch, "comboSearch")
|
|
||||||
|
|
||||||
// console.log(noSubcatCardData, "noSubcatCardData")
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
ProdCat &&
|
||||||
|
(ItemCard || withoutSubCatItemCard) &&
|
||||||
|
(!noSubcatCardData || noSubcatCardData?.length === 0)
|
||||||
|
) {
|
||||||
|
setNoSubcatCardData(
|
||||||
|
ItemCard?.length === 0 ? withoutSubCatItemCard : ItemCard
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, [ProdCat, ItemCard, withoutSubCatItemCard, noSubcatCardData]);
|
||||||
|
|
||||||
useEffect(() => {
|
const priceChangeColumns = [
|
||||||
if (ProdCat && (ItemCard || withoutSubCatItemCard) && (!noSubcatCardData || noSubcatCardData?.length === 0)) {
|
{
|
||||||
setNoSubcatCardData(ItemCard?.length === 0 ? withoutSubCatItemCard : ItemCard);
|
title: 'S.No',
|
||||||
}
|
dataIndex: 'SlNo',
|
||||||
}, [ProdCat, ItemCard, withoutSubCatItemCard, noSubcatCardData]);
|
key: 'SlNo',
|
||||||
|
width: '60px',
|
||||||
|
align: 'center',
|
||||||
|
render: (text, record, index) => (
|
||||||
|
<div>{(currentPage - 1) * pageSize + index + 1}</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Product Name',
|
||||||
|
dataIndex: 'ProdName',
|
||||||
|
key: 'ProdName',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Old MRP',
|
||||||
|
dataIndex: 'MRP',
|
||||||
|
key: 'MRP',
|
||||||
|
width: '100px',
|
||||||
|
align: 'right',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'New MRP (Optional)',
|
||||||
|
dataIndex: 'NewMRP',
|
||||||
|
key: 'NewMRP',
|
||||||
|
width: '100px',
|
||||||
|
align: 'right',
|
||||||
|
render: (text, record, index) => {
|
||||||
|
// if (index === editingKey) {
|
||||||
|
|
||||||
const priceChangeColumns = [
|
// }
|
||||||
{
|
// return <div>{text ? text : 'Enter New MRP'}</div>
|
||||||
title: 'S.No',
|
return (
|
||||||
dataIndex: 'SlNo',
|
<Form.Item
|
||||||
key: 'SlNo',
|
name={`NewMRP${index}`}
|
||||||
width: '60px',
|
rules={[
|
||||||
align: 'center',
|
{
|
||||||
render: (text, record, index) => <div>{(currentPage - 1) * pageSize + index + 1}</div>
|
validator: async (_, value) => {
|
||||||
},
|
if (value === '') {
|
||||||
{
|
return Promise.resolve();
|
||||||
title: 'Product Name',
|
} else if (parseFloat(value) < 1) {
|
||||||
dataIndex: 'ProdName',
|
return Promise.reject(`MRP should be greater than 0`);
|
||||||
key: 'ProdName',
|
}
|
||||||
},
|
return Promise.resolve();
|
||||||
{
|
},
|
||||||
title: 'Old MRP',
|
},
|
||||||
dataIndex: 'MRP',
|
]}
|
||||||
key: 'MRP',
|
>
|
||||||
width: '100px',
|
<InputField
|
||||||
align: 'right',
|
value={text}
|
||||||
},
|
placeholder="Enter New MRP"
|
||||||
{
|
onChange={(e) => handleNewMRPChange(e?.target?.value, index)}
|
||||||
title: 'New MRP (Optional)',
|
inputMode="decimal"
|
||||||
dataIndex: 'NewMRP',
|
onInput={(e) => {
|
||||||
key: 'NewMRP',
|
let cleanedValue = e.target.value.replace(/[^0-9.]/g, ''); // Remove invalid characters
|
||||||
width: '100px',
|
const parts = cleanedValue.split('.');
|
||||||
align: 'right',
|
|
||||||
render: (text, record, index) => {
|
|
||||||
// if (index === editingKey) {
|
|
||||||
|
|
||||||
// }
|
if (cleanedValue.startsWith('.')) {
|
||||||
// return <div>{text ? text : 'Enter New MRP'}</div>
|
cleanedValue = '0' + cleanedValue;
|
||||||
return (
|
}
|
||||||
<Form.Item
|
|
||||||
name={`NewMRP${index}`}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
validator: async (_, value) => {
|
|
||||||
if (value === '') {
|
|
||||||
return Promise.resolve();
|
|
||||||
} else if (parseFloat(value) < 1) {
|
|
||||||
return Promise.reject(`MRP should be greater than 0`)
|
|
||||||
}
|
|
||||||
return Promise.resolve();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]}>
|
|
||||||
<InputField
|
|
||||||
value={text}
|
|
||||||
placeholder="Enter New MRP"
|
|
||||||
onChange={(e) => handleNewMRPChange(e?.target?.value, index)}
|
|
||||||
inputMode="decimal"
|
|
||||||
onInput={(e) => {
|
|
||||||
let cleanedValue = e.target.value.replace(
|
|
||||||
/[^0-9.]/g,
|
|
||||||
''
|
|
||||||
); // Remove invalid characters
|
|
||||||
const parts = cleanedValue.split('.');
|
|
||||||
|
|
||||||
if (cleanedValue.startsWith('.')) {
|
e.target.value =
|
||||||
cleanedValue = '0' + cleanedValue;
|
parts.length > 2
|
||||||
}
|
? `${parts[0]}.${parts.slice(1).join('')}`
|
||||||
|
: cleanedValue;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Old Sell Price',
|
||||||
|
dataIndex: 'SellPrice',
|
||||||
|
key: 'SellPrice',
|
||||||
|
width: '120px',
|
||||||
|
align: 'right',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'New Sell Price',
|
||||||
|
dataIndex: 'NewSellPrice',
|
||||||
|
key: 'NewSellPrice',
|
||||||
|
width: '160px',
|
||||||
|
align: 'right',
|
||||||
|
render: (text, record, index) => {
|
||||||
|
// if (index === editingKey) {
|
||||||
|
|
||||||
e.target.value =
|
// }
|
||||||
parts.length > 2
|
// return <div>{text ? text : 'Enter New Sell Price'}</div>
|
||||||
? `${parts[0]}.${parts.slice(1).join('')}`
|
return (
|
||||||
: cleanedValue;
|
<Form.Item
|
||||||
}}
|
name={`NewSellPrice${index}`}
|
||||||
/>
|
rules={[
|
||||||
</Form.Item>
|
{
|
||||||
);
|
validator: async (_, value) => {
|
||||||
},
|
if (value === '') {
|
||||||
},
|
return Promise.resolve();
|
||||||
{
|
} else if (parseFloat(value) < 1) {
|
||||||
title: 'Old Sell Price',
|
return Promise.reject(
|
||||||
dataIndex: 'SellPrice',
|
`Sell Price should be greater than 0`
|
||||||
key: 'SellPrice',
|
);
|
||||||
width: '120px',
|
}
|
||||||
align: 'right',
|
return Promise.resolve();
|
||||||
},
|
},
|
||||||
{
|
},
|
||||||
title: 'New Sell Price',
|
]}
|
||||||
dataIndex: 'NewSellPrice',
|
>
|
||||||
key: 'NewSellPrice',
|
<InputField
|
||||||
width: '160px',
|
value={text}
|
||||||
align: 'right',
|
placeholder="Enter New Sell Price"
|
||||||
render: (text, record, index) => {
|
onChange={(e) =>
|
||||||
// if (index === editingKey) {
|
handleNewSellPriceChange(e?.target?.value, index)
|
||||||
|
}
|
||||||
|
inputMode="decimal"
|
||||||
|
onInput={(e) => {
|
||||||
|
let cleanedValue = e.target.value.replace(/[^0-9.]/g, ''); // Remove invalid characters
|
||||||
|
const parts = cleanedValue.split('.');
|
||||||
|
|
||||||
// }
|
if (cleanedValue.startsWith('.')) {
|
||||||
// return <div>{text ? text : 'Enter New Sell Price'}</div>
|
cleanedValue = '0' + cleanedValue;
|
||||||
return (
|
}
|
||||||
<Form.Item
|
|
||||||
name={`NewSellPrice${index}`}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
validator: async (_, value) => {
|
|
||||||
if (value === '') {
|
|
||||||
return Promise.resolve();
|
|
||||||
} else if (parseFloat(value) < 1) {
|
|
||||||
return Promise.reject(`Sell Price should be greater than 0`)
|
|
||||||
}
|
|
||||||
return Promise.resolve();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<InputField
|
|
||||||
value={text}
|
|
||||||
placeholder="Enter New Sell Price"
|
|
||||||
onChange={(e) => handleNewSellPriceChange(e?.target?.value, index)}
|
|
||||||
inputMode="decimal"
|
|
||||||
onInput={(e) => {
|
|
||||||
let cleanedValue = e.target.value.replace(
|
|
||||||
/[^0-9.]/g,
|
|
||||||
''
|
|
||||||
); // Remove invalid characters
|
|
||||||
const parts = cleanedValue.split('.');
|
|
||||||
|
|
||||||
if (cleanedValue.startsWith('.')) {
|
e.target.value =
|
||||||
cleanedValue = '0' + cleanedValue;
|
parts.length > 2
|
||||||
}
|
? `${parts[0]}.${parts.slice(1).join('')}`
|
||||||
|
: cleanedValue;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
e.target.value =
|
const cardData = !globalAccessForOthers
|
||||||
parts.length > 2
|
? CardAccess
|
||||||
? `${parts[0]}.${parts.slice(1).join('')}`
|
? SelectedDatas?.length > 1
|
||||||
: cleanedValue;
|
? SelectedDatas
|
||||||
}}
|
: SelectedDatas?.[0]?.AppId === 0 && SelectedDatas?.[0]?.CompId === 0
|
||||||
/>
|
? []
|
||||||
</Form.Item>
|
: SelectedDatas
|
||||||
);
|
: ItemCard?.length === 0 ||
|
||||||
},
|
(ItemCard?.[0]?.AppId === 0 && ItemCard?.[0]?.CompId === 0)
|
||||||
},
|
? noSubcatCardData
|
||||||
];
|
: ItemCard
|
||||||
|
: [];
|
||||||
|
|
||||||
const cardData = !globalAccessForOthers
|
console.log(cardData, 'noSubcatCardDatanoSubcatCardData', ItemCard);
|
||||||
? CardAccess
|
|
||||||
? SelectedDatas?.length > 1
|
|
||||||
? SelectedDatas
|
|
||||||
: SelectedDatas?.[0]?.AppId === 0 && SelectedDatas?.[0]?.CompId === 0
|
|
||||||
? []
|
|
||||||
: SelectedDatas
|
|
||||||
: ItemCard?.length === 0 || (ItemCard?.[0]?.AppId === 0 && ItemCard?.[0]?.CompId === 0)
|
|
||||||
? noSubcatCardData
|
|
||||||
: ItemCard
|
|
||||||
: '';
|
|
||||||
|
|
||||||
console.log(cardData, "noSubcatCardDatanoSubcatCardData", ItemCard)
|
useEffect(() => {
|
||||||
|
|
||||||
useEffect(() => {
|
const extractStockDtls = (data) => {
|
||||||
const extractStockDtls = (data) => {
|
if (data?.length === 0 || !data) return [];
|
||||||
if (data?.length === 0) return [];
|
|
||||||
|
|
||||||
let stockDtls = [];
|
let stockDtls = [];git
|
||||||
|
|
||||||
data?.forEach(item => {
|
data?.forEach((item) => {
|
||||||
let products = item?.ProductDetail?.flatMap(product => product);
|
let products = item?.ProductDetail?.flatMap((product) => product);
|
||||||
|
|
||||||
let variants = products?.flatMap(product => product?.ProdVariantDetails);
|
let variants = products?.flatMap(
|
||||||
const filteredVariants = variants?.filter(variant => variant?.StockDetails?.length > 0);
|
(product) => product?.ProdVariantDetails
|
||||||
const stocks = filteredVariants?.flatMap(variant =>
|
);
|
||||||
variant?.StockDetails?.map(stock => ({
|
const filteredVariants = variants?.filter(
|
||||||
...stock,
|
(variant) => variant?.StockDetails?.length > 0
|
||||||
ProdName: products?.[0]?.ProdName + (variant?.ProdVariantName ? ` (${variant?.ProdVariantName})` : ''),
|
);
|
||||||
StockAvailable: products?.[0]?.StockAvailable,
|
const stocks = filteredVariants?.flatMap((variant) =>
|
||||||
ProdVariantName: variant?.ProdVariantName
|
variant?.StockDetails?.map((stock) => ({
|
||||||
}))
|
...stock,
|
||||||
);
|
ProdName:
|
||||||
|
products?.[0]?.ProdName +
|
||||||
|
(variant?.ProdVariantName
|
||||||
|
? ` (${variant?.ProdVariantName})`
|
||||||
|
: ''),
|
||||||
|
StockAvailable: products?.[0]?.StockAvailable,
|
||||||
|
ProdVariantName: variant?.ProdVariantName,
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
stockDtls.push(...stocks?.filter(stock =>
|
stockDtls.push(
|
||||||
stock?.StockAvailable === 'Y'
|
...stocks?.filter((stock) =>
|
||||||
? stock?.BatchRef
|
stock?.StockAvailable === 'Y' ? stock?.BatchRef : true
|
||||||
: true
|
)
|
||||||
));
|
);
|
||||||
|
});
|
||||||
|
console.log('extractStockDtls', stockDtls);
|
||||||
|
return stockDtls;
|
||||||
|
};
|
||||||
|
setTableData(extractStockDtls(priceChangeProduct || cardData || []));
|
||||||
|
setCurrentPage(1);
|
||||||
|
}, [cardData, priceChangeProduct]);
|
||||||
|
|
||||||
});
|
const handleNewMRPChange = (value, index) => {
|
||||||
console.log("extractStockDtls", stockDtls);
|
const updatedTableData = [...tableData];
|
||||||
return stockDtls;
|
updatedTableData[index].NewMRP = value;
|
||||||
}
|
setTableData(updatedTableData);
|
||||||
setTableData(extractStockDtls(priceChangeProduct || cardData))
|
updatedTableData[index].NewSellPrice = null;
|
||||||
setCurrentPage(1)
|
formRef.current.setFieldsValue({
|
||||||
}, [cardData, priceChangeProduct])
|
[`NewMRP${index}`]: value,
|
||||||
|
[`NewSellPrice${index}`]: null,
|
||||||
|
});
|
||||||
|
|
||||||
const handleNewMRPChange = (value, index) => {
|
const priceChangedProdList = [...priceChangedProducts];
|
||||||
|
const prodIndex = priceChangedProdList?.findIndex(
|
||||||
|
(prod) => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId
|
||||||
|
);
|
||||||
|
if (prodIndex !== -1) {
|
||||||
|
priceChangedProdList[prodIndex] = {
|
||||||
|
...priceChangedProdList?.[prodIndex],
|
||||||
|
NewMRP: value,
|
||||||
|
NewSellPrice: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
setPriceChangedProducts(priceChangedProdList);
|
||||||
|
};
|
||||||
|
|
||||||
const updatedTableData = [...tableData];
|
const handleNewSellPriceChange = (value, index) => {
|
||||||
updatedTableData[index].NewMRP = value;
|
const updatedTableData = [...tableData];
|
||||||
setTableData(updatedTableData);
|
if (updatedTableData[index]?.NewMRP) {
|
||||||
|
if (parseFloat(value) > parseFloat(updatedTableData[index]?.NewMRP)) {
|
||||||
|
setMessageType('error');
|
||||||
|
setMessageData('New Sell Price cannot be greater than New MRP');
|
||||||
|
formRef.current.setFieldsValue({
|
||||||
|
[`NewSellPrice${index}`]: null,
|
||||||
|
});
|
||||||
updatedTableData[index].NewSellPrice = null;
|
updatedTableData[index].NewSellPrice = null;
|
||||||
formRef.current.setFieldsValue({
|
|
||||||
[`NewMRP${index}`]: value,
|
|
||||||
[`NewSellPrice${index}`]: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
const priceChangedProdList = [...priceChangedProducts];
|
|
||||||
const prodIndex = priceChangedProdList?.findIndex(prod => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId);
|
|
||||||
if (prodIndex !== -1) {
|
|
||||||
priceChangedProdList[prodIndex] = {
|
|
||||||
...priceChangedProdList?.[prodIndex],
|
|
||||||
NewMRP: value,
|
|
||||||
NewSellPrice: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
setPriceChangedProducts(priceChangedProdList);
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleNewSellPriceChange = (value, index) => {
|
|
||||||
const updatedTableData = [...tableData];
|
|
||||||
if (updatedTableData[index]?.NewMRP) {
|
|
||||||
if (parseFloat(value) > parseFloat(updatedTableData[index]?.NewMRP)) {
|
|
||||||
setMessageType('error');
|
|
||||||
setMessageData('New Sell Price cannot be greater than New MRP');
|
|
||||||
formRef.current.setFieldsValue({
|
|
||||||
[`NewSellPrice${index}`]: null,
|
|
||||||
});
|
|
||||||
updatedTableData[index].NewSellPrice = null;
|
|
||||||
setTableData(updatedTableData);
|
|
||||||
const priceChangedProdList = [...priceChangedProducts];
|
|
||||||
const prodIndex = priceChangedProdList?.findIndex(prod => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId);
|
|
||||||
|
|
||||||
if (prodIndex !== -1) {
|
|
||||||
priceChangedProdList.splice(prodIndex, 1);
|
|
||||||
}
|
|
||||||
setPriceChangedProducts(priceChangedProdList);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!updatedTableData[index]?.NewMRP && updatedTableData[index]?.MRP) {
|
|
||||||
if (parseFloat(value) > parseFloat(updatedTableData[index]?.MRP)) {
|
|
||||||
setMessageType('error');
|
|
||||||
setMessageData('New Sell Price cannot be greater than MRP');
|
|
||||||
formRef.current.setFieldsValue({
|
|
||||||
[`NewSellPrice${index}`]: null,
|
|
||||||
});
|
|
||||||
updatedTableData[index].NewSellPrice = null;
|
|
||||||
setTableData(updatedTableData);
|
|
||||||
const priceChangedProdList = [...priceChangedProducts];
|
|
||||||
const prodIndex = priceChangedProdList?.findIndex(prod => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId);
|
|
||||||
|
|
||||||
if (prodIndex !== -1) {
|
|
||||||
priceChangedProdList.splice(prodIndex, 1);
|
|
||||||
}
|
|
||||||
setPriceChangedProducts(priceChangedProdList);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updatedTableData[index].NewSellPrice = value;
|
|
||||||
setTableData(updatedTableData);
|
setTableData(updatedTableData);
|
||||||
formRef.current.setFieldsValue({
|
|
||||||
[`NewSellPrice${index}`]: value,
|
|
||||||
});
|
|
||||||
|
|
||||||
const priceChangedProdList = [...priceChangedProducts];
|
const priceChangedProdList = [...priceChangedProducts];
|
||||||
const prodIndex = priceChangedProdList?.findIndex(prod => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId);
|
const prodIndex = priceChangedProdList?.findIndex(
|
||||||
|
(prod) => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId
|
||||||
|
);
|
||||||
|
|
||||||
if (prodIndex !== -1) {
|
if (prodIndex !== -1) {
|
||||||
priceChangedProdList[prodIndex] = {
|
priceChangedProdList.splice(prodIndex, 1);
|
||||||
...priceChangedProdList[prodIndex],
|
|
||||||
SellPrice: String(value)
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
priceChangedProdList.push({
|
|
||||||
ProdId: updatedTableData[index]?.ProdId,
|
|
||||||
ProdName: updatedTableData[index]?.ProdName,
|
|
||||||
MRP: String(updatedTableData[index]?.NewMRP || updatedTableData[index]?.MRP),
|
|
||||||
SellPrice: String(value),
|
|
||||||
AdjComment: "string",
|
|
||||||
InwardDtlId: updatedTableData[index]?.InwardDtlId
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setPriceChangedProducts(priceChangedProdList);
|
setPriceChangedProducts(priceChangedProdList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (!updatedTableData[index]?.NewMRP && updatedTableData[index]?.MRP) {
|
||||||
|
if (parseFloat(value) > parseFloat(updatedTableData[index]?.MRP)) {
|
||||||
|
setMessageType('error');
|
||||||
|
setMessageData('New Sell Price cannot be greater than MRP');
|
||||||
|
formRef.current.setFieldsValue({
|
||||||
|
[`NewSellPrice${index}`]: null,
|
||||||
|
});
|
||||||
|
updatedTableData[index].NewSellPrice = null;
|
||||||
|
setTableData(updatedTableData);
|
||||||
|
const priceChangedProdList = [...priceChangedProducts];
|
||||||
|
const prodIndex = priceChangedProdList?.findIndex(
|
||||||
|
(prod) => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId
|
||||||
|
);
|
||||||
|
|
||||||
const edit = (record, index) => {
|
if (prodIndex !== -1) {
|
||||||
console.log("edit", record, index);
|
priceChangedProdList.splice(prodIndex, 1);
|
||||||
setEditingKey(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
|
||||||
console.log("submit");
|
|
||||||
|
|
||||||
if (priceChangedProducts?.length > 0) {
|
|
||||||
console.log("priceChangedProducts", priceChangedProducts);
|
|
||||||
const validation = priceChangedProducts?.every((prod) => {
|
|
||||||
if (parseFloat(prod?.MRP) < parseFloat(prod?.SellPrice)) {
|
|
||||||
setMessageType('error');
|
|
||||||
setMessageData(`${prod?.ProdName}: MRP cannot be less than Sell Price`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!parseFloat(prod?.SellPrice) || !parseFloat(prod?.MRP)) {
|
|
||||||
setMessageType('error');
|
|
||||||
setMessageData(`${prod?.ProdName}: Please give Sell Price or MRP`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
if (!validation) return;
|
|
||||||
|
|
||||||
const data = {
|
|
||||||
AppId: AppId,
|
|
||||||
CompId: CompId,
|
|
||||||
BranchId: BranchId,
|
|
||||||
ProductDetails: priceChangedProducts,
|
|
||||||
UpdatedBy: UserId,
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await dispatch(PutStockPrice(data))?.unwrap();
|
|
||||||
if (res?.data?.statusCode === 1) {
|
|
||||||
setMessageData('Price Changed Successfully');
|
|
||||||
setMessageType('success');
|
|
||||||
setPriceChangeModal(false);
|
|
||||||
setProductPriceChange(false);
|
|
||||||
setEditingKey(null);
|
|
||||||
setPriceChangedProducts([]);
|
|
||||||
setTableData([]);
|
|
||||||
dispatch(triggerProductCard())
|
|
||||||
setPriceChangeProduct(null);
|
|
||||||
formRef.current.resetFields();
|
|
||||||
} else {
|
|
||||||
setMessageData('Error Updating Product Price')
|
|
||||||
setMessageType('error');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setMessageType('error');
|
|
||||||
setMessageData('No changes made / No sell price entered');
|
|
||||||
}
|
}
|
||||||
|
setPriceChangedProducts(priceChangedProdList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updatedTableData[index].NewSellPrice = value;
|
||||||
|
setTableData(updatedTableData);
|
||||||
|
formRef.current.setFieldsValue({
|
||||||
|
[`NewSellPrice${index}`]: value,
|
||||||
|
});
|
||||||
|
|
||||||
|
const priceChangedProdList = [...priceChangedProducts];
|
||||||
|
const prodIndex = priceChangedProdList?.findIndex(
|
||||||
|
(prod) => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId
|
||||||
|
);
|
||||||
|
|
||||||
|
if (prodIndex !== -1) {
|
||||||
|
priceChangedProdList[prodIndex] = {
|
||||||
|
...priceChangedProdList[prodIndex],
|
||||||
|
SellPrice: String(value),
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
priceChangedProdList.push({
|
||||||
|
ProdId: updatedTableData[index]?.ProdId,
|
||||||
|
ProdName: updatedTableData[index]?.ProdName,
|
||||||
|
MRP: String(
|
||||||
|
updatedTableData[index]?.NewMRP || updatedTableData[index]?.MRP
|
||||||
|
),
|
||||||
|
SellPrice: String(value),
|
||||||
|
AdjComment: 'string',
|
||||||
|
InwardDtlId: updatedTableData[index]?.InwardDtlId,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const onComplete = useCallback(() => {
|
setPriceChangedProducts(priceChangedProdList);
|
||||||
setMessageData(null);
|
};
|
||||||
setMessageType(null);
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return (
|
const edit = (record, index) => {
|
||||||
<>
|
console.log('edit', record, index);
|
||||||
|
setEditingKey(index);
|
||||||
|
};
|
||||||
|
|
||||||
<Messages messageData={messageData} messageType={messageType} onComplete={onComplete} />
|
const handleSubmit = async () => {
|
||||||
{showButton ? <Tooltip title="Price Change">
|
console.log('submit');
|
||||||
<button className="price-change-btn" type="button" onClick={() => {
|
|
||||||
if (comboSearch) {
|
if (priceChangedProducts?.length > 0) {
|
||||||
setMessageType('warning');
|
console.log('priceChangedProducts', priceChangedProducts);
|
||||||
setMessageData('Price change will not work for combo products');
|
const validation = priceChangedProducts?.every((prod) => {
|
||||||
return
|
if (parseFloat(prod?.MRP) < parseFloat(prod?.SellPrice)) {
|
||||||
}
|
setMessageType('error');
|
||||||
setPriceChangeModal(true)
|
setMessageData(
|
||||||
}}>
|
`${prod?.ProdName}: MRP cannot be less than Sell Price`
|
||||||
{/* <FaIndianRupeeSign size={35}/> */}
|
);
|
||||||
<img src={PriceChange} alt="" width={30} />
|
return false;
|
||||||
</button>
|
}
|
||||||
</Tooltip> : <></>}
|
if (!parseFloat(prod?.SellPrice) || !parseFloat(prod?.MRP)) {
|
||||||
<DefaultModal
|
setMessageType('error');
|
||||||
title="Price Change"
|
setMessageData(`${prod?.ProdName}: Please give Sell Price or MRP`);
|
||||||
className={'price-change-modal'}
|
return false;
|
||||||
open={priceChangeModal || productPriceChange}
|
}
|
||||||
footer={true}
|
return true;
|
||||||
width={800}
|
});
|
||||||
handleCancel={() => {
|
if (!validation) return;
|
||||||
setPriceChangeModal(false);
|
|
||||||
setProductPriceChange(false);
|
const data = {
|
||||||
setEditingKey(null);
|
AppId: AppId,
|
||||||
setPriceChangedProducts([]);
|
CompId: CompId,
|
||||||
formRef?.current?.resetFields();
|
BranchId: BranchId,
|
||||||
setPriceChangeProduct(null);
|
ProductDetails: priceChangedProducts,
|
||||||
}}
|
UpdatedBy: UserId,
|
||||||
handleSubmit={handleSubmit}
|
};
|
||||||
|
|
||||||
|
const res = await dispatch(PutStockPrice(data))?.unwrap();
|
||||||
|
if (res?.data?.statusCode === 1) {
|
||||||
|
setMessageData('Price Changed Successfully');
|
||||||
|
setMessageType('success');
|
||||||
|
setPriceChangeModal(false);
|
||||||
|
setProductPriceChange(false);
|
||||||
|
setEditingKey(null);
|
||||||
|
setPriceChangedProducts([]);
|
||||||
|
setTableData([]);
|
||||||
|
dispatch(triggerProductCard());
|
||||||
|
setPriceChangeProduct(null);
|
||||||
|
formRef.current.resetFields();
|
||||||
|
} else {
|
||||||
|
setMessageData('Error Updating Product Price');
|
||||||
|
setMessageType('error');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setMessageType('error');
|
||||||
|
setMessageData('No changes made / No sell price entered');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onComplete = useCallback(() => {
|
||||||
|
setMessageData(null);
|
||||||
|
setMessageType(null);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Messages
|
||||||
|
messageData={messageData}
|
||||||
|
messageType={messageType}
|
||||||
|
onComplete={onComplete}
|
||||||
|
/>
|
||||||
|
{showButton ? (
|
||||||
|
<Tooltip title="Price Change">
|
||||||
|
<button
|
||||||
|
className="price-change-btn"
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
if (comboSearch) {
|
||||||
|
setMessageType('warning');
|
||||||
|
setMessageData('Price change will not work for combo products');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setPriceChangeModal(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{/* <FaIndianRupeeSign size={35}/> */}
|
||||||
|
<img src={PriceChange} alt="" width={30} />
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
|
<DefaultModal
|
||||||
|
title="Price Change"
|
||||||
|
className={'price-change-modal'}
|
||||||
|
open={priceChangeModal || productPriceChange}
|
||||||
|
footer={true}
|
||||||
|
width={800}
|
||||||
|
handleCancel={() => {
|
||||||
|
setPriceChangeModal(false);
|
||||||
|
setProductPriceChange(false);
|
||||||
|
setEditingKey(null);
|
||||||
|
setPriceChangedProducts([]);
|
||||||
|
formRef?.current?.resetFields();
|
||||||
|
setPriceChangeProduct(null);
|
||||||
|
}}
|
||||||
|
handleSubmit={handleSubmit}
|
||||||
|
>
|
||||||
|
<div className="price-change-table">
|
||||||
|
{/* <div className="table-notes">Note : Click on a row to edit/modify</div> */}
|
||||||
|
<Form ref={formRef}>
|
||||||
|
<Tables
|
||||||
|
columns={priceChangeColumns}
|
||||||
|
data={tableData?.slice(
|
||||||
|
(currentPage - 1) * pageSize,
|
||||||
|
currentPage * pageSize
|
||||||
|
)}
|
||||||
|
onRow={(record, index) => ({
|
||||||
|
onClick: () => {
|
||||||
|
edit(record, index);
|
||||||
|
},
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
margin: '20px 0',
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div className="price-change-table">
|
<Pagination
|
||||||
{/* <div className="table-notes">Note : Click on a row to edit/modify</div> */}
|
current={currentPage}
|
||||||
<Form ref={formRef}>
|
pageSize={pageSize}
|
||||||
<Tables
|
total={tableData?.length}
|
||||||
columns={priceChangeColumns}
|
onChange={(page) => setCurrentPage(page)}
|
||||||
data={tableData?.slice((currentPage - 1) * pageSize, currentPage * pageSize)}
|
showSizeChanger={false}
|
||||||
onRow={(record, index) => ({
|
showTotal={(total, range) =>
|
||||||
onClick: () => {
|
`${range[0]}-${range[1]} of ${total} items`
|
||||||
edit(record, index);
|
}
|
||||||
},
|
/>
|
||||||
})}
|
</div>
|
||||||
/>
|
</Form>
|
||||||
<div style={{ display: 'flex', justifyContent: 'center', margin: '20px 0' }}>
|
</div>
|
||||||
<Pagination
|
</DefaultModal>
|
||||||
current={currentPage}
|
</>
|
||||||
pageSize={pageSize}
|
);
|
||||||
total={tableData?.length}
|
};
|
||||||
onChange={(page) => setCurrentPage(page)}
|
|
||||||
showSizeChanger={false}
|
|
||||||
showTotal={(total, range) => `${range[0]}-${range[1]} of ${total} items`}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</Form>
|
|
||||||
</div>
|
|
||||||
</DefaultModal>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ProductPriceChange;
|
export default ProductPriceChange;
|
||||||
Loading…
Reference in New Issue