sales bill edit print

This commit is contained in:
unknown 2026-02-05 09:30:32 +05:30
parent 1d64c7cd3b
commit 0340bd9e08
5 changed files with 5367 additions and 5432 deletions

View File

@ -1,518 +1,449 @@
import { shallowEqual, useSelector } from 'react-redux'; import { shallowEqual, useSelector } from "react-redux";
import { import { GlobalAccessForOthers, GlobalCardAccess, GlobalCombosearch, GlobalItemCard, GlobalProductCategorie, GlobalSelectedDatas, GlobalWithoutSubCatItemCard, triggerProductCard } from "../../../../Features/BookingScreen/BookingData/BookingData";
GlobalAccessForOthers, import { DefaultModal } from "../../../../Components/Modal/DefaultModal";
GlobalCardAccess, import { useCallback, useEffect, useRef, useState } from "react";
GlobalCombosearch, import { Tables } from "../../../../Components/Tables/Table";
GlobalItemCard, import { InputField } from "../../../../Components/Forms/InputField";
GlobalProductCategorie, import { Form, Pagination, Tooltip } from "antd";
GlobalSelectedDatas, import { getSession } from "../../../../Services/Others";
GlobalWithoutSubCatItemCard, import { Messages } from "../../../../Components/Notifications/Messages";
triggerProductCard, import { useDispatch } from "react-redux";
} from '../../../../Features/BookingScreen/BookingData/BookingData'; import { PutStockPrice } from "../../../../Features/StockPriceUpdate/StockPriceUpdateMaster";
import { DefaultModal } from '../../../../Components/Modal/DefaultModal'; import PriceChange from "../../../../Images/PayOptImgs/PriceChange.svg"
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 = ({ const ProductPriceChange = ({ showButton = true, priceChangeProduct = null, productPriceChange = false, setProductPriceChange = () => { }, setPriceChangeProduct = () => { } }) => {
showButton = true,
priceChangeProduct = [],
productPriceChange = false,
setProductPriceChange = () => {},
setPriceChangeProduct = () => {},
}) => {
const formRef = useRef(null);
const dispatch = useDispatch();
const AppId = getSession('AppId'); const formRef = useRef(null);
const CompId = getSession('CompId'); const dispatch = useDispatch();
const BranchId = getSession('BranchId');
const UserId = getSession('UserId');
const [messageData, setMessageData] = useState(null); const AppId = getSession('AppId');
const [messageType, setMessageType] = useState(null); const CompId = getSession('CompId');
const [currentPage, setCurrentPage] = useState(1); const BranchId = getSession('BranchId');
const [pageSize] = useState(10); const UserId = getSession('UserId');
const [noSubcatCardData, setNoSubcatCardData] = useState(); const [messageData, setMessageData] = useState(null);
const [priceChangeModal, setPriceChangeModal] = useState(false); const [messageType, setMessageType] = useState(null);
const [currentPage, setCurrentPage] = useState(1);
const [pageSize] = useState(10);
const comboSearch = useSelector(GlobalCombosearch); const [noSubcatCardData, setNoSubcatCardData] = useState();
const ProdCat = useSelector(GlobalProductCategorie, shallowEqual); const [priceChangeModal, setPriceChangeModal] = useState(false);
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") const comboSearch = useSelector(GlobalCombosearch);
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")
useEffect(() => { // console.log(noSubcatCardData, "noSubcatCardData")
if (
ProdCat &&
(ItemCard || withoutSubCatItemCard) &&
(!noSubcatCardData || noSubcatCardData?.length === 0)
) {
setNoSubcatCardData(
ItemCard?.length === 0 ? withoutSubCatItemCard : ItemCard
);
}
}, [ProdCat, ItemCard, withoutSubCatItemCard, noSubcatCardData]);
const priceChangeColumns = [ useEffect(() => {
{ if (ProdCat && (ItemCard || withoutSubCatItemCard) && (!noSubcatCardData || noSubcatCardData?.length === 0)) {
title: 'S.No', setNoSubcatCardData(ItemCard?.length === 0 ? withoutSubCatItemCard : ItemCard);
dataIndex: 'SlNo', }
key: 'SlNo', }, [ProdCat, ItemCard, withoutSubCatItemCard, noSubcatCardData]);
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> {
return ( title: 'S.No',
<Form.Item dataIndex: 'SlNo',
name={`NewMRP${index}`} key: 'SlNo',
rules={[ width: '60px',
{ align: 'center',
validator: async (_, value) => { render: (text, record, index) => <div>{(currentPage - 1) * pageSize + index + 1}</div>
if (value === '') { },
return Promise.resolve(); {
} else if (parseFloat(value) < 1) { title: 'Product Name',
return Promise.reject(`MRP should be greater than 0`); dataIndex: 'ProdName',
} key: 'ProdName',
return Promise.resolve(); },
}, {
}, title: 'Old MRP',
]} dataIndex: 'MRP',
> key: 'MRP',
<InputField width: '100px',
value={text} align: 'right',
placeholder="Enter New MRP" },
onChange={(e) => handleNewMRPChange(e?.target?.value, index)} {
inputMode="decimal" title: 'New MRP (Optional)',
onInput={(e) => { dataIndex: 'NewMRP',
let cleanedValue = e.target.value.replace(/[^0-9.]/g, ''); // Remove invalid characters key: 'NewMRP',
const parts = cleanedValue.split('.'); width: '100px',
align: 'right',
render: (text, record, index) => {
// if (index === editingKey) {
if (cleanedValue.startsWith('.')) { // }
cleanedValue = '0' + cleanedValue; // return <div>{text ? text : 'Enter New MRP'}</div>
} 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('.');
e.target.value = if (cleanedValue.startsWith('.')) {
parts.length > 2 cleanedValue = '0' + cleanedValue;
? `${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 =
// return <div>{text ? text : 'Enter New Sell Price'}</div> parts.length > 2
return ( ? `${parts[0]}.${parts.slice(1).join('')}`
<Form.Item : cleanedValue;
name={`NewSellPrice${index}`} }}
rules={[ />
{ </Form.Item>
validator: async (_, value) => { );
if (value === '') { },
return Promise.resolve(); },
} else if (parseFloat(value) < 1) { {
return Promise.reject( title: 'Old Sell Price',
`Sell Price should be greater than 0` dataIndex: 'SellPrice',
); key: 'SellPrice',
} width: '120px',
return Promise.resolve(); align: 'right',
}, },
}, {
]} title: 'New Sell Price',
> dataIndex: 'NewSellPrice',
<InputField key: 'NewSellPrice',
value={text} width: '160px',
placeholder="Enter New Sell Price" align: 'right',
onChange={(e) => render: (text, record, index) => {
handleNewSellPriceChange(e?.target?.value, index) // if (index === editingKey) {
}
inputMode="decimal"
onInput={(e) => {
let cleanedValue = e.target.value.replace(/[^0-9.]/g, ''); // Remove invalid characters
const parts = cleanedValue.split('.');
if (cleanedValue.startsWith('.')) { // }
cleanedValue = '0' + cleanedValue; // return <div>{text ? text : 'Enter New Sell Price'}</div>
} 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('.');
e.target.value = if (cleanedValue.startsWith('.')) {
parts.length > 2 cleanedValue = '0' + cleanedValue;
? `${parts[0]}.${parts.slice(1).join('')}` }
: cleanedValue;
}}
/>
</Form.Item>
);
},
},
];
const cardData = !globalAccessForOthers e.target.value =
? CardAccess parts.length > 2
? SelectedDatas?.length > 1 ? `${parts[0]}.${parts.slice(1).join('')}`
? SelectedDatas : cleanedValue;
: SelectedDatas?.[0]?.AppId === 0 && SelectedDatas?.[0]?.CompId === 0 }}
? [] />
: SelectedDatas </Form.Item>
: ItemCard?.length === 0 || );
(ItemCard?.[0]?.AppId === 0 && ItemCard?.[0]?.CompId === 0) },
? noSubcatCardData },
: ItemCard ];
: [];
console.log(cardData, 'noSubcatCardDatanoSubcatCardData', ItemCard); const cardData = !globalAccessForOthers
? 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
: '';
useEffect(() => { console.log(cardData, "noSubcatCardDatanoSubcatCardData", ItemCard)
if (priceChangeModal || productPriceChange) {
const extractStockDtls = (data) => {
if (data?.length === 0 || !data) return [];
let stockDtls = []; useEffect(() => {
const extractStockDtls = (data) => {
if (data?.length === 0) return [];
data?.forEach((item) => { let stockDtls = [];
let products = item?.ProductDetail?.flatMap((product) => product);
let variants = products?.flatMap( data?.forEach(item => {
(product) => product?.ProdVariantDetails let products = item?.ProductDetail?.flatMap(product => product);
);
const filteredVariants = variants?.filter(
(variant) => variant?.StockDetails?.length > 0
);
const stocks = filteredVariants?.flatMap((variant) =>
variant?.StockDetails?.map((stock) => ({
...stock,
ProdName:
products?.[0]?.ProdName +
(variant?.ProdVariantName
? ` (${variant?.ProdVariantName})`
: ''),
StockAvailable: products?.[0]?.StockAvailable,
ProdVariantName: variant?.ProdVariantName,
}))
);
stockDtls.push( let variants = products?.flatMap(product => product?.ProdVariantDetails);
...stocks?.filter((stock) => const filteredVariants = variants?.filter(variant => variant?.StockDetails?.length > 0);
stock?.StockAvailable === 'Y' ? stock?.BatchRef : true const stocks = filteredVariants?.flatMap(variant =>
) variant?.StockDetails?.map(stock => ({
); ...stock,
}); ProdName: products?.[0]?.ProdName + (variant?.ProdVariantName ? ` (${variant?.ProdVariantName})` : ''),
console.log('extractStockDtls', stockDtls); StockAvailable: products?.[0]?.StockAvailable,
return stockDtls; ProdVariantName: variant?.ProdVariantName
}; }))
setTableData(extractStockDtls(priceChangeProduct || cardData || [])); );
setCurrentPage(1);
}
}, [cardData, priceChangeProduct, priceChangeModal, productPriceChange]);
const handleNewMRPChange = (value, index) => { stockDtls.push(...stocks?.filter(stock =>
const updatedTableData = [...tableData]; stock?.StockAvailable === 'Y'
updatedTableData[index].NewMRP = value; ? stock?.BatchRef
setTableData(updatedTableData); : true
updatedTableData[index].NewSellPrice = null; ));
formRef.current.setFieldsValue({
[`NewMRP${index}`]: value,
[`NewSellPrice${index}`]: null,
});
const priceChangedProdList = [...priceChangedProducts]; });
const prodIndex = priceChangedProdList?.findIndex( console.log("extractStockDtls", stockDtls);
(prod) => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId return stockDtls;
); }
if (prodIndex !== -1) { setTableData(extractStockDtls(priceChangeProduct || cardData))
priceChangedProdList[prodIndex] = { setCurrentPage(1)
...priceChangedProdList?.[prodIndex], }, [cardData, priceChangeProduct])
NewMRP: value,
NewSellPrice: null,
};
}
setPriceChangedProducts(priceChangedProdList);
};
const handleNewSellPriceChange = (value, index) => { const handleNewMRPChange = (value, index) => {
const updatedTableData = [...tableData];
if (updatedTableData[index]?.NewMRP) { const updatedTableData = [...tableData];
if (parseFloat(value) > parseFloat(updatedTableData[index]?.NewMRP)) { updatedTableData[index].NewMRP = value;
setMessageType('error');
setMessageData('New Sell Price cannot be greater than New MRP');
formRef.current.setFieldsValue({
[`NewSellPrice${index}`]: null,
});
updatedTableData[index].NewSellPrice = null;
setTableData(updatedTableData); setTableData(updatedTableData);
const priceChangedProdList = [...priceChangedProducts]; updatedTableData[index].NewSellPrice = null;
const prodIndex = priceChangedProdList?.findIndex( formRef.current.setFieldsValue({
(prod) => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId [`NewMRP${index}`]: value,
); [`NewSellPrice${index}`]: null,
});
const priceChangedProdList = [...priceChangedProducts];
const prodIndex = priceChangedProdList?.findIndex(prod => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId);
if (prodIndex !== -1) { if (prodIndex !== -1) {
priceChangedProdList.splice(prodIndex, 1); priceChangedProdList[prodIndex] = {
...priceChangedProdList?.[prodIndex],
NewMRP: value,
NewSellPrice: null,
};
} }
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
);
if (prodIndex !== -1) {
priceChangedProdList.splice(prodIndex, 1);
}
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,
});
} }
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);
const edit = (record, index) => { if (prodIndex !== -1) {
console.log('edit', record, index); priceChangedProdList.splice(prodIndex, 1);
setEditingKey(index); }
}; setPriceChangedProducts(priceChangedProdList);
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');
}
};
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; return;
} }
setPriceChangeModal(true); }
}} if (!updatedTableData[index]?.NewMRP && updatedTableData[index]?.MRP) {
> if (parseFloat(value) > parseFloat(updatedTableData[index]?.MRP)) {
{/* <FaIndianRupeeSign size={35}/> */} setMessageType('error');
<img src={PriceChange} alt="" width={30} /> setMessageData('New Sell Price cannot be greater than MRP');
</button> formRef.current.setFieldsValue({
</Tooltip> [`NewSellPrice${index}`]: null,
) : ( });
<></> updatedTableData[index].NewSellPrice = null;
)} setTableData(updatedTableData);
<DefaultModal const priceChangedProdList = [...priceChangedProducts];
title="Price Change" const prodIndex = priceChangedProdList?.findIndex(prod => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId);
className={'price-change-modal'}
open={priceChangeModal || productPriceChange} if (prodIndex !== -1) {
footer={true} priceChangedProdList.splice(prodIndex, 1);
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',
}}
>
<Pagination
current={currentPage}
pageSize={pageSize}
total={tableData?.length}
onChange={(page) => setCurrentPage(page)}
showSizeChanger={false}
showTotal={(total, range) =>
`${range[0]}-${range[1]} of ${total} items`
} }
/> setPriceChangedProducts(priceChangedProdList);
</div> return;
</Form> }
</div> }
</DefaultModal> 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
});
}
setPriceChangedProducts(priceChangedProdList);
}
const edit = (record, index) => {
console.log("edit", record, index);
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');
}
}
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' }}>
<Pagination
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;

View File

@ -103,6 +103,7 @@ const Printstyle6 = ({
const GlobalLogo = useSelector(GlobalprintLogo); const GlobalLogo = useSelector(GlobalprintLogo);
const GlobalCredit = useSelector(GlobalprintCredit); const GlobalCredit = useSelector(GlobalprintCredit);
const SettingData = useSelector(PreferenceData); const SettingData = useSelector(PreferenceData);
const SelectedHeaderColor = useSelector(GlobalSelectedPrintHeaderColor);
console.log(CashierNameField, "GlobaldummyData") console.log(CashierNameField, "GlobaldummyData")
const estimatePrintHeader = const estimatePrintHeader =
SettingData?.[0]?.SettingDtlDetails?.find( SettingData?.[0]?.SettingDtlDetails?.find(
@ -3267,7 +3268,7 @@ const Printstyle6 = ({
/> />
) : null} ) : null}
</div> </div>
<div style={{ color: SelectedHeaderColor }}> <div style={{ color: SelectedHeaderColor }}>
{GlobaldummyData ? 'XYZ Shop' : table2Data?.BrName} {GlobaldummyData ? 'XYZ Shop' : table2Data?.BrName}
</div> </div>
</div> </div>