import { useState, useEffect, useCallback, useRef, useMemo } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useNavigate, useLocation } from 'react-router-dom';
import {
Space,
Form,
Tooltip,
Pagination,
Table,
Tour,
Popconfirm,
Radio,
Button,
Empty,
message,
} from 'antd';
import { debounce } from 'lodash';
import {
EditFilled,
DeleteFilled,
PlusOutlined,
ReloadOutlined,
PrinterFilled,
CloseOutlined,
ArrowRightOutlined,
CheckSquareOutlined,
} from '@ant-design/icons';
import { BiAddToQueue } from 'react-icons/bi';
import { FiUploadCloud, FiInfo, FiEyeOff } from 'react-icons/fi';
import { BsCameraFill } from 'react-icons/bs';
import { MdDeleteForever } from 'react-icons/md';
import QRCode from 'qrcode';
import { InputField } from '../../Components/Forms/InputField.jsx';
import { DropDowns } from '../../Components/Forms/DropDown';
import { DefaultModal } from '../../Components/Modal/DefaultModal.jsx';
import { Search } from '../../Components/Forms/Search';
import Buttons from '../../Components/Forms/Buttons';
import { Messages } from '../../Components/Notifications/Messages';
import FormHeader from '../PageComponents/FormHeader.jsx';
import {
changeBreadCrumb,
getEmpAccess,
} from '../../Features/AppPage/CenterPage.js';
import {
getProductDataPageNo,
deleteProductData,
getAllsubcatdata,
getAllbrandcatdata,
bulkpostdata,
uomDataSelector,
prodCatDataSelector,
taxSelector,
supplierSelector,
getProdCatData,
getUomData,
getSupplierData,
getAdmin,
Deletebulkdatas,
getProductDataSearch,
onlineimages,
putProductData,
getAllprodIds,
updateProductImage,
PostPedalOCR,
// getUserGuideLines,
// postUserGuideLines
} from '../../Features/ProductPage/ProductPage.js';
import {
getSession,
printDiv,
roundToDecimal,
validateSafeInput,
} from '../../Services/Others';
import {
emptyExcelData,
excelDataSelector,
} from '../../Features/ExcelUploadPage/ExcelUploadPage.js';
import moment from 'moment';
import ProductExcel from '../Product/ExcelUpload.jsx';
import TertiaryButton from '../../Components/Forms/tertiaryButton.jsx';
import { useAuth } from '../../AuthContext.jsx';
import { MdOutlineAutoDelete } from 'react-icons/md';
import '../../Styles/OverAllStyle/OverAllStyle.scss';
import {
getBarcodeSessionsIDs,
getBarcodeTemplate,
} from '../../Features/Barcode/Barcode.js';
import { style, getPageStyle } from './Printstyles.js';
import JsBarcode from 'jsbarcode';
import { uploadImage } from '../../Features/upload/upload.js';
import CropUpload from '../../Components/Forms/CropUpload.jsx';
import { getPreferenceData } from '../../Features/BookingScreen/BookingData/BookingData.js';
import { ApplicationPreferences } from '../../Features/BrachLogin/BranchLogin.js';
import { FaRegEye } from 'react-icons/fa';
import { HiOutlineRocketLaunch } from 'react-icons/hi2';
import GooglePayUPIButton from '../UPIPayButton/UpiPay.jsx';
import ScannedProductTable from '../../Components/PedalOCR/scannedProductTable.jsx';
import MultiCameraCropOCR from '../../Components/PedalOCR/MultiCameraCropOCR.jsx';
import OCRLoader from '../../Components/PedalOCR/OCRLoader.jsx';
import { GiHorizontalFlip, GiVerticalFlip } from 'react-icons/gi';
import { FaPlus } from "react-icons/fa6";
import { Tables } from '../../../ownLib/my-ui-lib.js';
const colorText = 'Color : Red';
const ProductList = () => {
const { SadminuserAccess } = useAuth();
let SAAccessCommonMaster = SadminuserAccess?.find(
(e) => e?.MenuName === 'Add Product'
);
const formRef = useRef();
// const ref1 = useRef(null);
const navigateTo = useNavigate();
const dispatch = useDispatch();
const location = useLocation();
const barCodeImage =
'https://cdn.pixabay.com/photo/2014/04/02/16/19/barcode-306926_1280.png';
const qrCodeImage =
'https://cdn.pixabay.com/photo/2015/03/21/09/34/qr-683354_640.png';
const previewText = 'Barcode Preview';
const CompId = getSession('CompId');
const BranchId = getSession('BranchId');
const AppId = getSession('AppId');
const UserId = getSession('UserId');
const UserType = getSession('UserType');
const [AllProdIds, setAllProdIds] = useState([]);
const [cachedData, setCachedData] = useState({});
const [CachedDataSearch, setCachedDataSearch] = useState({});
const [searchedText, setSearchedText] = useState('');
const [SearchProdData, setSearchProdData] = useState([]);
const [productData, setproductData] = useState([]);
const [currentPage, setCurrentPage] = useState(1);
const [activeTab, setActiveTab] = useState('stock');
let SalesStatus = productData?.[0]?.SalesStatus;
const UomData = useSelector(uomDataSelector);
const ProdCatData = useSelector(prodCatDataSelector);
const SupplierData = useSelector(supplierSelector);
const TaxData = useSelector(taxSelector);
const excelDataValues = useSelector(excelDataSelector);
const appPreferences = useSelector(ApplicationPreferences);
const UomTypePreference = appPreferences?.find(
(preference) => preference?.PreferredCatName === 'Product Uom'
)?.PreferenceCatDetails;
const isCheckSportsApp = appPreferences
?.find((preference) => preference?.PreferredCatName === 'Common Module')
?.PreferenceCatDetails?.some(
(e) =>
e?.PreferredSubCatName === 'SportsApp' && e?.PreferredStatus === 'Y'
);
const UomPreference = UomData?.filter((item) =>
UomTypePreference?.some?.(
(e) =>
e?.PreferredSubCatName?.toLowerCase() ==
item?.ConfigName?.toLowerCase() && e?.PreferredStatus == 'Y'
)
);
const productFieldPreferences = appPreferences?.find(
(preference) =>
preference?.PreferredCatName?.toLowerCase() === 'product form fields'
)?.PreferenceCatDetails;
const filteredFields = productFieldPreferences?.filter(
(field) => field?.PreferredStatus === 'Y'
);
const brandColumn = filteredFields?.find(
(field) => field?.PreferredSubCatName === 'Brand'
);
const qrCodeColumn = filteredFields?.find(
(field) => field?.PreferredSubCatName === 'Auto Generate QRCode'
);
const subCategory = filteredFields?.find(
(field) => field?.PreferredSubCatName === 'Sub Category'
);
//local states
const [QrandbarcodeDatas, setQrandbarcodeDatas] = useState([]);
const [uploadImageModal, setUploadImageModal] = useState(false);
const [MultiCode, setMultiCode] = useState(false);
const [selectedRecords, setSelectedRecords] = useState([]);
const [imageModalRowIndex, setImageModalRowIndex] = useState(null);
const [rowRecord, setRowRecord] = useState(null);
const [sortedInfo, setSortedInfo] = useState({});
const [messageType, setMessageType] = useState(null);
const [messageData, setMessageData] = useState(null);
const [open, setOpen] = useState(false);
const [breadModalOpen, setBreadModalOpen] = useState(false);
const [breadData, setBreadData] = useState([]);
const [openPaddleOCR, setOpenPaddleOCR] = useState(false);
const [uploadedFile, setUploadedFile] = useState(null);
const [uploadedFiles, setUploadedFiles] = useState([]);
const [showTips, setShowTips] = useState(false);
const [isOCRProcessing, setIsOCRProcessing] = useState({
Length: 0,
Loader: false,
});
const [isDelete, setisDelete] = useState(false);
const [allowDecimal, setAllowDecimal] = useState(false);
const [inputError, setInputError] = useState('');
const [openExcel, setOpenExcel] = useState(false);
const [empData, setEmpData] = useState();
const [dropdownValue, setDropdownValue] = useState();
const [printProductName, setPrintProductName] = useState(false);
const [copies, setCopies] = useState();
const [proName, setProName] = useState();
const [nickName, setNickName] = useState(null);
const [ProdId, setProdId] = useState();
const [detail, setDetail] = useState();
const [size, setSize] = useState();
const [qrCodeUrl, setQrCodeUrl] = useState('');
const [page, setpage] = useState(1);
const [subCatData, setSubCatData] = useState();
const [allBrandData, setallBrandData] = useState();
const [Exceldatasubmit, setExceldatasubmit] = useState(null);
const [coresdata, setCoresdata] = useState([]);
const [barcodeTemplateDetails, setBarcodeTemplateDetails] = useState([]);
const [PopUp, setPopUp] = useState(false);
const [fromPage, setFromPage] = useState(1);
const [Bulkpost, setBulkpost] = useState(false);
const [templateOptions, setTemplateOptions] = useState({
mrp: false,
barcode: false,
color: false,
eDate: false,
mDate: false,
sellingPrice: false,
productName: false,
value: '',
secondValue: '',
qrcode: false,
codeType: '',
});
const secondValueStyle = {
flexDirection: templateOptions.secondValue === 'R' ? 'row' : 'row-reverse',
};
const valueStyleRow = {
flexDirection: templateOptions.value === 'R' ? 'row' : 'row-reverse',
};
const valueStyleColumn = {
flexDirection: templateOptions.value === 'T' ? 'column' : 'column-reverse',
};
const [base64Image, setBase64Image] = useState(null);
const [barcodeBase64Image, setBarcodeBase64Image] = useState(null);
const [deleteProductPages, setDeleteProductPages] = useState([]);
const [paginatedDeleteData, setPaginatedDeleteData] = useState([]);
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
const countOfProduct =
SearchProdData?.length > 0
? SearchProdData?.length
: deleteProductPages?.length > 0
? selectedRowKeys?.length
: productData?.[0]?.TotalCount;
const [addnewAccess, setaddnewAccess] = useState(true);
const [imageopen, setimageOpen] = useState(false);
const [imagedata, setimagedata] = useState();
const [selectedImage, setSelectedImage] = useState(null);
const [onlineImage, setOnlineImage] = useState(null);
const [imageUrl, setImageUrl] = useState('');
const [recordIndex, setRecordIndex] = useState(null);
const [rangeFrom, setRangeFrom] = useState('');
const [rangeTo, setRangeTo] = useState('');
const [deleteInput, setDeleteInput] = useState(null);
const [stockWiseQrcode, setstockWiseQrcode] = useState(false);
const [productWiseQrcode, setProductWiseQrcode] = useState(false);
const lastRangeIdsRef = useRef([]);
const subDirectory = import.meta.env.ENV_BASE_URL;
// const [openTour, setOpenTour] = useState(false);
// const steps = [
// {
// title: 'Click here to add a new product',
// description: 'This button allows you to add a new product to the inventory.',
// target: () => ref1.current,
// placement: 'top',
// },
// ];
const items = [
{
name: 'Home',
link: `${subDirectory}app-page/home`,
},
{
name: isCheckSportsApp ? 'Add Slot' : 'Product',
link: `${subDirectory}setting/product-master`,
},
];
// const stockAvailableCount = selectedRecords?.filter(
// item => item?.StockAvailable === "Y"
// ).length
const Qrcode = (record) => {
setProName(record?.ProdName);
setProdId(record?.QRCode);
setDetail(record);
setSize(record.Size + record.UomName);
setOpen(true);
};
const handlePageChange = (current) => {
if (deleteProductPages?.length > 0) {
setproductData(paginatedDeleteData[current]);
}
setpage(current);
setCurrentPage(current);
};
const pagewisefn = () => {
setPopUp(true);
};
useEffect(() => {
if (deleteProductPages?.length > 0) {
getForDeleteProduct(deleteProductPages);
} else if (deleteProductPages?.length === 0) {
getProdfun();
return;
}
}, [deleteProductPages]);
useEffect(() => {
if (coresdata?.length > 0 && open) {
CoresOnChange(coresdata?.[0].ConfigName);
}
}, [open]);
useEffect(() => {
if (!AllProdIds?.length) return;
const cleaned = deleteInput?.replace(/\s+/g, '');
const parts = cleaned?.split(',') || [];
let newRangeIds = [];
let globalIndex = [];
for (const part of parts) {
if (/^\d+$/.test(part)) {
// Single index
const index = parseInt(part, 10);
if (index > 0 && index <= AllProdIds?.length) {
newRangeIds.push(AllProdIds[index - 1]?.ProdId);
globalIndex.push(Math.ceil(index / 10));
}
} else if (/^\d+-\d+$/.test(part)) {
// Range
const [start, end] = part?.split('-').map(Number);
if (start > 0 && end >= start && end <= AllProdIds?.length) {
const pages = getPagesToCall(start, end);
pages?.forEach((page) => globalIndex.push(page));
for (let i = start; i <= end; i++) {
newRangeIds?.push(AllProdIds[i - 1]?.ProdId);
}
}
}
}
const idsToRemove = lastRangeIdsRef.current.filter(
(id) => !newRangeIds?.includes(id)
);
const idsToAdd = newRangeIds.filter(
(id) => !lastRangeIdsRef?.current?.includes(id)
);
setCurrentPage(1);
setpage(1);
const withRemoved = selectedRowKeys?.filter(
(id) => !idsToRemove?.includes(id)
);
const withAdded = [...withRemoved, ...idsToAdd];
const newSelectedRowKeys = Array.from(new Set(withAdded));
setSelectedRowKeys(newSelectedRowKeys);
setDeleteProductPages(Array.from(new Set(globalIndex)));
lastRangeIdsRef.current = newRangeIds;
}, [deleteInput, AllProdIds]);
function getPagesToCall(from, to, itemsPerPage = 10) {
const startPage = Math.ceil(from / itemsPerPage);
const endPage = Math.ceil(to / itemsPerPage);
const pages = [];
for (let i = startPage; i <= endPage; i++) {
pages.push(i);
}
return pages;
}
const validateDeleteInput = (input, totalCount) => {
if (!input?.trim()) return { isValid: true, error: '' };
const cleaned = input.replace(/\s+/g, '');
const parts = cleaned.split(',');
const rangeRegex = /^\d+(-\d+)?$/;
for (const part of parts) {
if (!rangeRegex.test(part)) {
return {
isValid: false,
error: 'Invalid range, use e.g. 1-5, 8, 9-10',
};
}
if (part.includes('-')) {
const [start, end] = part.split('-').map(Number);
if (
isNaN(start) ||
isNaN(end) ||
start <= 0 ||
end <= 0 ||
start > end ||
start > totalCount ||
end > totalCount
) {
return {
isValid: false,
error: `Out of bounds product reference, limit is ${totalCount}`,
};
}
} else {
const val = parseInt(part, 10);
if (
isNaN(val) ||
val <= 0 ||
!Number.isInteger(val) ||
val > totalCount
) {
return {
isValid: false,
error: `Out of bounds product reference, limit is ${totalCount}`,
};
}
}
}
return { isValid: true, error: '' };
};
// const columns = useMemo(
// () => [
// {
// title: 'Sl.No',
// key: 'sno',
// align: 'center',
// width: '60px',
// render: (text, object, index) => (
// {(page - 1) * 10 + index + 1}
// ),
// },
// {
// title: 'Category',
// dataIndex: 'CategoryName',
// key: 'CategoryName',
// width: '100px',
// render: (text) => {text},
// columnKey: 'CategoryName',
// sorter: (a, b) => a?.CategoryName?.localeCompare(b?.CategoryName),
// sortOrder:
// sortedInfo.columnKey === 'CategoryName' ? sortedInfo.order : null,
// ellipsis: true,
// },
// {
// title: isCheckSportsApp ? 'Name' : 'Product',
// dataIndex: 'ProdName',
// key: 'ProdName',
// width: '100px',
// render: (text) => {text},
// sorter: (a, b) => a?.ProdName?.localeCompare(b?.ProdName),
// columnKey: 'ProdName',
// sortOrder:
// sortedInfo.columnKey === 'ProdName' ? sortedInfo.order : null,
// ellipsis: true,
// },
// brandColumn && subCategory
// ? {
// title: 'Brand',
// dataIndex: 'BrandName',
// key: 'BrandName',
// columnKey: 'BrandName',
// width: '100px',
// render: (text) => {text},
// sorter: (a, b) => a?.BrandName?.localeCompare(b?.BrandName),
// sortOrder:
// sortedInfo.columnKey === 'BrandName' ? sortedInfo.order : null,
// ellipsis: true,
// }
// :null,
// {
// title: 'Qty',
// dataIndex: 'Size',
// key: 'Size',
// width: '100px',
// align: 'center',
// render: (text, record) => (
// {`${record?.Size}${record?.UomName}`}
// ),
// ellipsis: true,
// },
// // {
// // title: 'Unit',
// // dataIndex: 'UomName',
// // key: 'UomName',
// // width: '100px',
// // render: (text) => {text},
// // ellipsis: true,
// // },
// {
// title: 'Sell Price',
// dataIndex: 'SellPrice',
// key: 'SellPrice',
// width: '100px',
// align: 'right',
// render: (text) => (
// {roundToDecimal(text, allowDecimal)}
// ),
// ellipsis: true,
// },
// // {
// // title: "Stock Available",
// // dataIndex: "StockAvailable",
// // key: "StockAvailable",
// // width: "100px",
// // render: (text) => {text},
// // ellipsis: true,
// // },
// qrCodeColumn
// ? {
// title: 'QRCode',
// dataIndex: 'QRCode',
// key: 'QRCode',
// width: '100px',
// render: (text) => (
// {text ? text : '-'}
// ),
// ellipsis: true,
// }
// : {},
// qrCodeColumn
// ? {
// title: 'Print QRCode',
// key: 'Print',
// dataIndex: 'Print',
// width: '100px',
// render: (_, record, index) =>
// productData.length >= 1 ? (
//
// {record?.QRCode ? (
//
// {
// Qrcode(record);
// }}
// />
//
// ) : (
// '-'
// )}
//
// ) : null,
// }
// : {},
// {
// title: 'Action',
// key: 'Action',
// dataIndex: 'Action',
// width: '100px',
// render: (_, record, index) =>
// productData.length >= 1 ? (
//
// {record.ActiveStatus === 'A' ? (
//
//
// UserType === 'Super Admin' ||
// (UserType === 'Super Admin User' &&
// SAAccessCommonMaster?.UpdateAccess === 'Y') ||
// (UserType === 'Employee' &&
// empData?.UpdateAccess === 'Y') ||
// UserType === 'Admin'
// ? actionsFormatter(record, index)
// : null
// }
// />
//
// ) : (
// ''
// )}
//
// {record.ActiveStatus === 'A' ? (
//
// UserType === 'Super Admin' ||
// (UserType === 'Super Admin User' &&
// SAAccessCommonMaster?.DeleteAccess === 'Y') ||
// (UserType === 'Employee' &&
// empData?.DeleteAccess === 'Y') ||
// UserType === 'Admin'
// ? statusFormatter(record)
// : null
// }
// />
// ) : (
//
// UserType === 'Super Admin' ||
// (UserType === 'Super Admin User' &&
// SAAccessCommonMaster?.DeleteAccess === 'Y') ||
// (UserType === 'Employee' &&
// empData?.DeleteAccess === 'Y') ||
// UserType === 'Admin'
// ? statusFormatter(record)
// : null
// }
// />
// )}
//
//
// ) : null,
// },
// {
// title: 'Image',
// key: 'ProdLogo',
// dataIndex: 'ProdLogo',
// width: '100px',
// align: 'center',
// render: (_, record, index) => (
// //
//
//
// {
// setRowRecord(record);
// setImageModalRowIndex(index);
// setUploadImageModal(true);
// setOnlineImage(null);
// setSelectedImage(null);
// }}
// />
//
//
// ),
// },
// {
// title: (
// <>
//
//
// {isDelete ? (
// <>
// {/* {
// setisDelete(false);
// setSelectedRowKeys([]);
// setRangeFrom('');
// setRangeTo('');
// e.stopPropagation();
// }}
// /> */}
// {
// setisDelete(false);
// setSelectedRowKeys([]);
// setRangeFrom('');
// setRangeTo('');
// // setCachedData({})
// setDeleteInput();
// setDeleteProductPages([]);
// getProdfun();
// e.stopPropagation();
// }}
// />
// >
// ) : (
// {
// setisDelete(true);
// }}
// okText="Yes"
// cancelText="No"
// placement="bottom"
// >
// {
// e.stopPropagation();
// }}
// />
//
// )}
// {isDelete && selectedRowKeys.length !== AllProdIds.length && (
// 0 &&
// selectedRowKeys.length === AllProdIds.length
// }
// indeterminate={
// selectedRowKeys.length > 0 &&
// selectedRowKeys.length < AllProdIds.length
// }
// onChange={(e) => {
// if (e.target.checked) {
// const allProductIds = AllProdIds.map((p) => p.ProdId);
// setSelectedRowKeys(allProductIds);
// setRangeFrom('');
// setRangeTo('');
// } else {
// setSelectedRowKeys([]);
// }
// }}
// />
// )}
//
// {/* {isDelete && selectedRowKeys.length !== AllProdIds.length && (
//
// {
// const val = e.target.value.replace(/[^\d]/g, '');
// setRangeFrom(val);
// }}
// />
// {
// const val = e.target.value.replace(/[^\d]/g, '');
// setRangeTo(val);
// }}
// />
//
// )} */}
// {isDelete && selectedRowKeys.length !== AllProdIds.length && (
//
//
// {
// const val = e?.target?.value;
// setDeleteInput(val);
// const totalCount = productData?.[0]?.TotalCount || 0;
// const { isValid, error } = validateDeleteInput(
// val,
// totalCount
// );
// setInputError(isValid ? '' : error);
// }}
// placeholder="e.g. 1-5, 8, 9-10"
// style={{
// borderColor: inputError ? 'red' : undefined,
// borderWidth: inputError ? 1 : undefined,
// }}
// />
//
// {inputError && (
//
// {inputError}
//
// )}
//
// )}
//
// >
// ),
// dataIndex: 'checkbox',
// key: 'checkbox',
// width: '100px',
// align: 'center',
// render: (_, record) =>
// isDelete ? (
//
{
// if (e.target.checked) {
// setSelectedRowKeys((prev) => [...prev, record.ProdId]);
// } else {
// setSelectedRowKeys((prev) =>
// prev.filter((id) => id !== record.ProdId)
// );
// }
// }}
// />
// ) : null,
// sorter: false,
// },
// ],
// [
// AllProdIds,
// selectedRowKeys,
// rangeFrom,
// rangeTo,
// page,
// productData,
// isDelete,
// sortedInfo,
// onlineImage,
// ]
// );
const formatDate = (dateStr) => {
const d = new Date(dateStr);
const day = String(d.getDate()).padStart(2, '0');
const months = [
'JAN',
'FEB',
'MAR',
'APR',
'MAY',
'JUN',
'JUL',
'AUG',
'SEP',
'OCT',
'NOV',
'DEC',
];
const month = months[d.getMonth()];
const year = String(d.getFullYear()).slice(-2);
return `${day}-${month}-${year}`;
};
const handleCheckboxChange = (record, checked) => {
setSelectedRecords((prev) => {
if (checked) {
return [...prev, record]; // add record
} else {
return prev.filter((r) => r.ProdId !== record.ProdId); // remove record
}
});
};
const CreateQrcode = async (isChecked, code, productName, StockAvailable, copiesCount = 0) => {
if (!code) return;
if (isChecked) {
const data = await QRCode.toDataURL(code);
setQrandbarcodeDatas((prev) => [
...prev,
{
key: code,
url: data,
productName: productName,
copiesCount: copiesCount,
StockAvailable: StockAvailable
},
]);
} else {
setQrandbarcodeDatas((prev) => prev.filter((item) => item.key !== code));
}
};
const CreateQrcodesBatch = async (products, isChecked) => {
if (isChecked) {
const batchSize = 5;
for (let i = 0; i < products.length; i += batchSize) {
const batch = products.slice(i, i + batchSize);
await Promise.all(
batch.map((product) => CreateQrcode(true, product.QRCode, product.ProdName, product.StockAvailable, product.TotalBalanceQty))
);
// Small delay to prevent UI blocking
if (i + batchSize < products.length) {
await new Promise((resolve) => setTimeout(resolve, 10));
}
}
} else {
products.forEach((product) => CreateQrcode(false, product.QRCode, product.ProdName, product.StockAvailable, product.TotalBalanceQty));
}
};
const columns = useMemo(() => {
const cols = [
{
title: 'Sl.No',
key: 'sno',
align: 'center',
width: '60px',
render: (text, object, index) => (
{(page - 1) * 10 + index + 1}
),
},
{
title: 'Category',
dataIndex: 'CategoryName',
key: 'CategoryName',
width: '100px',
render: (text) =>
{text},
columnKey: 'CategoryName',
sorter: (a, b) => a?.CategoryName?.localeCompare(b?.CategoryName),
sortOrder:
sortedInfo.columnKey === 'CategoryName' ? sortedInfo.order : null,
ellipsis: true,
},
{
title: isCheckSportsApp ? 'Name' : 'Product',
dataIndex: 'ProdName',
key: 'ProdName',
width: '100px',
render: (text) =>
{text},
sorter: (a, b) => a?.ProdName?.localeCompare(b?.ProdName),
columnKey: 'ProdName',
sortOrder:
sortedInfo.columnKey === 'ProdName' ? sortedInfo.order : null,
ellipsis: true,
},
...(brandColumn && subCategory
? [
{
title: 'Brand',
dataIndex: 'BrandName',
key: 'BrandName',
columnKey: 'BrandName',
width: '100px',
render: (text) =>
{text},
sorter: (a, b) => a?.BrandName?.localeCompare(b?.BrandName),
sortOrder:
sortedInfo.columnKey === 'BrandName' ? sortedInfo.order : null,
ellipsis: true,
},
]
: []),
{
title: 'Qty',
dataIndex: 'Size',
key: 'Size',
width: '100px',
align: 'center',
render: (text, record) => (
{`${record?.Size} ${record?.UomName}`}
),
ellipsis: true,
},
...(qrCodeColumn
? [
{
title: 'QRCode',
dataIndex: 'QRCode',
key: 'QRCode',
width: '100px',
align: 'center',
render: (text) => (
{text ? text : '-'}
),
ellipsis: true,
},
{
title: (
{MultiCode && (
0 &&
productData
.filter((p) => p?.QRCode)
.every((p) =>
selectedRecords.some((r) => r.ProdId === p.ProdId)
)
}
onChange={(e) => {
const productsWithQR = productData.filter(
(p) => p?.QRCode
);
if (e.target.checked) {
const newSelections = productsWithQR.filter(
(p) =>
!selectedRecords.some(
(r) => r.ProdId === p.ProdId
)
);
setSelectedRecords((prev) => [
...prev,
...newSelections,
]);
// Create QR codes for newly selected products
CreateQrcodesBatch(newSelections, true);
} else {
// Remove QR codes for deselected products
CreateQrcodesBatch(productsWithQR, false);
setSelectedRecords((prev) =>
prev.filter(
(r) =>
!productsWithQR.some(
(p) => p.ProdId === r.ProdId
)
)
);
}
}}
/>
)}
Print QRCode
{
setMultiCode((prev) => {
const newValue = !prev;
if (!newValue) {
setSelectedRecords([]);
}
return newValue;
});
}}
/>
),
key: 'Print',
dataIndex: 'Print',
width: '100px',
align: 'center',
render: (_, record) =>
productData.length >= 1 ? (
{MultiCode ? (
record?.QRCode ? (
r.ProdId == record.ProdId
)}
onChange={(e) => {
handleCheckboxChange(record, e.target.checked);
CreateQrcode(e.target.checked, record.QRCode, record?.ProdName, record?.StockAvailable, record?.TotalBalanceQty);
}}
/>
) : (
'-'
)
) : record?.QRCode ? (
Qrcode(record)}
/>
) : (
'-'
)}
) : null,
},
]
: []),
{
title: 'Action',
key: 'Action',
dataIndex: 'Action',
width: '100px',
align: 'center',
render: (_, record, index) =>
productData.length >= 1 ? (
{record.ActiveStatus === 'A' ? (
UserType === 'Super Admin' ||
(UserType === 'Super Admin User' &&
SAAccessCommonMaster?.UpdateAccess === 'Y') ||
(UserType === 'Employee' &&
empData?.UpdateAccess === 'Y') ||
UserType === 'Admin'
? actionsFormatter(record, index)
: null
}
/>
) : (
''
)}
{record.ActiveStatus === 'A' ? (
UserType === 'Super Admin' ||
(UserType === 'Super Admin User' &&
SAAccessCommonMaster?.DeleteAccess === 'Y') ||
(UserType === 'Employee' &&
empData?.DeleteAccess === 'Y') ||
UserType === 'Admin'
? statusFormatter(record)
: null
}
/>
) : (
UserType === 'Super Admin' ||
(UserType === 'Super Admin User' &&
SAAccessCommonMaster?.DeleteAccess === 'Y') ||
(UserType === 'Employee' &&
empData?.DeleteAccess === 'Y') ||
UserType === 'Admin'
? statusFormatter(record)
: null
}
/>
)}
) : null,
},
{
title: 'Image',
key: 'ProdLogo',
dataIndex: 'ProdLogo',
width: '60px',
align: 'center',
render: (_, record, index) => (
//
{
setRowRecord(record);
setImageModalRowIndex(index);
setUploadImageModal(true);
setOnlineImage(null);
setSelectedImage(null);
}}
/>
),
},
{
title: (
<>
>
),
dataIndex: 'checkbox',
key: 'checkbox',
width: '50px',
align: 'center',
render: (_, record) =>
isDelete ? (
{
if (e.target.checked) {
setSelectedRowKeys((prev) => [...prev, record.ProdId]);
} else {
setSelectedRowKeys((prev) =>
prev.filter((id) => id !== record.ProdId)
);
}
}}
/>
) : null,
sorter: false,
},
];
// ✅ Filter out any null, undefined, or empty columns safely
return cols.filter(
(col) => col && typeof col === 'object' && Object.keys(col).length > 0
);
}, [
MultiCode,
selectedRecords,
AllProdIds,
selectedRowKeys,
rangeFrom,
rangeTo,
page,
productData,
isDelete,
sortedInfo,
onlineImage,
]);
const handleImageTag = (w, h = '40px', barcodeOrQr) => {
return (

);
};
const updateImageUrl = (url) => {
setImageUrl(url);
};
useEffect(() => {
if (imageUrl == '') {
setOnlineImage(null);
}
}, [imageUrl]);
const handleimage = () => {
setimageOpen(false);
setOnlineImage('');
setOnlineImage(null);
};
const browseImage = async (productName, index) => {
if (productName !== null) {
let response = await dispatch(onlineimages(productName)).unwrap();
setimageOpen(true);
setimagedata(response?.data?.data);
setImageUrl('');
setRecordIndex(index);
}
};
const handleImageModalClose = () => {
setUploadImageModal(false);
setOnlineImage(null);
setImageModalRowIndex(null);
setSelectedImage(null);
};
const submitimage = async () => {
let response = await fetch(selectedImage.image);
let data = await response?.blob();
let metadata = {
type: 'image/jpeg',
};
let file = new File([data], 'image.jpg', metadata);
let uploadImgData = await dispatch(uploadImage(file)).unwrap();
if (uploadImgData?.data?.status) {
setOnlineImage(uploadImgData?.data?.image);
setImageUrl(uploadImgData?.data?.image);
}
setimageOpen(false);
};
const handleProductListGetApi = async () => {
const response = await dispatch(
getProductDataPageNo({
CompId: CompId,
BranchId: BranchId,
AppId: AppId,
PageNumber: currentPage,
})
).unwrap();
if (response?.data?.statusCode === 1) {
setCachedData((prev) => ({
...prev,
[currentPage]: response?.data?.data,
})); // Cache the new data
setproductData(response?.data?.data);
} else {
setCachedData({});
setproductData([]);
}
};
const handleImageUpload = async (img, record) => {
const { ProdId } = record;
const putData = {
AppId,
CompId,
BranchId,
ProdId,
ProdLogo: img,
UpdatedBy: UserId,
};
const response = await dispatch(updateProductImage(putData)).unwrap();
if (response?.data?.statusCode == 1) {
setimageOpen(false);
setOnlineImage('');
setOnlineImage(null);
handleProductListGetApi();
setRowRecord((prev) => ({
...prev,
ProdLogo: img,
}));
}
};
useEffect(() => {
async function fetchImage() {
try {
const base64 = await imageUrlToBase64(qrCodeUrl);
setBase64Image(base64);
} catch (error) {
setConversionError(error.message || 'Error converting image');
}
}
if (qrCodeUrl) {
fetchImage();
}
}, [qrCodeUrl]);
useEffect(() => {
try {
dispatch(changeBreadCrumb({ items: items }));
if (location?.state?.Notiffy) {
setMessageType(location?.state?.Notiffy.messageType);
setMessageData(location?.state?.Notiffy.messageData);
}
} catch (err) {
console.log(err, 'err');
}
barcodeApiData();
getPreference();
getAllProdId();
// userTour()
// if (UserType === "Employee") {
// fetchApi()
// }
}, []);
useEffect(() => {
if (UserType === 'Employee') {
fetchApi();
}
}, [UserType]);
useEffect(() => {
let hasAccess = false;
if (UserType === 'Admin' || UserType === 'Super Admin') {
hasAccess = true;
} else if (UserType === 'Employee') {
hasAccess = empData?.AddAccess === 'Y';
} else if (UserType === 'Super Admin User') {
hasAccess = SAAccessCommonMaster?.AddAccess === 'Y';
}
setaddnewAccess(!hasAccess);
}, [empData, SAAccessCommonMaster, UserType]);
useEffect(() => {
if (
SearchProdData?.length === 0 &&
searchedText?.length === 0 &&
!(deleteProductPages?.length > 0)
) {
getProdfun();
}
}, [currentPage, SearchProdData]);
const getAllProdId = async () => {
let data = {
CompId: CompId,
BranchId: BranchId,
AppId: AppId,
};
let response = await dispatch(getAllprodIds(data)).unwrap();
if ((response.data.statusCode = 1)) {
setAllProdIds(response.data.data);
} else {
setAllProdIds([]);
}
};
const getPreference = async () => {
const data = { AppId: AppId, CompId: CompId, BranchId: BranchId };
const { data: res } = await dispatch(getPreferenceData(data)).unwrap();
const decimalSetting = res?.data?.[0]?.SettingDtlDetails?.find(
(setting) =>
setting?.SettingIdName?.toLowerCase() === 'decimal' &&
setting?.SettingValue === 'Y'
);
if (decimalSetting) {
setAllowDecimal(true);
}
};
const getProdfun = async () => {
if (cachedData[currentPage]) {
// Use cached data if available
setproductData(cachedData[currentPage]);
} else {
let response = await dispatch(
getProductDataPageNo({
CompId,
BranchId,
AppId,
PageNumber: currentPage,
})
).unwrap();
if (response?.data?.statusCode === 1) {
setCachedData((prev) => ({
...prev,
[currentPage]: response?.data?.data,
})); // Cache the new data
// Merge old and new data
setproductData(response?.data?.data);
}
}
// setproductData
};
const getForDeleteProduct = async (productPages) => {
if (selectedRowKeys?.length === 0) return;
let cacheData = {};
for (let i = 0; i < productPages?.length; i++) {
if (!cachedData[productPages[i]]) {
let response = await dispatch(
getProductDataPageNo({
CompId,
BranchId,
AppId,
PageNumber: productPages[i],
})
).unwrap();
if (response?.data?.statusCode === 1) {
cacheData[productPages[i]] = response?.data?.data;
setCachedData((prev) => ({
...prev,
[productPages[i]]: response?.data?.data,
}));
}
} else {
cacheData[productPages[i]] = cachedData[productPages[i]];
}
}
let selectedDelete = [];
for (let key in cacheData) {
cacheData?.[key]?.forEach((data) => {
if (selectedRowKeys.includes(data?.ProdId)) {
selectedDelete.push(data);
}
});
}
const paginatedResults = paginateData(selectedDelete);
setPaginatedDeleteData(paginatedResults);
setproductData(paginatedResults[currentPage]);
};
useEffect(() => {
if (ProdId) {
QRCode?.toDataURL(ProdId)
.then((url) => {
setQrCodeUrl(url);
})
.catch((error) => {
console.error('Error generating QR code:', error);
});
}
}, [ProdId]);
const onComplete = useCallback(() => {
setMessageData(null);
setMessageType(null);
}, []);
const fetchApi = async () => {
let data = {
CompId: CompId,
BranchId: BranchId,
AppId: AppId,
EmpId: UserId,
};
let response = await dispatch(getEmpAccess(data)).unwrap();
let datas = response?.data?.data?.[0]?.EmpAccessDetails?.filter(
(item) => item.ConfigName === 'Add Product'
);
setEmpData(datas?.[0]);
};
const barcodeApiData = async () => {
const getResponse = await dispatch(
getBarcodeTemplate({ compId: CompId, appId: AppId, branchId: BranchId })
).unwrap();
if (getResponse?.data?.statusCode === 1) {
if (getResponse?.data?.data?.length > 0) {
const { TemplateDetails } = getResponse?.data?.data?.[0];
setBarcodeTemplateDetails(TemplateDetails);
}
}
};
const actionsFormatter = async (row, rowIndex) => {
if (row.ActiveStatus !== 'D') {
if (isCheckSportsApp) {
navigateTo(
`${subDirectory}setting/products-master/update`,
{
state: {
editstate: { ...row, DiscountValue: row?.DiscountLimit ?? 0 },
},
},
{ key: rowIndex }
);
} else {
navigateTo(
`${subDirectory}setting/product-master/update`,
{
state: {
editstate: { ...row, DiscountValue: row?.DiscountLimit ?? 0 },
},
},
{ key: rowIndex }
);
}
}
};
const generateQRCode = (code) => {
let Data = QrandbarcodeDatas?.find((e) => e?.key === code)?.url;
return Data
}
const generateQRCodeCopy = (code) => {
const found = QrandbarcodeDatas?.find((e) => e?.key === code);
const count = Number(found?.copiesCount);
return Number.isFinite(count) && count > 0 ? count : 0;
};
const imageUrlToBase64 = async (url) => {
try {
const response = await fetch(url);
const blob = await response.blob();
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsDataURL(blob);
});
} catch (error) {
console.error('Error fetching or converting image:', error);
throw error;
}
};
const statusFormatter = async (row) => {
let deleteData = {
ProdId: row.ProdId,
ActiveStatus: row.ActiveStatus === 'A' ? 'D' : 'A',
UpdatedBy: getSession('UserId'),
};
let response = await dispatch(deleteProductData(deleteData)).unwrap();
if (response?.data?.statusCode === 1) {
setMessageType('success');
setMessageData(
row.ActiveStatus === 'A'
? 'In-Activated Successfully'
: 'Activated Successfully'
);
// Fetch the updated data for the current page only
let updatedResponse = await dispatch(
getProductDataPageNo({
CompId,
BranchId,
AppId,
PageNumber: currentPage,
})
).unwrap();
if (updatedResponse?.data?.statusCode === 1) {
if (SearchProdData?.length > 0) {
fetchSearchResults(searchedText);
} else {
setCachedData((prev) => ({
...prev,
[currentPage]: updatedResponse?.data?.data,
}));
setproductData((prev) => {
let updatedData = [...prev];
const startIndex = (currentPage - 1) * 10;
if (updatedData.length >= startIndex + 10) {
updatedData.splice(
startIndex,
10,
...updatedResponse?.data?.data
);
} else {
updatedData = [...updatedResponse?.data?.data];
}
return updatedData;
});
}
}
}
};
const handleChange = (pagination, filters, sorter) => {
setSortedInfo(sorter);
};
const paginateData = (allProducts) => {
let paginatedData = {};
for (let i = 0; i < allProducts.length; i += 10) {
paginatedData[i / 10 + 1] = allProducts.slice(i, i + 10);
}
return paginatedData;
};
const fetchSearchResults = useCallback(
debounce(async (searchValue) => {
if (searchValue.length > 0) {
let response = await dispatch(
getProductDataSearch({
CompId,
BranchId,
AppId,
prodName: searchValue,
})
).unwrap();
if (response?.data?.statusCode === 1) {
const paginatedResults = paginateData(response?.data?.data);
setCachedDataSearch(paginatedResults);
setSearchProdData(response?.data?.data);
// setSearchProdData(response?.data?.data);
setpage(1);
setCurrentPage(1);
setproductData(paginatedResults[1] || []);
} else {
setSearchProdData([]);
setproductData([]);
setCachedDataSearch([]);
setpage(1);
setCurrentPage(1);
}
} else {
setSearchProdData([]);
setproductData([]);
setCachedDataSearch([]);
setpage(1);
setCurrentPage(1);
}
}, 500), // 500ms debounce time
[dispatch, CompId, BranchId, AppId]
);
const onSearchChange = async (e) => {
setSearchedText(e?.target?.value);
fetchSearchResults(e?.target?.value);
};
const handelAddButton = () => {
if (isCheckSportsApp) {
navigateTo(`${subDirectory}setting/products-master/new`);
} else {
navigateTo(`${subDirectory}setting/product-master/new`);
}
};
const handelBulkAdd = () => {
navigateTo(`${subDirectory}setting/product-master/turbo-add`);
};
const CoresOnChange = (params) => {
setDropdownValue(params);
formRef.current?.setFieldsValue({ Cross: params });
const template = barcodeTemplateDetails?.find(
(find) => find.SessionName === params
);
const checkComponent = (name) =>
template?.OptionDetails?.some((some) => some.OptionName === name);
const productName = checkComponent('Product Name');
setPrintProductName(productName);
};
const CopiesOnChange = (params) => {
setCopies(params);
formRef.current?.setFieldsValue({ Copies: params });
};
const onFinish = async () => {
const template = barcodeTemplateDetails?.find(
(find) => find.SessionName === dropdownValue
);
const templateAvailable = template === undefined ? false : true;
if (templateAvailable) {
const checkComponent = (name) =>
template?.OptionDetails?.some((some) => some.OptionName === name);
const mrp = checkComponent('MRP');
const barcode = checkComponent('Barcode');
const color = checkComponent('Color');
const eDate = checkComponent('E Date');
const mDate = checkComponent('M Date');
const sellingPrice = checkComponent('Selling Price');
const productName = checkComponent('Product Name');
const qrcode = checkComponent('Qrcode');
const position = template.Position !== '' ? template.Position : '';
const positionString =
template.PositionString !== '' ? template.PositionString : '';
setTemplateOptions({
mrp: mrp,
barcode: barcode,
color: color,
eDate: eDate,
mDate: mDate,
sellingPrice: sellingPrice,
productName: productName,
value: position,
secondValue: positionString,
qrcode: qrcode,
codeType: template?.CodeType,
});
}
switch (dropdownValue) {
case '15X15 6cross': // COMPLETE
await printDiv(
templateAvailable ? '15X156cross' : 'StickerPrints0',
style + getPageStyle(92)
);
handleQRStickerPrinterModelCancel();
break;
case '22X35 3cross': // Need to check
await printDiv(
templateAvailable ? '22X353cross' : 'StickerPrints1',
style + getPageStyle(105)
);
handleQRStickerPrinterModelCancel();
break;
case '25X25 4cross': // COMPLETE
await printDiv(
templateAvailable ? '25X254cross' : 'StickerPrints2',
style + getPageStyle(100)
);
handleQRStickerPrinterModelCancel();
break;
case '25X50 2cross': //Need to check
await printDiv(
templateAvailable ? '25X502cross' : 'StickerPrints3',
style
);
handleQRStickerPrinterModelCancel();
break;
case '50X30 Single': // COMPLETE
await printDiv(
templateAvailable ? '50X30Single' : 'StickerPrints4',
style
);
handleQRStickerPrinterModelCancel();
break;
case '50X25 Single': // COMPLETE
await printDiv(
templateAvailable ? '50X25Single' : 'StickerPrints5',
style
);
handleQRStickerPrinterModelCancel();
break;
case '100X13 (55MM Printable)': //Need to check
await printDiv(
templateAvailable ? '100X13(55MMPrintable)' : 'StickerPrints6',
style
);
handleQRStickerPrinterModelCancel();
break;
case '100X15 (70MM Printable)': // COMPLETE
await printDiv(
templateAvailable ? '100X15(70MMPrintable)' : 'StickerPrints7',
style
);
handleQRStickerPrinterModelCancel();
break;
case '100X150': // COMPLETE
await printDiv(templateAvailable ? '100X150' : 'StickerPrints8', style);
handleQRStickerPrinterModelCancel();
break;
default:
alert('! Select correct cross ');
}
};
useEffect(() => {
Bulkuploadsubdata();
getBarcodeSessionData();
}, []);
const Bulkuploadsubdata = async () => {
let response = await dispatch(
getAllsubcatdata({ AppId: AppId, TypeName: 'Product Sub-Category' })
).unwrap();
setSubCatData(response?.data?.data);
let res = await dispatch(
getAllbrandcatdata({ AppId: AppId, TypeName: 'Product Brand' })
).unwrap();
setallBrandData(res?.data?.data);
dispatch(getProdCatData({ AppId: AppId }));
dispatch(getUomData({ TypeName: 'Unit of Measure' }));
dispatch(
getSupplierData({ AppId: AppId, BranchId: BranchId, CompId: CompId })
);
dispatch(getAdmin({ AppId: AppId, CompId: CompId }));
setOpen(false);
formRef?.current?.resetFields();
};
const handleCancel = () => {
setOpenExcel(false);
handleResetExcelData();
};
const openModal = () => {
setOpenExcel(true);
};
const handleResetExcelData = () => {
dispatch(emptyExcelData());
};
const handleSubmitbulk = (excelData) => {
setExceldatasubmit(excelData);
};
const handleSubmit = async () => {
setBulkpost(true);
let FilterData = Exceldatasubmit?.filter((a) => a['ProductName'] != '');
if (FilterData && FilterData.length > 0) {
const formattedData = FilterData?.map((data) => ({
AppId: getSession('AppId'),
CompId: getSession('CompId'),
BranchId: getSession('BranchId'),
CreatedBy: getSession('UserId'),
ProdName: data?.ProductName,
ProdVariantName: data?.ProductVariantName,
Size: data?.Quantity,
UOM: data?.UOM,
MRP: data?.MRP,
WhSalePrice: data?.WhSalePrice,
SellPrice: data?.SellPrice,
ProdCat: data?.Category ? data?.Category : 'General',
ProdSubCat: data?.SubCategory,
Brand: data?.Brand ? data?.Brand : '',
AutoGenerateQr: data?.AutoGenerateQrcode
? data?.AutoGenerateQrcode
: 'No',
QRCode: data?.AddQrCode,
StockAvailable: data?.StockAvailable ? data?.StockAvailable : 'No',
TaxId: data?.Tax ? data?.Tax : 'NIL - 0%',
Cess: data?.Cess,
HSNCode: data?.HSN,
PartNumber: data?.PartNumber,
Rack: data?.Rack,
ManufDate: moment(data?.ManufactureDate, ['M/D/YY']).format(
'YYYY-MM-DDTHH:mm:ss'
),
ExpDate: moment(data?.ExpireDate, ['M/D/YY']).format(
'YYYY-MM-DDTHH:mm:ss'
),
AvailableFrom: data?.AvailableFrom
? moment(data?.AvailableFrom, ['M/D/YY']).format('HH:mm:ss')
: '',
AvailableTo: data?.AvailableTo
? moment(data?.AvailableTo, ['M/D/YY']).format('HH:mm:ss')
: '',
OnePcsAvailable: data?.Amountperpiece ? data?.Amountperpiece : 'No',
OnePcsPrice: data?.AmountperpiecePrice,
// NoOfPcs:data?.NumberOfPieceInside,
AutoGenerateSingleQr: data?.AutoGenerateOnePieceQrcode
? data?.AutoGenerateOnePieceQrcode
: 'No',
OnePcQR: data?.AutoGenerateOnePieceQrcodeNumber,
// ProductType:data?.ProductType,
TokenAvailable: data?.TokenAvailable ? data?.TokenAvailable : 'No',
ProdLogo: data?.Productimage,
}));
let postDatas = { prodDetails: formattedData };
let response = await dispatch(bulkpostdata(postDatas)).unwrap();
if (response?.data?.statusCode == 1) {
setMessageType('success');
setMessageData(response?.data?.response);
setBulkpost(false);
setpage(1);
var responseData = await dispatch(
getProductDataPageNo({ CompId, BranchId, AppId, PageNumber: 1 })
).unwrap();
setCurrentPage(1);
if (responseData?.data?.statusCode === 1) {
setCachedData({ [currentPage]: responseData?.data?.data });
setproductData(responseData?.data?.data);
}
} else {
setMessageType('error');
setMessageData(responseData?.data?.response);
}
handleResetExcelData();
handleCancel();
} else {
setMessageType('error');
setMessageData('No data to submit. Please upload an Excel file.');
}
};
const Unit = UomPreference?.map((e) => e.ConfigName);
const CategoryId = ProdCatData?.map((e) => e.ConfigId);
const CategoryNames = ProdCatData?.map((e) => e.ConfigName);
const CatconfigId = ProdCatData?.map((e) => e.ConfigId);
const Subcatnames = subCatData?.map((e) => e.ConfigName);
const SubcatId = subCatData?.map((e) => e.ConfigId);
const SubcatNumFId = subCatData?.map((e) => e.NumFId);
const BrandNumFId = allBrandData?.map((e) => e.NumFId);
const BrandId = allBrandData?.map((e) => e.ConfigId);
const BrandName = allBrandData?.map((e) => e.ConfigName);
const SuplierNames = SupplierData?.map((e) => e.SuppName);
const TaxDatas = TaxData?.map((e) => e.TaxIdName);
const TaxData1 = TaxData?.map((e) => e.TaxPercentage);
const combinedTaxData = TaxDatas?.map(
(taxIdName, index) => `${taxIdName} - ${TaxData1[index]}%`
);
const Deletebulk = async () => {
let data = {
AppId: AppId,
CompId: CompId,
BranchId: BranchId,
ProdId: selectedRowKeys,
};
let res = await dispatch(Deletebulkdatas(data)).unwrap();
if (res?.data?.statusCode == 1) {
setMessageData('Product Deleted Successfully');
setMessageType('success');
setRangeFrom(null);
setRangeTo(null);
setSelectedRowKeys([]);
setisDelete(false);
let response = await dispatch(
getProductDataPageNo({
CompId: CompId,
BranchId: BranchId,
AppId: AppId,
PageNumber: currentPage,
})
).unwrap();
if (response?.data?.statusCode === 1) {
setCachedData((prev) => ({
...prev,
[currentPage]: response?.data?.data,
})); // Cache the new data
setproductData(response?.data?.data);
} else {
setCachedData({});
setproductData([]);
}
setDeleteProductPages([]);
setDeleteInput();
} else {
setMessageType('error');
setMessageData(res?.data?.response);
}
};
useEffect(() => {
if (ProdId) {
try {
const svg = document.createElementNS(
'http://www.w3.org/2000/svg',
'svg'
);
JsBarcode(svg, ProdId, {
format: 'CODE128',
displayValue: true,
lineColor: '#000',
width: 2,
height: 50,
});
setTimeout(() => {
convertSvgToBase64(svg);
}, 500);
} catch (error) {
console.error('Error generating barcode:', error);
}
}
}, [ProdId]);
const totalCopies = QrandbarcodeDatas?.reduce(
(sum, item) => sum + Number(item?.copiesCount || 0),
0
);
const convertSvgToBase64 = (svgElement) => {
try {
const svgData = new XMLSerializer().serializeToString(svgElement);
const svgBlob = new Blob([svgData], {
type: 'image/svg+xml;charset=utf-8',
});
const reader = new FileReader();
reader.onloadend = () => {
setBarcodeBase64Image(reader.result);
};
reader.readAsDataURL(svgBlob);
} catch (error) {
console.error('Error converting barcode to Base64:', error);
}
};
const getBarcodeSessionData = async () => {
try {
let resp = await dispatch(getBarcodeSessionsIDs()).unwrap();
if (resp?.data?.statusCode === 1) {
setCoresdata(
resp?.data?.data?.filter(
(item) => !item.ConfigName?.includes('100X13 (55MM Printable Gold)')
) || []
);
} else {
setCoresdata([]);
}
} catch (error) {
console.error('Error fetching barcode session data:', error);
}
};
const imageTagBarcodeAndQR = (w = 'auto', fs = '6px', codeData = null) => {
const currentCode = codeData || ProdId;
console.log(currentCode, '1111111111', codeData);
return (
(templateOptions.barcode || templateOptions.qrcode) && (
<>

{templateOptions.codeType !== 'B' && (
{currentCode}
)}
>
)
);
};
const generateBarcode = (code) => {
try {
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
JsBarcode(svg, code, {
format: 'CODE128',
displayValue: false,
lineColor: '#030303',
width: 2,
height: 40,
});
const svgData = new XMLSerializer().serializeToString(svg);
return `data:image/svg+xml;base64,${btoa(svgData)}`;
} catch (error) {
return null;
}
};
// const generateQRCode = (code) => {
// return base64Image;
// };
const generateCodeImage = (code, codeType = 'Q') => {
if (codeType === 'B') {
return generateBarcode(code);
} else {
return generateQRCode(code);
}
};
const handleQRStickerPrinterModelCancel = () => {
setDropdownValue();
setCopies();
setOpen(false);
formRef?.current?.resetFields();
setSelectedRecords([]);
setQrandbarcodeDatas([])
setMultiCode(false);
setNickName(null);
};
const handleProcessMultipleOCR = async (formDataArray) => {
if (formDataArray.length === 0) return;
setIsOCRProcessing({ Length: formDataArray.length, Loader: true });
try {
const combinedFormData = new FormData();
formDataArray.forEach((formData, index) => {
const imageBlob = formData.get('image');
combinedFormData.append(
`image${index}`,
imageBlob,
`cropped${index}.jpg`
);
});
const Response = await dispatch(PostPedalOCR(combinedFormData)).unwrap();
if (Response?.data?.statusCode === 1 && Response?.data?.data) {
setBreadData(
Response.data.data?.map((e) => ({
...e,
Products: e?.Products?.map((p) => ({
...p,
NoOfUnits: 1,
UOM: 'PCS',
})),
}))
);
setMessageType('success');
setMessageData(`${formDataArray.length} images processed successfully`);
setBreadModalOpen(true);
} else {
setMessageType('error');
setMessageData('No products found in images');
}
setOpenPaddleOCR(false);
setUploadedFiles([]);
} catch (error) {
setMessageType('error');
setMessageData('Error processing images');
console.error('OCR Error:', error);
} finally {
setIsOCRProcessing({ Length: 0, Loader: false });
}
};
const handleBulkUpload = async () => {
if (breadData?.length === 0) {
setMessageType('error');
setMessageData('No products to upload');
return;
}
const Postdata =
breadData?.flatMap(
(p) =>
p?.Products?.map((e) => ({
AppId,
CompId,
BranchId,
CreatedBy: UserId,
ProdName: e?.Product,
ProdVariantName: '',
ProdCat: p?.Category,
ProdSubCat: '',
Brand: '',
PartNumber: '',
HSNCode: '',
UOM: e?.UOM,
Size: e?.NoOfUnits,
MRP: e?.MRP,
SellPrice: e?.MRP,
WhSalePrice: '',
TaxId: 'NIL - 0%',
StockAvailable: 'No',
OnePcsAvailable: 'No',
TokenAvailable: 'No',
AutoGenerateQr: 'No',
AutoGenerateSingleQr: 'No',
OnePcQR: '',
QRCode: '',
Rack: '',
AvailableFrom: null,
AvailableTo: null,
ManufDate: null,
ExpDate: null,
})) || []
) || [];
console.log(Postdata, 'Postdata');
const response = await dispatch(
bulkpostdata({ ProdDetails: Postdata })
).unwrap();
};
useEffect(() => {
const from = parseInt(rangeFrom, 10);
const to = parseInt(rangeTo, 10);
let newRangeIds = [];
if (
!isNaN(from) &&
!isNaN(to) &&
from > 0 &&
to > 0 &&
from <= to &&
to <= AllProdIds.length
) {
newRangeIds = AllProdIds.slice(from - 1, to).map((p) => p.ProdId);
}
const idsToRemove = lastRangeIdsRef.current.filter(
(id) => !newRangeIds.includes(id)
);
const idsToAdd = newRangeIds.filter(
(id) => !lastRangeIdsRef.current.includes(id)
);
setSelectedRowKeys((prev) => {
const withRemoved = prev.filter((id) => !idsToRemove.includes(id));
const withAdded = [...withRemoved, ...idsToAdd];
return Array.from(new Set(withAdded));
});
lastRangeIdsRef.current = newRangeIds;
}, [rangeFrom, rangeTo, AllProdIds]);
const tableData = useMemo(() => {
return SearchProdData?.length > 0
? [...CachedDataSearch[page]]
: [...productData];
}, [SearchProdData, CachedDataSearch, page, productData]);
return (
{/*
*/}
{/*
*/}
{/*
*/}
{
setOpenPaddleOCR(true);
}}
disabled={addnewAccess}
icon={}
/>
handelAddButton()}
color="901D77"
icon={}
/>
{!isCheckSportsApp && (
<>
}
/>
handelBulkAdd()}
color="901D77"
icon={}
/>
>
)}
{countOfProduct > 10 && (
`Total ${countOfProduct ? countOfProduct : 0} items`
}
/>
)}{' '}
{/*
*/}
{/* */}
{isDelete && selectedRowKeys?.length > 0 && (
{
Deletebulk();
}}
/>
)}
{!isDelete && MultiCode && selectedRecords?.length > 0 && (
{
setOpen(true);
}}
/>
)}
{/* */}
{/* */}
{MultiCode &&
setActiveTab('stock')}
>
Stock Wise
({selectedRecords?.length})
{
e.stopPropagation();
setstockWiseQrcode(true);
}}
style={{
animation: activeTab === 'stock' ? 'blink 1s infinite' : 'none'
}}>
Add
setActiveTab('product')}
>
Product Wise
({selectedRecords?.length})
{
e.stopPropagation();
setProductWiseQrcode(true);
}} style={{
animation: activeTab === 'product' ? 'blink 1s infinite' : 'none'
}}>
Add
}
{coresdata?.map((option) => (
CoresOnChange(option.ConfigName)}
className={`radio-sidebar-item ${dropdownValue === option.ConfigName ? 'selected' : ''}`}
>
{option.ConfigName}
))}
PREVIEW
{(() => {
const template = barcodeTemplateDetails?.find(
(find) => find.SessionName === dropdownValue
);
const templateAvailable =
template === undefined ? false : true;
// Define constants using the lookup map
const checkComponent = (name) =>
template?.OptionDetails?.some(
(some) => some.OptionName === name
);
const mrp = checkComponent('MRP');
const qrcode = checkComponent('Qrcode');
const barcode = checkComponent('Barcode');
const color = checkComponent('Color');
const eDate = checkComponent('E Date');
const mDate = checkComponent('M Date');
const sellingPrice = checkComponent('Selling Price');
const productName = checkComponent('Product Name');
const barcodeOrQr = template?.CodeType
? template?.CodeType === 'B'
: true;
// setPreviewTemplateOptions({
// mrp: mrp,
// barcode: barcode,
// color: color,
// eDate: eDate,
// mDate: mDate,
// sellingPrice: sellingPrice,
// productName: productName,
// value: template?.Position !== '' ? template?.Position : '',
// secondValue:
// template?.PositionString !== ''
// ? template?.PositionString
// : '',
// qrcode: qrcode,
// codeType: template?.CodeType,
// });
const templateValue =
template?.Position !== '' ? template?.Position : '';
switch (dropdownValue) {
case '15X15 6cross':
return templateAvailable ? (
!(productName || barcode || qrcode || mrp) ? (
) : (
<>
{[...Array(6)].map((_, index) => (
{(barcode || qrcode) &&
templateValue === 'T' &&
handleImageTag(
barcodeOrQr ? 50 : 20,
20,
barcodeOrQr
)}
{productName && (
12 ? 'text-ellipsis' : ''}`}
>
{nickName
? nickName
: proName
? proName
: 'Product Name'}
)}
{(barcode || qrcode) &&
templateValue === 'C' &&
handleImageTag(
barcodeOrQr ? 50 : 20,
20,
barcodeOrQr
)}
{mrp && (
{'₹:' +
(detail?.MRP
? detail?.MRP
: 0.0)}
)}
{(barcode || qrcode) &&
templateValue === 'B' &&
handleImageTag(
barcodeOrQr ? 50 : 20,
20,
barcodeOrQr
)}
))}
Vertical
{' '}
- {'15mm'}
Horizontal
{' '}
- {'15mm'}
>
)
) : (
<>
{Array.from({ length: 6 }).map(
(_, index) => (
)
)}
Vertical
{' '}
- {'15mm'}
Horizontal
{' '}
- {'15mm'}
>
);
case '22X35 3cross':
return templateAvailable ? (
//"B","T"
!(barcode || qrcode || mrp) ? (
) : (
<>
{[...Array(3)].map((_, index) => (
{(barcode || qrcode) &&
handleImageTag(
barcodeOrQr ? 100 : 35,
35,
barcodeOrQr
)}
{(productName || mrp) && (
{productName && (
12 ? 'text-ellipsis' : ''}`}
>
{nickName
? nickName
: (proName || 'Product Name')}
)}
{mrp && (
{'₹:' +
(detail?.MRP
? detail?.MRP
: 10.0)}
)}
)}
))}
Vertical
{' '}
- {'22mm'}
Horizontal
{' '}
- {'35mm'}
>
)
) : (
<>
{Array?.from({ length: 3 })?.map(
(_, index) => (
8 ? 'text-ellipsis' : ''}`}
>
{proName || 'Product Name'} ({size || '1 PCS'})
{ProdId || 'QR579890770'}
)
)}
Vertical
{' '}
- {'22mm'}
Horizontal
{' '}
- {'35mm'}
>
);
case '25X25 4cross':
return templateAvailable ? (
!(
productName ||
mDate ||
eDate ||
barcode ||
qrcode ||
mrp
) ? (
) : (
// 4 Cross idhu 25 * 25 * 25 * 25 = 1 inch
<>
{[...Array(4)].map((_, index) => (
{(barcode || qrcode) &&
templateValue === 'T' &&
handleImageTag(
barcodeOrQr ? 60 : 35,
35,
barcodeOrQr
)}
{productName && (
12 ? 'text-ellipsis' : ''}`}
>
{nickName
? nickName
: proName
? proName
: 'Product Name'}
)}
{mrp && (
{'₹:' +
(detail?.MRP
? detail?.MRP
: 10.0)}
)}
{(barcode || qrcode) &&
templateValue === 'C' &&
handleImageTag(
barcodeOrQr ? 60 : 35,
35,
barcodeOrQr
)}
{mDate && (
)}
{eDate && (
DD-MM-YYYY
)}
{(barcode || qrcode) &&
templateValue === 'B' &&
handleImageTag(
barcodeOrQr ? 60 : 35,
35,
barcodeOrQr
)}
))}
Vertical
{' '}
- {'25mm'}
Horizontal
{' '}
- {'25mm'}
>
)
) : (
<>
{Array.from({ length: 4 })?.map(
(_, index) => (
12 ? 'text-ellipsis' : ''}`}
>
{nickName
? nickName
: proName
? proName
: 'Product Name'}
({size || '1 PCS'})
{ProdId || 'QR8575956'}
)
)}
Vertical
{' '}
- {'25mm'}
Horizontal
{' '}
- {'25mm'}
>
);
case '25X50 2cross':
return templateAvailable ? (
//"B","T"
!(productName || barcode || qrcode || mrp) ? (
) : (
<>
{[...Array(2)].map((_, index) => (
{(barcode || qrcode) &&
handleImageTag(
barcodeOrQr ? 140 : 30,
30,
barcodeOrQr
)}
{productName && (
12 ? 'text-ellipsis' : ''}`}
>
{nickName
? nickName
: proName
? proName
: 'Product Name'}
)}
{mrp && (
{'₹:' +
(detail?.MRP
? detail?.MRP
: 10.0)}
)}
))}
Vertical
{' '}
- {'25mm'}
Horizontal
{' '}
- {'50mm'}
>
)
) : (
<>
{Array.from({ length: 2 })?.map(
(_, index) => (
12 ? 'text-ellipsis' : ''}`}
>
{proName || 'Product Name'} ({size || '1 PCS'})
{ProdId || 'QR74478578'}
)
)}
Vertical
{' '}
- {'25mm'}
Horizontal
{' '}
- {'50mm'}
>
);
case '50X30 Single':
return templateAvailable ? (
!(
productName ||
mDate ||
eDate ||
barcode ||
qrcode ||
mrp
) ? (
) : (
<>
{productName && (
12 ? 'text-ellipsis' : ''}`}
>
{nickName
? nickName
: proName
? proName
: 'Product Name'}
)}
{mDate &&
detail?.ProdVariantPriceDetails?.[0]
?.ManufDate && (
{formatDate(
detail
?.ProdVariantPriceDetails?.[0]
?.ManufDate
)}
)}
{eDate &&
detail?.ProdVariantPriceDetails?.[0]
?.ExpDate && (
{formatDate(
detail
?.ProdVariantPriceDetails?.[0]
?.ExpDate
)}
)}
{(barcode || qrcode) &&
handleImageTag(
barcodeOrQr ? 70 : 35,
35,
barcodeOrQr
)}
{mrp && (
{'MRP : ' + (detail?.MRP || 10.0)}
)}
Vertical
{' '}
- {'30mm'}
Horizontal
{' '}
- {'50mm'}
>
)
) : (
<>
12 ? 'text-ellipsis' : ''}`}
>
{proName || 'Product Name'} ({size || '1 PCS'})
{ProdId || 'QR987968'}
Vertical
{' '}
- {'30mm'}
Horizontal
{' '}
- {'50mm'}
>
);
case '50X25 Single':
return templateAvailable ? (
!(
productName ||
mDate ||
barcode ||
qrcode ||
mrp
) ? (
) : (
<>
{productName && (
12 ? 'text-ellipsis' : ''}`}
>
{nickName
? nickName
: proName
? proName
: 'Product Name'}
)}
{mDate &&
detail?.ProdVariantPriceDetails?.[0]
?.ManufDate && (
{formatDate(
detail
?.ProdVariantPriceDetails?.[0]
?.ManufDate
)}
)}
{(barcode || qrcode) &&
handleImageTag(
barcodeOrQr ? 70 : 35,
35,
barcodeOrQr
)}
{mrp && (
{'MRP : ' + (detail?.MRP || '10.0')}
)}
Vertical
{' '}
- {'25mm'}
Horizontal
{' '}
- {'50mm'}
>
)
) : (
<>
12 ? 'text-ellipsis' : ''}`}
>
{proName || 'Product Name'} ({size || '1 PCS'})
{ProdId || 'QR8798639'}
Vertical
{' '}
- {'25mm'}
Horizontal
{' '}
- {'50mm'}
>
);
case '100X13 (55MM Printable)':
return templateAvailable ? (
//"C", "T", "B"
!(
productName ||
sellingPrice ||
barcode ||
qrcode
) ? (
) : (
<>
{(barcode || qrcode) &&
handleImageTag(
barcodeOrQr ? 140 : 35,
35,
barcodeOrQr
)}
{productName && (
12 ? 'text-ellipsis' : ''}`}
>
{nickName
? nickName
: proName
? proName
: 'Product Name'}
)}
{sellingPrice && (
{`Selling Price : ` +
(detail?.SellPrice || '10.0')}
)}
Vertical
{' '}
- {'13mm'}
Horizontal
{' '}
- {'100mm'}
>
)
) : (
<>
12 ? 'text-ellipsis' : ''}`}
>
{proName || 'Product Name'} ({size || '1 PCS'})
{ProdId || 'QR0970970'}
Vertical
{' '}
- {'13mm'}
Horizontal
{' '}
- {'100mm'}
>
);
case '100X15 (70MM Printable)':
return templateAvailable ? (
// "L","R"
!(
productName ||
sellingPrice ||
barcode ||
qrcode ||
mrp
) ? (
) : (
<>
{productName && (
12 ? 'text-ellipsis' : ''}`}
>
{nickName
? nickName
: proName
? proName
: 'Product Name'}
)}
{mrp && (
{'MRP : ' + (detail?.MRP || '10.0')}
)}
{sellingPrice && (
{`Selling Price : ` +
(detail?.SellPrice || '10.0')}
)}
{(barcode || qrcode) &&
handleImageTag(
barcodeOrQr ? 90 : 40,
null,
barcodeOrQr
)}
Vertical
{' '}
- {'15mm'}
Horizontal
{' '}
- {'100mm'}
>
)
) : (
<>
12 ? 'text-ellipsis' : ''}`}
>
{proName || 'Product Name'} ({size || '1 PCS'})
{ProdId || 'QR858755'}
Vertical
{' '}
- {'15mm'}
Horizontal
{' '}
- {'100mm'}
>
);
case '100X150':
return templateAvailable ? (
!(
productName ||
sellingPrice ||
mDate ||
eDate ||
color ||
barcode ||
qrcode ||
mrp
) ? (
) : (
<>
{productName && (
12 ? 'text-ellipsis' : ''}`}
>
{nickName
? nickName
: proName
? proName
: 'Product Name'}
)}
{sellingPrice && (
{`Selling Price : ` +
detail?.SellPrice}
)}
{mDate &&
detail?.ProdVariantPriceDetails?.[0]
?.ManufDate && (
{formatDate(
detail
?.ProdVariantPriceDetails?.[0]
?.ManufDate
)}
)}
{eDate &&
detail?.ProdVariantPriceDetails?.[0]
?.ExpDate && (
{formatDate(
detail
?.ProdVariantPriceDetails?.[0]
?.ExpDate
)}
)}
{color && (
{colorText}
)}
{(barcode || qrcode) &&
handleImageTag(
barcodeOrQr ? 140 : 35,
35,
barcodeOrQr
)}
{mrp && (
{'MRP : ' + (detail?.MRP || '10.0')}
)}
Vertical
{' '}
- {'150mm'}
Horizontal
{' '}
- {'100mm'}
>
)
) : (
<>
Product Name:{' '}
12 ? 'text-ellipsis' : ''}`}
>
{nickName
? nickName
: proName
? proName
: 'Product Name'}
SIZE:{' '}
{size || '1 PCS'}
Id:{' '}
{ProdId || 'QR86868'}
MRP:{' '}
{'MRP : ' + (detail?.MRP || '10.0')}
Selling Price:{' '}
{(detail?.SellPrice || '10.0')}
Vertical
{' '}
- {'150mm'}
Horizontal
{' '}
- {'100mm'}
>
);
default:
return
;
}
})()}
{dropdownValue}
{!MultiCode &&
{
await validateSafeInput(value); // To block HTML tags & SQL keywords
return Promise.resolve();
},
},
]}
>
Copies}
isOnChange={false}
onChange={(e) => {
CopiesOnChange(e?.target?.value);
}}
/>
}
{proName?.length > 12 && printProductName && !MultiCode && (
<>
Note: Product name is very long. Please add a short/nick
name to proceed print.
{
setNickName(e?.target?.value);
}}
maxLength={12}
/>
>
)}
{(!MultiCode || totalCopies > 0) && (
)}
{MultiCode && totalCopies === 0 && (
)}
}
/>
< div style={{ display: 'none' }}>
{selectedRecords?.length > 0
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
console.log(copyCount, "copyCountcopyCountcopyCount")
return Array.from({ length: copyCount })?.map((_, copyIndex) => (
));
})
: Array.from({ length: copies })?.map((_, index) => (
))}
{selectedRecords?.length > 0
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
return Array?.from({ length: copyCount })?.map((_, copyIndex) => (
8 ? 'text-ellipsis' : ''}`}
>
{record.ProdName} ({record.Size}
{record.UomName})
{record.QRCode}
))
}
)
: Array?.from({ length: copies })?.map((_, index) => (
8 ? 'text-ellipsis' : ''}`}
>
{proName} ({size})
{ProdId}
))}
{(selectedRecords?.length > 0)
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
console.log(copyCount, 'copyCount2')
return Array.from({ length: copyCount })?.map((_, copyIndex) => (
14 ? 'text-ellipsis' : ''}`}
>
{record?.NickName || record?.ProdName}
({record?.Size}
{record?.UomName})
{record?.QRCode || record?.ProdId}
))
}
)
: Array.from({ length: copies })?.map((_, index) => (
14 ? 'text-ellipsis' : ''}`}
>
{nickName
? nickName
: proName
? proName
: 'Product Name'}
({size})
{ProdId}
))}
{selectedRecords?.length > 0
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
console.log(copyCount, 'copyCount3')
return Array.from({ length: copyCount })?.map((_, copyIndex) => (
12 ? 'text-ellipsis' : ''}`}
>
{record?.NickName || record?.ProdName} ({record?.Size}
{record?.UomName})
{record?.QRCode || record?.ProdId}
))
})
: Array.from({ length: copies })?.map((_, index) => (
12 ? 'text-ellipsis' : ''}`}
>
{proName} ({size})
{ProdId}
))}
{selectedRecords?.length > 0
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
console.log(copyCount, 'copyCount4')
return Array.from({ length: copyCount })?.map((_, copyIndex) => (
12 ? 'text-ellipsis' : ''}`}
>
{record?.NickName || record?.ProdName} ({record?.Size}
{record?.UomName})
{record?.QRCode || record?.ProdId}
))
})
: Array.from({ length: copies })?.map((_, index) => (
12 ? 'text-ellipsis' : ''}`}
>
{proName} ({size})
{ProdId}
))}
{selectedRecords?.length > 0
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
console.log(copyCount, 'copyCount5')
return Array.from({ length: copyCount })?.map((_, copyIndex) => (
12 ? 'text-ellipsis' : ''}`}
>
{record?.NickName || record?.ProdName} ({record?.Size}
{record?.UomName})
{record?.QRCode || record?.ProdId}
))
})
: Array.from({ length: copies })?.map((_, index) => (
12 ? 'text-ellipsis' : ''}`}
>
{proName} ({size})
{ProdId}
))}
{selectedRecords?.length > 0
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
console.log(copyCount, 'copyCount6')
return Array.from({ length: copyCount })?.map((_, copyIndex) => (
12 ? 'text-ellipsis' : ''}`}
>
{record?.NickName || record?.ProdName} ({record?.Size}
{record?.UomName})
{record?.QRCode || record?.ProdId}
))
})
: Array.from({ length: copies })?.map((_, index) => (
12 ? 'text-ellipsis' : ''}`}
>
{proName} ({size})
{ProdId}
))}
{selectedRecords?.length > 0
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
console.log(copyCount, 'copyCount7')
return Array.from({ length: copyCount })?.map((_, copyIndex) => (
12 ? 'text-ellipsis' : ''}`}
>
{record?.NickName || record?.ProdName} ({record?.Size}
{record?.UomName})
{record?.QRCode || record?.ProdId}
))
})
: Array.from({ length: copies })?.map((_, index) => (
12 ? 'text-ellipsis' : ''}`}
>
{proName} ({size})
{ProdId}
))}
{selectedRecords?.length > 0
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
console.log(copyCount, 'copyCount8')
return Array.from({ length: copyCount })?.map((_, copyIndex) => (
{record?.BrName || detail?.BrName}
Product Name:{' '}
12 ? 'text-ellipsis' : ''}`}
>
{record?.NickName || record?.ProdName}
SIZE:{' '}
{record?.Size}
{record?.UomName}
Id:{' '}
{record?.QRCode || record?.ProdId}
MRP:{' '}
{'MRP : ' + record?.MRP}
Selling Price:{' '}
{record?.SellPrice}
))
})
: Array.from({ length: copies })?.map((_, index) => (
Product Name:{' '}
12 ? 'text-ellipsis' : ''}`}
>
{proName}
SIZE: {size}
Id: {ProdId}
MRP:{' '}
{'MRP : ' + detail?.MRP}
Selling Price:{' '}
{detail?.SellPrice}
))}
{selectedRecords?.length > 0
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
return Array.from({ length: copyCount })?.map((_, copyIndex) => {
const hasProductName = !!templateOptions.productName;
const hasMrp = !!templateOptions.mrp;
const hasMDate = templateOptions.mDate && record?.ManufDate;
const hasEDate = templateOptions.eDate && record?.ExpDate;
// IMAGE SIZE LOGIC
let imageSize = 50;
if (!hasMDate && !hasEDate) {
imageSize = 52;
}
if (!hasProductName || !hasMrp) {
imageSize = 60;
}
if (!hasProductName && !hasMrp) {
imageSize = 80;
}
// FLEX DIRECTION LOGIC
const forceColumnLayout =
!hasProductName || !hasMrp || (!hasMDate && !hasEDate);
return (
{templateOptions.value === 'T' && (
{imageTagBarcodeAndQR(
templateOptions.codeType === 'B'
? '90%'
: `${imageSize}%`,
'7px',
record?.QRCode || record?.ProdId
)}
)}
{hasProductName && (
12 ? 'text-ellipsis' : ''}`}
>
{record?.NickName || record?.ProdName}
)}
{hasMrp && (
{'₹' + record?.MRP}
)}
{templateOptions.value === 'C' && (
{imageTagBarcodeAndQR(
templateOptions.codeType === 'B'
? '90%'
: `${imageSize}%`,
'7px',
record?.QRCode || record?.ProdId
)}
)}
{(hasMDate || hasEDate) && (
{hasMDate && (
{hasMDate && !hasEDate ? 'MFG: ' : ''}
{formatDate(record?.ManufDate)}
)}
{hasMDate && hasEDate && (
|
)}
{hasEDate && (
{!hasMDate && hasEDate ? 'EXP: ' : ''}
{formatDate(record?.ExpDate)}
)}
)}
{templateOptions.value === 'B' && (
{imageTagBarcodeAndQR(
templateOptions.codeType === 'B'
? '25mm'
: `${imageSize}%`,
'7px',
record?.QRCode || record?.ProdId
)}
)}
);
})
}
)
: Array.from({ length: copies })?.map((_, index) => {
const hasProductName = !!templateOptions.productName;
const hasMrp = !!templateOptions.mrp;
const hasMDate =
templateOptions.mDate &&
detail?.ProdVariantPriceDetails?.[0]?.ManufDate;
const hasEDate =
templateOptions.eDate &&
detail?.ProdVariantPriceDetails?.[0]?.ExpDate;
// IMAGE SIZE LOGIC
let imageSize = 50;
if (!hasMDate && !hasEDate) {
imageSize = 52;
}
if (!hasProductName || !hasMrp) {
imageSize = 60;
}
if (!hasProductName && !hasMrp) {
imageSize = 80;
}
// FLEX DIRECTION LOGIC
const forceColumnLayout =
!hasProductName || !hasMrp || (!hasMDate && !hasEDate);
return (
{templateOptions.value === 'T' && (
{imageTagBarcodeAndQR(
templateOptions.codeType === 'B'
? '90%'
: `${imageSize}%`,
'7px'
)}
)}
{hasProductName && (
12 ? 'text-ellipsis' : ''}`}
>
{nickName
? nickName
: proName
? proName
: 'Product Name'}
)}
{hasMrp && (
{'₹' + detail?.MRP}
)}
{templateOptions.value === 'C' && (
{imageTagBarcodeAndQR(
templateOptions.codeType === 'B'
? '90%'
: `${imageSize}%`,
'7px'
)}
)}
{(hasMDate || hasEDate) && (
{hasMDate && (
{hasMDate && !hasEDate ? 'MFG: ' : ''}
{formatDate(
detail?.ProdVariantPriceDetails?.[0]
?.ManufDate
)}
)}
{hasMDate && hasEDate && (
|
)}
{hasEDate && (
{!hasMDate && hasEDate ? 'EXP: ' : ''}
{formatDate(
detail?.ProdVariantPriceDetails?.[0]?.ExpDate
)}
)}
)}
{templateOptions.value === 'B' && (
{imageTagBarcodeAndQR(
templateOptions.codeType === 'B'
? '25mm'
: `${imageSize}%`,
'7px'
)}
)}
);
})}
{selectedRecords?.length > 0
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
return Array.from({ length: copyCount })?.map((_, copyIndex) => (
{imageTagBarcodeAndQR(
templateOptions.codeType === 'B' ? '90%' : '35%',
'6px',
record?.QRCode || record?.ProdId
)}
{templateOptions.productName && (
12 ? 'text-ellipsis' : ''}`}
>
{record?.NickName || record?.ProdName}
)}
{templateOptions.mrp && (
{'MRP : ' + record?.MRP}
)}
))
}
)
: Array.from({ length: copies })?.map((_, index) => (
{imageTagBarcodeAndQR(
templateOptions.codeType === 'B' ? '90%' : '35%'
)}
{templateOptions.productName && (
12 ? 'text-ellipsis' : ''}`}
>
{proName}
)}
{templateOptions.mrp && (
{'MRP : ' + detail?.MRP}
)}
))}
{selectedRecords?.length > 0
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
return Array.from({ length: copyCount })?.map((_, copyIndex) => (
{templateOptions.productName && (
12 ? 'text-ellipsis' : ''}`}
>
{record?.NickName || record?.ProdName}
)}
{templateOptions.mDate && record?.ManufDate && (
{record?.ManufDate}
)}
{templateOptions.eDate && record?.ExpDate && (
{record?.ExpDate}
)}
{imageTagBarcodeAndQR(
'70%',
'6px',
record?.QRCode || record?.ProdId
)}
{templateOptions.mrp && (
{'MRP : ' + record?.MRP}
)}
))
}
)
: Array.from({ length: copies })?.map((_, index) => (
{templateOptions.productName && (
12 ? 'text-ellipsis' : ''}`}
>
{nickName
? nickName
: proName
? proName
: 'Product Name'}
)}
{templateOptions.mDate &&
detail?.ProdVariantPriceDetails?.[0]?.ManufDate && (
{detail?.ProdVariantPriceDetails?.[0]?.ManufDate}
)}
{templateOptions.eDate &&
detail?.ProdVariantPriceDetails?.[0]?.ExpDate && (
{detail?.ProdVariantPriceDetails?.[0]?.ExpDate}
)}
{imageTagBarcodeAndQR('70%')}
{templateOptions.mrp && (
{'MRP : ' + detail?.MRP}
)}
))}
{selectedRecords?.length > 0
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
return Array.from({ length: copyCount })?.map((_, copyIndex) => (
{templateOptions.productName && (
12 ? 'text-ellipsis' : ''}`}
>
{record?.NickName || record?.ProdName}
)}
{templateOptions.mDate && record?.ManufDate && (
{record?.ManufDate}
)}
{templateOptions.eDate && record?.ExpDate && (
{record?.ExpDate}
)}
{imageTagBarcodeAndQR(
'90%',
'6px',
record?.QRCode || record?.ProdId
)}
{templateOptions.mrp && (
{'MRP : ' + record?.MRP}
)}
))
}
)
: Array.from({ length: copies })?.map((_, index) => (
{templateOptions.productName && (
12 ? 'text-ellipsis' : ''}`}
>
{nickName
? nickName
: proName
? proName
: 'Product Name'}
)}
{templateOptions.mDate &&
detail?.ProdVariantPriceDetails?.[0]?.ManufDate && (
{detail?.ProdVariantPriceDetails?.[0]?.ManufDate}
)}
{templateOptions.eDate &&
detail?.ProdVariantPriceDetails?.[0]?.ExpDate && (
{detail?.ProdVariantPriceDetails?.[0]?.ExpDate}
)}
{imageTagBarcodeAndQR('90%')}
{templateOptions.mrp && (
{'MRP : ' + detail?.MRP}
)}
))}
{selectedRecords?.length > 0
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
return Array.from({ length: copyCount })?.map((_, copyIndex) => (
{imageTagBarcodeAndQR(
'auto',
'6px',
record?.QRCode || record?.ProdId
)}
{templateOptions.productName && (
{'Product Name :' +
(record?.NickName || record?.ProdName)}
)}
{templateOptions.sellingPrice && (
{'Selling Price :' + record?.SellPrice}
)}
))
}
)
: Array.from({ length: copies })?.map((_, index) => (
{imageTagBarcodeAndQR()}
{templateOptions.productName && (
{'Product Name :' + proName}
)}
{templateOptions.sellingPrice && (
{'Selling Price :' + detail?.SellPrice}
)}
))}
{selectedRecords?.length > 0
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
return Array.from({ length: copyCount })?.map((_, copyIndex) => (
{templateOptions.productName && (
12 ? 'text-ellipsis' : ''}`}
>
{'Product Name: ' +
(record?.NickName || record?.ProdName)}
)}
{templateOptions.mrp && (
{'MRP : ' + record?.MRP}
)}
{templateOptions.sellingPrice && (
{'Selling Price :' + record?.SellPrice}
)}
{imageTagBarcodeAndQR(
'auto',
'6px',
record?.QRCode || record?.ProdId
)}
))
}
)
: Array.from({ length: copies })?.map((_, index) => (
{templateOptions.productName && (
12 ? 'text-ellipsis' : ''}`}
>
{'Product Name' + proName}
)}
{templateOptions.mrp && (
{'MRP : ' + detail?.MRP}
)}
{templateOptions.sellingPrice && (
{'Selling Price :' + detail?.SellPrice}
)}
{imageTagBarcodeAndQR()}
))}
{selectedRecords?.length > 0
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
return Array.from({ length: copyCount })?.map((_, copyIndex) => (
{templateOptions.productName && (
12 ? 'text-ellipsis' : ''}`}
>
{'Product Name: ' +
(record?.NickName || record?.ProdName)}
)}
{templateOptions.sellingPrice && (
{'Selling Price :' + record?.SellPrice}
)}
{templateOptions.mDate && record?.ManufDate && (
{record?.ManufDate}
)}
{templateOptions.eDate && record?.ExpDate && (
{record?.ExpDate}
)}
{templateOptions.color && (
{record?.Color || colorText}
)}
{
{imageTagBarcodeAndQR(
'70%',
'6px',
record?.QRCode || record?.ProdId
)}
}
{templateOptions.mrp && (
{'MRP : ' + record?.MRP}
)}
))
}
)
: Array.from({ length: copies })?.map((_, index) => (
{templateOptions.productName && (
12 ? 'text-ellipsis' : ''}`}
>
{'Product Name' + (nickName ? nickName : proName)}
)}
{templateOptions.sellingPrice && (
{'Selling Price :' + detail?.SellPrice}
)}
{templateOptions.mDate &&
detail?.ProdVariantPriceDetails?.[0]?.ManufDate && (
{detail?.ProdVariantPriceDetails?.[0]?.ManufDate}
)}
{templateOptions.eDate &&
detail?.ProdVariantPriceDetails?.[0]?.ExpDate && (
{detail?.ProdVariantPriceDetails?.[0]?.ExpDate}
)}
{templateOptions.color && (
{colorText}
)}
{
{imageTagBarcodeAndQR('70%')}
}
{templateOptions.mrp && (
{'MRP : ' + detail?.MRP}
)}
))}
{selectedRecords?.length > 0
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
return Array.from({ length: copyCount })?.map((_, copyIndex) => (
{templateOptions.value === 'T' &&
imageTagBarcodeAndQR(
templateOptions.codeType === 'B' ? '100%' : '50%',
'6px',
record?.QRCode || record?.ProdId
)}
{templateOptions.productName && (
{record?.NickName
? record?.NickName
: record?.ProdName}
)}
{templateOptions.value === 'C' &&
imageTagBarcodeAndQR(
templateOptions.codeType === 'B'
? '80%'
: !templateOptions.productName &&
!templateOptions.mrp
? '80%'
: '35%',
'6px',
record?.QRCode || record?.ProdId
)}
{templateOptions.mrp && (
{'₹:' + record?.MRP}
)}
{templateOptions.value === 'B' &&
imageTagBarcodeAndQR(
templateOptions.codeType === 'B' ? '100%' : '50%',
'6px',
record?.QRCode || record?.ProdId
)}
))
}
)
: Array.from({ length: copies })?.map((_, index) => (
{templateOptions.value === 'T' &&
imageTagBarcodeAndQR(
templateOptions.codeType === 'B' ? '100%' : '50%'
)}
{templateOptions.productName && (
12 ? 'text-ellipsis' : ''}`}
>
{nickName
? nickName
: proName
? proName
: 'Product Name'}
)}
{templateOptions.value === 'C' &&
imageTagBarcodeAndQR(
templateOptions.codeType === 'B'
? '80%'
: !templateOptions.productName &&
!templateOptions.mrp
? '80%'
: '35%'
)}
{templateOptions.mrp && (
{'₹:' + (detail?.MRP ? detail?.MRP : 10.0)}
)}
{templateOptions.value === 'B' &&
imageTagBarcodeAndQR(
templateOptions.codeType === 'B' ? '100%' : '50%'
)}
))}
{/* //Qrcode */}
{selectedRecords?.length > 0
? selectedRecords?.map((record, recordIndex) => {
const copyCount = generateQRCodeCopy(record?.QRCode);
return Array.from({ length: copyCount })?.map((_, copyIndex) => (
{imageTagBarcodeAndQR(
templateOptions.codeType === 'B'
? '100%'
: !templateOptions.mrp &&
!templateOptions.productName
? '60%'
: '40%',
'8px',
record?.QRCode || record?.ProdId
)}
{(templateOptions.productName ||
templateOptions.mrp) && (
{templateOptions.productName && (
12 ? 'text-ellipsis' : ''}`}
>
{record?.NickName
? record?.NickName
: record?.ProdName}
)}
{templateOptions.mrp && (
{'MRP : ' + record?.MRP}
)}
)}
))
}
)
: Array.from({ length: copies })?.map((_, index) => (
{imageTagBarcodeAndQR(
templateOptions.codeType === 'B'
? '100%'
: !templateOptions.mrp && !templateOptions.productName
? '60%'
: '40%',
'8px'
)}
{(templateOptions.productName || templateOptions.mrp) && (
{templateOptions.productName && (
12 ? 'text-ellipsis' : ''}`}
>
{nickName
? nickName
: proName
? proName
: 'Product Name'}
)}
{templateOptions.mrp && (
{'MRP : ' + detail?.MRP}
)}
)}
))}
0 ? 2500 : 600}
className={'bulkuploadmodal'}
children={
<>
{Bulkpost && (
)}
>
}
handleSubmit={handleSubmit}
handleCancel={handleCancel}
/>
{imagedata?.map((item, index) => (
setSelectedImage(item)}
>
))}
}
handleSubmit={submitimage}
handleCancel={handleimage}
/>
{ }}
handleClose={handleImageModalClose}
/>
}
/>
Scan Menu Card
}
handleCancel={() => {
setOpenPaddleOCR(false);
setUploadedFile(null);
setUploadedFiles([]);
setBreadData([]);
}}
footer={false}
width={600}
children={
}
/>
setBreadModalOpen(false)}
footer={false}
children={
<>
{
handleBulkUpload(breadData);
setBreadModalOpen(false);
setBreadData([]);
}}
icon={}
htmlType={true}
/>
>
}
/>
setstockWiseQrcode(false)}
handleSubmit={() => {
if (totalCopies == 0) {
message.error("Please enter copies count")
return;
}
else {
setstockWiseQrcode(false)
onFinish();
}
}}
footer={true}
children={
<>