diff --git a/src/Pages/StockMaster/StockForm.jsx b/src/Pages/StockMaster/StockForm.jsx
index 8d2481b..e4b86f9 100644
--- a/src/Pages/StockMaster/StockForm.jsx
+++ b/src/Pages/StockMaster/StockForm.jsx
@@ -12,6 +12,7 @@ import {
ArrowRightOutlined,
PlusCircleOutlined,
InfoCircleOutlined,
+ SearchOutlined,
} from '@ant-design/icons';
import {
Form,
@@ -22,10 +23,11 @@ import {
AutoComplete,
Switch,
} from 'antd';
-import { IoAddCircleSharp } from 'react-icons/io5';
+import { IoAddCircleSharp, IoSettingsOutline } from 'react-icons/io5';
import { ScannerInputField } from '../../Components/Forms/ScannerInputField.jsx';
import { InputField } from '../../Components/Forms/InputField.jsx';
import Buttons from '../../Components/Forms/Buttons.jsx';
+import { Modal } from 'antd';
import { Messages } from '../../Components/Notifications/Messages.jsx';
import { DeleteFilled } from '@ant-design/icons';
import { changeBreadCrumb } from '../../Features/AppPage/CenterPage.js';
@@ -74,6 +76,8 @@ import {
productTypeDataSelector,
getProductTypeData,
bulkpostdata,
+ postFieldSetup,
+ getFieldSetupData,
} from '../../Features/ProductPage/ProductPage.js';
import { postConfiguration } from '../../Features/ConfigMasterPage/ConfigMasterPage.js';
import SupplierProductMappingForm from '../SupplierProductMapping/SuplierProductMappingForm.jsx';
@@ -85,7 +89,7 @@ import {
getSupplaierIdwithTypeBasedProducts,
postSupplaierProducts,
} from '../../Features/SupplierProductMapping/SupplierProductMapping.js';
-import { getCommonAppPreference } from '../../Features/BrachLogin/BranchLogin.js';
+import { ApplicationPreferences, getCommonAppPreference } from '../../Features/BrachLogin/BranchLogin.js';
import {
getConfigType,
getPaymentOptionFeatureApi,
@@ -157,12 +161,12 @@ const EditableCell = ({
margin: 0,
}}
name={dataIndex}
- // rules={[
- // (dataIndex == "imei1" || dataIndex == "imei2") && {
- // pattern: /^[0-9]{15}$/,
- // message: 'IMEI must be a 15-digit number'
- // }
- // ]}
+ // rules={[
+ // (dataIndex == "imei1" || dataIndex == "imei2") && {
+ // pattern: /^[0-9]{15}$/,
+ // message: 'IMEI must be a 15-digit number'
+ // }
+ // ]}
>
- {/* {dataIndex === "CurrentAmt" && Array.isArray(record[dataIndex])
- ? record[dataIndex]?.map((item, index) => (
-
- {item.CurrentAmt + "-" + item.CurrentAmt}
-
- ))
- : children} */}
+
{
const BrandData = useSelector(brandDataSelector);
const UomData = useSelector(uomDataSelector);
const ProductTypeData = useSelector(productTypeDataSelector);
+ const appPreferences = useSelector(ApplicationPreferences)
const [applicationRestrictedFields, setApplicationRestrictedFields] =
useState({
DatesAndExpiry: false,
BatchAndModelDetails: false,
AmountPerPieceDetail: false,
});
+ const [selectedAdditionalColumn, setSelectedAdditionalColumn] = useState([]);
+ console.log(selectedAdditionalColumn, "selectedAdditionalColumn")
+ const [showColumnModal, setShowColumnModal] = useState(false);
+ const [tempSelectedColumns, setTempSelectedColumns] = useState([]);
+ const [tableFieldPreferences, setTableFieldPreferences] = useState([]);
+ const [selectedFields, setSelectedFields] = useState([]);
const [SupplierData, setSupplierData] = useState([]);
const [StockOpen, setStockOpen] = useState('N');
const [SupplierOpen, setSupplierOpen] = useState('own');
@@ -275,6 +282,7 @@ const StockForm = ({ formType }) => {
const [imageSubCategoryUrl, setSubCategoryImageUrl] = useState('');
const [imageBrandUrl, setBrandImageUrl] = useState('');
const [PurchaseData, setPurchaseData] = useState([]);
+ console.log(PurchaseData, "PurchaseData")
const [additionalInfoModal, setAdditionalInfoModal] = useState(false);
const [selectedRowIndex, setSelectedRowIndex] = useState(null);
const [selectedRowRecord, setSelectedRowRecord] = useState({});
@@ -342,6 +350,24 @@ const StockForm = ({ formType }) => {
const [extractorData, setExtractorData] = useState(null);
const [isLoading, setIsLoading] = useState(false);
const [loadingText, setLoadingText] = useState('');
+ const [filteredPurchaseData, setFilteredPurchaseData] = useState([]);
+ const [searchValue, setSearchValue] = useState('');
+ const isSearching = Boolean(searchValue?.trim());
+ useEffect(() => {
+ if (searchValue?.trim()) {
+ const search = searchValue.toLowerCase();
+
+ const filtered = PurchaseData.filter(item =>
+ item?.ProdName?.toLowerCase().includes(search)
+ );
+
+ setFilteredPurchaseData(filtered);
+ } else {
+ setFilteredPurchaseData([]);
+ }
+ }, [PurchaseData, searchValue]);
+
+
const items = [
{
name: 'Home',
@@ -357,6 +383,9 @@ const StockForm = ({ formType }) => {
link: null,
},
];
+ const categoryId = appPreferences?.find(
+ p => p?.PreferredCatName?.toLowerCase() === "purchase entry"
+ )?.PreferredCatId;
useEffect(() => {
dispatch(changeBreadCrumb({ items: items }));
dispatch(
@@ -519,20 +548,27 @@ const StockForm = ({ formType }) => {
};
useEffect(() => {
- let total = PurchaseData?.reduce((accumulator, currentValue) => {
- return accumulator + currentValue.Amount;
+ const total = PurchaseData?.reduce((acc, item) => {
+ return acc + Number(item?.Amount || 0);
}, 0);
- setSelInvoiceAmount(!isNaN(total) && total !== 0 ? total : null);
+ const invoiceAmount =
+ !isNaN(total) && total !== 0 ? total : null;
+
+ setSelInvoiceAmount(invoiceAmount);
+
formRef.current?.setFieldsValue({
- InvoiceAmount: !isNaN(total) && total !== 0 ? total : null,
+ InvoiceAmount: invoiceAmount,
});
- let totaltax = PurchaseData?.reduce((accumulator, currentValue) => {
- return accumulator + currentValue.TaxAmt;
+
+ const totalTax = PurchaseData?.reduce((acc, item) => {
+ return acc + Number(item?.TaxAmt || 0);
}, 0);
- setTotalTaxAmount(totaltax);
+
+ setTotalTaxAmount(totalTax);
}, [PurchaseData]);
+
const getPurchaseOrders = async () => {
const { data: res } = await dispatch(
PendingOrdersPE({ CompId, AppId, BranchId })
@@ -576,7 +612,26 @@ const StockForm = ({ formType }) => {
);
return { mappedSupplierProducts, SuppId: finalList?.[0]?.SuppId };
};
-
+ useEffect(() => {
+ getFieldSetup();
+ }, [categoryId])
+ const getFieldSetup = async () => {
+ try {
+ const response = await dispatch(getFieldSetupData({ AppId, CompId, BranchId, categoryId, Type: "PE" })).unwrap();
+ if (response?.data?.statusCode === 1) {
+ 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) || []);
+ setSelectedAdditionalColumn(response?.data?.data?.[0]?.ConfigDtl?.filter(c => c.ConfigId && c.Access === 'Y')?.map(c => c.ConfigName) || [])
+ 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);
+ }
+ };
const AddSupplierimg = async (subSupplierData) => {
const addSupplierData = {
CompId: getSession('CompId'),
@@ -688,8 +743,8 @@ const StockForm = ({ formType }) => {
const allSupplierProducts = response?.data?.data || [];
const matchingProdIds = [];
- const NewImageProducts=[]
- console.log(unmatchedProducts,"unmatchedProductsunmatchedProducts")
+ const NewImageProducts = []
+ console.log(unmatchedProducts, "unmatchedProductsunmatchedProducts")
// check if the unmatched products exists in our products list
unmatchedProducts.forEach((item) => {
const match = allSupplierProducts?.[0]?.ProductDetails.find(
@@ -700,89 +755,89 @@ const StockForm = ({ formType }) => {
if (match) {
matchingProdIds.push(match.ProdId);
}
- else{
+ else {
NewImageProducts.push(item?.parsedData);
}
});
- console.log(NewImageProducts,"NewImageProductsNewImageProducts")
+ console.log(NewImageProducts, "NewImageProductsNewImageProducts")
// Bulk upload new image products
if (NewImageProducts.length > 0) {
- const newProductsData = NewImageProducts.map(product => ({
- AppId: AppId || 0,
- CompId: CompId || "",
- BranchId: BranchId || "",
- CreatedBy: UserId || 0,
- ProdName: product.description?.trim() || "",
- ProdVariantName: "",
- Size: 1 || "",
- UOM: product.unit || "",
- MRP: parseFloat(product.rate) || 0,
- WhSalePrice: 0,
- SellPrice: parseFloat(product.rate) || 0,
- ProdCat: "General",
- ProdSubCat: "",
- Brand: "",
- AutoGenerateQr: "",
- QRCode: "",
- StockAvailable: 'No',
- TaxId: "",
- HSNCode: "",
- PartNumber: "",
- Rack: 0,
- ManufDate: "",
- ExpDate: "",
- AvailableFrom: "",
- AvailableTo: "",
- ProdLogo: "",
- OnePcsAvailable: "No",
- AutoGenerateSingleQr:'No',
- TaxId: 'NIL - 0%',
- OnePcQR: "",
- TokenAvailable: 'No',
- OpeningQty: 0,
- QtyBasedPrice: "",
- InwardDate: "",
- SuppId: suppId || "",
- Reference: "",
- ReceivedQty: 0,
- AcceptedQty: 0,
- RejectedQty: 0,
- RejectionReason: "",
- IssuedQty: 0,
- BalanceQty: 0,
- InwardPrice: 0,
- OfferPrice: 0,
- SpecialPrice: 0,
- Cess: 0,
- }));
+ const newProductsData = NewImageProducts.map(product => ({
+ AppId: AppId || 0,
+ CompId: CompId || "",
+ BranchId: BranchId || "",
+ CreatedBy: UserId || 0,
+ ProdName: product.description?.trim() || "",
+ ProdVariantName: "",
+ Size: 1 || "",
+ UOM: product.unit || "",
+ MRP: parseFloat(product.rate) || 0,
+ WhSalePrice: 0,
+ SellPrice: parseFloat(product.rate) || 0,
+ ProdCat: "General",
+ ProdSubCat: "",
+ Brand: "",
+ AutoGenerateQr: "",
+ QRCode: "",
+ StockAvailable: 'No',
+ TaxId: "",
+ HSNCode: "",
+ PartNumber: "",
+ Rack: 0,
+ ManufDate: "",
+ ExpDate: "",
+ AvailableFrom: "",
+ AvailableTo: "",
+ ProdLogo: "",
+ OnePcsAvailable: "No",
+ AutoGenerateSingleQr: 'No',
+ TaxId: 'NIL - 0%',
+ OnePcQR: "",
+ TokenAvailable: 'No',
+ OpeningQty: 0,
+ QtyBasedPrice: "",
+ InwardDate: "",
+ SuppId: suppId || "",
+ Reference: "",
+ ReceivedQty: 0,
+ AcceptedQty: 0,
+ RejectedQty: 0,
+ RejectionReason: "",
+ IssuedQty: 0,
+ BalanceQty: 0,
+ InwardPrice: 0,
+ OfferPrice: 0,
+ SpecialPrice: 0,
+ Cess: 0,
+ }));
- const bulkResponse = await dispatch(bulkpostdata({ ProdDetails: newProductsData })).unwrap();
-
- if (bulkResponse?.data?.statusCode === 1) {
- // After successful bulk upload, check the condition again
- const updatedResponse = await dispatch(
- getSupplaierIdBasedProducts({ CompId, AppId, BranchId, SuppId: suppId })
- ).unwrap();
- if (updatedResponse?.data?.statusCode === 1) {
- const updatedAllSupplierProducts = updatedResponse?.data?.data || [];
- const updatedMatchingProdIds = [];
-
- unmatchedProducts.forEach((item) => {
- const match = updatedAllSupplierProducts?.[0]?.ProductDetails.find(
- (supp) =>
- supp?.ProdName?.toLowerCase() ===
- item?.parsedData?.description?.toLowerCase()
- );
- if (match) {
- updatedMatchingProdIds.push(match.ProdId);
- }
- });
-
- if (updatedMatchingProdIds.length > 0) {
- matchingProdIds.push(...updatedMatchingProdIds);
- }
+ const bulkResponse = await dispatch(bulkpostdata({ ProdDetails: newProductsData })).unwrap();
+
+ if (bulkResponse?.data?.statusCode === 1) {
+ // After successful bulk upload, check the condition again
+ const updatedResponse = await dispatch(
+ getSupplaierIdBasedProducts({ CompId, AppId, BranchId, SuppId: suppId })
+ ).unwrap();
+ if (updatedResponse?.data?.statusCode === 1) {
+ const updatedAllSupplierProducts = updatedResponse?.data?.data || [];
+ const updatedMatchingProdIds = [];
+
+ unmatchedProducts.forEach((item) => {
+ const match = updatedAllSupplierProducts?.[0]?.ProductDetails.find(
+ (supp) =>
+ supp?.ProdName?.toLowerCase() ===
+ item?.parsedData?.description?.toLowerCase()
+ );
+ if (match) {
+ updatedMatchingProdIds.push(match.ProdId);
}
+ });
+
+ if (updatedMatchingProdIds.length > 0) {
+ matchingProdIds.push(...updatedMatchingProdIds);
}
+ }
+ }
}
// if there is matching products, map them to the supplier
if (matchingProdIds.length > 0) {
@@ -828,6 +883,7 @@ const StockForm = ({ formType }) => {
for (const item of matchedProducts) {
if (item.matchFound) {
const newProduct = await ProductDropDownChange(
+ item?.selectedProduct.ProdVariantName,
item.selectedProdId,
{ label: item.selectedProduct.ProdName },
mappedSupplierProducts,
@@ -914,6 +970,8 @@ const StockForm = ({ formType }) => {
for (const item of matchedProducts) {
if (item.matchFound) {
const newProduct = await ProductDropDownChange(
+
+ item?.selectedProduct?.ProdVariantName,
item.selectedProdId,
{ label: item.selectedProduct.ProdName },
supplierProducts,
@@ -1118,12 +1176,12 @@ const StockForm = ({ formType }) => {
formRef?.current?.getFieldsValue(),
'formRefformRefformRefformRef'
);
- if(extractorData?.invoiceNo !== null && extractorData?.invoiceNo !== ""){
- formRef?.current?.setFieldsValue({
- SuppInvoiceNo: extractorData?.invoiceNo,
- });
+ if (extractorData?.invoiceNo !== null && extractorData?.invoiceNo !== "") {
+ formRef?.current?.setFieldsValue({
+ SuppInvoiceNo: extractorData?.invoiceNo,
+ });
}
-
+
formRef?.current?.setFieldsValue({
PaymentAmount: extractorData?.TotalAmtData,
});
@@ -1206,6 +1264,7 @@ const StockForm = ({ formType }) => {
};
const ProductDropDownChange = async (
+ VariantName,
ProdId,
option,
productsList,
@@ -1213,55 +1272,58 @@ const StockForm = ({ formType }) => {
extractedItem,
existingProducts
) => {
+
setProductSearchText('');
setSelectedProductName(option?.label ? option?.label : '');
formRef?.current?.resetFields(['VarProdId']);
setselectedProductVariantData(null);
setSelectedProductData(ProdId);
- let x = (productsList || productData)?.find(
- (e) => e.ProdId == ProdId
- )?.ProdName;
- let OnePcsAvailable =
- (productsList || productData)?.find((e) => e.ProdId == ProdId)
- ?.OnePcsAvailable == 'Y';
- let variantValues1 = await dispatch(
- getProdvaraiantdata({
- CompId: SupplierCompId,
- AppId: SupplierAppId,
- BranchId: SupplierBranchId,
- prodName: x,
- })
- ).unwrap();
- let variants = variantValues1?.data?.data;
- let cc = variants?.filter((variant) =>
- variant?.ProductDetail?.some((e) => e.ProdId == ProdId)
- )?.[0]?.ProductDetail;
+ // let x = (productsList || productData)?.find(
+ // (e) => e.ProdId == ProdId
+ // )?.ProdName;
+ let OnePcsAvailable = (productsList || productData)?.find((e) => e.ProdId == ProdId && e?.ProdVariantName == VariantName)?.OnePcsAvailable == 'Y';
+ // let variantValues1 = await dispatch(
+ // getProdvaraiantdata({
+ // CompId: SupplierCompId,
+ // AppId: SupplierAppId,
+ // BranchId: SupplierBranchId,
+ // prodName: x,
+ // })
+ // ).unwrap();
+ // let variants = variantValues1?.data?.data;
- setVariants(
- cc?.[0]?.ProdVariantDetails?.map((detail) => ({
- ...detail,
- ProdIdProdName: `${detail.ProdVariantName} ${detail.ProdId}`,
- OnePcsAvailable,
- }))
- );
+ // let cc = variants?.filter((variant) =>
+ // variant?.ProductDetail?.some((e) => e.ProdId == ProdId)
+ // )?.[0]?.ProductDetail;
- if (
- cc?.[0]?.ProdVariantDetails?.length < 2 ||
- (extractedProduct ? cc?.[0]?.ProdVariantDetails?.length > 0 : false)
+ // setVariants(
+ // cc?.[0]?.ProdVariantDetails?.map((detail) => ({
+ // ...detail,
+ // ProdIdProdName: `${detail.ProdVariantName} ${detail.ProdId}`,
+ // OnePcsAvailable,
+ // }))
+ // );
+
+ if (true
+ // cc?.[0]?.ProdVariantDetails?.length < 2 ||
+ // (extractedProduct ? cc?.[0]?.ProdVariantDetails?.length > 0 : false)
) {
// let getSuppId = (productsList || productData)?.filter((item) => item.ProdId == ProdId);
formRef.current?.setFieldsValue({ ProdId: ProdId });
await setSelectedProductData(ProdId);
// await setSelectedSupplierData(getSuppId?.[0]?.["SuppId"]) ,CustSuppId:getSuppId?.[0]?.["SuppId"]
- if ((existingProducts || PurchaseData)?.some((e) => e.ProdId == ProdId)) {
+ if ((existingProducts || PurchaseData)?.some((e) => e.ProdId == ProdId && e?.ProdVariantName == VariantName)) {
+ const existingProduct = (existingProducts || PurchaseData)?.find((e) => e.ProdId == ProdId && e?.ProdVariantName == VariantName);
setMessageType('error');
- setMessageData('Already Product Exists');
+ setMessageData(`Product "${existingProduct?.ProdName} - ${existingProduct?.ProdVariantName}" already exists`);
return null;
- } else {
+ }
+ else {
+
let ProductData1 = (productsList || productData)?.find(
- (e) => e.ProdId == ProdId
+ (e) => e.ProdId == ProdId && e?.ProdVariantName == VariantName
);
let DefaultVariant = ProductData1?.ProdVariantPriceDetails?.find(
(item) => item?.DefaultVariant === 'Y' && item?.ReceivedQty === 0
@@ -1275,10 +1337,13 @@ const StockForm = ({ formType }) => {
SellPrice: ProductData1?.SellPrice,
StockAvailable: ProductData1?.StockAvailable,
OnePcsAvailable: ProductData1?.OnePcsAvailable,
- NumberofPieceinside: ProductData1?.NoOfPcs,
- AmountPerPiece: ProductData1?.OnePcsPrice,
+ // NumberofPieceinside: ProductData1?.NoOfPcs,
+ // AmountPerPiece: ProductData1?.OnePcsPrice,
+ OnePcsPrice: ProductData1?.OnePcsPrice,
+ NoOfPcs: ProductData1?.NoOfPcs,
TaxId: ProductData1?.TaxId,
TaxPercentage: ProductData1?.TaxPercentage,
+ ProdVariantName: ProductData1?.ProdVariantName,
};
const qty = extractedProduct
@@ -1304,7 +1369,7 @@ const StockForm = ({ formType }) => {
RejectedQty: qty - acceptedQty,
OfferPrice: 0,
SpecialPrice: 0,
- ProdVariantName: 'Variant 1',
+ // ProdVariantName: 'Variant 1',
FreeItem: 0,
TaxAmt: 0,
TaxType: SelectedPurcTaxType ? SelectedPurcTaxType : 0,
@@ -1330,6 +1395,7 @@ const StockForm = ({ formType }) => {
let productName = {};
productName.label = `${matchedProduct?.ProdName} (${matchedProduct.Size} ${matchedProduct.UomName})${matchedProduct?.BrandName ? ` - ${matchedProduct?.BrandName}` : ''}`;
const newProduct = await ProductDropDownChange(
+ matchedProduct?.ProdVariantName,
matchedProduct.ProdId,
productName
);
@@ -1380,115 +1446,6 @@ const StockForm = ({ formType }) => {
VarProdId: null,
});
};
- const ProductVariantDropDownChange = (value) => {
- const ProdName2 = Variants?.filter(
- (item) => item.ProdIdProdName === value
- )?.[0]?.ProdVariantName;
-
- const ProdName1 = PurchaseData?.some(
- (item) =>
- item.ProdId === selectedProductData &&
- item.ProdVariantName === ProdName2
- );
- if (ProdName1) {
- setMessageType('error');
- setMessageData('Already variant Exists');
- } else {
- const ProdName = Variants?.filter(
- (item) => item.ProdIdProdName === value
- )?.[0]?.ProdVariantName;
- const OnePcsAvailable = Variants?.filter(
- (item) => item.ProdIdProdName === value
- )?.[0]?.OnePcsAvailable;
- formRef?.current?.setFieldsValue({ VarProdId: value });
- setselectedProductVariantData(ProdName);
-
- let ProductData1 = productData?.find(
- (e) => e.ProdId == selectedProductData
- );
- let mrp;
- let sellprice;
- if (ProdName == 'Variant 1') {
- mrp = ProductData1?.MRP;
- sellprice = ProductData1?.SellPrice;
- } else {
- mrp = ProductData1?.ProdVariantPriceDetails?.find(
- (item) => item.ProdVariantName == ProdName
- )?.MRP;
- sellprice = ProductData1?.ProdVariantPriceDetails?.find(
- (item) => item.ProdVariantName == ProdName
- )?.SellPrice;
- }
- let DefaultVariant = ProductData1?.ProdVariantPriceDetails?.find(
- (item) => item?.ProdVariantName === ProdName && item?.ReceivedQty === 0
- )?.DefaultVariant;
- let ProduData2 = {
- DefaultVariant: DefaultVariant,
- ProdId: ProductData1?.ProdId,
- MRP: mrp,
- ProdName: ProductData1?.ProdName,
- UomName: ProductData1?.UomName,
- SellPrice: sellprice,
- StockAvailable: ProductData1?.StockAvailable,
- OnePcsAvailable: ProductData1?.OnePcsAvailable,
- NumberofPieceinside: ProductData1?.NoOfPcs,
- AmountPerPiece: ProductData1?.OnePcsPrice,
- TaxId: ProductData1?.TaxId,
- TaxPercentage: ProductData1?.TaxPercentage,
- };
- // ProduData2["StockAvailable"]="Y"
-
- const localId = uuidv4();
- let tempPurData = {
- ...ProduData2,
- BalanceQty: 0,
- InwardPrice: 0,
- PurcDisc: 0,
- Amount: 0,
- WhSalePrice: 0,
- ReceivedQty: 0,
- AcceptedQty: 0,
- FreeItem: 0,
- RejectedQty: 0,
- OfferPrice: 0,
- SpecialPrice: 0,
- ProdVariantName: ProdName,
- // 'TaxId': PurcselectedTax ? PurcselectedTax : 0,
- TaxAmt: 0,
- TaxType: SelectedPurcTaxType ? SelectedPurcTaxType : 0,
- PurcDiscType: 'P',
- localId: localId,
- PurchaseTax: 0,
- };
- form?.setFieldsValue({
- [`SellPrice${localId}`]: tempPurData?.SellPrice,
- [`PurchaseTax${localId}`]: tempPurData?.PurchaseTax,
- });
-
- setPurchaseData([tempPurData, ...PurchaseData]);
-
- Delete
- ? (form.setFieldsValue({
- [`BalanceQty${index}`]: undefined,
- [`ReceivedQty${index}`]: undefined,
- [`AcceptedQty${index}`]: undefined,
- [`RejectedQty${index}`]: undefined,
- [`Amount${index}`]: undefined,
- [`FreeQty${index}`]: undefined,
- [`InwardPrice${index}`]: undefined,
- [`MRP${index}`]: undefined,
- [`PurcDisc${index}`]: undefined,
- [`SellPrice${index}`]: undefined,
- [`WhSalePrice${index}`]: undefined,
- [`offerSalePrice${index}`]: undefined,
- [`splSalePrice${index}`]: undefined,
- [`NumberofPieceinside${index}`]: undefined,
- [`AmountPerPiece${index}`]: undefined,
- }),
- setDelete(false))
- : ' ';
- }
- };
const handleTaxDropDownChange = async (TaxId) => {
formProductRef.current?.setFieldsValue({ TaxId: TaxId });
@@ -1789,98 +1746,134 @@ const StockForm = ({ formType }) => {
if (Delete) {
form.setFieldsValue({
- BalanceQty: { [localId]: undefined },
- ReceivedQty: { [localId]: undefined },
- AcceptedQty: { [localId]: undefined },
- RejectedQty: { [localId]: undefined },
- Amount: { [localId]: undefined },
- FreeQty: { [localId]: undefined },
- InwardPrice: { [localId]: undefined },
- MRP: { [localId]: undefined },
- PurcDisc: { [localId]: undefined },
- SellPrice: { [localId]: undefined },
- WhSalePrice: { [localId]: undefined },
- offerSalePrice: { [localId]: undefined },
- splSalePrice: { [localId]: undefined },
- NumberofPieceinside: { [localId]: undefined },
- AmountPerPiece: { [localId]: undefined },
- PurcDiscType: { [localId]: undefined },
+ [`BalanceQty${localId}`]: undefined,
+ [`ReceivedQty${localId}`]: undefined,
+ [`AcceptedQty${localId}`]: undefined,
+ [`RejectedQty${localId}`]: undefined,
+ [`Amount${localId}`]: undefined,
+ [`Freeqty${localId}`]: undefined,
+ [`InwardPrice${localId}`]: undefined,
+ [`MRP${localId}`]: undefined,
+ [`PurcDisc${localId}`]: undefined,
+ [`SellPrice${localId}`]: undefined,
+ [`WhSalePrice${localId}`]: undefined,
+ [`offerSalePrice${localId}`]: undefined,
+ [`splSalePrice${localId}`]: undefined,
+ [`NumberofPieceinside${localId}`]: undefined,
+ [`AmountPerPiece${localId}`]: undefined,
+ [`PurcDiscType${localId}`]: undefined,
+ [`ManufDate${localId}`]: undefined,
+ [`ExpDate${localId}`]: undefined,
+ [`OnePcsPrice${localId}`]: undefined,
+ [`NoOfPcs${localId}`]: undefined,
});
setDelete(false);
} else {
form.setFieldsValue({
- BalanceQty: { [localId]: record?.BalanceQty },
- ReceivedQty: { [localId]: record?.ReceivedQty },
- AcceptedQty: { [localId]: record?.AcceptedQty },
- RejectedQty: { [localId]: record?.RejectedQty },
- PurcDiscType: { [localId]: record?.PurcDiscType },
- Amount: { [localId]: record?.Amount },
- FreeQty: { [localId]: record?.FreeItem },
- InwardPrice: { [localId]: record?.InwardPrice },
- MRP: { [localId]: record?.MRP },
- PurcDisc: { [localId]: record?.PurcDisc },
- SellPrice: { [localId]: record?.SellPrice },
- WhSalePrice: { [localId]: record?.WhSalePrice },
- offerSalePrice: { [localId]: record?.OfferPrice },
- splSalePrice: { [localId]: record?.SpecialPrice },
- NumberofPieceinside: { [localId]: record?.NumberofPieceinside },
- AmountPerPiece: { [localId]: record?.AmountPerPiece },
+ [`BalanceQty${localId}`]: record?.BalanceQty,
+ [`ReceivedQty${localId}`]: record?.ReceivedQty,
+ [`AcceptedQty${localId}`]: record?.AcceptedQty,
+ [`RejectedQty${localId}`]: record?.RejectedQty,
+ [`Freeqty${localId}`]: record?.FreeItem,
+ [`MRP${localId}`]: record?.MRP,
+ [`ManufDate${localId}`]: record?.ManufDate,
+ [`ExpDate${localId}`]: record?.ExpDate,
+ [`SellPrice${localId}`]: record?.SellPrice,
+ [`WhSalePrice${localId}`]: record?.WhSalePrice,
+ [`PurcDiscType${localId}`]: record?.PurcDiscType,
+ [`Amount${localId}`]: record?.Amount,
+ [`InwardPrice${localId}`]: record?.InwardPrice,
+ [`PurcDisc${localId}`]: record?.PurcDisc,
+ [`offerSalePrice${localId}`]: record?.OfferPrice,
+ [`splSalePrice${localId}`]: record?.SpecialPrice,
+ [`OnePcsPrice${localId}`]: record?.OnePcsPrice,
+ [`NoOfPcs${localId}`]: record?.NoOfPcs,
+
+
});
+
if (applicationRestrictedFields.BatchAndModelDetails) {
form.setFieldsValue({
- BatchRef: { [localId]: record?.BatchRef },
+ [`BatchRef${localId}`]: record?.BatchRef,
});
}
}
};
- const save = async (index) => {
+ const save = async (localId) => {
try {
- const row = await form?.validateFields();
+ const row = await form.validateFields();
const modifiedObject = {};
+
for (const key in row) {
- const newKey = key.slice(0, -1); // Remove the last character ("0") from the key
- modifiedObject[newKey] = row[key];
+ // remove localId suffix from field names
+ if (key.endsWith(localId)) {
+ const newKey = key.replace(localId, '');
+ modifiedObject[newKey] = row[key];
+ }
}
- const newData = [...PurchaseData];
- // const index = newData.findIndex((item) => recordKey === item.InwardDtlId);
- if (index > -1) {
- const item = newData[index];
- newData.splice(index, 1, { ...item, ...modifiedObject });
- setPurchaseData(newData);
- setEditingKey('');
- }
+ setPurchaseData((prev) =>
+ prev.map((item) =>
+ item.localId === localId
+ ? { ...item, ...modifiedObject }
+ : item
+ )
+ );
+
+ setEditingKey('');
} catch (err) {
console.error('Save failed:', err);
}
};
- const handleKeyPress = async (e, record, index) => {
+
+ const handleKeyPress = async (e, record) => {
if (e.key === 'Enter') {
try {
await form.validateFields();
- save(index);
+ save(record.localId);
} catch (error) {
console.error('Save failed:', error);
}
}
};
- const openAdditionalInfoModal = (record, index) => {
- console.log(record, 'recordrecord');
- if (record?.ReceivedQty === 0 || record?.ReceivedQty === '') {
- setMessageType('error');
- setMessageData('Please Enter Qty');
- return;
- }
- setSelectedRowIndex(index);
- setSelectedRowRecord(record);
- setAdditionalInfoModal(true);
+
+ const formatDateForDisplay = (dateString) => {
+ if (!dateString) return '';
+ return moment(dateString).format('DD-MMM-YY');
};
+
+ const updateRowValues = (localId, updates) => {
+ setPurchaseData((prev) =>
+ prev.map((item) =>
+ item.localId === localId ? { ...item, ...updates } : item
+ )
+ );
+
+ const formUpdates = {};
+ Object.keys(updates).forEach((key) => {
+ formUpdates[`${key}${localId}`] = updates[key];
+ });
+
+ form.setFieldsValue(formUpdates);
+ };
+ const updateRowValue = (localId, key, value) => {
+ setPurchaseData((prev) =>
+ prev.map((item) =>
+ item.localId === localId ? { ...item, [key]: value } : item
+ )
+ );
+
+ form.setFieldsValue({
+ [`${key}${localId}`]: value,
+ });
+ }
+
const columns = [
{
title: 'SL.NO',
@@ -1891,13 +1884,24 @@ const StockForm = ({ formType }) => {
),
},
{
- title: 'Product Name',
+ title: 'Name',
dataIndex: 'ProdName',
key: 'ProdName',
align: 'left',
render: (text, record, index) => (
- {record?.ProdName + '(' + record?.ProdVariantName + ')'}
+ {record?.ProdName}
+
+ ),
+ },
+ {
+ title: 'Variant',
+ dataIndex: 'ProdVariantName',
+ key: 'ProdVariantName',
+ align: 'left',
+ render: (text, record, index) => (
+
+ {record?.ProdVariantName}
),
},
@@ -1934,9 +1938,9 @@ const StockForm = ({ formType }) => {
]}
>
handleKeyPress(e, record, index)}
+ onPressEnter={(e) => handleKeyPress(e, record)}
onBlur={(e) => handleQtyChange(e, record)}
- onChange={(e) => handleQtyChange(e, record, index)}
+ onChange={(e) => handleQtyChange(e, record)}
inputMode="decimal"
onInput={(e) => {
let cleanedValue = e.target.value.replace(/[^0-9.]/g, ''); // Remove invalid characters
@@ -1961,7 +1965,7 @@ const StockForm = ({ formType }) => {
{
title: (
+ Some products are missing Qty or Amount. +
+ ++ Affected row(s): {invalidRowNumbers.join(', ')} +
+ ++ Are you sure you want to continue without these products? +
+