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,32 +1,18 @@
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'; const ProductPriceChange = ({ showButton = true, priceChangeProduct = null, productPriceChange = false, setProductPriceChange = () => { }, setPriceChangeProduct = () => { } }) => {
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 = [],
productPriceChange = false,
setProductPriceChange = () => {},
setPriceChangeProduct = () => {},
}) => {
const formRef = useRef(null); const formRef = useRef(null);
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -46,32 +32,20 @@ const ProductPriceChange = ({
const comboSearch = useSelector(GlobalCombosearch); const comboSearch = useSelector(GlobalCombosearch);
const ProdCat = useSelector(GlobalProductCategorie, shallowEqual); const ProdCat = useSelector(GlobalProductCategorie, shallowEqual);
const ItemCard = useSelector(GlobalItemCard, shallowEqual); const ItemCard = useSelector(GlobalItemCard, shallowEqual);
const withoutSubCatItemCard = useSelector( const withoutSubCatItemCard = useSelector(GlobalWithoutSubCatItemCard, shallowEqual);
GlobalWithoutSubCatItemCard,
shallowEqual
);
const CardAccess = useSelector(GlobalCardAccess, shallowEqual); const CardAccess = useSelector(GlobalCardAccess, shallowEqual);
const globalAccessForOthers = useSelector( const globalAccessForOthers = useSelector(GlobalAccessForOthers, shallowEqual);
GlobalAccessForOthers,
shallowEqual
);
const SelectedDatas = useSelector(GlobalSelectedDatas, shallowEqual); const SelectedDatas = useSelector(GlobalSelectedDatas, shallowEqual);
const [tableData, setTableData] = useState([]); const [tableData, setTableData] = useState([]);
const [editingKey, setEditingKey] = useState(null); const [editingKey, setEditingKey] = useState(null);
const [priceChangedProducts, setPriceChangedProducts] = useState([]); const [priceChangedProducts, setPriceChangedProducts] = useState([]);
console.log(comboSearch, 'comboSearch'); console.log(comboSearch, "comboSearch")
// console.log(noSubcatCardData, "noSubcatCardData") // console.log(noSubcatCardData, "noSubcatCardData")
useEffect(() => { useEffect(() => {
if ( if (ProdCat && (ItemCard || withoutSubCatItemCard) && (!noSubcatCardData || noSubcatCardData?.length === 0)) {
ProdCat && setNoSubcatCardData(ItemCard?.length === 0 ? withoutSubCatItemCard : ItemCard);
(ItemCard || withoutSubCatItemCard) &&
(!noSubcatCardData || noSubcatCardData?.length === 0)
) {
setNoSubcatCardData(
ItemCard?.length === 0 ? withoutSubCatItemCard : ItemCard
);
} }
}, [ProdCat, ItemCard, withoutSubCatItemCard, noSubcatCardData]); }, [ProdCat, ItemCard, withoutSubCatItemCard, noSubcatCardData]);
@ -82,9 +56,7 @@ const ProductPriceChange = ({
key: 'SlNo', key: 'SlNo',
width: '60px', width: '60px',
align: 'center', align: 'center',
render: (text, record, index) => ( render: (text, record, index) => <div>{(currentPage - 1) * pageSize + index + 1}</div>
<div>{(currentPage - 1) * pageSize + index + 1}</div>
),
}, },
{ {
title: 'Product Name', title: 'Product Name',
@ -118,20 +90,22 @@ const ProductPriceChange = ({
if (value === '') { if (value === '') {
return Promise.resolve(); return Promise.resolve();
} else if (parseFloat(value) < 1) { } else if (parseFloat(value) < 1) {
return Promise.reject(`MRP should be greater than 0`); return Promise.reject(`MRP should be greater than 0`)
} }
return Promise.resolve(); return Promise.resolve();
}, },
}, },
]} ]}>
>
<InputField <InputField
value={text} value={text}
placeholder="Enter New MRP" placeholder="Enter New MRP"
onChange={(e) => handleNewMRPChange(e?.target?.value, index)} onChange={(e) => handleNewMRPChange(e?.target?.value, index)}
inputMode="decimal" inputMode="decimal"
onInput={(e) => { onInput={(e) => {
let cleanedValue = e.target.value.replace(/[^0-9.]/g, ''); // Remove invalid characters let cleanedValue = e.target.value.replace(
/[^0-9.]/g,
''
); // Remove invalid characters
const parts = cleanedValue.split('.'); const parts = cleanedValue.split('.');
if (cleanedValue.startsWith('.')) { if (cleanedValue.startsWith('.')) {
@ -175,9 +149,7 @@ const ProductPriceChange = ({
if (value === '') { if (value === '') {
return Promise.resolve(); return Promise.resolve();
} else if (parseFloat(value) < 1) { } else if (parseFloat(value) < 1) {
return Promise.reject( return Promise.reject(`Sell Price should be greater than 0`)
`Sell Price should be greater than 0`
);
} }
return Promise.resolve(); return Promise.resolve();
}, },
@ -187,12 +159,13 @@ const ProductPriceChange = ({
<InputField <InputField
value={text} value={text}
placeholder="Enter New Sell Price" placeholder="Enter New Sell Price"
onChange={(e) => onChange={(e) => handleNewSellPriceChange(e?.target?.value, index)}
handleNewSellPriceChange(e?.target?.value, index)
}
inputMode="decimal" inputMode="decimal"
onInput={(e) => { onInput={(e) => {
let cleanedValue = e.target.value.replace(/[^0-9.]/g, ''); // Remove invalid characters let cleanedValue = e.target.value.replace(
/[^0-9.]/g,
''
); // Remove invalid characters
const parts = cleanedValue.split('.'); const parts = cleanedValue.split('.');
if (cleanedValue.startsWith('.')) { if (cleanedValue.startsWith('.')) {
@ -218,58 +191,49 @@ const ProductPriceChange = ({
: SelectedDatas?.[0]?.AppId === 0 && SelectedDatas?.[0]?.CompId === 0 : SelectedDatas?.[0]?.AppId === 0 && SelectedDatas?.[0]?.CompId === 0
? [] ? []
: SelectedDatas : SelectedDatas
: ItemCard?.length === 0 || : ItemCard?.length === 0 || (ItemCard?.[0]?.AppId === 0 && ItemCard?.[0]?.CompId === 0)
(ItemCard?.[0]?.AppId === 0 && ItemCard?.[0]?.CompId === 0)
? noSubcatCardData ? noSubcatCardData
: ItemCard : ItemCard
: []; : '';
console.log(cardData, 'noSubcatCardDatanoSubcatCardData', ItemCard); console.log(cardData, "noSubcatCardDatanoSubcatCardData", ItemCard)
useEffect(() => { useEffect(() => {
if (priceChangeModal || productPriceChange) {
const extractStockDtls = (data) => { const extractStockDtls = (data) => {
if (data?.length === 0 || !data) return []; if (data?.length === 0) return [];
let stockDtls = []; let stockDtls = [];
data?.forEach((item) => { data?.forEach(item => {
let products = item?.ProductDetail?.flatMap((product) => product); let products = item?.ProductDetail?.flatMap(product => product);
let variants = products?.flatMap( let variants = products?.flatMap(product => product?.ProdVariantDetails);
(product) => product?.ProdVariantDetails const filteredVariants = variants?.filter(variant => variant?.StockDetails?.length > 0);
); const stocks = filteredVariants?.flatMap(variant =>
const filteredVariants = variants?.filter( variant?.StockDetails?.map(stock => ({
(variant) => variant?.StockDetails?.length > 0
);
const stocks = filteredVariants?.flatMap((variant) =>
variant?.StockDetails?.map((stock) => ({
...stock, ...stock,
ProdName: ProdName: products?.[0]?.ProdName + (variant?.ProdVariantName ? ` (${variant?.ProdVariantName})` : ''),
products?.[0]?.ProdName +
(variant?.ProdVariantName
? ` (${variant?.ProdVariantName})`
: ''),
StockAvailable: products?.[0]?.StockAvailable, StockAvailable: products?.[0]?.StockAvailable,
ProdVariantName: variant?.ProdVariantName, ProdVariantName: variant?.ProdVariantName
})) }))
); );
stockDtls.push( stockDtls.push(...stocks?.filter(stock =>
...stocks?.filter((stock) => stock?.StockAvailable === 'Y'
stock?.StockAvailable === 'Y' ? stock?.BatchRef : true ? stock?.BatchRef
) : true
); ));
}); });
console.log('extractStockDtls', stockDtls); console.log("extractStockDtls", stockDtls);
return stockDtls; return stockDtls;
};
setTableData(extractStockDtls(priceChangeProduct || cardData || []));
setCurrentPage(1);
} }
}, [cardData, priceChangeProduct, priceChangeModal, productPriceChange]); setTableData(extractStockDtls(priceChangeProduct || cardData))
setCurrentPage(1)
}, [cardData, priceChangeProduct])
const handleNewMRPChange = (value, index) => { const handleNewMRPChange = (value, index) => {
const updatedTableData = [...tableData]; const updatedTableData = [...tableData];
updatedTableData[index].NewMRP = value; updatedTableData[index].NewMRP = value;
setTableData(updatedTableData); setTableData(updatedTableData);
@ -280,9 +244,7 @@ const ProductPriceChange = ({
}); });
const priceChangedProdList = [...priceChangedProducts]; const priceChangedProdList = [...priceChangedProducts];
const prodIndex = priceChangedProdList?.findIndex( const prodIndex = priceChangedProdList?.findIndex(prod => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId);
(prod) => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId
);
if (prodIndex !== -1) { if (prodIndex !== -1) {
priceChangedProdList[prodIndex] = { priceChangedProdList[prodIndex] = {
...priceChangedProdList?.[prodIndex], ...priceChangedProdList?.[prodIndex],
@ -291,7 +253,7 @@ const ProductPriceChange = ({
}; };
} }
setPriceChangedProducts(priceChangedProdList); setPriceChangedProducts(priceChangedProdList);
}; }
const handleNewSellPriceChange = (value, index) => { const handleNewSellPriceChange = (value, index) => {
const updatedTableData = [...tableData]; const updatedTableData = [...tableData];
@ -305,9 +267,7 @@ const ProductPriceChange = ({
updatedTableData[index].NewSellPrice = null; updatedTableData[index].NewSellPrice = null;
setTableData(updatedTableData); setTableData(updatedTableData);
const priceChangedProdList = [...priceChangedProducts]; const priceChangedProdList = [...priceChangedProducts];
const prodIndex = priceChangedProdList?.findIndex( const prodIndex = priceChangedProdList?.findIndex(prod => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId);
(prod) => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId
);
if (prodIndex !== -1) { if (prodIndex !== -1) {
priceChangedProdList.splice(prodIndex, 1); priceChangedProdList.splice(prodIndex, 1);
@ -326,9 +286,7 @@ const ProductPriceChange = ({
updatedTableData[index].NewSellPrice = null; updatedTableData[index].NewSellPrice = null;
setTableData(updatedTableData); setTableData(updatedTableData);
const priceChangedProdList = [...priceChangedProducts]; const priceChangedProdList = [...priceChangedProducts];
const prodIndex = priceChangedProdList?.findIndex( const prodIndex = priceChangedProdList?.findIndex(prod => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId);
(prod) => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId
);
if (prodIndex !== -1) { if (prodIndex !== -1) {
priceChangedProdList.splice(prodIndex, 1); priceChangedProdList.splice(prodIndex, 1);
@ -344,47 +302,41 @@ const ProductPriceChange = ({
}); });
const priceChangedProdList = [...priceChangedProducts]; const priceChangedProdList = [...priceChangedProducts];
const prodIndex = priceChangedProdList?.findIndex( const prodIndex = priceChangedProdList?.findIndex(prod => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId);
(prod) => prod?.InwardDtlId === updatedTableData[index]?.InwardDtlId
);
if (prodIndex !== -1) { if (prodIndex !== -1) {
priceChangedProdList[prodIndex] = { priceChangedProdList[prodIndex] = {
...priceChangedProdList[prodIndex], ...priceChangedProdList[prodIndex],
SellPrice: String(value), SellPrice: String(value)
}; };
} else { } else {
priceChangedProdList.push({ priceChangedProdList.push({
ProdId: updatedTableData[index]?.ProdId, ProdId: updatedTableData[index]?.ProdId,
ProdName: updatedTableData[index]?.ProdName, ProdName: updatedTableData[index]?.ProdName,
MRP: String( MRP: String(updatedTableData[index]?.NewMRP || updatedTableData[index]?.MRP),
updatedTableData[index]?.NewMRP || updatedTableData[index]?.MRP
),
SellPrice: String(value), SellPrice: String(value),
AdjComment: 'string', AdjComment: "string",
InwardDtlId: updatedTableData[index]?.InwardDtlId, InwardDtlId: updatedTableData[index]?.InwardDtlId
}); });
} }
setPriceChangedProducts(priceChangedProdList); setPriceChangedProducts(priceChangedProdList);
}; }
const edit = (record, index) => { const edit = (record, index) => {
console.log('edit', record, index); console.log("edit", record, index);
setEditingKey(index); setEditingKey(index);
}; }
const handleSubmit = async () => { const handleSubmit = async () => {
console.log('submit'); console.log("submit");
if (priceChangedProducts?.length > 0) { if (priceChangedProducts?.length > 0) {
console.log('priceChangedProducts', priceChangedProducts); console.log("priceChangedProducts", priceChangedProducts);
const validation = priceChangedProducts?.every((prod) => { const validation = priceChangedProducts?.every((prod) => {
if (parseFloat(prod?.MRP) < parseFloat(prod?.SellPrice)) { if (parseFloat(prod?.MRP) < parseFloat(prod?.SellPrice)) {
setMessageType('error'); setMessageType('error');
setMessageData( setMessageData(`${prod?.ProdName}: MRP cannot be less than Sell Price`);
`${prod?.ProdName}: MRP cannot be less than Sell Price`
);
return false; return false;
} }
if (!parseFloat(prod?.SellPrice) || !parseFloat(prod?.MRP)) { if (!parseFloat(prod?.SellPrice) || !parseFloat(prod?.MRP)) {
@ -402,7 +354,7 @@ const ProductPriceChange = ({
BranchId: BranchId, BranchId: BranchId,
ProductDetails: priceChangedProducts, ProductDetails: priceChangedProducts,
UpdatedBy: UserId, UpdatedBy: UserId,
}; }
const res = await dispatch(PutStockPrice(data))?.unwrap(); const res = await dispatch(PutStockPrice(data))?.unwrap();
if (res?.data?.statusCode === 1) { if (res?.data?.statusCode === 1) {
@ -413,52 +365,42 @@ const ProductPriceChange = ({
setEditingKey(null); setEditingKey(null);
setPriceChangedProducts([]); setPriceChangedProducts([]);
setTableData([]); setTableData([]);
dispatch(triggerProductCard()); dispatch(triggerProductCard())
setPriceChangeProduct(null); setPriceChangeProduct(null);
formRef.current.resetFields(); formRef.current.resetFields();
} else { } else {
setMessageData('Error Updating Product Price'); setMessageData('Error Updating Product Price')
setMessageType('error'); setMessageType('error');
} }
} else { } else {
setMessageType('error'); setMessageType('error');
setMessageData('No changes made / No sell price entered'); setMessageData('No changes made / No sell price entered');
} }
};
}
const onComplete = useCallback(() => { const onComplete = useCallback(() => {
setMessageData(null); setMessageData(null);
setMessageType(null); setMessageType(null);
}, []); }, [])
return ( return (
<> <>
<Messages
messageData={messageData} <Messages messageData={messageData} messageType={messageType} onComplete={onComplete} />
messageType={messageType} {showButton ? <Tooltip title="Price Change">
onComplete={onComplete} <button className="price-change-btn" type="button" onClick={() => {
/>
{showButton ? (
<Tooltip title="Price Change">
<button
className="price-change-btn"
type="button"
onClick={() => {
if (comboSearch) { if (comboSearch) {
setMessageType('warning'); setMessageType('warning');
setMessageData('Price change will not work for combo products'); setMessageData('Price change will not work for combo products');
return; return
} }
setPriceChangeModal(true); setPriceChangeModal(true)
}} }}>
>
{/* <FaIndianRupeeSign size={35}/> */} {/* <FaIndianRupeeSign size={35}/> */}
<img src={PriceChange} alt="" width={30} /> <img src={PriceChange} alt="" width={30} />
</button> </button>
</Tooltip> </Tooltip> : <></>}
) : (
<></>
)}
<DefaultModal <DefaultModal
title="Price Change" title="Price Change"
className={'price-change-modal'} className={'price-change-modal'}
@ -480,39 +422,28 @@ const ProductPriceChange = ({
<Form ref={formRef}> <Form ref={formRef}>
<Tables <Tables
columns={priceChangeColumns} columns={priceChangeColumns}
data={tableData?.slice( data={tableData?.slice((currentPage - 1) * pageSize, currentPage * pageSize)}
(currentPage - 1) * pageSize,
currentPage * pageSize
)}
onRow={(record, index) => ({ onRow={(record, index) => ({
onClick: () => { onClick: () => {
edit(record, index); edit(record, index);
}, },
})} })}
/> />
<div <div style={{ display: 'flex', justifyContent: 'center', margin: '20px 0' }}>
style={{
display: 'flex',
justifyContent: 'center',
margin: '20px 0',
}}
>
<Pagination <Pagination
current={currentPage} current={currentPage}
pageSize={pageSize} pageSize={pageSize}
total={tableData?.length} total={tableData?.length}
onChange={(page) => setCurrentPage(page)} onChange={(page) => setCurrentPage(page)}
showSizeChanger={false} showSizeChanger={false}
showTotal={(total, range) => showTotal={(total, range) => `${range[0]}-${range[1]} of ${total} items`}
`${range[0]}-${range[1]} of ${total} items`
}
/> />
</div> </div>
</Form> </Form>
</div> </div>
</DefaultModal> </DefaultModal>
</> </>
); )
}; }
export default ProductPriceChange; export default ProductPriceChange;

View File

@ -104,6 +104,7 @@ const PrintStyle11 = ({
const GlobalCashierName = useSelector(GlobalprintCashierName); const GlobalCashierName = useSelector(GlobalprintCashierName);
const GlobalLogo = useSelector(GlobalprintLogo); const GlobalLogo = useSelector(GlobalprintLogo);
const GlobalCredit = useSelector(GlobalprintCredit); const GlobalCredit = useSelector(GlobalprintCredit);
const SelectedHeaderColor = useSelector(GlobalSelectedPrintHeaderColor);
const estimatePrintHeader = const estimatePrintHeader =
SettingData?.[0]?.SettingDtlDetails?.find( SettingData?.[0]?.SettingDtlDetails?.find(
(setting) => (setting) =>

View File

@ -103,6 +103,7 @@ const Printstyle12 = ({
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);
const estimatePrintHeader = const estimatePrintHeader =
SettingData?.[0]?.SettingDtlDetails?.find( SettingData?.[0]?.SettingDtlDetails?.find(
(setting) => (setting) =>

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(

View File

@ -99,6 +99,7 @@ const PrintStyle7 = ({
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);
const estimatePrintHeader = const estimatePrintHeader =
SettingData?.[0]?.SettingDtlDetails?.find( SettingData?.[0]?.SettingDtlDetails?.find(
(setting) => (setting) =>