import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import QrImage from '../../../Images/QRcode.png';
import { extractLastNumber, extractLastNumberOrderId } from '../../../Services/Others';
import {
    GlobalprintSlNo,
    GlobalprintItem,
    GlobalprintMRP,
    GlobalprintDiscount,
    GlobalprintQuantity,
    GlobalprintRate,
    GlobalprintAmount,
    GlobalprintHsnCode,
    GlobalprintQrcodet,
    GlobalPritdummyData,
    changeReprintDataFound,
    GloabalFieldDetails,
    GlobalprintSignature,
    GlobalprinttermsAndConditions,
    GlobalSignatureImage,
    Globalnotes,
    GlobalthemeFormat,
    GlobalBillName,
} from '../../../Features/ThemeChange/ThemeChange';
import { GlobalUpiIDprint } from '../../../Features/BookingScreen/BookingData/BookingData';
import '../../../Styles/BookingScreen/PrintTemplates/ThermalPrinter/PrintStyle8.scss';
import signature from "../../../Images/signatureimage.jpg"
import { ApplicationPreferences } from '../../../Features/BrachLogin/BranchLogin';

const PurchaseOrdStyle8 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, BranchAddress, BranchCity, BranchZip, CashierName, totalQuantity, OrderDetailGST, OrderDetailIGST,
    OrderDetailVAT, table2Data, PrintGreeting, printDatas }) => {

    const dispatch = useDispatch();
    const GlobalUpiID = useSelector(GlobalUpiIDprint)
    // const FieldDetails = useSelector(GloabalFieldDetails);
    
    const FieldDetails = printDatas?.FieldDetails?.reduce((acc, item) => {
        acc[item.ConfigName] = true;
        return acc;
    }, {});
    const SLNO = FieldDetails?.["Sl.No"];
    const Item = FieldDetails?.["Item"];
    const MRP = FieldDetails?.["MRP"];
    const Discount = FieldDetails?.["Discount"];
    const Quantity = FieldDetails?.["Quantity"];
    const Rate = FieldDetails?.["Rate"];
    const Amount = FieldDetails?.["Amount"];
    const HsnCode = FieldDetails?.["HsnCode"];
    const Qrcodet = FieldDetails?.["Qrcode"];
    const GlobalSlNo = useSelector(GlobalprintSlNo);
    const GlobalItem = useSelector(GlobalprintItem);
    const GlobalMRP = useSelector(GlobalprintMRP);
    const GlobalDiscount = useSelector(GlobalprintDiscount);
    const GlobalQuantity = useSelector(GlobalprintQuantity);
    const GlobalRate = useSelector(GlobalprintRate);
    const GlobalAmount = useSelector(GlobalprintAmount);
    const GlobalHsnCode = useSelector(GlobalprintHsnCode);
    const GlobalQrcodet = useSelector(GlobalprintQrcodet);
    const GlobaldummyData = useSelector(GlobalPritdummyData);
    const GlobalSignature = useSelector(GlobalprintSignature);
    const GlobaltermsAndConditions = useSelector(GlobalprinttermsAndConditions);
    const GlobalSignatureImages = useSelector(GlobalSignatureImage);
    const GlobalIsnotes = useSelector(Globalnotes);
    const GlobalthemeFormatr = useSelector(GlobalthemeFormat)
    const GlobalBilltext = useSelector(GlobalBillName)
    const appPreferences = useSelector(ApplicationPreferences);
    const bookingTypePreference = appPreferences?.find((preference) => preference?.PreferredCatName === 'Booking Type')?.PreferenceCatDetails
    const dinePreference = bookingTypePreference?.find((type) => type?.PreferredSubCatName?.toLowerCase() === "dine in" && type?.PreferredStatus === 'Y')
    const takeAwayPreference = bookingTypePreference?.find((type) => type?.PreferredSubCatName?.toLowerCase() === "take away" && type?.PreferredStatus === 'Y')

    console.log(GlobalDiscount, Discount, "Discount");

    let TermsAndConditions = printDatas?.TermsandConditions
    let SignatureImg = printDatas?.Signature
    let Notestext = printDatas?.Notes
    let BillName = printDatas?.PrintHdrName
    let FormatTheme = printDatas?.PrintType == "S" ? true : false
    let PageSize = printDatas?.PageSize;
    const Signature = FieldDetails?.["signature"];
    const TermsnAdCondition = FieldDetails?.["terms&conditions"];

    const keysLength = Object.keys(table2Data ?? {}).length;
    if (keysLength > 0) {
        dispatch(changeReprintDataFound(true));
    }

    const currentDate = new Date();
    const day = currentDate.getDate().toString().padStart(2, '0');
    const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
    const monthIndex = currentDate.getMonth();
    const year = currentDate.getFullYear().toString().slice(-2);

    const formattedDate = `${day}-${monthNames[monthIndex]}-${year}`;

    const productsData = table2Data?.productDetails || [];
    console.log('productsData:', productsData); // Debug log
    const offers = table2Data?.OrderOfferDetails || [];



    console.log(printDatas, "printDatasjk")
    const chunkSize = PageSize == "A5" ? 10 : 16;
    // Assign dataSource directly from table2Data.productDetails
    let dataSource = table2Data?.productDetails || [];

    // Paginate the data
    const paginatedChunks = [];
    for (let i = 0; i < dataSource.length; i += chunkSize) {
        paginatedChunks.push(dataSource.slice(i, i + chunkSize));
    }
    const lastChunkRows = paginatedChunks.length > 0 ? paginatedChunks[paginatedChunks.length - 1].length : 0;
    const shouldFooterBeOnNewPage = lastChunkRows > (PageSize == "A5" ? 5 : 13);
    console.log(paginatedChunks, "paginatedChunks");


    const purchaseData = table2Data?.productDetails || [];
    const calculatedTotalQuantity = purchaseData?.reduce((total, item) => {
        return total + (Number(item?.SalesQty) || 0);
    }, 0);
    return (
        <>
            {FormatTheme ?
                <div id={`PrintStyle8`} className='PrintStyle8MasterDiv' style={{ fontFamily: "'Courier New', Courier, monospace", position: "relative", width: "100%", minHeight: PageSize == "A5" ? '210mm' : '297mm' }}>
                    {paginatedChunks.map((dataChunk, chunkIndex) => (
                        <div className={`container print-chunk${chunkIndex > 0 ? ' print-page-break' : ''}`} style={{ display: "flex", flexDirection: "column", justifyContent: ((chunkIndex === paginatedChunks.length - 1) && (!shouldFooterBeOnNewPage)) && FormatTheme ? "space-between" : "", height: FormatTheme ? PageSize == "A5" ? '170mm' : "257mm" : "", }} key={chunkIndex}>


                            <div className="header" style={{ position: "fixed", top: 0, width: "100%" }}>
                                <div className='PrintStyle8-fistDiv' style={{}} >
                                    {/* <h3>{table2Data?.BrName}</h3> */}
                                    <div style={{ fontSize: "clamp(1.25rem, 2.5vw, 1.75rem)", fontWeight: '600', }} >{table2Data?.BrName}</div>
                                    <div className='PrintStyle8-BrAddress' style={{ fontSize: "clamp(0.63rem, 2.5vw, 1.2rem)" }}>
                                        {BranchAddress || ''} {BranchCity ? (BranchAddress && BranchCity ? '-' : '') + BranchCity : ''} {BranchZip ? (BranchCity && BranchZip ? '-' : '') + BranchZip : ''}
                                    </div>
                                    <div className='PrintStyle8-BrAddress' style={{ fontSize: "clamp(0.63rem, 2.5vw, 1.2rem)" }}>  Mobile : +91 {table2Data?.BrMobile}</div>
                                </div>
                                {table2Data?.OrderType === "E" && <div className='PrintStyle4-FourthSpan' style={{ textTransform: 'uppercase', fontWeight: '600' }}>Estimate </div>}

                                {table2Data?.OrderType === "E" ? "" : <div className='PrintStyle4-FourthSpan' style={{ textTransform: 'uppercase', fontWeight: '600' }}>{BillName ? BillName : "Payment" + ' Bill'}</div>}

                                <div className='PrintStyle8-SecondDiv'>
                                    {/* <div style={{ fontWeight: '600' }}>Purchase Order No :{table2Data?.OrderId && extractLastNumberOrderId(table2Data?.OrderId, table2Data?.FYStatus)}</div> */}
                                    <div style={{ fontSize: "clamp(0.63rem, 2.5vw, 1.2rem)" }}>{formattedDate}</div>
                                </div>

                                <hr className="PrintStyle8-print-dottline" />
                            </div>
                            <div style={{ marginTop: "0rem" }} className="print-body">
                                {(productsData?.length > 0) &&
                                    <>
                                        <div className="PrintStyle8-print-tableMaster">
                                            <table className="PrintStyle8-print-table">
                                                <thead>
                                                    <tr>
                                                        {SLNO && <th style={{ width: "10px", textAlign: "center" }}>S.No</th>}
                                                        {Item && <th>Dis</th>}
                                                        {HsnCode && <th style={{ width: "10px", textAlign: "right" }}>HSN</th>}
                                                        {MRP && <th style={{ width: "10px", textAlign: "right" }}>MRP</th>}
                                                        {Rate && <th style={{ width: "10px", textAlign: "right" }}>Rate</th>}
                                                        {Discount && <th style={{ width: "10px", textAlign: "right" }}>(%)</th>}
                                                        {Quantity && <th style={{ width: "10px", textAlign: "right" }}>Qty</th>}
                                                        {Amount && <th style={{ width: "10px", textAlign: "right" }}>Amt</th>}
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    {dataChunk?.map((item, index) => {
                                                        return (
                                                            <tr key={index}>
                                                                {SLNO && <td style={{ textAlign: 'center' }}>{chunkIndex * chunkSize + index + 1}</td>}
                                                                {Item && <td>{item?.ProdName}</td>}
                                                                {HsnCode && <td>{item?.HSN}</td>}
                                                                {MRP && <td style={{ textAlign: 'right' }}>{item?.MRP}</td>}
                                                                {Rate && <td style={{ textAlign: 'right' }}>{item?.Rate}</td>}
                                                                {Discount && <td style={{ textAlign: 'right' }}>{item?.discount}</td>}
                                                                {Quantity && <td style={{ textAlign: 'right' }}>{item?.SalesQty}</td>}
                                                                {Amount && <td style={{ width: "10px", textAlign: 'right' }}>{item?.TotalAmt}</td>}
                                                            </tr>
                                                        )
                                                    })}
                                                </tbody>
                                            </table>
                                        </div>
                                    </>
                                }
                            </div>

                            {((chunkIndex === paginatedChunks.length - 1) && (!shouldFooterBeOnNewPage)) && FormatTheme &&

                                <>
                                    <hr className="PrintStyle8-print-dottline" />


                                    <div className='PrintStyle8-FourthDiv'>

                                        <div className='PrintStyle8-FourthP'>
                                            <div>
                                                {((OrderDetailGST?.length > 0 && OrderDetailGST?.[0]?.TaxAmt > 0) ||
                                                    (OrderDetailIGST?.length > 0 && OrderDetailIGST?.[0]?.TaxAmt > 0) ||
                                                    (OrderDetailVAT?.length > 0 && OrderDetailVAT?.[0]?.TaxAmt > 0)) &&
                                                    <>
                                                        <hr className="PrintStyle8-print-dottline" />

                                                        <div>
                                                            <p style={{ margin: 0, padding: 0, fontSize: "12px", textAlign: "center" }}>
                                                                --------- GST Breakup Details -----------</p>
                                                            {(OrderDetailGST?.length > 0 && OrderDetailGST?.[0]?.TaxAmt > 0) &&
                                                                <table style={{ width: "90%" }}>

                                                                    <tr>
                                                                        <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                            Taxable Amount
                                                                        </td>
                                                                        <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                            CGST ({(OrderDetailGST?.[0]?.TaxPercentage) / 2}%)
                                                                        </td>
                                                                        <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                            SGST ({(OrderDetailGST?.[0]?.TaxPercentage) / 2}%)
                                                                        </td>
                                                                        <td style={{ fontSize: "10px", textAlign: "center" }}>

                                                                            Total Amount
                                                                        </td>
                                                                    </tr>
                                                                    {OrderDetailGST?.map((item) =>
                                                                        <tr>
                                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                                {Number(item.WithOutTaxAmount).toFixed(2)}
                                                                            </td>
                                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                                {Number(item.CGST).toFixed(2)}
                                                                            </td>
                                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                                {Number(item.SGST).toFixed(2)}
                                                                            </td>
                                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>{Number(item.TotalAmt).toFixed(2)}</td>
                                                                        </tr>
                                                                    )
                                                                    }
                                                                </table>
                                                            }

                                                            {(OrderDetailIGST?.length > 0 && OrderDetailIGST?.[0]?.TaxAmt > 0) &&
                                                                <>
                                                                    <div style={{ border: "0.01px dashed black", margin: "10px 0 5px 10px", width: '90%' }}></div>
                                                                    <table style={{ width: "90%" }}>

                                                                        <tr>
                                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                                Taxable Amount
                                                                            </td>
                                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                                IGST ({OrderDetailIGST?.[0]?.TaxPercentage}%)
                                                                            </td>

                                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>

                                                                                Total Amount
                                                                            </td>
                                                                        </tr>
                                                                        {OrderDetailIGST?.map((item) =>
                                                                            <tr>
                                                                                <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                                    {Number(item.WithOutTaxAmount).toFixed(2)}
                                                                                </td>
                                                                                <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                                    {Number(item.TaxAmt).toFixed(2)}
                                                                                </td>

                                                                                <td style={{ fontSize: "10px", textAlign: "center" }}>{Number(item.TotalAmt).toFixed(2)}</td>
                                                                            </tr>
                                                                        )
                                                                        }
                                                                    </table>
                                                                </>
                                                            }
                                                            {(OrderDetailVAT?.length > 0 && OrderDetailVAT?.[0]?.TaxAmt > 0) &&
                                                                <>
                                                                    <div style={{ border: "0.01px dashed black", margin: "10px 0 5px 10px", width: '90%' }}></div>
                                                                    <table style={{ width: "90%" }}>

                                                                        <tr>
                                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                                Taxable Amount
                                                                            </td>
                                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                                VAT ({OrderDetailVAT?.[0]?.TaxPercentage}%)
                                                                            </td>

                                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>

                                                                                Total Amount
                                                                            </td>
                                                                        </tr>
                                                                        {OrderDetailVAT?.map((item) =>
                                                                            <tr>
                                                                                <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                                    {Number(item.WithOutTaxAmount).toFixed(2)}
                                                                                </td>
                                                                                <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                                    {Number(item.TaxAmt).toFixed(2)}
                                                                                </td>

                                                                                <td style={{ fontSize: "10px", textAlign: "center" }}>{Number(item.TotalAmt).toFixed(2)}</td>
                                                                            </tr>
                                                                        )
                                                                        }
                                                                    </table>
                                                                </>
                                                            }

                                                        </div>
                                                        <hr className="PrintStyle8-print-dottline" />

                                                    </>
                                                }
                                            </div>
                                        </div>

                                    </div>


                                    <hr className="PrintStyle8-print-dottline" />

                                    <div className='PrintStyle8-Qr-Order'>

                                        <div className='PrintStyle8-OrderNo'>
                                            {/* <p>Split Payment:</p> */}
                                            {/* {Object.keys(aggregatedPayments).map((paymentType) => ( */}
                                            {/*     <div key={paymentType} style={{ margin: 0, padding: 0, fontSize: "12px" }}> */}
                                            {/*         {paymentType}: {aggregatedPayments[paymentType].toFixed(2)} */}
                                            {/*     </div> */}
                                            {/* ))} */}
                                        </div>

                                        {/* <div style={{ marginLeft: '14px', padding: 0, fontSize: "12px", fontWeight: "600" }}> Cashier : {CashierName}</div> */}

                                        {/* {CashierName && CashierName !== undefined && CashierName !== null &&
                                            <div style={{ marginLeft: '14px', padding: 0, fontSize: "12px", fontWeight: "600" }}>Cashier : {CashierName}
                                            </div>
                                        } */}
                                        <div style={{ marginLeft: '14px', padding: 0, fontSize: "12px", fontWeight: "600" }}> Supplier Name : {table2Data?.CustSuppName}</div>


                                        {(table2Data?.BookingTypeName === "Dine In" && dinePreference) && <div style={{ marginLeft: '14px', padding: 0, fontSize: "12px", fontWeight: "600" }}>Waiter: {table2Data?.SalesTableLinkDetails?.[0]?.WaiterName}</div>}
                                    </div>



                                    <div className="page-footerA4Style11"
                                        style={{
                                            marginTop: "auto",
                                            pageBreakBefore: "avoid",
                                            pageBreakInside: "avoid",
                                            minHeight: "auto",
                                        }}
                                    >
                                        {
                                            Notestext && (<div>
                                                <p style={{ padding: "0rem 1rem" }}>{Notestext}</p>

                                                <hr className="PrintA4Style11-print-dottline" />
                                            </div>)
                                        }


                                        <div style={{ display: "flex", width: "90%", padding: "0 1rem", justifyContent: GlobaltermsAndConditions ? "space-between" : "flex-end", alignItems: "center" }}>
                                            {
                                                (TermsnAdCondition == true && TermsAndConditions?.length > 0) && (<div style={{ margin: "8px 0", fontFamily: "sans-serif", width: "100%", display: "flex", flexDirection: "column", alignItems: "flex-start" }}>
                                                    <p style={{ fontSize: "13px", fontWeight: "bold", marginBottom: "6px" }}>
                                                        Terms & Conditions
                                                    </p>
                                                    <ol style={{ fontSize: "12px", paddingLeft: "18px", margin: 0, lineHeight: "1" }}>
                                                        {TermsAndConditions?.map(item => (<li style={{ textAlign: "start" }}>{item?.TermsandConditions}</li>))}
                                                        {/* <li>Please check the product before leaving the counter.</li> */}
                                                    </ol>
                                                </div>)
                                            }

                                            {Signature == true && (<div style={{ display: "flex", flexDirection: "column", alignItems: "center", marginTop: "1rem", paddingBottom: "1rem" }}>
                                                <p style={{ fontSize: "13px", fontWeight: "bold", marginBottom: "6px" }}>Signature</p>
                                                <img style={{ width: "100px", height: "60px" }} src={SignatureImg} alt="" />
                                            </div>)}

                                        </div>
                                    </div>


                                    {PrintGreeting?.SettingValue === "Y" &&
                                        <div className='PrintStyle8-FourthSpan'>
                                            Thank You
                                        </div>
                                    }
                                </>
                            }
                        </div>
                    ))}



                </div>
                :
                <div id={`PrintStyle8`} className='PrintStyle8MasterDiv' style={{ fontFamily: "'Courier New', Courier, monospace" }}>
                    <div className='PrintStyle8-fistDiv' style={{}} >
                        {/* <h3>{table2Data?.BrName}</h3> */}
                        <div style={{ fontSize: "clamp(1.25rem, 2.5vw, 1.75rem)", fontWeight: '600', }} >{table2Data?.BrName}</div>
                        <div className='PrintStyle8-BrAddress' style={{ fontSize: "clamp(0.63rem, 2.5vw, 1.2rem)" }}>
                            {BranchAddress || ''} {BranchCity ? (BranchAddress && BranchCity ? '-' : '') + BranchCity : ''} {BranchZip ? (BranchCity && BranchZip ? '-' : '') + BranchZip : ''}
                        </div>
                        <div className='PrintStyle8-BrAddress' style={{ fontSize: "clamp(0.63rem, 2.5vw, 1.2rem)" }}>  Mobile : +91 {table2Data?.BrMobile}</div>
                    </div>
                    {table2Data?.OrderType === "E" && <div className='PrintStyle4-FourthSpan' style={{ textTransform: 'uppercase', fontWeight: '600' }}>Estimate </div>}

                    {table2Data?.OrderType === "E" ? "" : <div className='PrintStyle4-FourthSpan' style={{ textTransform: 'uppercase', fontWeight: '600' }}>{BillName ? BillName : "Payment" + ' Bill'}</div>}

                    <div className='PrintStyle8-SecondDiv'>
                        {/* <div style={{ fontWeight: '600' }}>Purchase Order No :{table2Data?.OrderId && extractLastNumberOrderId(table2Data?.OrderId, table2Data?.FYStatus)}</div> */}
                        <div style={{ fontSize: "clamp(0.63rem, 2.5vw, 1.2rem)" }}>{formattedDate}</div>
                    </div>

                    <hr className="PrintStyle8-print-dottline" />
                    {(productsData?.length > 0) &&
                        <>
                            <div className="PrintStyle8-print-tableMaster">
                                <table className="PrintStyle8-print-table">
                                    <thead>
                                        <tr>
                                            {SLNO && <th style={{ width: "10px", textAlign: "center" }}>S.No</th>}
                                            {Item && <th>Dis</th>}
                                            {HsnCode && <th style={{ width: "10px", textAlign: "right" }}>HSN</th>}
                                            {MRP && <th style={{ width: "10px", textAlign: "right" }}>MRP</th>}
                                            {Rate && <th style={{ width: "10px", textAlign: "right" }}>Rate</th>}
                                            {Discount && <th style={{ width: "10px", textAlign: "right" }}>(%)</th>}
                                            {Quantity && <th style={{ width: "10px", textAlign: "right" }}>Qty</th>}
                                            {Amount && <th style={{ width: "10px", textAlign: "right" }}>Amt</th>}
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {productsData?.map((item, index) => {
                                            return (
                                                <tr key={index}>
                                                    {SLNO && <td style={{ textAlign: 'center' }}>{index + 1}</td>}
                                                    {Item && <td>{item?.ProdName}</td>}
                                                    {HsnCode && <td>{item?.HSN}</td>}
                                                    {MRP && <td style={{ textAlign: 'right' }}>{item?.MRP}</td>}
                                                    {Rate && <td style={{ textAlign: 'right' }}>{item?.Rate}</td>}
                                                    {Discount && <td style={{ textAlign: 'right' }}>{item?.discount}</td>}
                                                    {Quantity && <td style={{ textAlign: 'right' }}>{item?.SalesQty}</td>}
                                                    {Amount && <td style={{ width: "10px", textAlign: 'right' }}>{item?.TotalAmt}</td>}
                                                </tr>
                                            )
                                        })}
                                    </tbody>
                                </table>
                            </div>
                        </>
                    }
                    <hr className="PrintStyle8-print-dottline" />


                    <div className='PrintStyle8-FourthDiv'>

                        <div className='PrintStyle8-FourthP'>
                            <div>
                                {((OrderDetailGST?.length > 0 && OrderDetailGST?.[0]?.TaxAmt > 0) ||
                                    (OrderDetailIGST?.length > 0 && OrderDetailIGST?.[0]?.TaxAmt > 0) ||
                                    (OrderDetailVAT?.length > 0 && OrderDetailVAT?.[0]?.TaxAmt > 0)) &&
                                    <>
                                        <hr className="PrintStyle8-print-dottline" />

                                        <div>
                                            <p style={{ margin: 0, padding: 0, fontSize: "12px", textAlign: "center" }}>
                                                --------- GST Breakup Details -----------</p>
                                            {(OrderDetailGST?.length > 0 && OrderDetailGST?.[0]?.TaxAmt > 0) &&
                                                <table style={{ width: "90%" }}>

                                                    <tr>
                                                        <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                            Taxable Amount
                                                        </td>
                                                        <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                            CGST ({(OrderDetailGST?.[0]?.TaxPercentage) / 2}%)
                                                        </td>
                                                        <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                            SGST ({(OrderDetailGST?.[0]?.TaxPercentage) / 2}%)
                                                        </td>
                                                        <td style={{ fontSize: "10px", textAlign: "center" }}>

                                                            Total Amount
                                                        </td>
                                                    </tr>
                                                    {OrderDetailGST?.map((item) =>
                                                        <tr>
                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                {Number(item.WithOutTaxAmount).toFixed(2)}
                                                            </td>
                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                {Number(item.CGST).toFixed(2)}
                                                            </td>
                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                {Number(item.SGST).toFixed(2)}
                                                            </td>
                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>{Number(item.TotalAmt).toFixed(2)}</td>
                                                        </tr>
                                                    )
                                                    }
                                                </table>
                                            }

                                            {(OrderDetailIGST?.length > 0 && OrderDetailIGST?.[0]?.TaxAmt > 0) &&
                                                <>
                                                    <div style={{ border: "0.01px dashed black", margin: "10px 0 5px 10px", width: '90%' }}></div>
                                                    <table style={{ width: "90%" }}>

                                                        <tr>
                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                Taxable Amount
                                                            </td>
                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                IGST ({OrderDetailIGST?.[0]?.TaxPercentage}%)
                                                            </td>

                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>

                                                                Total Amount
                                                            </td>
                                                        </tr>
                                                        {OrderDetailIGST?.map((item) =>
                                                            <tr>
                                                                <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                    {Number(item.WithOutTaxAmount).toFixed(2)}
                                                                </td>
                                                                <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                    {Number(item.TaxAmt).toFixed(2)}
                                                                </td>

                                                                <td style={{ fontSize: "10px", textAlign: "center" }}>{Number(item.TotalAmt).toFixed(2)}</td>
                                                            </tr>
                                                        )
                                                        }
                                                    </table>
                                                </>
                                            }
                                            {(OrderDetailVAT?.length > 0 && OrderDetailVAT?.[0]?.TaxAmt > 0) &&
                                                <>
                                                    <div style={{ border: "0.01px dashed black", margin: "10px 0 5px 10px", width: '90%' }}></div>
                                                    <table style={{ width: "90%" }}>

                                                        <tr>
                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                Taxable Amount
                                                            </td>
                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                VAT ({OrderDetailVAT?.[0]?.TaxPercentage}%)
                                                            </td>

                                                            <td style={{ fontSize: "10px", textAlign: "center" }}>

                                                                Total Amount
                                                            </td>
                                                        </tr>
                                                        {OrderDetailVAT?.map((item) =>
                                                            <tr>
                                                                <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                    {Number(item.WithOutTaxAmount).toFixed(2)}
                                                                </td>
                                                                <td style={{ fontSize: "10px", textAlign: "center" }}>
                                                                    {Number(item.TaxAmt).toFixed(2)}
                                                                </td>

                                                                <td style={{ fontSize: "10px", textAlign: "center" }}>{Number(item.TotalAmt).toFixed(2)}</td>
                                                            </tr>
                                                        )
                                                        }
                                                    </table>
                                                </>
                                            }

                                        </div>
                                        <hr className="PrintStyle8-print-dottline" />

                                    </>
                                }
                            </div>
                        </div>

                    </div>


                    <hr className="PrintStyle8-print-dottline" />

                    <div className='PrintStyle8-Qr-Order'>

                        <div className='PrintStyle8-OrderNo'>
                            {/* <p>Split Payment:</p> */}
                            {/* {Object.keys(aggregatedPayments).map((paymentType) => ( */}
                            {/*     <div key={paymentType} style={{ margin: 0, padding: 0, fontSize: "12px" }}> */}
                            {/*         {paymentType}: {aggregatedPayments[paymentType].toFixed(2)} */}
                            {/*     </div> */}
                            {/* ))} */}
                        </div>

                        {/* <div style={{ marginLeft: '14px', padding: 0, fontSize: "12px", fontWeight: "600" }}> Cashier : {CashierName}</div> */}

                        {/* {CashierName && CashierName !== undefined && CashierName !== null &&
                            <div style={{ marginLeft: '14px', padding: 0, fontSize: "12px", fontWeight: "600" }}>Cashier : {CashierName}</div>
                        } */}
                        <div style={{ marginLeft: '14px', padding: 0, fontSize: "12px", fontWeight: "600" }}> Supplier Name  : {table2Data?.CustSuppName}</div>


                        {table2Data?.BookingTypeName === "Dine In" && <div style={{ marginLeft: '14px', padding: 0, fontSize: "12px", fontWeight: "600" }}>Waiter: {table2Data?.SalesTableLinkDetails?.[0]?.WaiterName}</div>}
                    </div>



                    <div className="page-footerA4Style11"
                        style={{
                            marginTop: "auto",
                            pageBreakBefore: "avoid",
                            pageBreakInside: "avoid",
                            minHeight: "auto",
                        }}
                    >
                        {
                            Notestext && (<div>
                                <p style={{ padding: "0rem 1rem" }}>{Notestext}</p>

                                <hr className="PrintA4Style11-print-dottline" />
                            </div>)
                        }


                        <div style={{ display: "flex", width: "90%", padding: "0 1rem", justifyContent: GlobaltermsAndConditions ? "space-between" : "flex-end", alignItems: "center" }}>
                            {
                                (TermsnAdCondition == true && TermsAndConditions?.length > 0) && (<div style={{ margin: "8px 0", fontFamily: "sans-serif", width: "100%", display: "flex", flexDirection: "column", alignItems: "flex-start" }}>
                                    <p style={{ fontSize: "13px", fontWeight: "bold", marginBottom: "6px" }}>
                                        Terms & Conditions
                                    </p>
                                    <ol style={{ fontSize: "12px", paddingLeft: "18px", margin: 0, lineHeight: "1" }}>
                                        {TermsAndConditions?.map(item => (<li style={{ textAlign: "start" }}>{item?.TermsandConditions}</li>))}
                                        {/* <li>Please check the product before leaving the counter.</li> */}
                                    </ol>
                                </div>)
                            }

                            {Signature == true && (<div style={{ display: "flex", flexDirection: "column", alignItems: "center", marginTop: "1rem", paddingBottom: "1rem" }}>
                                <p style={{ fontSize: "13px", fontWeight: "bold", marginBottom: "6px" }}>Signature</p>
                                <img style={{ width: "100px", height: "60px" }} src={SignatureImg} alt="" />
                            </div>)}

                        </div>
                    </div>


                    {PrintGreeting?.SettingValue === "Y" &&
                        <div className='PrintStyle8-FourthSpan'>
                            Thank You
                        </div>
                    }

                </div>
            }

        </>
    )
}

export default PurchaseOrdStyle8
