import React, { useCallback, useEffect, useState } from 'react'; import { useLocation, useNavigate } from 'react-router-dom'; import { useDispatch } from 'react-redux'; import { Button, Form, Input, Space } from 'antd'; import { PlusOutlined } from '@ant-design/icons'; import { Messages } from '../../Components/Notifications/Messages'; import { Tables } from '../../Components/Tables/Table'; import { Search } from '../../Components/Forms/Search'; import { changeBreadCrumb, getEmpAccess, } from '../../Features/AppPage/CenterPage.js'; import Buttons from '../../Components/Forms/Buttons'; import { getSession, printDiv, pdfDiv } from '../../Services/Others'; import FormHeader from '../PageComponents/FormHeader.jsx'; import { useAuth } from '../../AuthContext.jsx'; import '../../Styles/OverAllStyle/OverAllStyle.scss'; import { getDeliveryChallan } from '../../Features/DeliveryChallan/DeliveryChallan.js'; import { DefaultModal } from '../../Components/Modal/DefaultModal.jsx'; import { IoEye } from 'react-icons/io5'; import { MdOutlineMail } from 'react-icons/md'; import { FaPrint } from 'react-icons/fa'; import DeliveryPrint from './DeliveryPrint.jsx'; import { DCPrintStyleFunction } from './DCPrintStyleFunction.js'; import { Emailsend } from '../../Features//PurchaseOrder/PurchaseOrder.js'; import { getPrintSelectionComponentData } from '../../Features/ThemeChange/ThemeChange.js'; const subDirectory = import.meta.env.ENV_BASE_URL; const items = [ { name: 'Home', link: `${subDirectory}app-page/home`, }, { name: 'Delivery Challan / list', link: `${subDirectory}setting/delivery-challan`, }, ]; const DeliveryChallanList = () => { const [form] = Form.useForm(); const location = useLocation(); const { SadminuserAccess } = useAuth(); let SAAccessCommonMaster = SadminuserAccess?.find( (e) => e?.MenuName === 'Delivery Challan' ); console.log(SadminuserAccess, 'SadminuserAccess', SAAccessCommonMaster); const [page, setpage] = useState(1); const CompId = getSession('CompId'); const BranchId = getSession('BranchId'); const AppId = getSession('AppId'); const UserId = getSession('UserId'); const UserType = getSession('UserType'); const navigateTo = useNavigate(); const dispatch = useDispatch(); const [DCPrintTemplateStyle, setDCPrintTemplateStyle] = useState(null); const [DCPrintTemplateDtl, setDCPrintTemplateDtl] = useState(null); const [tabledata, setTabledata] = useState(); const [messageType, setMessageType] = useState(null); const [messageData, setMessageData] = useState(null); const [filteredInfo, setFilteredInfo] = useState({}); const [searchedText, setSearchedText] = useState(''); const [sortedInfo, setSortedInfo] = useState({}); const [empData, setEmpData] = useState(); const [addnewAccess, setaddnewAccess] = useState(true); const [ProductShow, setProductShow] = useState(false); const [ProductDetails, setProductDetails] = useState(); const [PrintingData, setPrintingData] = useState([]); const [iSEmail, setiSEmail] = useState(false); const [enteredEmail, setEnteredEmail] = useState(''); const [pendingOrderDetails, setPendingOrderDetails] = useState(null); const [pendingRecord, setPendingRecord] = useState(null); console.log(ProductDetails, 'ProductDetails'); const PurchaseOrderStyle = ``; const handelAddButton = () => { navigateTo(`${subDirectory}setting/delivery-challan`); }; const handleChange = (pagination, filters, sorter) => { setFilteredInfo(filters); setSortedInfo(sorter); }; const handlePageChange = (current) => { setpage(current); }; async function fetchData() { if (location?.state?.Notiffy) { setMessageType(location?.state?.Notiffy.messageType); setMessageData(location?.state?.Notiffy.messageData); } } useEffect(() => { fetchData(); TableData(); dispatch(changeBreadCrumb({ items: items })); getPrintData() // 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]); 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 === 'Delivery Challan' ); setEmpData(datas?.[0]); }; const TableData = async () => { let response = await dispatch( getDeliveryChallan({ CompId: CompId, BranchId: BranchId, AppId: AppId }) ).unwrap(); if (response?.data?.statusCode == 1) { setTabledata(response?.data?.data); } }; const getPrintData = async () => { let data = { CompId: CompId, BranchId: BranchId, AppId: AppId, }; let response = await dispatch(getPrintSelectionComponentData(data)).unwrap(); if(response?.data?.statusCode === 1) { let DCPrintTemplate = response?.data?.data?.[0]?.ComponentDetails?.find( (item) => item.SetasDefault == 'Y' && item.PrintTypeName === 'Delivery Chalan' ); console.log(DCPrintTemplate,response?.data?.data?.[0]?.ComponentDetails?.find( (item) => item.SetasDefault == 'Y' && item.PrintTypeName === 'Delivery Chalan' ), 'DCPrintTemplate'); setDCPrintTemplateStyle(DCPrintTemplate?.StyleName); setDCPrintTemplateDtl(DCPrintTemplate); } }; const actionsFormatter = async (row, rowIndex) => { if (row.ActiveStatus !== 'D') { navigateTo( `${subDirectory}setting/dinein-master/edit`, { state: { editstate: row } }, { key: rowIndex } ); } }; const onSearch = (value) => { setSearchedText(value); }; const onSearchChange = (e) => { setSearchedText(e?.target?.value); }; const onComplete = useCallback(() => { setMessageData(null); setMessageType(null); }, []); const handlePrint = (OrderDetails, record) => { const orderData = { OrderId: record?.PurOrderId, PurOrderDate: record?.PurOrderDate, SupplierName: record?.SuppName, SuppMobile: record?.SuppMobile, SuppGSTIN: record?.SuppGSTIN, Remarks: record?.Remarks, DCNo: record?.DCNo, DCDate: record?.DCDate, CustMobile: record?.CustMobile, CustName: record?.CustName, TransporterName: record?.TransporterName, ModeOfTransport: record?.ModeOfTransport, TransporterId: record?.TransporterId, ProductDetails: record?.ProductDetails || [], TotalAmount: record?.TotalAmount, }; setPrintingData([orderData]); print() }; const print=async()=>{ const DCstyle = await DCPrintStyleFunction( DCPrintTemplateStyle == undefined ? 'Style 13' : DCPrintTemplateStyle); const stylesMap = { 'Style 1': 'DCPrintStyle1', 'Style 2': 'DCPrintStyle2', 'Style 3': 'DCPrintStyle3', 'Style 4': 'DCPrintStyle4', 'Style 5': 'DCPrintStyle5', 'Style 6': 'DCPrintStyle6', 'Style 7': 'DCPrintStyle7', 'Style 8': 'DCPrintStyle8', 'Style 9': 'DCPrintStyle9', 'Style 10': 'DCPrintStyle10', 'Style 11': 'DCPrintStyle11', 'Style 12': 'DCPrintStyle12', 'Style 13': 'DC-Default-Print', A4: 'DCPrintStyleA4', A5: 'DCPrintStyleA5', A4Standard: 'DCPrintStyleA4Standard', }; const selectedStyle = stylesMap[ DCPrintTemplateStyle == undefined ? 'Style 13' : DCPrintTemplateStyle ]; console.log(selectedStyle,DCstyle, 'selectedStyle'); setTimeout(() => { printDiv(`${selectedStyle}`, DCstyle); }, 100); } const handleEmailClick = async (ProductDetails, record) => { // alert("This feature is not available yet. Please contact support for assistance."); const orderData = { 0: { ...record }, customerName: record?.CustName || '', CustName: record?.CustName || '', customerAddress: record?.AddressDetails || '', Address1: record?.AddressDetails || '', customerMobile: record?.CustMobile || '', MobileNo: record?.CustMobile || '', CustMail: record?.CustEmail, }; // setPrintData(record); if (orderData?.CustMail) { setTimeout(async () => { try { const blob = await pdfDiv('Pur-Order-Print', PurchaseOrderStyle); console.log(blob, 'blobblob'); const payload = { fileBlob: blob, toEmail: orderData?.CustMail, type: 'PurchaseOrder', messageTemplatesList: [], }; const res = await dispatch(Emailsend(payload))?.unwrap(); console.log('✅ API Response:', res?.data || res); setMessageData('Email sent successfully'); setMessageType('success'); } catch (error) { console.error('❌ Email send failed:', error); setMessageData('Email failed to send'); setMessageType('error'); } }, 300); } else { setPendingOrderDetails(ProductDetails); setPendingRecord(record); setiSEmail(true); } }; const handleSendEmailWithEnteredEmail = async (values) => { const record = { ...pendingRecord, CustEmail: values.email }; await handleEmailClick(pendingOrderDetails, record); setiSEmail(false); setPendingOrderDetails(null); setPendingRecord(null); form.resetFields(); }; const columns = [ { title: 'Sl.No', key: 'sno', align: 'center', // width: '100px', render: (text, object, index) => ( {(page - 1) * 10 + index + 1} ), }, { title: 'Customer Name', dataIndex: 'CustName', key: 'CustName', // width: '150px', render: (text, object, index) => ( {object?.CustName || object?.CustMobile} ), filteredValue: [searchedText], onFilter: (value, record) => { return ( String(record.CustShortName) .toLowerCase() .includes(value.toLowerCase()) || String(record.CustName).toLowerCase().includes(value.toLowerCase()) || String(record.CustMobile).toLowerCase().includes(value.toLowerCase()) ); }, }, { title: 'Mode Of Transport', dataIndex: 'ModeOfTransport', key: 'ModeOfTransport', // width: '150px', // }, // { // title: 'Transporter Name', // dataIndex: 'TransporterName', // key: 'TransporterName', // width: '150px', // // // }, { title: 'Products', dataIndex: 'TransporterName', key: 'TransporterName', width: '150px', render: (_, record) => ( { setProductShow(true); setProductDetails(record?.ProductDetails); }} /> ), // }, { title: 'Shared Product Details', key: 'Order Details', dataIndex: 'OrderDetails', align: 'center', render: (OrderDetails, record) => (
handleEmailClick(OrderDetails, record)} /> handlePrint(OrderDetails, record)} />
), }, // { // title: 'Chair Count', // dataIndex: 'ChairCount', // key: 'ChairCount', // width: '100px', // align: 'right', // render: (text) => {text}, // filteredValue: filteredInfo.ChairCount || null, // onFilter: (value, record) => record.ChairCount.includes(value), // sorter: (a, b) => a?.ChairCount?.length - b?.ChairCount?.length, // sortOrder: // sortedInfo.columnKey === 'ChairCount' ? sortedInfo.order : null, // ellipsis: true, // }, // { // title: 'DineIn Type', // dataIndex: 'DineInTypeName', // key: 'DineInTypeName', // render: (text) => {text}, // filteredValue: filteredInfo.CompName || null, // onFilter: (value, record) => record.DineInTypeName.includes(value), // sorter: (a, b) => a?.DineInTypeName?.length - b?.DineInTypeName?.length, // sortOrder: // sortedInfo.columnKey === 'DineInTypeName' ? sortedInfo.order : null, // ellipsis: true, // }, // { // title: 'Chair Level Serve', // dataIndex: 'ChairLevelSer', // key: 'ChairLevelSer', // render: (text) => {text}, // filteredValue: filteredInfo.ChairLevelSer || null, // onFilter: (value, record) => record.ChairLevelSer.includes(value), // sorter: (a, b) => a?.ChairLevelSer?.length - b?.ChairLevelSer?.length, // sortOrder: // sortedInfo.columnKey === 'ChairLevelSer' ? sortedInfo.order : null, // ellipsis: true, // }, // { // title: 'Chair Name', // dataIndex: 'ChairLevelSerDetails', // key: 'ChairLevelSerDetails', // width: '150px', // render: (ChairLevelSerDetails) => ( // // {ChairLevelSerDetails?.length > 0 // ? ChairLevelSerDetails?.map((item) => item.ChairName).join(',') // : ' - '} // // ), // }, // { // title: 'Action', // key: 'Action', // dataIndex: 'Action', // render: (_, record, index) => // tabledata.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, // }, ]; const Productcolumns = [ { title: 'Sl.No', key: 'sno', align: 'center', width: '100px', render: (text, object, index) => ( {(page - 1) * 10 + index + 1} ), }, { title: 'Product ', dataIndex: 'ProdName', key: 'ProdName', width: '150px', // }, { title: 'Variant', dataIndex: 'ProdVariantName', key: 'ProdVariantName', width: '150px', // }, { title: 'Qty', dataIndex: 'Qty', key: 'Qty', width: '150px', // }, // { // title: 'Chair Count', // dataIndex: 'ChairCount', // key: 'ChairCount', // width: '100px', // align: 'right', // render: (text) => {text}, // filteredValue: filteredInfo.ChairCount || null, // onFilter: (value, record) => record.ChairCount.includes(value), // sorter: (a, b) => a?.ChairCount?.length - b?.ChairCount?.length, // sortOrder: // sortedInfo.columnKey === 'ChairCount' ? sortedInfo.order : null, // ellipsis: true, // }, // { // title: 'DineIn Type', // dataIndex: 'DineInTypeName', // key: 'DineInTypeName', // render: (text) => {text}, // filteredValue: filteredInfo.CompName || null, // onFilter: (value, record) => record.DineInTypeName.includes(value), // sorter: (a, b) => a?.DineInTypeName?.length - b?.DineInTypeName?.length, // sortOrder: // sortedInfo.columnKey === 'DineInTypeName' ? sortedInfo.order : null, // ellipsis: true, // }, // { // title: 'Chair Level Serve', // dataIndex: 'ChairLevelSer', // key: 'ChairLevelSer', // render: (text) => {text}, // filteredValue: filteredInfo.ChairLevelSer || null, // onFilter: (value, record) => record.ChairLevelSer.includes(value), // sorter: (a, b) => a?.ChairLevelSer?.length - b?.ChairLevelSer?.length, // sortOrder: // sortedInfo.columnKey === 'ChairLevelSer' ? sortedInfo.order : null, // ellipsis: true, // }, // { // title: 'Chair Name', // dataIndex: 'ChairLevelSerDetails', // key: 'ChairLevelSerDetails', // width: '150px', // render: (ChairLevelSerDetails) => ( // // {ChairLevelSerDetails?.length > 0 // ? ChairLevelSerDetails?.map((item) => item.ChairName).join(',') // : ' - '} // // ), // }, // { // title: 'Action', // key: 'Action', // dataIndex: 'Action', // render: (_, record, index) => // tabledata.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, // }, ]; return (
handelAddButton()} disabled={addnewAccess} color="901D77" icon={} > OPEN
} handleCancel={() => { setProductShow(false); }} /> setiSEmail(false)} footer={false} children={
} />
); }; export default DeliveryChallanList;