import React, { useEffect, useState } from 'react';
import {
  Descriptions,
  Badge,
  Layout,
  Row,
  Col,
  Card,
  Button,
  Spin,
  Input,
} from 'antd';
import documentsFontSizeStyle from './documents-prints-style.module.css';
import './documents.css';
import { SaleOrderService } from '@gtpl/shared-services/sale-management';
import {
  ConditionsRequest,
  CrrencySymbols,
  FactoriesInput,
  PlantInvoiceDetailsModel,
  PlantInvoiceDetailsRequest,
  UnitsOfWeightInput,
} from '@gtpl/shared-models/sale-management';
import { AlertMessages } from '@gtpl/shared-utils/alert-messages';
import { ExporterDataInput } from '@gtpl/shared-models/logistics';
import { GlobalStatus, ModeOfExportEnum, UomEnum } from '@gtpl/shared-models/common-models';
import { useLocation } from 'react-router-dom';
import { PrinterOutlined } from '@ant-design/icons';
let converter = require('number-to-words');
import { numberToWords } from 'amount-to-words';
import ReactHTMLTableToExcel from 'react-html-table-to-excel';
import moment from 'moment';
import stampImage from './stamp.png';
import signature from './signature.png';
import { GlobalPriceChartService } from 'libs/shared-services/masters/src/lib/global-price-chart.service';

// import documentsStyle from './documents.module.css'
/* eslint-disable-next-line */
export interface PostPlantPackingListProps {
  saleOrderId: number;
}

export function PostPlantPackingList(props: PostPlantPackingListProps) {
  let location = useLocation();
  const salOrderService = new SaleOrderService();
  const [plantDetails, setPlantDetails] = useState<PlantInvoiceDetailsModel>();
  const soId = location.state;
  const [remarksData, setRemarksData] = useState<string>(undefined);
  const { TextArea } = Input;
  const defaultDeclaration =
    'We declare that this invoice shows the actual price of the goods described and that all particulars are true and correct';
  const [conditionRes, setConditionRes] = useState([]);
  console.log(conditionRes, 'consitionnnnnnnnnnnnresssssssssssss');
  let spanVal = 0;
  let adjustSpan = 0;
  let totalCases = 0;
  let totalLbWeight = 0;
  let totalGrossWeight = 0;
  let totalFrozenWeight = 0;
  let totalAmnt = 0;
  let netWeightInKgs = 0;
  let netWeightInLbs = 0;
  let totalAmount = 0;
  let lbPouchWeight;
  let kgPouchWeight;
  let totalAm = 0;
  let grossWeightInKg;
  let frozenWeightInKg;
  const [mainData, setMainData] = useState<any[]>([]);
  const globalPriceService = new GlobalPriceChartService();

  useEffect(() => {
    getAntiDumpingPrice();
  }, []);

  const getAntiDumpingPrice = () => {
    globalPriceService
      .getAntiDumpingPrice()
      .then((res) => {
        if (res.status) {
          setMainData(res.data);
        } else {
          setMainData([]);
        }
      })
      .catch((err) => {
        setMainData([]);
      });
  };

  const getData = (saleOrderId) => {
    const reqObj = new PlantInvoiceDetailsRequest(1);
    salOrderService
      .getPlantInvoiceDetails(new PlantInvoiceDetailsRequest(saleOrderId))
      .then((res) => {
        if (res.status) {
          setPlantDetails(res.data);
          res.data.gradeInfo.map((res) =>
            res.info.filter((val) => val.itemCode != null)
          );

          const request = new ConditionsRequest();
          console.log('Request object before API call:', request);
          request.country = res.data.country;
          request.frozenWeight = res.data.frozenWeight;
          request.grossWeight = res.data.grossWeight;
          request.notifyParty = res.data.notifyPartyOne;
          request.deliveryTerms = res.data.deliveryTerms;
          request.buyer = res.data.endCustomerName;
          request.buyerAddress = plantDetails?.saleOrderItems[0]?.buyerAddress;
          request.deliveryAddress =
            plantDetails?.saleOrderItems[0]?.deliveryaddress;
          request.grossWeightPerKg =
            plantDetails?.saleOrderItems[0]?.grossWeightPerKg;
          // request.code = plantDetails?.code;
          // request.productionDate = plantDetails?.productionDate;
          // request.bestBeforeDate = plantDetails?.bestBeforeDate;
          console.log('Request object after setting values:', request);

          salOrderService.getConditionsBasedLogistics(request).then((res) => {
            console.log('Response from getConditionsBasedLogistics:', res);
            if (res.status) {
              console.log('Condition response data:', res.data);
              setConditionRes(res.data);
            }
          });
        } else {
          if (res.intlCode) {
            setPlantDetails(undefined);
            AlertMessages.getErrorMessage(res.internalMessage);
          } else {
            AlertMessages.getErrorMessage(res.internalMessage);
          }
        }
      })
      .catch((err) => {
        AlertMessages.getErrorMessage(err.message);
        setPlantDetails(undefined);
      });
  };

  const handleRemarks = (value) => {
    console.log(value);
    console.log(value.target.defaultValue);
    setRemarksData(value);
  };
  useEffect(() => {
    if (props.saleOrderId) {
      getData(props.saleOrderId);
    }
    // window.print()
  }, [props.saleOrderId]);

  let exporterDetails = ExporterDataInput;
  const idToFind = plantDetails?.isInvoiced === "YES" 
  ? plantDetails?.exporterId 
  : plantDetails?.unitId;
const exporterData = exporterDetails.find(
  (item) => item.value == idToFind
);
  const processingId= plantDetails?.processingUnit;

  const processingData = exporterDetails.find(
    (item) => item.value === processingId
  );
   let exporterPlant = FactoriesInput;
   const exportersPlant = exporterPlant.find(
     (item) => item.id == processingId
   );
  let unitInput = FactoriesInput;
  const unitsData = FactoriesInput.find(
    (item) => item.id == plantDetails?.unitId
  );
  const tableData = () => {
    const tableDataArray = [];
    for (const data of plantDetails?.saleOrderItems) {
      const tableDataArray = data;
    }
  };
  let hasNumber = /\d/;
  let normalOrder = hasNumber.test(plantDetails?.buyerPoNo);
  let lotRefString = '';
  let lotNo = '';
  let RefNo = '';
  if (normalOrder) {
    if (plantDetails?.lotCode) {
      lotNo = 'LOT NO. ' + plantDetails?.lotCode + ', ';
    }
    if (plantDetails?.buyerPoNo) {
      RefNo = 'REF NO. ' + plantDetails?.buyerPoNo;
    }
    lotRefString = lotNo + RefNo;
  }
  // return 'test';

  const rowSpanValue = Math.round(plantDetails?.gradeInfo?.length / 2);
  if (
    plantDetails?.gradeInfo?.length % 2 !== 0 &&
    plantDetails?.gradeInfo?.length > 1
  ) {
    console.log('odd and > 1', Math.round(plantDetails?.gradeInfo?.length / 2));

    spanVal = Math.round(plantDetails?.gradeInfo?.length / 2);
    adjustSpan = Math.round(plantDetails?.gradeInfo?.length / 2) - 1;
  } else if (plantDetails?.gradeInfo?.length === 1) {
    spanVal = 1;
    console.log('equals to 1', Math.round(plantDetails?.gradeInfo?.length));

    adjustSpan = 1;
  } else {
    spanVal = Math.round(plantDetails?.gradeInfo?.length / 2);
    adjustSpan = Math.round(plantDetails?.gradeInfo?.length / 2);
    console.log('even', Math.round(plantDetails?.gradeInfo?.length / 2));
  }

  console.log(conditionRes?.[0]?.frozenWeight, 'console frozenWeight details');

  let totalContainersRowSpan = 0;
  let containerProductLevelRowSpan = new Map<number, number>(); // map of array_index_of_product => no of rows in it
  plantDetails?.gradeInfo?.forEach((g, prodIndex) => {
    let prodRowCount = 0;
    g?.info?.forEach((r, i) => {
      // incre,ent the total row span for every record
      totalContainersRowSpan++;
      prodRowCount++;
    });
    containerProductLevelRowSpan.set(prodIndex, prodRowCount);
  });
  const copiedContainerRowSpan = totalContainersRowSpan;

  const sealNoRowPortionSpan = totalContainersRowSpan / 2;
  console.log(totalContainersRowSpan);
  console.log(containerProductLevelRowSpan);
  // return (<></>);

  const lhsContent = [];
  const rhsContent = [];

  function ConstrunctLhsContent(plantDetails: PlantInvoiceDetailsModel) {
    console.log('innnnnnnnn');

    lhsContent.push(
      <>
        <b>Exporter:</b> <br />
        <h4>
          {exporterData?.name ? exporterData?.name : ''}
          <br />
          {exporterData?.addressOne ? exporterData?.addressOne + ',' : ''}
          <br />
          {exporterData?.addressTwo
            ? exporterData?.addressTwo + ' - ' + exporterData?.postalCode
            : ''}
          <br />
          {exporterData?.state + ', ' + exporterData?.country}
          <br />
          
          {exporterData?.phoneNumber? 
          <>PHONE:{exporterData?.phoneNumber}
          <br />
          </>:''}
          {exporterData?.faxNo!=null? <>FAX:{exporterData?.faxNo}</>:''}
          <br />
          GSTIN: {exporterData?.GSTNumber}
          <br/>
          USFDA REGN NO: {exporterData?.usfdaRegNo}
        </h4>
      </>
    );

    {
      plantDetails?.consigneeAddress != undefined ||
      plantDetails?.consignee != null ? (
        lhsContent.push(
          <>
            <b>
              <u>Consignee:</u>
            </b>
            <br />
            {plantDetails?.consignee}
            {plantDetails?.consignee ? ':' : ''}
            <br />
            {plantDetails?.consigneeAddress?.split(',')}
            <br />
            {plantDetails?.country ? plantDetails?.country : ''}
          </>
        )
      ) : (
        <></>
      );
    }
    // --------old-------
//     {
//       conditionRes?.[0]?.importerDetails === true ? (
        
//         (plantDetails?.endCustomerName === "BEAVER STREET FISHERIES, INC")? (
//         lhsContent.push(
//           <>
//           {/* <tr style={{maxHeight:'100%',backgroundColor:'pink'}}>
//             <td  className={'ta-b'}  colSpan={3}>
//             <b>Importer of record:</b>
//           <div><h4>
//             {exporterData?.name ? exporterData?.name : ''}
//           </h4></div>
//           <div>{exporterData?.addressOne + ','}</div>
//          <div> {exporterData?.addressTwo
//             ? exporterData?.addressTwo + ' - ' + exporterData?.postalCode
//             : ''}</div>
//           <div> {exporterData?.state + ', ' + exporterData?.country}
//           </div>
//           PHONE:{exporterData?.phoneNumber}
//           <br />
//           {exporterData?.faxNo!=null? <div>FAX:{exporterData?.faxNo}</div>:''}
//           <br/>
//           <b>Import On Record: </b>
//           {plantDetails?.country === 'USA'
//             ? exporterData?.importerOfRecord
//             : ''}
//             </td>
//             <td  className={'ta-b'}  colSpan={3}>
//             <u><b>SHIPPING TERMS:</b></u>
//                  <br />
//                  {plantDetails?.shipmentTerms}
//             </td>
//           </tr> */}
//          <tr style={{height:'100%',width:'100%'}} >
//   <td colSpan={6} >
//     <div style={{ display: 'flex', justifyContent: 'space-between', width: '100%', height: '100%' }}>
//       <div style={{ flex: 1, paddingRight: '1rem' ,borderRight:'1px solid black'}}>
//       <b>Importer of record:</b>
//           <div><h4>
//             {exporterData?.name ? exporterData?.name : ''}
//           </h4></div>
//           <div>{exporterData?.addressOne + ','}</div>
//          <div> {exporterData?.addressTwo
//             ? exporterData?.addressTwo + ' - ' + exporterData?.postalCode
//             : ''}</div>
//           <div> {exporterData?.state + ', ' + exporterData?.country}
//           </div>
//           PHONE:{exporterData?.phoneNumber}
//           <br />
//           {exporterData?.faxNo!=null? <div>FAX:{exporterData?.faxNo}</div>:''}
//           <br/>
//           <b>Import On Record: </b>
//           {plantDetails?.country === 'USA'
//             ? exporterData?.importerOfRecord
//             : ''}  </div>
//       <div style={{ textAlign: 'left'}}>
//         <u><b>SHIPPING TERMS:</b></u>
//         <br />
//         {plantDetails?.shipmentTerms}
//       </div>
//     </div>
//   </td>
// </tr>

//         </>
//         )
//       ):(
//         <>
//         <b>Importer of record:</b>
//         <div><h4>
//           {exporterData?.name ? exporterData?.name : ''}
//         </h4></div>
//         <div>{exporterData?.addressOne + ','}</div>
//        <div> {exporterData?.addressTwo
//           ? exporterData?.addressTwo + ' - ' + exporterData?.postalCode
//           : ''}</div>
//         <div> {exporterData?.state + ', ' + exporterData?.country}
//         </div>
//         PHONE:{exporterData?.phoneNumber}
//         <br />
//         {exporterData?.faxNo!=null? <div>FAX:{exporterData?.faxNo}</div>:''}
//         <br/>
//         <b>Import On Record: </b>
//         {plantDetails?.country === 'USA'
//           ? exporterData?.importerOfRecord
//           : ''}
//       </>
//       )
      
//       ) : (
//         <></>
//       );

    if (conditionRes?.[0]?.importerDetails === true) {
      if (plantDetails?.endCustomerName === "BEAVER STREET FISHERIES, INC") {
        lhsContent.push(
          <>
            <div style={{ display: 'flex' }}>
              <div style={{ width: '70%', padding: '10px' }}>
                <u><b>IMPORTER OF RECORD:</b></u>
                <br />
                {exporterData?.company ? exporterData?.company : ''}
                <br />
                {exporterData?.addressOne ? exporterData?.addressOne + ',' : ''}
                <br />
                {exporterData?.addressTwo
                  ? exporterData?.addressTwo + ' - ' + exporterData?.postalCode
                  : ''}
                <br />
                {exporterData?.state + ', ' + exporterData?.country}
                <br />
                PHONE: {exporterData?.phoneNumber}
                <br />
                {exporterData?.faxNo ? <>FAX: {exporterData?.faxNo} <br /></> : <></>}
                <b>IMPORT ON RECORD: </b>
                {plantDetails?.country === 'USA' ? exporterData?.importerOfRecord : ''}
              </div>
              <div style={{ width: '1px', background: 'black' }}></div>
              <div style={{ width: '30%', padding: '10px' }}>
                <u><b>SHIPPING TERMS:</b></u>
                <br />
                {plantDetails?.shipmentTerms}
              </div>
            </div>
          </>
        );
      } else {
        lhsContent.push(
          <>
            <u><b>IMPORTER OF RECORD:</b></u>
            <br />
            {exporterData?.company ? exporterData?.company : ''}
            <br />
            {exporterData?.addressOne ? exporterData?.addressOne + ',' : ''}
            <br />
            {exporterData?.addressTwo
              ? exporterData?.addressTwo + ' - ' + exporterData?.postalCode
              : ''}
            <br />
            {exporterData?.state + ', ' + exporterData?.country}
            <br />
            PHONE: {exporterData?.phoneNumber}
            <br />
            {exporterData?.faxNo ? <>FAX: {exporterData?.faxNo}</> : ''}
            <br />
            <b>IMPORT ON RECORD: </b>
            {plantDetails?.country === 'USA' ? exporterData?.importerOfRecord : ''}
          </>
        );
      }
    }
    // if (conditionRes?.[0]?.importerDetails === true) {
    //   if (plantDetails?.endCustomerName === "BEAVER STREET FISHERIES, INC") {
    //     lhsContent.push(
    //       <>
           
    //             {/* Importer of Record */}
    //             <td style={{ width: "70%", borderRight: "1px solid black", padding: "10px", verticalAlign: "top" }}>
    //               <u><b>IMPORTER OF RECORD:</b></u>
    //               <br />
    //               {exporterData?.company ? exporterData?.company : ''}
    //               <br />
    //               {exporterData?.addressOne ? exporterData?.addressOne + ',' : ''}
    //               <br />
    //               {exporterData?.addressTwo
    //                 ? exporterData?.addressTwo + ' - ' + exporterData?.postalCode
    //                 : ''}
    //               <br />
    //               {exporterData?.state + ', ' + exporterData?.country}
    //               <br />
    //               PHONE: {exporterData?.phoneNumber}
    //               <br />
    //               {exporterData?.faxNo ? <>FAX: {exporterData?.faxNo} <br /></> : <></>}
                  
    //               <b>IMPORT ON RECORD: </b>
    //               {plantDetails?.country === 'USA' ? exporterData?.importerOfRecord : ''}
    //             </td>
    
    //             {/* Shipping Terms */}
    //             <td style={{ width: "30%", borderLeft: "1px solid black", padding: "10px", verticalAlign: "top" }}>
    //               <u><b>SHIPPING TERMS:</b></u>
    //               <br />
    //               {plantDetails?.shipmentTerms}
    //             </td>
             
    //       </>
    //     );
    //   } 
    //   else {
    //     // Only Importer of Record should appear
    //     lhsContent.push(
    //       <>
    //               <u><b>IMPORTER OF RECORD:</b></u>
    //               <br />
    //               {exporterData?.company ? exporterData?.company : ''}
    //               <br />
    //               {exporterData?.addressOne ? exporterData?.addressOne + ',' : ''}
    //               <br />
    //               {exporterData?.addressTwo
    //                 ? exporterData?.addressTwo + ' - ' + exporterData?.postalCode
    //                 : ''}
    //               <br />
    //               {exporterData?.state + ', ' + exporterData?.country}
    //               <br />
    //               PHONE: {exporterData?.phoneNumber}
    //               <br />
    //               {exporterData?.faxNo ? <>FAX: {exporterData?.faxNo}</> : ''}
    //               <br />
    //               <b>IMPORT ON RECORD: </b>
    //               {plantDetails?.country === 'USA' ? exporterData?.importerOfRecord : ''}
    //       </>
    //     );
    //   }
    // }

    // console.log(
    //   lhsContent,
    //   'lhssssssssss000000000000000000000000000000000000000000000000'
    // );

    rhsContent.push(
      <>
        <b>Invoice No: </b>
        {plantDetails?.invoiceNumber}
      </>
    );
    // console.log(
    //   rhsContent,
    //   'rhssssssssss000000000000000000000000000000000000000000000000'
    // );

    rhsContent.push(
      <>
        <b>Invoice Date: </b>
        {plantDetails?.invoiceDate
          ? moment(plantDetails?.invoiceDate).format('DD-MM-YYYY')
          : ''}
      </>
    );
    // console.log(
    //   rhsContent,
    //   'rhssssssssss000000000000000000000000000000000000000000000000'
    // );

    rhsContent.push(
      <>
        <b>Place Of Supply: </b>{' '}
        {plantDetails?.saleOrderItems?.[0]?.destinationDetails
          ? `${plantDetails.saleOrderItems[0].destinationDetails.toUpperCase()} , ${plantDetails.country ? plantDetails.country : ''}`
          : ''}
      </>
    );
    // console.log(
    //   rhsContent,
    //   'rhssssssssss000000000000000000000000000000000000000000000000'
    // );

    rhsContent.push(
      <>
        <b>Tax is payable On Reverse Charge : NO</b>
      </>
    );
    // console.log(
    //   rhsContent,
    //   'rhssssssssss000000000000000000000000000000000000000000000000'
    // );

    // rhsContent.push(
    //   <>
    //     <b>GST NO: </b>
    //     {exporterData?.GSTNumber}
    //   </>
    // );
    // console.log(
    //   rhsContent,
    //   'rhssssssssss000000000000000000000000000000000000000000000000'
    // );

    rhsContent.push(
      <>
        <b>
          Exporter's Ref
          <br />
          IE Code{' '}
        </b>{' '}
        {exporterData?.ieCode}
      </>
    );
    // console.log(
    //   rhsContent,
    //   'rhssssssssss000000000000000000000000000000000000000000000000'
    // );
    {
      conditionRes?.[0]?.duplicateBuyer === false ? (
        rhsContent.push(
          <>
            {plantDetails?.consigneeAddress != undefined ||
            plantDetails?.consignee != null ? (
              <b> Buyer </b>
            ) : (
              <b>Buyer & Consignee:</b>
            )}
           <br />
        {plantDetails?.endCustomerName}
        {plantDetails?.endCustomerName ? ':' : ''}
        <br />
        {plantDetails?.saleOrderItems[0]?.buyerAddress?.split(',')}
        <br />
        {plantDetails?.country ? plantDetails?.country:''}
      </>
        )
      ) : (
        <></>
      );
    }

    // rhsContent.push(
    //   <>
    //     {plantDetails?.consigneeAddress != undefined ||
    //     plantDetails?.consignee != null ? (
    //       <b> Buyer </b>
    //     ) : (
    //       <b>Buyer & Consignee:</b>
    //     )}
    //     <br />
    //     {plantDetails?.endCustomerName}
    //     {plantDetails?.endCustomerName ? ':' : ''}
    //     <br />
    //     {plantDetails?.saleOrderItems[0]?.buyerAddress?.split(',')}
    //     <br />
    //     {plantDetails?.country ? plantDetails?.country:''}
    //     <br/>
    //     {/* {plantDetails?.saleOrderItems[0]?.buy} */}
    //   </>
    // );

    {
      conditionRes?.[0]?.notifyPartyParam === true ? (
        rhsContent.push(
          <>
            <b>Notify Party:</b>
            {plantDetails.notifyPartyOne != null ? (
              <>
                {/* <u>Notify party 1</u> */}
                <br />
                <b>{plantDetails?.notifyPartyOne?.split('\n')[0]}</b>
                <br />
                {plantDetails?.notifyPartyOne?.split('\n')[1]}
                <br />
                {plantDetails?.notifyPartyOne?.split('\n')[2]}
                <br />
                {plantDetails?.notifyPartyOne?.split('\n')[3]}
                <br />
              </>
            ) : (
              ''
            )}
            {plantDetails?.notifyPartyTwo != null ? (
              <>
                {/* <u>Notify party 2</u> */}
                <br />
                <b>{plantDetails?.notifyPartyTwo?.split('\n')[0]}</b>
                <br />
                {plantDetails?.notifyPartyTwo?.split('\n')[1]}
                <br />
                {plantDetails?.notifyPartyTwo?.split('\n')[2]}
                <br />
                {plantDetails?.notifyPartyTwo?.split('\n')[3]}
                <br />
                <br />
              </>
            ) : (
              ''
            )}
            {plantDetails?.notifyPartyThree != null ? (
              <>
                {/* <u>Notify party 3</u> */}
                <br />
                <b>{plantDetails?.notifyPartyThree?.split('\n')[0]}</b>
                <br />
                {plantDetails?.notifyPartyThree?.split('\n')[1]}
                <br />
                {plantDetails?.notifyPartyThree?.split('\n')[2]}
                <br />
                {plantDetails?.notifyPartyThree?.split('\n')[3]}
                <br />
                <br />
              </>
            ) : (
              ''
            )}
            {plantDetails?.notifyPartyFour != null ? (
              <>
                {/* <u>Notify party 4</u> */}
                <br />
                <b>{plantDetails?.notifyPartyFour?.split('\n')[0]}</b>
                <br />
                {plantDetails?.notifyPartyFour?.split('\n')[1]}
                <br />
                {plantDetails?.notifyPartyFour?.split('\n')[2]}
                <br />
                {plantDetails?.notifyPartyFour?.split('\n')[3]}
                <br />
                <br />
              </>
            ) : (
              ''
            )}
          </>
        )
      ) : (
        <></>
      );
    }
    console.log(
      rhsContent,
      'rhssssssssss000000000000000000000000000000000000000000000000'
    );

    {
      plantDetails?.htsInfo?.[0]?.htsCode != null ||
      plantDetails?.htsInfo?.[0]?.htsCode != undefined ? (
        rhsContent.push(
          <>
            <b>HTS Code : </b>
            {plantDetails?.htsInfo.map((e) => e.htsCode).join(',')}
          </>
        )
      ) : (
        <></>
      );
    }
    console.log(
      rhsContent,
      'rhssssssssss000000000000000000000000000000000000000000000000'
    );

    rhsContent.push(
      <>
        <b>{conditionRes?.[0]?.terms} : </b> {plantDetails?.deliveryTerms}
      </>
    );
    console.log(
      rhsContent,
      'rhssssssssss000000000000000000000000000000000000000000000000'
    );

    {
      plantDetails?.saleOrderItems[0]?.buyerAddress?.replace(/,/g, '') !=
      plantDetails?.saleOrderItems[0]?.deliveryaddress?.replace(/,/g, '') ? (
        rhsContent.push(
          <>
            <b>
              <u>Shipp to:</u>
            </b>
            {plantDetails?.saleOrderItems[0]?.deliveryaddress}
          </>
        )
      ) : (
        <></>
      );
    }
  }
  console.log(ConstrunctLhsContent(plantDetails));

  // -----old-------
  // let lhsCount = lhsContent.length;
  // let rhsCount = rhsContent.length;
  // console.log(lhsCount, 'lhsCount');
  // console.log(rhsCount, 'rhsCount');

  // const lhsRowSpanMap = new Map<number, number>();
  // const lhsRowSpanCopyMap = new Map<number, number>();
  // const blockSpanSize = Math.round(rhsCount / lhsCount); //10/4=3
  // let blockSpanSizeRem = Math.round(rhsCount % lhsCount);
  // let rowNumber = 1;
  // let index = 0; //1
  // let fulfilledCount = 0;
  // while (lhsCount > 0) {
  //   if (index === 0) {
  //     lhsRowSpanMap.set(rowNumber, blockSpanSize); //1,3
  //     lhsRowSpanCopyMap.set(rowNumber, blockSpanSize); //1 ,3
  //     fulfilledCount = blockSpanSize; //3
  //   } else {
  //     const remaing = rhsCount - fulfilledCount; //10-3=7
  //     console.log(remaing, 'oooooooo');
  //     const rem = Math.floor(remaing % lhsCount);
  //     const breakDownVal = Math.round(remaing / lhsCount) + rem; //7/3+3 =2,4
  //     lhsRowSpanMap.set(rowNumber, breakDownVal); //1,5 | 2,1
  //     lhsRowSpanCopyMap.set(rowNumber, breakDownVal); //1 ,5 | 2,1
  //     fulfilledCount = blockSpanSize + breakDownVal;
  //   }
  //   console.log(fulfilledCount, 'fullllllllll');
  //   console.log(lhsRowSpanMap, '');

  //   index++; //1
  //   rowNumber++; //2
  //   lhsCount--; //1
  // }

  // let lhsPrintingRowNumber = 1;
  // let lhsPrintingIndexNumber = 0;
  // let totalSpanSum = 0;
  // lhsRowSpanMap.forEach((value) => {
  //   totalSpanSum += value;
  // });

// ------new---
  let lhsCount = lhsContent.length;
  let rhsCount = rhsContent.length;
  console.log(lhsCount, 'lhsCount');
  console.log(rhsCount, 'rhsCount');
  
  const lhsRowSpanMap = new Map<number, number>();
  const lhsRowSpanCopyMap = new Map<number, number>();
  const baseSpanSize = Math.floor(rhsCount / lhsCount); 
  const remainder = rhsCount % lhsCount;
  
  let rowNumber = 1;
  let totalSpanSum = 0;
  
  for (let i = 0; i < lhsCount; i++) {

    const span = i === lhsCount - 1 ? baseSpanSize + remainder : baseSpanSize;
    lhsRowSpanMap.set(rowNumber, span);
    lhsRowSpanCopyMap.set(rowNumber, span);
    totalSpanSum += span;
    rowNumber++;
  }
  
  console.log('lhsRowSpanMap:', lhsRowSpanMap);
  console.log('Total span sum:', totalSpanSum);
  
  // Ensure total span matches rhsCount
  if (totalSpanSum < rhsCount) {
    const lastRow = lhsCount;
    const additionalSpan = rhsCount - totalSpanSum;
    lhsRowSpanMap.set(lastRow, lhsRowSpanMap.get(lastRow) + additionalSpan);
    lhsRowSpanCopyMap.set(lastRow, lhsRowSpanCopyMap.get(lastRow) + additionalSpan);
    totalSpanSum = rhsCount;
    console.log('Adjusted lhsRowSpanMap:', lhsRowSpanMap);
    console.log('Adjusted totalSpanSum:', totalSpanSum);
  }

  let lhsPrintingRowNumber = 1;
  let lhsPrintingIndexNumber = 0;
  lhsRowSpanMap.forEach((value) => {
    totalSpanSum += value;
  });
  console.log('Total span sum:', totalSpanSum);
  // lhsRowSpanMap.set(1, blockSpanSize + blockSpanSizeRem);
  // lhsRowSpanCopyMap.set(1, blockSpanSize + blockSpanSizeRem);
  const allDates = plantDetails?.gradeInfo?.map(g => g.info.map(r => r.productionDate)) // produces array of arrays
  .reduce((acc, curr) => acc.concat(curr), [])  // flatten once
  .reduce((acc, curr) => acc.concat(curr), []); // flatten twice

const uniqueProductionDates = [...new Set(allDates)];  
console.log(uniqueProductionDates,'uniqueProductionDatesuniqueProductionDates');
console.log(conditionRes?.[0]?.bestByDate!=' DAY CODES','conditionRes?.[0]?.bestByDate!= DAY CODES');
// const allProductionDates: string[] = [];
// plantDetails?.gradeInfo?.forEach(g => {
//   g?.info?.forEach(r => {
//     (r?.productionDate ?? []).forEach(d => {
//       if (d.date) {
//         allProductionDates.push(moment(d.date).format('DD-MM-YYYY'));
//       }
//     });
//   });
// });
const productionDateSet = new Set<string>();
const bestBeforeDateSet = new Set<any>();
const dayCodeSet = new Set<string>();

plantDetails?.gradeInfo?.forEach(g => {
  g?.info?.forEach(r => {
    (r?.productionDate ?? []).forEach(d => {
      if (d.date) {
        const formattedDate = moment(d.date).format('DD-MM-YYYY');
        productionDateSet.add(formattedDate);
      }
      
    });
     (r?.bestBeforeDate ?? []).forEach(d => {
      if (d.date) {
        const formattedDate = moment(d.date)?moment(d.date).format('DD-MM-YYYY'):d.date;
        bestBeforeDateSet.add(formattedDate);
      }
      
    });
    (r?.code ?? []).forEach(d => {
      if (d.code) {
        const formattedDate = d.code;
        dayCodeSet.add(formattedDate);
      }
      
    });
  });
});

const allProductionDates = Array.from(productionDateSet);
const allBestBeforeDates = Array.from(bestBeforeDateSet);
const allDayCodes = Array.from(dayCodeSet);

console.log(allProductionDates,'ppppppppppppp');
console.log(allBestBeforeDates,'allBestBeforeDates');
console.log(allDayCodes,'allDayCodes');
console.log(allDayCodes?.map(item => item).join(", "),'allDayCodes');



return (
    <>
      <span style={{ alignContent: "end", backgroundColor: 'red' }}>
        <ReactHTMLTableToExcel
          id="test-table-xls-button"
          className="download-table-xls-button"
          table="table-to-xls"
          filename="postpackinglist"
          sheet="postpackinglist"
          buttonText="Get Excel"
        />
      </span>
      {plantDetails ? (
        <html>
          <head></head>

          <br />
          <body id="print" className={'stylesInfo'}>
            <br></br>
            <table
              className={'ta-b'}
              style={{ width: '100%' }}
              id="table-to-xls"
            >
              <tr>
                <td
                  className={'ta-b'}
                  colSpan={
                    plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? 13 : 9
                  }
                  style={{
                    textAlign: 'center',
                    fontSize: '16px',
                    lineHeight: '12px',
                    paddingTop: '20px',
                  }}
                >
                  <h1>PACKING LIST</h1>
                </td>
              </tr>
              {/* {rhsContent.map((r, i) => {
                console.log(lhsPrintingRowNumber, 'pppppppp');
                console.log(lhsPrintingRowNumber, 'pppppppp');

                let currRowSpanConsumption = lhsRowSpanMap.get(
                  lhsPrintingRowNumber
                ); // 3
                let currRowSpanReducedCons = lhsRowSpanCopyMap.get(
                  lhsPrintingRowNumber
                ); // 3/2
                lhsRowSpanCopyMap.set(
                  lhsPrintingRowNumber,
                  currRowSpanReducedCons - 1
                ); // 2/1
                console.log(lhsPrintingRowNumber);
                console.log(currRowSpanReducedCons);

                if (Number(currRowSpanReducedCons) - 1 === 0) {
                  console.log(currRowSpanReducedCons, 'currRowSpanReducedCons');
                  lhsPrintingIndexNumber++;
                  lhsPrintingRowNumber++;
                }

                return (
                  <>
                    <tr>
                      <td
                        colSpan={
                          plantDetails?.saleOrderItems[0]?.grossWeightPerKg
                            ? 6
                            : 5
                        }
                        className={'ta-b'}
                        rowSpan={currRowSpanConsumption}
                        style={{
                          display:
                            currRowSpanConsumption === currRowSpanReducedCons
                              ? ''
                              : 'none',
                        }}
                      >
                        {lhsContent[lhsPrintingIndexNumber]}
                      </td>
                      <td
                        className={'ta-b'}
                        colSpan={
                          plantDetails?.saleOrderItems[0]?.grossWeightPerKg
                            ? 6
                            : 5
                        }
                      >
                        {r}
                      </td>
                    </tr>
                  </>
                );
              })} */}
{/* ---------------------old------------- */}
{/* {rhsContent.map((r, i) => {
                  let currRowSpanConsumption = lhsRowSpanMap.get(lhsPrintingRowNumber);
                  let currRowSpanReducedCons = lhsRowSpanCopyMap.get(lhsPrintingRowNumber);
                  lhsRowSpanCopyMap.set(lhsPrintingRowNumber, currRowSpanReducedCons - 1);

                  if (Number(currRowSpanReducedCons) - 1 === 0) {
                    lhsPrintingIndexNumber++;
                    lhsPrintingRowNumber++;
                  }

                  return (
                    <>

       
                    <tr key={i}>
                      {currRowSpanConsumption === currRowSpanReducedCons && (
                        <td
                          colSpan={6}
                          className={'ta-b'}
                          rowSpan={currRowSpanConsumption}
                          style={{
                            display:
                              currRowSpanConsumption === currRowSpanReducedCons ? '' : 'none',
                              verticalAlign:'top',
                          }}
                        >
                          {lhsContent[lhsPrintingIndexNumber]}
                        </td>
                      )}
                      <td className={'ta-b'} colSpan={6}>
                        {r}
                      </td>
                    </tr>
                    </>

                  );
   })} */}
   {/* ----------------------new------------------------ */}
{rhsContent.map((r, i) => {
  let currRowSpanConsumption = lhsRowSpanMap.get(lhsPrintingRowNumber) || 1;
  let currRowSpanReducedCons = lhsRowSpanCopyMap.get(lhsPrintingRowNumber) || 1;
  lhsRowSpanCopyMap.set(lhsPrintingRowNumber, currRowSpanReducedCons - 1);

  if (Number(currRowSpanReducedCons) - 1 === 0 && lhsPrintingIndexNumber < lhsCount - 1) {
    lhsPrintingIndexNumber++;
    lhsPrintingRowNumber++;
  }

  return (
    <tr key={i}>
      {currRowSpanConsumption === currRowSpanReducedCons && lhsContent[lhsPrintingIndexNumber] && (
        <td
          colSpan={6}
          className={'ta-b'}
          rowSpan={currRowSpanConsumption}
          style={{ verticalAlign: 'top' }}
        >
          {lhsContent[lhsPrintingIndexNumber]}
        </td>
      )}
      <td className={'ta-b'} colSpan={6}>
        {r}
      </td>
    </tr>
  );
})}
  
              {/* <tr><td className={'ta-b'} colSpan={8} style={{ textAlign: 'center', fontSize: '16px', lineHeight: '12px', paddingTop: '20px' }}><h1>PACKING LIST</h1></td></tr> */}
              {/* {plantDetails?.isTaxApplicable === "YES" ? (
                <tr>
                  <td className={'ta-b'} colSpan={9}><h2>"SUPPLY MEANT FOR EXPORT LETTER OF UNDERTAking WITH PAYMENT OF IGST"</h2></td>
                  </tr>
                ) : (
                <tr>
                  <td className={'ta-b'} colSpan={9}><h2>"SUPPLY MEANT FOR EXPORT LETTER OF UNDERTAking WITHOUT PAYMENT OF IGST"</h2>
                  </td>
                  </tr>
                )} */}
              {/* <tr>
                <td
                  style={{
                    textAlign: 'left',
                    border: '1px solid black',
                    verticalAlign: 'top',
                    paddingTop: '5px',
                    paddingLeft: '5px',
                  }}
                  colSpan={
                    plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? 6 : 4
                  }
                  rowSpan={4}
                >
                  <b>Exporter:</b> <br />
                  <h4>
                    {exporterData?.name ? exporterData?.name : ''}
                    <br />
                    {exporterData?.addressOne
                      ? exporterData?.addressOne + ','
                      : ''}
                    <br />
                    {exporterData?.addressTwo
                      ? exporterData?.addressTwo +
                        ' - ' +
                        exporterData?.postalCode
                      : ''}
                    <br />
                    {exporterData?.state + ', ' + exporterData?.country}
                    <br />
                    GSTIN: {exporterData?.GSTNumber}
                    <br />
                    USFDA REGN NO: {exporterData?.usfdaRegNo}
                  </h4>
                </td>
                <td className={'ta-b'} colSpan={5}>
                  <b>Invoice No: </b>
                  {plantDetails?.invoiceNumber}
                  <br />
                </td>
              </tr> */}
              {/* <tr>
                <td className={'ta-b'} colSpan={5}>
                  <b>Invoice Date: </b>
                  {plantDetails?.invoiceDate
                    ? moment(plantDetails?.invoiceDate).format('DD-MMM-YYYY')
                    : ''}
                </td>
              </tr> */}
              {/* <tr>
                <td className={'ta-b'} colSpan={5}>
                  <b>Place Of Supply: </b>
                  {(plantDetails?.saleOrderItems[0]?.destinationDetails
                    ? plantDetails?.saleOrderItems[0]?.destinationDetails?.toUpperCase() +
                      ','
                    : '') +
                    (plantDetails?.country ? plantDetails?.country : '')}{' '}
                  <br />
                 
                </td>
              </tr> */}
              {/* <tr>
                <td className={'ta-b'} colSpan={5}>
                  <b>GST No:{exporterData?.GSTNumber} </b>
                </td>
              </tr> */}
              {/* <tr>
                <td
                  className={'ta-b'}
                  colSpan={
                    plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? 6 : 4
                  }
                  rowSpan={2}
                >
                  <b>
                    <u>Consignee:</u>
                  </b>
                  <br />
                  {plantDetails?.consignee}
                  {plantDetails?.consignee ? ':' : ''}
                  <br />
                  {plantDetails?.country ? plantDetails?.country : ''}
                  {plantDetails?.consigneeAddress?.split(',')[0] + ','}
                  <br />
                  {plantDetails?.consigneeAddress?.split(',')[1] + ','}
                  {plantDetails?.consigneeAddress?.split(',')[2] + ','}
                  {plantDetails?.consigneeAddress?.split(',')[3]}
                  <br />
                </td>
                <td
                  className={'ta-b'}
                  colSpan={
                    plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? 7 : 5
                  }
                >
                  <b>Exporter's Ref: IE Code </b> {exporterData?.ieCode}
                </td>
              </tr> */}
              {/* <tr>
              <td className={'ta-b'} colSpan={5}>
                  <b>Exporter's Ref<br />
                    IE Code </b> {exporterData?.ieCode}
                </td> 
              </tr> */}
              {/* <tr>
              <td className={'ta-b'} colSpan={5}>
              <b> Buyer & Consignee:</b><br />
                  {plantDetails?.consignee}{plantDetails?.consignee ? ':' : ''}<br />
                  {plantDetails?.country ? plantDetails?.country:''}
                  {plantDetails?.saleOrderItems[0]?.customeraddress?.split(",")[0] + ","}<br />
                  {plantDetails?.saleOrderItems[0]?.customeraddress?.split(",")[1] + ","}
                  {plantDetails?.saleOrderItems[0]?.customeraddress?.split(",")[2] + ","}
                  {plantDetails?.saleOrderItems[0]?.customeraddress?.split(",")[3]}<br /> */}
              {/* {
                    plantDetails?.endCustomerName === 'AZ Gems' ?
                    <>
                    <b>FDA REGISTRATION NO.</b>{unitsData?.consigneefdaRegNumber}
                    </> : ''
                  } */}
              {/* </td> */}
              {/* <td colSpan={5} className={'ta-b'}>
                  <b>Buyer's Order No. </b>
                  PO NO. {plantDetails.custPoNo}
                </td> */}
              {/* </tr> */}
              {/* <tr> */}
              {/* <td className={'ta-b'} colSpan={4} rowSpan={2}>
                  <b>
                    Importer of record:
                  </b><br />
                  <h4 style={{ display: 'inline',lineHeight:'1px' }}>{(exporterData?.name) ? exporterData?.name : ''}</h4><br />
                  {(exporterData?.addressOne) ? exporterData?.addressOne + ',' : ''}
                  <br />
                  {(exporterData?.addressTwo) ? (exporterData?.addressTwo) + ' - ' + exporterData?.postalCode : ''}
                  <br />
                  {exporterData?.state + ', ' + exporterData?.country}
                <br/>
                <b>Import On Record: </b>{plantDetails?.country==='USA'?exporterData?.importerOfRecord:''}
                </td> */}
              {/* <td className={'ta-b'} colSpan={5}>
                <b>Notify Party:</b>

                
                     {
                  (plantDetails.notifyPartyOne) ?
                    
                      <><u>
                      Notify party 1</u><br />
                        <b>{plantDetails?.notifyPartyOne?.split("\n")[0]}</b><br />
                        {plantDetails?.notifyPartyOne?.split("\n")[1]}<br />
                        {plantDetails?.notifyPartyOne?.split("\n")[2]}<br />
                        {plantDetails?.notifyPartyOne?.split("\n")[3]}<br /></>:''
                }
                {
                  (plantDetails.notifyPartyTwo) ?

                  <><u>
                      Notify party 2</u><br />
                        <b>{plantDetails?.notifyPartyTwo?.split("\n")[0]}</b><br />
                        {plantDetails?.notifyPartyTwo?.split("\n")[1]}<br />
                        {plantDetails?.notifyPartyTwo?.split("\n")[2]}<br />
                        {plantDetails?.notifyPartyTwo?.split("\n")[3]}<br /><br /></>:''

                      }


{
                  (plantDetails.notifyPartyThree) ?
                    
                      <><u>
                      Notify party 3</u><br /><pre>
                        <b>{plantDetails?.notifyPartyThree?.split("\n")[0]}</b><br />
                        {plantDetails?.notifyPartyThree?.split("\n")[1]}<br />
                        {plantDetails?.notifyPartyThree?.split("\n")[2]}<br />
                        {plantDetails?.notifyPartyThree?.split("\n")[3]}</pre><br /><br /></>:''


                      }
                {
                  (plantDetails.notifyPartyFour) ?

                  <><u>
                      Notify party 4</u><br />
                        <b>{plantDetails?.notifyPartyFour?.split("\n")[0]}</b><br />
                        {plantDetails?.notifyPartyFour?.split("\n")[1]}<br />
                        {plantDetails?.notifyPartyFour?.split("\n")[2]}<br />
                        {plantDetails?.notifyPartyFour?.split("\n")[3]}<br /><br /></>:''
                }
</td> */}
              {/* { conditionRes?.[0]?.notifyPartyParam === true ?(
                  <td className={'ta-b'} colSpan={5}>
                <b>Notify Party:</b>

                
                     {
                  (plantDetails.notifyPartyOne) ?
                    
                      <><u>
                      Notify party 1</u><br />
                        <b>{plantDetails?.notifyPartyOne?.split("\n")[0]}</b><br />
                        {plantDetails?.notifyPartyOne?.split("\n")[1]}<br />
                        {plantDetails?.notifyPartyOne?.split("\n")[2]}<br />
                        {plantDetails?.notifyPartyOne?.split("\n")[3]}<br /></>:''
                }
                {
                  (plantDetails.notifyPartyTwo) ?

                  <><u>
                      Notify party 2</u><br />
                        <b>{plantDetails?.notifyPartyTwo?.split("\n")[0]}</b><br />
                        {plantDetails?.notifyPartyTwo?.split("\n")[1]}<br />
                        {plantDetails?.notifyPartyTwo?.split("\n")[2]}<br />
                        {plantDetails?.notifyPartyTwo?.split("\n")[3]}<br /><br /></>:''

                      }


{
                  (plantDetails.notifyPartyThree) ?
                    
                      <><u>
                      Notify party 3</u><br /><pre>
                        <b>{plantDetails?.notifyPartyThree?.split("\n")[0]}</b><br />
                        {plantDetails?.notifyPartyThree?.split("\n")[1]}<br />
                        {plantDetails?.notifyPartyThree?.split("\n")[2]}<br />
                        {plantDetails?.notifyPartyThree?.split("\n")[3]}</pre><br /><br /></>:''


                      }
                {
                  (plantDetails.notifyPartyFour) ?

                  <><u>
                      Notify party 4</u><br />
                        <b>{plantDetails?.notifyPartyFour?.split("\n")[0]}</b><br />
                        {plantDetails?.notifyPartyFour?.split("\n")[1]}<br />
                        {plantDetails?.notifyPartyFour?.split("\n")[2]}<br />
                        {plantDetails?.notifyPartyFour?.split("\n")[3]}<br /><br /></>:''
                }
            </td>):<></>}
</tr> */}
              {/* <tr> */}
              {/* <td className={'ta-b'} colSpan={5}>
                    <b>Delivery Terms:</b>
                    {plantDetails?.deliveryTerms}
                </td> */}
              {/* <td className={'ta-b'} colSpan={5}>
                    <b>{conditionRes?.[0]?.terms}</b>
                    {plantDetails?.deliveryTerms}
                </td>
                </tr> */}
              {/* <tr>
                <td className={'ta-b'} colSpan={3}>
                    <b>Container No:</b>
                    {plantDetails?.saleOrderItems[0]?.containerNo}
                </td>
                <td className={'ta-b'} colSpan={2}>
                    <b>Seal No:</b>
                    {plantDetails?.saleOrderItems[0]?.linearSelaNo}
                </td>
                </tr> */}
              {/* <tr>
                {conditionRes?.[0]?.duplicateBuyer === true ? (
                  <>
                    <td
                      className={'ta-b'}
                      colSpan={
                        plantDetails?.saleOrderItems[0]?.grossWeightPerKg
                          ? 7
                          : 5
                      }
                    >
                      <b> Buyer & Consignee:</b>
                      <br />
                      {conditionRes?.[0]?.duplicateBuyerAddress}
                    </td>
                  </>
                ) : (
                  <>
                    <td
                      className={'ta-b'}
                      colSpan={
                        plantDetails?.saleOrderItems[0]?.grossWeightPerKg
                          ? 7
                          : 5
                      }
                    >
                      <b> Buyer & Consignee:</b>
                      <br />
                      {plantDetails?.endCustomerName}
                      {plantDetails?.endCustomerName ? ':' : ''}
                      <br />
                      {plantDetails?.country ? plantDetails?.country : ''}
                      {plantDetails?.saleOrderItems[0]?.customeraddress?.split(
                        ','
                      )[0] + ','}
                      <br />
                      {plantDetails?.saleOrderItems[0]?.customeraddress?.split(
                        ','
                      )[1] + ','}
                      {plantDetails?.saleOrderItems[0]?.customeraddress?.split(
                        ','
                      )[2] + ','}
                      {
                        plantDetails?.saleOrderItems[0]?.customeraddress?.split(
                          ','
                        )[3]
                      }
                      <br />
                    </td>
                  </>
                )}
              </tr> */}
              {/* <tr>
                {conditionRes?.[0]?.importerDetails === true ? (
                  <td
                    className={'ta-b'}
                    colSpan={
                      conditionRes?.[0]?.shipping === true
                        ? 2
                        : 4 ||
                          plantDetails?.saleOrderItems[0]?.buyerAddress.replace(/,/g, '') !=
                            plantDetails?.saleOrderItems[0]?.deliveryaddress.replace(/,/g, '')
                        ? 2
                        : 4
                    }
                    rowSpan={3}
                  >
                    <b>Importer of record:</b>
                    <br />
                    <h4 style={{ display: 'inline', lineHeight: '1px' }}>
                      {exporterData?.name ? exporterData?.name : ''}
                    </h4>
                    <br />
                    {exporterData?.addressOne
                      ? exporterData?.addressOne + ','
                      : ''}
                    <br />
                    {exporterData?.addressTwo
                      ? exporterData?.addressTwo +
                        ' - ' +
                        exporterData?.postalCode
                      : ''}
                    <br />
                    {exporterData?.state + ', ' + exporterData?.country}
                    <br />
                    <b>Import On Record: </b>
                    {plantDetails?.country === 'USA'
                      ? exporterData?.importerOfRecord
                      : ''}
                  </td>
                ) : (
                  <></>
                )}
                {conditionRes?.[0]?.shipping === true ? (
                  <td className={'ta-b'} colSpan={2} rowSpan={3}>
                    <b>
                      <u>Shipping terms:</u>
                    </b>
                    {plantDetails?.saleOrderItems[0]?.deliveryaddress}
                  </td>
                ) : (
                  <></>
                )}
                {plantDetails?.saleOrderItems[0]?.buyerAddress.replace(/,/g, '') !=
                plantDetails?.saleOrderItems[0]?.deliveryaddress.replace(/,/g, '') ? (
                  <td className={'ta-b'} colSpan={2} rowSpan={3}>
                    <b>
                      <u>Shipp to:</u>
                    </b>
                    {plantDetails?.saleOrderItems[0]?.deliveryaddress}
                  </td>
                ) : (
                  <></>
                )}
                {conditionRes?.[0]?.notifyPartyParam === true ? (
                  <td className={'ta-b'} colSpan={5}>
                    <b>Notify Party:</b>
                    {plantDetails.notifyPartyOne ? (
                      <>
                        <u>Notify party 1</u>
                        <br />
                        <b>{plantDetails?.notifyPartyOne?.split('\n')[0]}</b>
                        <br />
                        {plantDetails?.notifyPartyOne?.split('\n')[1]}
                        <br />
                        {plantDetails?.notifyPartyOne?.split('\n')[2]}
                        <br />
                        {plantDetails?.notifyPartyOne?.split('\n')[3]}
                        <br />
                      </>
                    ) : (
                      ''
                    )}
                    {plantDetails.notifyPartyTwo ? (
                      <>
                        <u>Notify party 2</u>
                        <br />
                        <b>{plantDetails?.notifyPartyTwo?.split('\n')[0]}</b>
                        <br />
                        {plantDetails?.notifyPartyTwo?.split('\n')[1]}
                        <br />
                        {plantDetails?.notifyPartyTwo?.split('\n')[2]}
                        <br />
                        {plantDetails?.notifyPartyTwo?.split('\n')[3]}
                        <br />
                        <br />
                      </>
                    ) : (
                      ''
                    )}
                    {plantDetails.notifyPartyThree ? (
                      <>
                        <u>Notify party 3</u>
                        <br />
                        <pre>
                          <b>
                            {plantDetails?.notifyPartyThree?.split('\n')[0]}
                          </b>
                          <br />
                          {plantDetails?.notifyPartyThree?.split('\n')[1]}
                          <br />
                          {plantDetails?.notifyPartyThree?.split('\n')[2]}
                          <br />
                          {plantDetails?.notifyPartyThree?.split('\n')[3]}
                        </pre>
                        <br />
                        <br />
                      </>
                    ) : (
                      ''
                    )}
                    {plantDetails.notifyPartyFour ? (
                      <>
                        <u>Notify party 4</u>
                        <br />
                        <b>{plantDetails?.notifyPartyFour?.split('\n')[0]}</b>
                        <br />
                        {plantDetails?.notifyPartyFour?.split('\n')[1]}
                        <br />
                        {plantDetails?.notifyPartyFour?.split('\n')[2]}
                        <br />
                        {plantDetails?.notifyPartyFour?.split('\n')[3]}
                        <br />
                        <br />
                      </>
                    ) : (
                      ''
                    )}
                  </td>
                ) : (
                  <></>
                )}
              </tr> */}
              {/* <tr>
                {plantDetails?.htsCode ? (
                  <td className={'ta-b'} colSpan={5}>
                    <b>HTS Code : </b>
                    {plantDetails?.htsCode}
                  </td>
                ) : (
                  <></>
                )}
              </tr> */}
              {/* <tr>
                <td className={'ta-b'} colSpan={5}>
                  <b>{conditionRes?.[0]?.terms}</b>
                  {plantDetails?.deliveryTerms}
                </td>
              </tr> */}
              <tr>
                <td
                  className={'ta-b'}
                  colSpan={
                    plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? 12 : 9
                  }
                  style={{
                    textAlign: 'center',
                    fontSize: '16px',
                    lineHeight: '10px',
                    paddingTop: '20px',
                  }}
                >
                  <b>{conditionRes?.[0]?.poLabel} : </b>
                  {''}
                  {plantDetails.custPoNo} <b>Date : </b>
                  {moment(plantDetails.poDate).format('DD-MM-YYYY')}
                </td>
              </tr>
              {plantDetails?.lcName ? (
                <>
                  <tr>
                    <td
                      className={'ta-b'}
                      colSpan={9}
                      style={{ textAlign: 'center' }}
                    >
                      <b>{plantDetails?.lcName} : </b>
                      {plantDetails?.lcNo} <b> date of issue : </b>
                      {moment(plantDetails?.lcDate).format('DD-MM-YYYY')},
                      <br />
                      {plantDetails?.lcBankAddress}, <b>For usd </b>
                      {plantDetails?.lcAmount}
                    </td>
                  </tr>
                </>
              ) : (
                <></>
              )}{' '}
              <tr>
                <td className={'ta-b'} style={{ textAlign: 'center' }}>
                  <b>Pre Carriage By</b>
                </td>
                <td className={'ta-b'} style={{ textAlign: 'center' }}>
                  <b>Vessel No</b>
                </td>
                <td className={'ta-b'} style={{ textAlign: 'center' }}>
                  <b>Port Of Loading</b>
                </td>
                <td className={'ta-b'} style={{ textAlign: 'center' }}>
                  <b>Port Of Discharge</b>
                </td>
                <td
                  className={'ta-b'}
                  style={{ textAlign: 'center' }}
                  colSpan={
                    plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? 3 : 2
                  }
                >
                  <b>
                    {conditionRes?.[0]?.destinationDetails
                      ? conditionRes?.[0]?.destinationDetails
                      : ''}
                  </b>
                </td>
                <td
                  className={'ta-b'}
                  style={{ textAlign: 'center' }}
                  colSpan={
                    plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? 3 : 2
                  }
                >
                  <b>Terms & Payments</b>
                </td>
                <td className={'ta-b'} style={{ textAlign: 'center' }} colSpan={2}>
                  <b>Origin Of Goods</b>
                </td>
              </tr>
              <tr>
                <td className={'ta-b'} style={{ textAlign: 'center' }}>
                  {plantDetails?.vesselName?.toUpperCase()}
                </td>
                <td className={'ta-b'} style={{ textAlign: 'center' }}>
                  {' '}
                  {plantDetails?.vesselNumber}
                </td>
                <td className={'ta-b'} style={{ textAlign: 'center' }}>
                  <b>
                    {plantDetails?.portofloading
                      ? plantDetails?.portofloading?.toUpperCase()
                      : ''}
                  </b>
                </td>
                <td className={'ta-b'} style={{ textAlign: 'center' }}>
                  {(plantDetails?.saleOrderItems[0]?.destinationDetails
                    ? plantDetails?.saleOrderItems[0]?.destinationDetails?.toUpperCase()
                    : '') +
                    ',' +
                    (plantDetails?.country ? plantDetails?.country : '')}
                </td>
                <td
                  className={'ta-b'}
                  style={{ textAlign: 'center' }}
                  colSpan={
                    plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? 3 : 2
                  }
                >
                  {(plantDetails?.saleOrderItems[0]?.destinationDetails
                    ? plantDetails?.saleOrderItems[0]?.destinationDetails?.toUpperCase()
                    : '') +
                    ',' +
                    (plantDetails?.country ? plantDetails?.country : '')}
                </td>
                <td
                  className={'ta-b'}
                  style={{ textAlign: 'center' }}
                  colSpan={
                    plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? 3 : 2
                  }
                >
                  {plantDetails?.saleOrderItems[0]?.paymentTerms}
                </td>
                <td
                  className={'ta-b'}
                  style={{ textAlign: 'center' }}
                  colSpan={2}
                >
                  INDIA
                </td>
              </tr>
              <tr>
                <td className={'ta-b'} style={{ textAlign: 'center' }}>
                  <b>Marks & Nos.</b>
                  {plantDetails?.marksAndNo}
                </td>
                <td
                  className={'ta-b'}
                  style={{ textAlign: 'center' }}
                  colSpan={plantDetails?.isItem === true ? 2 : 3}
                >
                  <b>Description Of Goods</b>
                </td>
                {plantDetails?.isItem === true ? (
                  <>
                    <td
                      className={'ta-b'}
                      style={{ textAlign: 'center' }}
                      colSpan={1}
                    >
                      <b>Item Code</b>
                    </td>
                  </>
                ) : (
                  <></>
                )}
                <td className={'ta-b'} style={{ textAlign: 'center' }}>
                  <b>Size</b>
                </td>
                {plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? (
                  <td className={'ta-b'} style={{ textAlign: 'center' }}>
                    <b>
                      {' '}
                      NET WEIGHT PER CARTON <br />
                      {conditionRes?.[0]?.quantityUom === true
                        ? ' ( IN LBS ) '
                        : ' ( IN KGS ) '}
                    </b>
                  </td>
                ) : (
                  ''
                )}
                {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !== null ? (
                  <td className={'ta-b'} style={{ textAlign: 'center' }}>
                    <b>
                      {' '}
                      GROSS WEIGHT PER CARTON
                      <br />
                      {conditionRes?.[0]?.quantityUom === true
                        ? ' ( IN LBS ) '
                        : ' ( IN KGS ) '}
                    </b>
                  </td>
                ) : (
                  ''
                )}
                <td className={'ta-b'} style={{ textAlign: 'center' }}>
                  <b>No.Of Cartons</b>
                </td>
                <td
                  className={'ta-b'}
                  colSpan={
                    plantDetails?.saleOrderItems[0]?.grossWeightPerKg ||
                    plantDetails?.isItem === true|| conditionRes?.[0]?.bestByDate!='DAY CODES'
                      ? 1
                      : 2
                  }
                  style={{ textAlign: 'center', borderBottom: '0px' }}
                >
                  <b>
                    Quantity <br />
                    {conditionRes?.[0]?.quantityUom === true
                      ? ' (IN LBS)'
                      : ' (IN KGS)'}
                  </b>
                </td>
                {plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? (
                  <td className={'ta-b'}>
                    GROSS WEIGHT
                    {conditionRes?.[0]?.quantityUom === true
                      ? ' (IN LBS)'
                      : ' (IN KGS)'}
                  </td>
                ) : (
                  ' '
                )}
                {conditionRes?.[0]?.bestByDate =='DAY CODES'?(

                <td className={'ta-b'} style={{ textAlign: 'center' }} colSpan={2}>
                  <b>
                    {' '}
                    Day Codes
                    {/* {
                    plantDetails?.country === 'CANADA' || plantDetails?.country === 'USA' || plantDetails?.country === 'UAE' ? <>
                    </> : <>{plantDetails?.shipmentTerms}</>
                  } <br />  */}
                  </b>
                </td>
                ):(
                  <>
                  <td className={'ta-b'} style={{ textAlign: 'center' }}>
                      <b>
                        {' '}
                        PRODUCTION DATES
                      </b>
                    </td><td className={'ta-b'} style={{ textAlign: 'center' }}>
                        <b>
                          {' '}
                          BEST BY DATES
                         </b>
                      </td></>
                )}
              </tr>
              {
                // let totalRowSpan = 0;
                plantDetails.gradeInfo.map((g, prodIndex) => {
                  let prodRowSpan = containerProductLevelRowSpan.get(prodIndex);
                  return g.info.map((r, index) => {
                    let freightCharges =
                      plantDetails?.freightCharges === undefined
                        ? 0
                        : plantDetails?.freightCharges;
                    let exchangeRate =
                      plantDetails?.exchangeRate === undefined
                        ? 0
                        : plantDetails?.exchangeRate;
                    totalCases += r.noOfCases;
                    const uom = UnitsOfWeightInput.find(
                      (uom) => uom.value == r.uomId
                    );
                    let finalNetWeight;
                    let unitPrice;
                    let invUnitPrice;
                    let grossPerKg;
                    if (plantDetails.isInvoiced == GlobalStatus.YES) {
                      if (uom.name == UomEnum.LB || uom.name == UomEnum.OZ) {
                        {
                          conditionRes?.[0]?.quantityUom === true
                            ? (finalNetWeight = Number(r.quatity))
                            : (finalNetWeight = (
                                Number(r.quatity) * 0.454
                              ).toFixed(3));
                        }
                        unitPrice = (Number(r.revisedPrice) * 0.454).toFixed(2);
                        grossWeightInKg = (
                          Number(
                            plantDetails?.grossWeight
                              ? plantDetails?.grossWeight
                              : 0
                          ) * 0.454
                        ).toFixed(3);
                        frozenWeightInKg = (
                          Number(
                            plantDetails?.frozenWeight
                              ? plantDetails?.frozenWeight
                              : 0
                          ) * 0.454
                        ).toFixed(3);
                        netWeightInKgs += Number(r.quatity) * 0.454;
                        netWeightInLbs += Number(r.quatity);
                      } else {
                        {
                          conditionRes?.[0]?.quantityUom === true
                            ? (finalNetWeight = (
                                Number(r.quatity) / 0.454
                              ).toFixed(3))
                            : (finalNetWeight = Number(r.quatity).toFixed(3));
                        }
                        unitPrice = Number(r.revisedPrice).toFixed(2);
                        grossWeightInKg = Number(
                          plantDetails?.grossWeight
                            ? plantDetails?.grossWeight
                            : 0
                        ).toFixed(3);
                        frozenWeightInKg = Number(
                          plantDetails?.frozenWeight
                            ? plantDetails?.frozenWeight
                            : 0
                        ).toFixed(3);
                        netWeightInKgs += Number(r.quatity);
                        netWeightInLbs += Number(r.quatity) / 0.454;
                      }
                    } else {
                      if (uom.name == UomEnum.LB || uom.name == UomEnum.OZ) {
                        {
                          conditionRes?.[0]?.quantityUom === true
                            ? (finalNetWeight = Number(r.quatity))
                            : (finalNetWeight = (
                                Number(r.quatity) * 0.454
                              ).toFixed(3));
                        }
                        unitPrice = (Number(r.revisedPrice) * 0.454).toFixed(2);
                        grossWeightInKg = (
                          Number(
                            plantDetails?.grossWeight
                              ? plantDetails?.grossWeight
                              : 0
                          ) * 0.454
                        ).toFixed(3);
                        frozenWeightInKg = (
                          Number(
                            plantDetails?.frozenWeight
                              ? plantDetails?.frozenWeight
                              : 0
                          ) * 0.454
                        ).toFixed(3);
                        netWeightInKgs += Number(r.quatity) * 0.454;
                        netWeightInLbs += Number(r.quatity);
                      } else {
                        {
                          conditionRes?.[0]?.quantityUom === true
                            ? (finalNetWeight = (
                                Number(r.quatity) / 0.454
                              ).toFixed(3))
                            : (finalNetWeight = Number(r.quatity).toFixed(3));
                        }
                        unitPrice = Number(r.revisedPrice).toFixed(2);
                        grossWeightInKg = Number(
                          plantDetails?.grossWeight
                            ? plantDetails?.grossWeight
                            : 0
                        ).toFixed(3);
                        frozenWeightInKg = Number(
                          plantDetails?.frozenWeight
                            ? plantDetails?.frozenWeight
                            : 0
                        ).toFixed(3);
                        netWeightInKgs += Number(r.quatity);
                        netWeightInLbs += Number(r.quatity) / 0.454;
                      }
                    }
                    {
                      conditionRes[0]?.isRevisedPrice === true
                        ? (invUnitPrice = Number(r.price ? r.price : 0).toFixed(
                            5
                          ))
                        : (invUnitPrice = Number(
                            r.revisedPrice ? r.revisedPrice : r.price
                          ));
                    }
                    // totalLbWeight += Number(finalNetWeight);
                    // totalAmount += Number(Number(invUnitPrice) * Number(finalNetWeight));
                    totalLbWeight += Number(finalNetWeight);
                    totalAmount += Number(
                      Number(invUnitPrice) * Number(finalNetWeight)
                    );
                    {
                      conditionRes?.[0]?.quantityUom === true
                        ? (grossPerKg = Number(
                            plantDetails?.saleOrderItems[0]?.grossWeightPerKg
                              ? plantDetails?.saleOrderItems[0]
                                  ?.grossWeightPerKg * 2.2046
                              : 0
                          ).toFixed(3))
                        : (grossPerKg = Number(
                            plantDetails?.saleOrderItems[0]?.grossWeightPerKg
                          ));
                    }
                    console.log(grossPerKg, 'ooooooooooooooooo');

                    // return (
                    //   <tr key={index}>
                    //     <td
                    //       className="ta-b"
                    //       rowSpan={totalContainersRowSpan}
                    //       style={{
                    //         display:
                    //           totalContainersRowSpan-- == copiedContainerRowSpan
                    //             ? ''
                    //             : 'none',
                    //       }}
                    //     >
                    //       <b>Container No:</b>
                    //       {plantDetails?.saleOrderItems[0]?.containerNo}
                    //       <br />
                    //       <hr />
                    //       <b>Seal No:</b>
                    //       {plantDetails?.saleOrderItems[0]?.linearSelaNo}
                    //     </td>
                    //     <td
                    //       className="ta-b"
                    //       rowSpan={containerProductLevelRowSpan.get(prodIndex)}
                    //       colSpan={plantDetails?.isItem === true ? 2 : 3}
                    //       style={{
                    //         display:
                    //           prodRowSpan-- ==
                    //           containerProductLevelRowSpan.get(prodIndex)
                    //             ? ''
                    //             : 'none',
                    //         textAlign: 'center',
                    //       }}
                    //     >
                    //       {g.productDescription}
                    //     </td>
                    //     {plantDetails?.isItem === true ? (
                    //       <td
                    //         className={'ta-b'}
                    //         style={{ textAlign: 'center' }}
                    //       >
                    //         {r.itemCode}
                    //       </td>
                    //     ) : (
                    //       <></>
                    //     )}
                    //     <td className={'ta-b'} style={{ textAlign: 'center' }}>
                    //       {r.minGrade}/{r.maxGrade}
                    //       {r.grade && (
                    //         <>
                    //           <br />({r.grade})
                    //         </>
                    //       )}
                    //     </td>
                    //     {plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? (
                    //       <td
                    //         className={'ta-b'}
                    //         style={{ textAlign: 'center' }}
                    //       >
                    //         {finalNetWeight && finalNetWeight != 0
                    //           ? (() => {
                    //               const quantity = Number(
                    //                 conditionRes?.[0]?.quantityUom === true
                    //                   ? netWeightInLbs
                    //                   : netWeightInKgs
                    //               );
                    //               return quantity !== 0
                    //                 ? Number(
                    //                     grossPerKg / quantity
                    //                   ).toLocaleString(undefined, {
                    //                     minimumFractionDigits: 3,
                    //                     maximumFractionDigits: 3,
                    //                   })
                    //                 : 0;
                    //             })()
                    //           : 0}
                    //       </td>
                    //     ) : (
                    //       ' '
                    //     )}

                    //     {plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? (
                    //       <td
                    //         className={'ta-b'}
                    //         style={{ textAlign: 'center' }}
                    //       >
                    //         {finalNetWeight && finalNetWeight != 0
                    //           ? Number(
                    //               Number(
                    //                 conditionRes?.[0]?.quantityUom === true
                    //                   ? netWeightInLbs
                    //                   : netWeightInKgs
                    //               ) / r.noOfCases
                    //             ).toLocaleString(undefined, {
                    //               minimumFractionDigits: 3,
                    //               maximumFractionDigits: 3,
                    //             })
                    //           : 0}
                    //       </td>
                    //     ) : (
                    //       ' '
                    //     )}
                    //     <td className={'ta-b'} style={{ textAlign: 'center' }}>
                    //       {r.noOfCases}
                    //     </td>
                    //     <td
                    //       className={'ta-b'}
                    //       style={{ textAlign: 'center' }}
                    //       colSpan={
                    //         plantDetails?.saleOrderItems[0]?.grossWeightPerKg ||
                    //         plantDetails?.isItem === true
                    //           ? 1
                    //           : 2
                    //       }
                    //     >
                    //       {finalNetWeight
                    //         ? Number(finalNetWeight).toLocaleString(undefined, {
                    //             minimumFractionDigits: 3,
                    //             maximumFractionDigits: 3,
                    //           })
                    //         : 0}
                    //     </td>
                    //     {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    //     null ? (
                    //       <td
                    //         className={'ta-b'}
                    //         style={{ textAlign: 'center' }}
                    //       >
                    //         {grossPerKg}
                    //       </td>
                    //     ) : (
                    //       ' '
                    //     )}
                    //     {/* <td className={'ta-b'}  style={{textAlign:"center"}}>{invUnitPrice}</td> */}
                    //     <td className={'ta-b'} style={{ textAlign: 'center' }}>
                    //       {r.code.map((e) => e.code).join(',')}
                    //     </td>
                    //   </tr>
                    // );
                    const showContainerCell = totalContainersRowSpan-- === copiedContainerRowSpan;
                    return (
                      <tr key={index}>
                        {plantDetails?.modeOfExport === ModeOfExportEnum.FLIGHT ? (
                          <td className="ta-b" style={{ textAlign: "center" }}>
                            {r.marksAndNo}
                          </td>
                        ) : (showContainerCell && (
                          <td
                            className="ta-b"
                            rowSpan={totalContainersRowSpan + 1} // Ensure correct row span
                          >
                            <b>Container No:</b> {plantDetails?.saleOrderItems[0]?.containerNo}
                            <br />
                            <hr
                              style={{
                                border: 'none',
                                borderBottom: '2px solid #000',
                                margin: 0,
                                marginBottom: '-1px',
                              }}
                            />
                            <b>Seal No:</b> {plantDetails?.saleOrderItems[0]?.linearSelaNo}
                          </td>
                        ))}
                    
                        {prodRowSpan-- === containerProductLevelRowSpan.get(prodIndex) && (
                          <td
                            className="ta-b"
                            rowSpan={containerProductLevelRowSpan.get(prodIndex)}
                            colSpan={plantDetails?.isItem ? 2 : 3}
                            style={{ textAlign: "center" }}
                          >
                            {g.productDescription}
                          </td>
                        )}
                    
                        {plantDetails?.isItem && <td className="ta-b">{r.itemCode}</td>}
                    
                        <td className="ta-b" style={{ textAlign: "center" }}>
                          {r.minGrade}/{r.maxGrade}
                          {r.grade && (
                            <>
                              <br />({r.grade})
                            </>
                          )}
                        </td>
                        {plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? (
                  <td className={'ta-b'} style={{ textAlign: 'center' }}>
                    {(Number(finalNetWeight)/Number(r.noOfCases)).toFixed(3)}
                  </td>
                ) : (
                  ''
                )}
                {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !== null ? (
                  <td className={'ta-b'} style={{ textAlign: 'center' }}>
                   {grossPerKg}
                    
                  </td>
                ) : (
                  ''
                )}
                        <td className="ta-b" style={{ textAlign: "center" }}>{r.noOfCases}</td>
                    
                        <td className="ta-b" style={{ textAlign: "center" }}  colSpan={
                    plantDetails?.saleOrderItems[0]?.grossWeightPerKg ||
                    plantDetails?.isItem === true|| conditionRes?.[0]?.bestByDate!='DAY CODES'
                      ? 1
                      : 2
                  }>
                          {finalNetWeight
                            ? Number(finalNetWeight).toLocaleString(undefined, {
                                minimumFractionDigits: 2,
                                maximumFractionDigits: 2,
                              })
                            : "0.00"}
                        </td>
                        {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !== null ? (
                        <td className="ta-b" style={{ textAlign: "center" }}>{Number(Number(grossPerKg)*Number(r.noOfCases)).toFixed(3)}</td>
                      ) : (
                        ''
                      )}
                        {/* <td className="ta-b" style={{ textAlign: "center" }}>
                          {parseFloat(invUnitPrice).toFixed(2)}
                        </td> */}
                    
                        {/* <td className="ta-b" style={{ textAlign: "center" }}>
                          {Number(r.invoiceAmount).toLocaleString(undefined, {
                            minimumFractionDigits: 2,
                            maximumFractionDigits: 2,
                          })}
                        </td> */}
{/* 
                        {conditionRes?.[0]?.bestByDate=='DAY CODES'?( 
                          <td  style={{ textAlign: "center",borderLeft:'1px solid black'}}  >
                          {r.code?.map(item => item.code).join(", ")}{r.code.length>0?`,`:''}
                        </td>):(
                           <>
                           <td className="ta-b" style={{ textAlign: "center" }}>
                           {r.productionDate?.map(item => item.date?moment(item.date).format('DD-MM-YYYY'):'').join(", ")}
                            </td><td className="ta-b" style={{ textAlign: "center" }}>
                                {r.bestBeforeDate?.map(item => item.date?moment(item.date).format('DD-MM-YYYY'):'').join(", ")}
                              </td>
                              </>
                        )} */}
                 
                       {showContainerCell && (
  conditionRes?.[0]?.bestByDate === 'DAY CODES' ? (
    <td
      className="ta-b"
      rowSpan={totalContainersRowSpan + 1}
      colSpan={2}
    >
 {allDayCodes?.map(item => item).join(", ")}     
</td>
  ) : (
    <>
      <td
        className="ta-b"
        rowSpan={totalContainersRowSpan + 1}
      >
        {allProductionDates?.join(", ")}
      </td>
      <td
        className="ta-b"
        rowSpan={totalContainersRowSpan + 1}
      >
        {allBestBeforeDates?.join(", ")}
      </td>
    </>
  )
)}

                      </tr>
                    );
                  });
                })
              }
              {/* ---------------------------old-------------------------------------- */}
              {/* <tr>
                <td className={'ta-b'}>
                  <b>Net Weight</b>
                </td>

                
                {conditionRes?.[0]?.lbParam == true ? (
                  <td className={'ta-b'}>
                    {Number(netWeightInLbs)?.toFixed(2)}
                    (LBS)
                  </td>
                ) : (
                  <td className={'ta-b'}></td>
                )}
                <td className={'ta-b'}>
                  {Number(netWeightInKgs)?.toFixed(2)}
                  (KGS)
                </td>
                {conditionRes?.[0]?.isHsn === true ? (
                  <td
                    className={'ta-b'}
                    rowSpan={conditionRes?.[0]?.frozenWeight === true ? 3 : 2}
                  >
                    <b>HSN Code: </b>
                
                    {[...new Set(plantDetails?.saleOrderItems?.map((item) => item.foodTypeHsnCode))].map((foodTypeHsnCode) => {
  return (
    <>
      <span>{foodTypeHsnCode}</span>
      <br />
    </>
  );
})}
                  </td>
                ) : (
                  <td
                    className={'ta-b'}
                    rowSpan={conditionRes?.[0]?.frozenWeight === true ? 3 : 2}
                  ></td>
                )}
                {conditionRes[0]?.blNo === true ? (
                  <>
                    <td className={'ta-b'}>
                      <b>Total</b>
                    </td>
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    null ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    null ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    <td className={'ta-b'} style={{ textAlign: 'center' }}>
                      {totalCases}
                    </td>
                    <td className={'ta-b'} style={{ textAlign: 'center' }}>
                      {totalLbWeight
                        ? Number(totalLbWeight)?.toLocaleString(undefined, {
                            minimumFractionDigits: 3,
                            maximumFractionDigits: 3,
                          })
                        : 0}
                    </td>
                    <td className={'ta-b'} style={{ textAlign: 'center' }}></td>
                    <td className={'ta-b'} style={{ textAlign: 'center' }}></td>
                  </>
                ) : (
                  <>
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    null ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    null ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    null ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    null ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    null ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    null ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    <td className={'ta-b'}></td>
                    <td className={'ta-b'}> </td>
                  </>
                )}
              </tr>
              {conditionRes?.[0]?.frozenWeight === true ? (
                <tr>
                  <td className={'ta-b'}>
                    <b>Frozen Weight</b>
                  </td>
                  
                  {conditionRes?.[0]?.lbParam == true ? (
                    <td className={'ta-b'}>
                      {Math.round(
                        frozenWeightInKg / 0.454
                      )?.toLocaleString('en-US', {
                        minimumFractionDigits: 3,
                        maximumFractionDigits: 3,
                      })}
                      (LBS)
                    </td>
                  ) : (
                    <td className={'ta-b'}></td>
                  )}
                  <td className={'ta-b'}>
                    {Math.round(frozenWeightInKg)?.toLocaleString('en-US', {
                      minimumFractionDigits: 3,
                      maximumFractionDigits: 3,
                    })}
                    (KGS)
                  </td>
                  {conditionRes?.[0]?.blNo == true ? (
                    <>
                      <td
                        className={'ta-b'}
                        colSpan={
                          plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                          null
                            ? 5
                            : 3
                        }
                        rowSpan={
                          conditionRes?.[0]?.frozenWeight === true ? 2 : 1
                        }
                      >
                        <b>BILL OF LADING NO:</b>
                        {plantDetails?.saleOrderItems[0]?.billOfLadingno}
                      </td>
                    </>
                  ) : (
                    <>
                     
                      <td className={'ta-b'}></td>
                      <td className="ta-b"></td>
                    </>
                  )}
                  <td
                    className={'ta-b'}
                    colSpan={
                      plantDetails?.saleOrderItems[0]?.grossWeightPerKg ||
                      plantDetails?.isItem === true
                        ? 1
                        : 2
                    }
                  ></td>
                  <td className={'ta-b'}></td>
                </tr>
              ) : (
                ''
              )}
              <tr>
                <td className={'ta-b'}>
                  <b>Gross Weight</b>
                </td>
                
                {conditionRes?.[0]?.lbParam == true ? (
                  <td className={'ta-b'}>
                    {Math.round(
                      grossWeightInKg / 0.454
                    )?.toLocaleString('en-US', {
                      minimumFractionDigits: 3,
                      maximumFractionDigits: 3,
                    })}
                    (LBS)
                  </td>
                ) : (
                  <td className={'ta-b'}></td>
                )}
                <td className={'ta-b'}>
                  {Math.round(grossWeightInKg)?.toLocaleString('en-US', {
                    minimumFractionDigits: 3,
                    maximumFractionDigits: 3,
                  })}
                  (KGS)
                </td>
                {conditionRes?.[0]?.blNo == true ? (
                  <></>
                ) : (
                  <>
                    <td className={'ta-b'}>
                      <b>Total</b>
                    </td>
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    <td className={'ta-b'}>{totalCases}</td>
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg ||
                    plantDetails?.isItem === true ? (
                      <td className={'ta-b'}></td>
                    ) : (
                      <></>
                    )}
           

                 
                  </>
                )}
                <td
                  className={'ta-b'}
                  colSpan={
                    plantDetails?.saleOrderItems[0]?.grossWeightPerKg ||
                    plantDetails?.isItem === true
                      ? 1
                      : 2
                  }
                >
                  Temp : {plantDetails?.temperaturee}
                </td>
                <td className={'ta-b'}>
                  {conditionRes?.[0]?.tempIndicatorNo} :
                  {plantDetails?.tempIndicatorNo1}
                  {''}
                  {plantDetails?.tempIndicatorNo2}
                  {''}
                  {plantDetails?.tempIndicatorNo3}
                </td>
              </tr> */}
              {/* --------------------------new----------------------------------------------- */}
              <tr>
                <td className={'ta-b'}>
                  <b>Net Weight</b>
                </td>

                
                {conditionRes?.[0]?.lbParam == true ? (
                  <td className={'ta-b'}>
                    {Number(netWeightInLbs)?.toFixed(2)}
                    (LBS)
                  </td>
                ) : (
                  <td className={'ta-b'}></td>
                )}
                <td className={'ta-b'}>
                  {Number(netWeightInKgs)?.toFixed(2)}
                  (KGS)
                </td>
                {conditionRes?.[0]?.isHsn === true ? (
                  <td
                    className={'ta-b'}
                    rowSpan={conditionRes?.[0]?.frozenWeight === true ? 3 : 2}
                  >
                    <b>HSN Code: </b>
                    {/* {plantDetails?.saleOrderItems?.map((item) => {
                      return (
                        <>
                          <span>{item.foodTypeHsnCode}</span>
                          <br />
                        </>
                      );
                    })} */}
                    {[...new Set(plantDetails?.saleOrderItems?.map((item) => item.foodTypeHsnCode))].map((foodTypeHsnCode) => {
  return (
    <>
      <span>{foodTypeHsnCode}</span>
      <br />
    </>
  );
})}
                  </td>
                ) : (
                  <td
                    className={'ta-b'}
                    rowSpan={conditionRes?.[0]?.frozenWeight === true ? 3 : 2}
                  ></td>
                )}
                {/* {conditionRes[0]?.blNo === true ? (
                  <> */}
                    <td className={'ta-b'}>
                      <b>Total</b>
                    </td>
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    null ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    null ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    <td className={'ta-b'} style={{ textAlign: 'center' }}>
                      {totalCases}
                    </td>
                    <td className={'ta-b'} style={{ textAlign: 'center' }}  colSpan={
                    plantDetails?.saleOrderItems[0]?.grossWeightPerKg ||
                    plantDetails?.isItem === true|| conditionRes?.[0]?.bestByDate!='DAY CODES'
                      ? 1
                      : 2
                  }>
                      {totalLbWeight
                        ? Number(totalLbWeight)?.toLocaleString(undefined, {
                            minimumFractionDigits: 3,
                            maximumFractionDigits: 3,
                          }) 
                        : 0}
                    </td>
                    {/* <td className={'ta-b'} style={{ textAlign: 'center' }}></td> */}
                    {/* <td className={'ta-b'} style={{ textAlign: 'center' }}></td> */}
                    <td className={'ta-b'} rowSpan={
                       conditionRes?.[0]?.frozenWeight === true && conditionRes?.[0]?.blNo === true
                       ? 1
                       : conditionRes?.[0]?.frozenWeight === true && conditionRes?.[0]?.blNo !== true
                       ? 3
                       : 2
                    } colSpan={
                          plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                          null 
                            ? 3
                            : 2
                        }>
                  {conditionRes?.[0]?.tempIndicatorNo} :
                  {plantDetails?.tempIndicatorNo1}
                  {''}
                  {plantDetails?.tempIndicatorNo2}
                  {''}
                  {plantDetails?.tempIndicatorNo3}
                </td>
                  {/* </>
                ) : (
                  <> */}
                    {/* {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    null ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    null ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    null ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    null ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    null ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )} */}
                    {/* {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !== null ? (
        <td className={'ta-b'}> </td>
      ) : (
        ' '
      )}
      {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !== null ? (
        <td className={'ta-b'}> </td>
      ) : (
        ' '
      )} */}
                    {/* {plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    null ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    <td className={'ta-b'}></td>
                    <td className={'ta-b'}> </td>
                  </>
                )} */}
              </tr>
              {conditionRes?.[0]?.frozenWeight === true ? (
                <tr>
                  <td className={'ta-b'}>
                    <b>Frozen Weight</b>
                  </td>
                  
                  {conditionRes?.[0]?.lbParam == true ? (
                    <td className={'ta-b'}>
                      {Math.round(
                        frozenWeightInKg / 0.454
                      )?.toLocaleString('en-US', {
                        minimumFractionDigits: 3,
                        maximumFractionDigits: 3,
                      })}
                      (LBS)
                    </td>
                  ) : (
                    <td className={'ta-b'}></td>
                  )}
                  <td className={'ta-b'}>
                    {Math.round(frozenWeightInKg)?.toLocaleString('en-US', {
                      minimumFractionDigits: 3,
                      maximumFractionDigits: 3,
                    })}
                    (KGS)
                  </td>
                  {conditionRes?.[0]?.blNo == true ? (
                    <>
                      <td
                        className={'ta-b'}
                        colSpan={
                          plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                          null
                            ? 5
                            : 3
                        }
                        rowSpan={
                          conditionRes?.[0]?.frozenWeight === true ? 2 : 1
                        }
                      >
                        <b>BILL OF LADING NO:</b>
                        {plantDetails?.saleOrderItems[0]?.billOfLadingno}
                      </td>
                      <td
                   className={'ta-b'}
                   colSpan={
                     plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                     null
                       ? 3
                       : 2
                   }
                   rowSpan={
                     conditionRes?.[0]?.frozenWeight === true ? 2 : 1
                   }
                >
                  Temp : {plantDetails?.temperaturee}
                </td>
                    </>
                  ) : (
                    <>
                    <td
                   className={'ta-b'}
                   colSpan={
                     plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                     null
                       ? 4
                       : 3
                   }
                   rowSpan={
                     conditionRes?.[0]?.frozenWeight === true ? 2 : 1
                   }
                >
                  Temp : {plantDetails?.temperaturee}
                </td>
                      {/* <td className={'ta-b'}></td>
        <td className={'ta-b'}></td> */}
                      {/* <td className={'ta-b'}></td> */}
                      {/* <td className={'ta-b'}></td>
                      <td className="ta-b"></td> */}
                    </>
                  )}
                  {/* <td
                    className={'ta-b'}
                    colSpan={
                      plantDetails?.saleOrderItems[0]?.grossWeightPerKg ||
                      plantDetails?.isItem === true
                        ? 1
                        : 2
                    }
                  ></td>
                  <td className={'ta-b'}></td> */}
                  
                </tr>
              ) : (
                ''
              )}
              <tr>
                <td className={'ta-b'}>
                  <b>Gross Weight</b>
                </td>
                
                {conditionRes?.[0]?.lbParam == true ? (
                  <td className={'ta-b'}>
                    {Math.round(
                      grossWeightInKg / 0.454
                    )?.toLocaleString('en-US', {
                      minimumFractionDigits: 3,
                      maximumFractionDigits: 3,
                    })}
                    (LBS)
                  </td>
                ) : (
                  <td className={'ta-b'}></td>
                )}
                <td className={'ta-b'}>
                  {Math.round(grossWeightInKg)?.toLocaleString('en-US', {
                    minimumFractionDigits: 3,
                    maximumFractionDigits: 3,
                  })}
                  (KGS)
                </td>
                {/* {conditionRes?.[0]?.blNo == true ? (
                  <></>
                ) : (
                  <>
                    <td className={'ta-b'}>
                      <b>Total</b>
                    </td>
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? (
                      <td className={'ta-b'}> </td>
                    ) : (
                      ' '
                    )}
                    <td className={'ta-b'}>{totalCases}</td>
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg ||
                    plantDetails?.isItem === true ? (
                      <td className={'ta-b'}></td>
                    ) : (
                      <></>
                    )}
                    {/* {totalLbWeight
                        ? Number(totalLbWeight)?.toLocaleString(undefined, {
                            minimumFractionDigits: 3,
                            maximumFractionDigits: 3,
                          })
                        : 0} 

                  
                  </>
                )} */}
                {/* <td
                  className={'ta-b'}
                  colSpan={
                    plantDetails?.saleOrderItems[0]?.grossWeightPerKg ||
                    plantDetails?.isItem === true
                      ? 1
                      : 2
                  }
                >
                  Temp : {plantDetails?.temperaturee}
                </td>
                <td className={'ta-b'}>
                  {conditionRes?.[0]?.tempIndicatorNo} :
                  {plantDetails?.tempIndicatorNo1}
                  {''}
                  {plantDetails?.tempIndicatorNo2}
                  {''}
                  {plantDetails?.tempIndicatorNo3}
                </td> */}
                {conditionRes?.[0]?.frozenWeight != true?(
                  <>
                  {conditionRes?.[0]?.blNo == true ? (
                    <>
                      <td
                        className={'ta-b'}
                        colSpan={
                          plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                          null
                            ? 5
                            : 3
                        }
                        rowSpan={
                          conditionRes?.[0]?.frozenWeight === true ? 2 : 1
                        }
                      >
                        <b>BILL OF LADING NO:</b>
                        {plantDetails?.saleOrderItems[0]?.billOfLadingno}
                      </td>
                      <td
                   className={'ta-b'}
                   colSpan={
                     plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                     null
                       ? 3
                       : 2
                   }
                   rowSpan={
                     conditionRes?.[0]?.frozenWeight === true ? 2 : 1
                   }
                >
                  Temp : {plantDetails?.temperaturee}
                </td>
                    </>
                  ) : 
                  (
                    <>
                    <td
                   className={'ta-b'}
                   colSpan={
                     plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                     null
                       ? 4
                       : 3
                   }
                   rowSpan={
                     conditionRes?.[0]?.frozenWeight === true ? 2 : 1
                   }
                >
                  Temp : {plantDetails?.temperaturee}
                </td>
                      {/* <td className={'ta-b'}></td>
        <td className={'ta-b'}></td> */}
                      {/* <td className={'ta-b'}></td> */}
                      {/* <td className={'ta-b'}></td>
                      <td className="ta-b"></td> */}
                    </>
                  )}
                  </>
                ):(<></>)}
                
              </tr>
              <tr>
              <td
                  className={'ta-b'}
                  colSpan={plantDetails?.saleOrderItems[0]?.grossWeightPerKg !==
                    null
                      ? 12
                      : 9}
                >
                  <b style={{ textAlign: 'left' }}>PACKED & PROCESSED BY : </b>
                  <h4 style={{ display: 'inline', textAlign: 'left' }}>
                    {processingData?.company ? processingData?.company : ''}
                  </h4>
                  <br />
                  {processingData?.addressOne ? processingData?.addressOne + ',' : ''}
          <br />
          {processingData?.addressTwo
            ? processingData?.addressTwo + ' - ' + processingData?.postalCode
            : ''}
          <br />
          {processingData?.state + ', ' + processingData?.country}
                  <br />
                  <b style={{ textAlign: 'center' }}>APPROVAL NUMBER :</b>
                  {exportersPlant?.approvalNum}{' '}
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  {exportersPlant?.feiNumber ? (
                    <>
                      <b style={{ textAlign: 'center' }}>USFDA REGN NO:</b>
                      {exportersPlant?.consigneefdaRegNumber}
                    </>
                  ) : (
                    <></>
                  )}
                </td>
              </tr>
              {plantDetails.remarks != null ? (
                <tr>
                  <td
                    className={'ta-b'}
                    colSpan={
                      plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? 12 : 9
                    }
                    style={{ fontSize: '16px', paddingTop: '20px' }}
                  >
                    <p>
                      <b>{plantDetails.remarks}</b>
                    </p>
                  </td>
                </tr>
              ) : (
                <></>
              )}
              <tr>
                <td
                  className={'ta-b'}
                  colSpan={
                    plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? 12 : 9
                  }
                  style={{ fontSize: '16px', paddingTop: '20px' }}
                >
                  <p>
                    <b>
                      SHIPPED UNDER D-2 AND "FISH, CRUSTACEANS, MOLLUSCES,
                      AQUATIC, INVERTEBRATES AND ANY AQUATIC ANIMALS PRODUCTS OF
                      MARINE OR FRESH WATER ORIGIN IN PROCESSED, PRESERVED AND
                      FROZEN FORM"
                    </b>
                  </p>
                </td>
              </tr>
              <tr>
                <td
                  className={'ta-b'}
                  colSpan={
                    plantDetails?.saleOrderItems[0]?.grossWeightPerKg ? 8 : 6
                  }
                  style={{ fontSize: '16px', paddingTop: '20px' }}
                >
                  <div>
                    <b>Declaration</b>
                  </div>
                  <div>
                    We declare that the invoice shows the actual price of goods
                    described
                  </div>
                  <div>
                    and all particulars are true and correct . "This Product has
                    not been{' '}
                  </div>
                  <div>
                    previously refused by any other country prior to the
                    shipment to USA,"
                  </div>
                </td>
                <td
                  colSpan={5}
                  className={'ta-b'}
                  style={{ textAlign: 'center' }}
                >
                  <div>
                    for <b>{exporterData?.name}</b>
                    <br />
                    <br />
                    <br />
                    <br />
                    <b>AUTHORISED SIGNATORY</b>
                  </div>
                </td>
              </tr>
              {/* {
                plantDetails?.saleOrderItems?.map(item => {
                  totalCases += item.invoicedCases;
                  const uom = UnitsOfWeightInput.find(uom => uom.value == item.uomId);
                  let finalNetWeight;
                  let unitPrice;
                  if (plantDetails.isInvoiced == GlobalStatus.YES) {
                    if (uom.name == UomEnum.LB || uom.name == UomEnum.OZ) {
                      finalNetWeight = (Number(item.invoicedQty) * 0.454).toFixed(3);
                      unitPrice = (Number(item.revisedUnitPrice) / 0.454).toFixed(5);
                    } else {
                      finalNetWeight = Number(item.invoicedQty).toFixed(3);
                      unitPrice = Number(item.unitPrice).toFixed(5);
                    }
                  }
                  else {
                    if (uom.name == UomEnum.LB || uom.name == UomEnum.OZ) {
                      finalNetWeight = (Number(item.netWeight) * 0.454).toFixed(3);
                      unitPrice = (Number(item.unitPrice) / 0.454).toFixed(5);
                    } else {
                      finalNetWeight = Number(item.netWeight).toFixed(3);
                      unitPrice = Number(item.unitPrice).toFixed(5);
                    }
                  }
                  totalLbWeight += Number(finalNetWeight);
                  totalGrossWeight += (Number(item.grossWeightPerKg) * Number(item.invoicedCases));
                  totalFrozenWeight += Number(item.frozenWeight);

                  // totalAmount += Number(unitPrice) * Number(finalNetWeight);
                  totalAmount = item.netAmount ;
                  totalAm += Number(item.netAmount);
                  let latinName = item.itemName === "Vannamei" ? "LITOPENAEUS VANNAMEI" : item.itemName === "Black Tiger" || "Sea Tiger" ? "PENAEUS MONODON" : "";
                  // let shrimp = item.itemName === "Vanname"?"SHRIMP":"";
                  let shrimp = "SHRIMPS";
                  let outputWeight = '';
                  if (uom.name == UomEnum.LB || uom.name == UomEnum.OZ) {
                    outputWeight = UomEnum.LB;
                  } else if (uom.name == UomEnum.KG || uom.name == UomEnum.Gms) {
                    outputWeight = UomEnum.KG;
                  }
                  lbPouchWeight = Number(item.pouchWeight)
                  kgPouchWeight = Number(item.pouchWeight)
                  if (uom.name == UomEnum.OZ) {
                    lbPouchWeight = lbPouchWeight * 0.0625
                  }
                  if (uom.name == UomEnum.Gms) {
                    kgPouchWeight = kgPouchWeight * 0.001
                  }
                  return (
                    <>
                    <tr style={{ border: '0px' }}>
                      <td className='ta-b'></td>
                      {/* <td className='ta-b' colSpan={3}>{item.pouches + ' * ' + ((uom.name == UomEnum.LB || uom.name == UomEnum.OZ) ? lbPouchWeight.toFixed(2) : kgPouchWeight.toFixed(2)) + " " + ((uom.name == UomEnum.LB || uom.name == UomEnum.OZ) ? 'LB' : 'KG')}<br />
                        <span className='ta-b'>{Number(item.caseWeight).toFixed(2) + " " + ((uom.name == UomEnum.LB || uom.name == UomEnum.OZ) ? 'LB' : 'KG')}</span><br /><span className='ta-b'>{(uom.name == UomEnum.LB || uom.name == UomEnum.OZ) ? <>{(Number(item.caseWeight) * 0.454).toFixed(3) + ' KGS'}</> : <></>}</span></td> */}
              {/* <td className='ta-b'>{item.hsnCode}</td> */}
              {/* <td colSpan={3} className='ta-b'>
                        {((item.foodTypeCode?.toLocaleUpperCase('en-US').charAt(0) == "C") ? 'COOKED' : item.foodTypeName?.toLocaleUpperCase('en-US')) + ' FROZEN ' + ((item.valueAdditionOneIdCode === 'EZPeel') ? ' HEADLESS ' : '') + item.valueAdditionOneIdName?.toLocaleUpperCase('en-US') + ' ' + (
                          (!(([
                            'HLSO', 'HOSO', 'EZPeel', 'N/A'
                          ].indexOf(item.valueAdditionOneIdCode)) > -1) ? " AND " : '')
                        ) + (item.valueAdditionTwoIdCode ? item.valueAdditionTwoIdName?.toLocaleUpperCase('en-US') : '')}<br />{(item.valueAdditionThreeIdCode ? item.valueAdditionThreeIdName?.toLocaleUpperCase('en-US') : '') + ' ' + (item.valueAdditionFiveIdCode ? item.valueAdditionFiveIdName?.toLocaleUpperCase('en-US') : '') + ' ' + item.itemName?.toLocaleUpperCase('en-US') + ' ' + shrimp.toUpperCase() + ',' + item.valueAdditionFourIdName?.toLocaleUpperCase('en-US')}<br />
                        {'PACKING : '+ item.pouches + ' * ' + ((uom.name == UomEnum.LB || uom.name == UomEnum.OZ) ? lbPouchWeight.toFixed(2) : kgPouchWeight.toFixed(2)) + " " + ((uom.name == UomEnum.LB || uom.name == UomEnum.OZ) ? 'LB' : 'KG')}<br/>
                        {'LATIN NAME : ' + latinName?.toLocaleUpperCase('en-US') + ' '}<br />
                        {' BRAND : ' + item.displayBrandName?.toLocaleUpperCase('en-US')}<br />
                        {lotRefString}<br />
                        {plantDetails?.finNumber ? ('FPO#/FIN# ' + (plantDetails?.finNumber)) : ''}
                        {/* {' BRAND : ' + item.brandName.toUpperCase()} */}
              {/* </td>  */}
              {/* <td style={{ textAlign: 'center' }} ></td>
                      <td className={'ta-b'} style={{ textAlign: 'center', borderTop: '0px', borderBottom: '0px' }}></td>
                      <td className={'ta-b'} style={{ textAlign: 'center', borderTop: '0px', borderBottom: '0px' }}></td>
                      <td className={'ta-b'} style={{ textAlign: 'center', borderTop: '0px', borderBottom: '0px' }}></td> */}
              {/* <td className={'ta-b'} style={{textAlign:'center', borderTop:'0px', borderBottom:'0px'}}></td> */}
              {/* <td className='ta-b'>{item.minGrade + '/' + item.maxGrade}</td> */}
              {/* <td style={{ textAlign: 'center' }} ></td> */}
              {/* <td className='ta-b'>{item.invoicedCases}</td> */}
              {/* <td className={'ta-b'}>{(finalNetWeight) ? Number(finalNetWeight).toLocaleString(undefined, { minimumFractionDigits: 3, maximumFractionDigits: 3 }) : 0}</td> */}
              {/* <td className={'ta-b'} style={{ textAlign: 'right', borderTop: '0px', borderBottom: '0px' }}></td> */}
              {/* <td className={'ta-b'} colSpan={2}></td> */}
              {/* </tr> */}
              {/* </> */}
              {/* )
                }
                )
              } */}
              {/* <tr>
                    <td className={'ta-b'}><b>Net Weight</b></td>
                    <td className={'ta-b'}>{(Math.round(totalLbWeight / 0.454)).toLocaleString('en-US', { minimumFractionDigits: 3, maximumFractionDigits: 3 })}</td>
                    <td className={'ta-b'}>{(Number(totalLbWeight)).toLocaleString('en-US', { minimumFractionDigits: 3, maximumFractionDigits: 3 })}</td>
                    <td className={'ta-b'} rowSpan={3}><b>HSN Code: </b></td>
                  {/* --------------- condition for total and temperature---------------- */}
              {/* <td className={'ta-b'}><b>Total</b></td> */}
              {/* <td className={'ta-b'}>{totalCases}</td> */}
              {/* <td className={'ta-b'}>{(totalLbWeight) ? Number(totalLbWeight).toLocaleString(undefined, { minimumFractionDigits: 3, maximumFractionDigits: 3 }) : 0}</td> */}
              {/* <td className={'ta-b'} rowSpan={3} colSpan={2}> TEMP Indicator No:</td> */}
              {/* </tr> */}
              {/* <tr> */}
              {/* <td className={'ta-b'}><b>Frozen Weight</b></td>
                    <td className={'ta-b'}></td>
                    <td className={'ta-b'}></td> */}
              {/* <td className={'ta-b'}></td> */}
              {/* <td className={'ta-b'}rowSpan={2} colSpan={3}>Temp:- </td> */}
              {/* <td className={'ta-b'}></td> */}
              {/* </tr> */}
              {/* <tr> */}
              {/* <td className={'ta-b'}><b>Gross Weight</b></td>
                    <td className={'ta-b'}>{Math.round((totalGrossWeight / 0.454) ? (totalGrossWeight / 0.454) : 0 ).toLocaleString('en-US', { minimumFractionDigits: 3, maximumFractionDigits: 3 })}</td>
                    <td className={'ta-b'}>{(Math.round(totalGrossWeight ? totalGrossWeight : 0 )).toLocaleString('en-US', { minimumFractionDigits: 3, maximumFractionDigits: 3 })}</td> */}
              {/* <td className={'ta-b'}></td> */}
              {/* <td className={'ta-b'}> 
                  {Number(totalAm).toLocaleString(CrrencySymbols.find(item => item.name == plantDetails?.saleOrderItems[0]?.currencyDetails).locale, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td> */}
              {/* </tr> */}
              {/* <tr> */}
              {/* <td className={'ta-b'} colSpan={9} style={{  fontSize: '16px', paddingTop: '20px' }}>
                <b style={{ textAlign: 'left'}}>PACKED & PROCESSED BY : </b>
                <h4 style={{ display: 'inline',textAlign: 'left' }}>{(exporterData?.name) ? exporterData?.name : ''}</h4><br />
                  {plantDetails?.invoicedPlant?.villageName + ", " + plantDetails?.invoicedPlant?.mandalName}<br />
                  {plantDetails?.invoicedPlant?.postalCode + ", " + plantDetails?.invoicedPlant?.distirctName + ", " + plantDetails?.invoicedPlant?.stateName + ", " + plantDetails?.invoicedPlant?.countryName}<br />
                  <b style={{ textAlign: 'center'}}>APPROVAL NUMBER :</b>{plantDetails?.invoicedPlant?.fdaRegNumber} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  {plantDetails?.invoicedPlant?.feiNumber ?
                    <><b style={{ textAlign: 'center'}}>USFDA REGN NO:</b>{plantDetails?.invoicedPlant?.feiNumber}</> : <></>}
                  </td> */}
              {/* </tr> */}
              {/* <tr>
                <td className={'ta-b'} colSpan={9} style={{  fontSize: '16px', paddingTop: '20px' }}><p><b>SHIPPED UNDER D-2 AND "FISH, CRUSTACEANS, MOLLUSCES, AQUATIC, INVERTEBRATES AND ANY AQUATIC ANIMALS PRODUCTS OF MARINE OR FRESH WATER ORIGIN IN PROCESSED, PRESERVED AND FROZEN FORM"</b></p>
                  </td>
                </tr> */}
              {/* <tr>
                <td colSpan={5} id='inputText'><b>Declaration :</b>
                  <TextArea style={{ outline: 'none', border: 'none' }} rows={3} contentEditable={true} defaultValue={defaultDeclaration}
                    onChange={(evt) => handleRemarks(evt)}
                  ></TextArea>
                  {plantDetails?.remarks?.length > 0 ? <>
                    <h4><b>REMARKS : {(plantDetails?.remarks) ? plantDetails?.remarks : ''}</b></h4>
                  </> : ''}
                </td>
                <td colSpan={4} className={'ta-b'} style={{ textAlign: 'left' }}>
                  <div className='stamp-and-print'>

                    <b>Signature & Date For:</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <h4>{exporterData?.name}</h4><br />
                    <h4>AUTHORISED SIGNATORY</h4>
                  </div>
                </td>
              </tr>  */}
            </table>
            {/* <table className={'ta-b'} style={{ width: '100%' }} id="table-to-xls">
              <tr><td className={'ta-b'} colSpan={8} style={{ textAlign: 'center', fontSize: '16px', lineHeight: '12px', paddingTop: '20px' }}><h1>PACKING LIST</h1></td></tr>
              <tr>
                <td className={'ta-b'} colSpan={3} rowSpan={2}>
                  <b>Exporter:</b> <br />
                  <h4 style={{ display: 'inline' }}>{(exporterData?.name) ? exporterData?.name : ''}</h4><br />
                  {(exporterData?.addressOne) ? exporterData?.addressOne + ',' : ''}
                  <br />
                  {(exporterData?.addressTwo) ? (exporterData?.addressTwo) + ' - ' + exporterData?.postalCode : ''}
                  <br />
                  {exporterData?.state + ', ' + exporterData?.country}
                  <br /><b>GSTIN:</b>
                  {exporterData?.GSTNumber}
                  <br />

                </td>
                <td className={'ta-b'} colSpan={3}>
                  <b>Invoice No. </b>
                  {plantDetails?.invoiceNumber}<br />
                  <b>Date:</b>
                  {moment(plantDetails?.invoiceDate).format('DD-MMM-YYYY')}
                </td>

                <td className={'ta-b'} colSpan={2}>
                  <b>Exporter's Ref<br />
                    IE Code </b> {exporterData?.ieCode}
                </td>
              </tr>
              <tr>
                <td colSpan={5} className={'ta-b'}>
                  <b>Buyer's Order No. </b>
                  PO NO. {plantDetails.custPoNo}
                  <h4><b>Date:</b>{plantDetails?.actualEdl ? (moment(plantDetails?.actualEdl).format('DD-MMM-YYYY')) : null}
                  </h4>
                </td>
              </tr>

              <tr>
                <td className={'ta-b'} colSpan={3} rowSpan={plantDetails?.notifyPartyThree ? 2 : 1} >
                  <b>PROCESSED & PACKED AT </b><br />
                  <h4 style={{ display: 'inline' }}>{(exporterData?.name) ? exporterData?.name : ''}</h4><br />
                  {plantDetails?.invoicedPlant?.villageName + ", " + plantDetails?.invoicedPlant?.mandalName}<br />
                  {plantDetails?.invoicedPlant?.postalCode + ", " + plantDetails?.invoicedPlant?.distirctName + ", " + plantDetails?.invoicedPlant?.stateName + ", " + plantDetails?.invoicedPlant?.countryName}<br />
                  <b>FDA REGISTRATION NUMBER :</b>{plantDetails?.invoicedPlant?.fdaRegNumber}
                  <br />
                  {plantDetails?.invoicedPlant?.feiNumber ?
                    <><b>FEI NUMBER:</b>{plantDetails?.invoicedPlant?.feiNumber}</> : <></>}
                </td>
                {
                  (plantDetails.notifyPartyOne) ?
                    <td colSpan={plantDetails?.notifyPartyOne ? 3 : 5} className={'ta-b'} style={{ textAlign: 'start' }}>
                      <u>
                        Notify party 1</u>
                      <br />
                      <pre>
                        <b>{plantDetails?.notifyPartyOne?.split("\n")[0]}</b><br />
                        {plantDetails?.notifyPartyOne?.split("\n")[1]}<br />
                        {plantDetails?.notifyPartyOne?.split("\n")[2]}<br />
                        {plantDetails?.notifyPartyOne?.split("\n")[3]}</pre><br />

                    </td> : <></>
                }
                {
                  (plantDetails.notifyPartyTwo) ?
                    <td colSpan={2} className={'ta-b'} style={{ textAlign: 'start', width: '50%' }}>
                      <u>
                        Notify party 2</u>
                      <br />
                      <pre>
                        <b>{plantDetails?.notifyPartyTwo?.split("\n")[0]}</b><br />
                        {plantDetails?.notifyPartyTwo?.split("\n")[1]}<br />
                        {plantDetails?.notifyPartyTwo?.split("\n")[2]}<br />
                        {plantDetails?.notifyPartyTwo?.split("\n")[3]}</pre><br /><br />

                    </td> : <></>
                }
              </tr>
              <tr >
                {
                  (plantDetails.notifyPartyThree) ?
                    <td colSpan={plantDetails.notifyPartyFour ? 3 : 5} className={'ta-b'} style={{ textAlign: 'start' }}>
                      <u>
                        Notify party 3</u>
                      <br />
                      <pre>
                        <b>{plantDetails?.notifyPartyThree?.split("\n")[0]}</b><br />
                        {plantDetails?.notifyPartyThree?.split("\n")[1]}<br />
                        {plantDetails?.notifyPartyThree?.split("\n")[2]}<br />
                        {plantDetails?.notifyPartyThree?.split("\n")[3]}</pre><br /><br />
                    </td>
                    : <></>
                }
                {
                  (plantDetails.notifyPartyFour) ?
                    <td colSpan={2} className={'ta-b'} style={{ textAlign: 'start' }}>
                      <u>
                        Notify party 4</u>
                      <br />
                      <pre>
                        <b>{plantDetails?.notifyPartyFour?.split("\n")[0]}</b><br />
                        {plantDetails?.notifyPartyFour?.split("\n")[1]}<br />
                        {plantDetails?.notifyPartyFour?.split("\n")[2]}<br />
                        {plantDetails?.notifyPartyFour?.split("\n")[3]}</pre><br /><br />
                    </td>
                    : <></>
                }

              </tr>


              <tr >
                <td colSpan={3} rowSpan={2} className={'ta-b'}>
                  <b>Consignee:</b><br />
                  {
                     plantDetails?.country === "CANADA" && (
                      <>
                         <b>AZ GEMS CANADA INC:</b>
                      </>
                     )
                  }
                  {
                    plantDetails?.country === "USA" && (
                      <><b>AZ GEMS INC.</b></>
                    )
                  }<br />
                  {plantDetails?.saleOrderItems[0]?.customeraddress?.split(",")[0] + ","}<br />
                  {plantDetails?.saleOrderItems[0]?.customeraddress?.split(",")[1] + ","}<br />
                  {plantDetails?.saleOrderItems[0]?.customeraddress?.split(",")[2] + ","}<br />
                  {plantDetails?.saleOrderItems[0]?.customeraddress?.split(",")[3]}<br />
                  {
                    plantDetails?.endCustomerName === 'AZ Gems' ?
                    <>
                    <b>FDA REGISTRATION NO.</b>{unitsData?.consigneefdaRegNumber}
                    </> : ''
                  }
                </td>

                <td colSpan={5} className={'ta-b'} >
                  <b>
                    Importer on record:
                  </b><br />
                        {
                     plantDetails?.country === "CANADA" && (
                      <>
                         <b>AZ GEMS CANADA INC:</b>
                      </>
                     )
                  }
                  {
                    plantDetails?.country === "USA" && (
                      <><b>AZ GEMS INC.</b></>
                    )
                  }<br />      
                  {plantDetails?.saleOrderItems[0]?.customeraddress?.split(",")[0] + ","}<br />
                  {plantDetails?.saleOrderItems[0]?.customeraddress?.split(",")[1] + "," + plantDetails?.saleOrderItems[0]?.customeraddress?.split(",")[2] + "," + plantDetails?.saleOrderItems[0]?.customeraddress.split(",")[3]}
                  <br />{
                    plantDetails?.endCustomerName === 'AZ Gems' ?
                    <>
                    <b>FDA REGISTRATION NO.</b>{unitsData?.consigneefdaRegNumber}
                    </> : ''
                  }
                </td>
              </tr>

              <tr>
                <td colSpan={3} className={'ta-b'}>
                  <b > Country of Origin of Goods:</b><br />
                  INDIA
                </td>
                <td colSpan={5} className={'ta-b'}>
                  <b> Country of Final Destination:</b><br />
                  {plantDetails?.country}{' '}

                </td>

              </tr>


              <tr>
                <td className={'ta-b'} colSpan={2}>
                  <b>Pre Carriage By:</b>
                  <h4>Road</h4>
                </td>
                <td className={'ta-b'} colSpan={1}>
                  <b>Place of Receipt of Pre-carrier:</b>
                  {(plantDetails?.placeOfReceipt) ? plantDetails?.placeOfReceipt : " "}
                </td>
                <td colSpan={5} className={'ta-b'}>
                  <b>Terms of Delivery and Payment:</b><br />

                  {plantDetails?.saleOrderItems[0]?.paymentTerms}

                </td>
              </tr>

              <tr>

                <td className={'ta-b'} colSpan={2}>
                  <b>Vessel / Flight No. </b>
                  {(plantDetails?.vesselName) ? (plantDetails?.vesselName).toUpperCase() : ""}
                </td>
                <td className={'ta-b'} colSpan={1}>
                  <b> Port of Loading: </b><br />

                  {plantDetails?.portofloading ? (plantDetails?.portofloading)?.toUpperCase() + ', INDIA' : ''}

                </td>

                <td colSpan={5} rowSpan={2} className={'ta-b'}>
                  <b> Container No.&nbsp;</b>
                  {plantDetails?.saleOrderItems[0]?.containerNo}
                  <br />
                  <b> Liner Seal No.&nbsp;</b>
                  {plantDetails?.saleOrderItems[0]?.linearSelaNo}

                  <br />
                  <b> Bill of Lading No.&nbsp;</b>
                  {plantDetails?.trackingNo}<br />

                </td>
              </tr>
              <tr>
                <td className={'ta-b'} colSpan={2}>
                  <b>Port of Discharge:</b><br />
                  {(plantDetails?.portOfDischarge ? (plantDetails?.portOfDischarge)?.toUpperCase() : '') + "," + (plantDetails?.country ? plantDetails?.country : '')}
                </td>
                <td className={'ta-b'} colSpan={1}><b>
                  Final Destination:</b><br />
                  {(plantDetails?.saleOrderItems[0]?.destinationDetails ? (plantDetails?.saleOrderItems[0]?.destinationDetails)?.toUpperCase() + "," : '') + (plantDetails?.country ? plantDetails?.country : '')}
                </td>
              </tr>

              <tr>
                <td colSpan={1} style={{ textAlign: 'center', fontSize: 10 }}>
                  Marks & Nos / No & Kind of Pkgs
                </td>
                <td colSpan={1} style={{ textAlign: 'center' }}>
                </td>
                <td style={{ textAlign: 'center' }} colSpan={2}>
                  Description of Goods
                </td>

                <td style={{ textAlign: 'center' }}>
                </td>
                <th className={'ta-b'} colSpan={1} style={{ textAlign: 'center', borderBottom: '0px' }} rowSpan={2}>
                  Quantity
                  <br />
                  {
                    plantDetails?.country === 'CANADA' ? <>
                      IN KGs
                    </> : <>IN LBs</>
                  } <br /> NET WEIGHT
                </th>
                <th className={'ta-b'} colSpan={1} style={{ textAlign: 'center', borderBottom: '0px' }} rowSpan={2}>

                </th>
                <th className={'ta-b'} colSpan={1} style={{ textAlign: 'center', borderBottom: '0px' }} rowSpan={2}>

                </th>
              </tr>
              <tr>
                <th colSpan={1} style={{ textAlign: 'center' }}>
                </th>
                <th colSpan={1} style={{ textAlign: 'center' }}>
                  HSN Code
                </th>
                <th colSpan={2} style={{ textAlign: 'left' }}>
                  Size
                </th>
                <th style={{ textAlign: 'left' }}>
                  No. Of Cartons
                </th>
              </tr>

              {
                plantDetails?.saleOrderItems?.map(item => {
                  totalCases += item.invoicedCases;
                  const uom = UnitsOfWeightInput.find(uom => uom.value == item.uomId);
                  let finalNetWeight;
                  let unitPrice;
                  if (plantDetails.isInvoiced == GlobalStatus.YES) {
                    if (uom.name == UomEnum.LB || uom.name == UomEnum.OZ) {
                      if (plantDetails?.country === 'CANADA') {
                        finalNetWeight = (Number(item.invoicedQty) * 0.454).toFixed(3);
                        unitPrice = Number(item.revisedUnitPrice).toFixed(5);
                      } else {
                        finalNetWeight = (Number(item.invoicedQty)).toFixed(3);
                        unitPrice = Number(item.revisedUnitPrice).toFixed(5);
                      }
                    } else {
                      finalNetWeight = Number((item.invoicedQty)).toFixed(3);
                      unitPrice = (Number(item.unitPrice)).toFixed(5);
                    }
                  }
                  else {
                    if (uom.name == UomEnum.LB || uom.name == UomEnum.OZ) {
                      finalNetWeight = (Number(item.netWeight) * 0.454).toFixed(3);
                      unitPrice = (Number(item.unitPrice) / 0.454).toFixed(5);
                    } else {
                      finalNetWeight = Number(item.netWeight).toFixed(3);
                      unitPrice = Number(item.unitPrice).toFixed(5);
                    }
                  }
                  totalLbWeight += Number(finalNetWeight);
                  totalGrossWeight += (Number(item.grossWeightPerKg) * Number(item.invoicedCases));
                  // totalAmount += Number(unitPrice) * Number(finalNetWeight);
                  totalAmount += (Number(plantDetails?.totalAmount))
                  let latinName = item.itemName === "Vannamei" ? "LITOPENAEUS VANNAMEI" : item.itemName === "Black Tiger" || "Sea Tiger" ? "PENAEUS MONODON" : "";
                  // let shrimp = item.itemName === "Vanname"?"SHRIMP":"";
                  let shrimp = "SHRIMPS";
                  let outputWeight = '';
                  if (uom.name == UomEnum.LB || uom.name == UomEnum.OZ) {
                    outputWeight = UomEnum.LB;
                  } else if (uom.name == UomEnum.KG || uom.name == UomEnum.Gms) {
                    outputWeight = UomEnum.KG;
                  }
                  lbPouchWeight = Number(item.pouchWeight)
                  kgPouchWeight = Number(item.pouchWeight)
                  if (uom.name == UomEnum.OZ) {
                    lbPouchWeight = lbPouchWeight * 0.0625
                  }
                  if (uom.name == UomEnum.Gms) {
                    kgPouchWeight = kgPouchWeight * 0.001
                  }
                  return (
                    <><tr style={{ border: '0px' }}>
                      <td style={{ textAlign: 'center' }}>{item.pouches + ' * ' + ((uom.name == UomEnum.LB || uom.name == UomEnum.OZ) ? lbPouchWeight.toFixed(2) : kgPouchWeight.toFixed(2)) + " " + ((uom.name == UomEnum.LB || uom.name == UomEnum.OZ) ? 'LB' : 'KG')}<br />
                        <span style={{ textAlign: 'center' }}>{Number(item.caseWeight).toFixed(2) + " " + ((uom.name == UomEnum.LB || uom.name == UomEnum.OZ) ? 'LB' : 'KG')}</span><br /><span style={{ textAlign: 'center' }}>{(uom.name == UomEnum.LB || uom.name == UomEnum.OZ) ? <>{(Number(item.caseWeight) * 0.454).toFixed(3) + ' KGS'}</> : <></>}</span></td>
                      <td style={{ textAlign: 'center' }}>{item.hsnCode}</td>
                      <td colSpan={2} style={{ textAlign: 'left', alignContent: 'center' }}>
                        {((item.foodTypeCode?.toLocaleUpperCase('en-US').charAt(0) == "C") ? 'COOKED' : item.foodTypeName?.toLocaleUpperCase('en-US')) + ' FROZEN ' + ((item.valueAdditionOneIdCode === 'EZPeel') ? ' HEADLESS ' : '') + item.valueAdditionOneIdName?.toLocaleUpperCase('en-US') + ' ' + (
                          (!(([
                            'HLSO', 'HOSO', 'EZPeel', 'N/A'
                          ].indexOf(item.valueAdditionOneIdCode)) > -1) ? " AND " : '')
                        ) + (item.valueAdditionTwoIdCode ? item.valueAdditionTwoIdName?.toLocaleUpperCase('en-US') : '')}<br />{(item.valueAdditionThreeIdCode ? item.valueAdditionThreeIdName?.toLocaleUpperCase('en-US') : '') + ' ' + (item.valueAdditionFiveIdCode ? item.valueAdditionFiveIdName?.toLocaleUpperCase('en-US') : '') + ' ' + item.itemName?.toLocaleUpperCase('en-US') + ' ' + shrimp.toUpperCase() + ',' + item.valueAdditionFourIdName?.toLocaleUpperCase('en-US')}<br />
                        {'LATIN NAME : ' + latinName?.toLocaleUpperCase('en-US') + ' '}<br />
                        {' BRAND : ' + item.displayBrandName?.toLocaleUpperCase('en-US')}<br />
                        {lotRefString}<br />
                        {plantDetails?.finNumber ? ('FPO#/FIN# ' + (plantDetails?.finNumber)) : ''}
                      </td>
                      <td style={{ textAlign: 'center' }} ></td>
                      <td className={'ta-b'} style={{ textAlign: 'center', borderTop: '0px', borderBottom: '0px' }}></td>
                      <td className={'ta-b'} style={{ textAlign: 'center', borderTop: '0px', borderBottom: '0px' }}></td>
                      <td className={'ta-b'} style={{ textAlign: 'center', borderTop: '0px', borderBottom: '0px' }}></td>
                    </tr>
                      <tr>
                        <td style={{ textAlign: 'center' }}></td>
                        <td style={{ textAlign: 'center' }}></td>
                        <td style={{ textAlign: 'left' }}>{item.minGrade + '/' + item.maxGrade}</td>
                        <td style={{ textAlign: 'center' }} ></td>
                        <td style={{ textAlign: 'right' }}>{item.invoicedCases}</td>
                        <td className={'ta-b'} style={{ textAlign: 'right', borderTop: '0px', borderBottom: '0px' }}>{(finalNetWeight) ? Number(finalNetWeight).toLocaleString(undefined, { minimumFractionDigits: 3, maximumFractionDigits: 3 }) : 0}</td>
                        <td className={'ta-b'} style={{ textAlign: 'right', borderTop: '0px', borderBottom: '0px' }}></td>
                        <td className={'ta-b'} style={{ textAlign: 'right', borderTop: '0px', borderBottom: '0px' }}></td>
                      </tr>
                    </>
                  )
                }
                )
              }
              <tr>
                <td className={'ta-b'} colSpan={4} style={{ textAlign: 'center', borderTop: '0px' }}>
                  <b> Total</b>
                </td>
                <td colSpan={1} className={'ta-b'} style={{ textAlign: 'right' }}><b>
                  {totalCases}</b>
                </td>
                <td style={{ textAlign: 'right' }} className={'ta-b'}><b>
                  {(totalLbWeight) ? Number(totalLbWeight).toLocaleString(undefined, { minimumFractionDigits: 3, maximumFractionDigits: 3 }) : 0}</b>
                </td>
                <td className={'ta-b'} style={{ borderTop: '0px' }}></td>
                <td className={'ta-b'} style={{ borderTop: '0px' }}></td>
              </tr>

              <br></br>
              <br></br>
              <br></br>
              <br></br>
              <br></br>

              <tr>
                <td style={{ width: '20%' }} className={'ta-b'}></td>
                {
                  plantDetails.country === 'CANADA' ? <>
                    <td style={{ textAlign: 'center', width: '20%', borderBottom: '0px' }} className={'ta-b'}>
                      <h4><b>IN LBS</b></h4>
                    </td>
                    <td style={{ textAlign: 'center', width: '20%', borderBottom: '0px' }} className={'ta-b'}>
                      <h4><b>IN KGS</b></h4>
                    </td>
                  </> : <>
                    <td style={{ textAlign: 'center', width: '20%', borderBottom: '0px' }} className={'ta-b'}>
                      <h4><b>IN LBS</b></h4>
                    </td>
                    <td style={{ textAlign: 'center', width: '20%', borderBottom: '0px' }} className={'ta-b'}>
                      <h4><b>IN KGS</b></h4>
                    </td>
                  </>
                }
                <td style={{ width: '30%' }}></td>
                <td className={'ta-b'} colSpan={4} style={{ width: '10%', borderTop: '0px', borderLeft: '0px', borderBottom: '0px' }}></td>
              </tr>
              <tr>
                <td style={{ width: '20%', borderBottom: '0px' }} className={'ta-b'}>
                  {' '}
                  <b>TOTAL NET WEIGHT:{' '}</b>
                </td>

                {
                  plantDetails.country === 'CANADA' ? <>
                    <td style={{ textAlign: 'right', width: '20%', borderTop: '0px', borderBottom: '0px' }} className={'ta-b'}>
                      <h4>{(Math.trunc(totalLbWeight / 0.454)).toLocaleString('en-US', { minimumFractionDigits: 3, maximumFractionDigits: 3 })}</h4>
                    </td>
                    <td style={{ textAlign: 'right', width: '20%', borderTop: '0px', borderBottom: '0px' }} className={'ta-b'}>
                      <h4>{(Number((totalLbWeight))).toLocaleString('en-US', { minimumFractionDigits: 3, maximumFractionDigits: 3 })}</h4>
                    </td>
                  </> : <>
                    <td style={{ textAlign: 'right', width: '20%', borderTop: '0px', borderBottom: '0px' }} className={'ta-b'}>
                      <h4>{(Math.trunc(totalLbWeight)).toLocaleString('en-US', { minimumFractionDigits: 3, maximumFractionDigits: 3 })}</h4>
                    </td>
                    <td style={{ textAlign: 'right', width: '20%', borderTop: '0px', borderBottom: '0px' }} className={'ta-b'}>
                      <h4>{(Number((totalLbWeight * 0.454))).toLocaleString('en-US', { minimumFractionDigits: 3, maximumFractionDigits: 3 })}</h4>
                    </td>
                  </>

                }

                <td colSpan={3} style={{ width: '30%', textAlign: 'center' }}>
                  <b>TOTAL NO. OF MASTER CARTONS:</b>
                </td>
                <td className={'ta-b'} colSpan={2} style={{ textAlign: 'right', width: '10%', borderTop: '0px', borderLeft: '0px', borderBottom: '0px' }}>
                  <h4>{totalCases}</h4>
                </td>


              </tr>
              <tr>
                <td style={{ width: '20%', borderTop: '0px' }} className={'ta-b'}>
                  {' '}
                  <b> TOTAL GROSS WEIGHT:</b>
                </td>
                <td style={{ textAlign: 'right', width: "20%", borderTop: '0px' }} className={'ta-b'}>
                  <h4>{Math.round((totalGrossWeight / 0.454) ? (totalGrossWeight / 0.454) : 0).toLocaleString('en-US', { minimumFractionDigits: 3, maximumFractionDigits: 3 })}</h4>
                </td>
                <td style={{ textAlign: 'right', width: '20%', borderTop: '0px' }} className={'ta-b'}>
                  <h4>{(Math.round(totalGrossWeight ? totalGrossWeight : 0)).toLocaleString('en-US', { minimumFractionDigits: 3, maximumFractionDigits: 3 })}</h4>
                </td>
                <td colSpan={3} style={{ width: '30%', textAlign: 'center' }}>
                </td>
                <td className={'ta-b'} colSpan={2} style={{ textAlign: 'right', width: '10%', borderTop: '0px', borderLeft: '0px', borderBottom: '0px' }}  >
                </td>
              </tr>
              <tr>
                <td colSpan={4} id='inputText'><b>Declaration :</b>
                  <TextArea style={{ outline: 'none', border: 'none' }} rows={3} contentEditable={true} defaultValue={defaultDeclaration}
                    onChange={(evt) => handleRemarks(evt)}
                  ></TextArea>
                  {plantDetails?.remarks?.length > 0 ? <>
                    <h4><b>REMARKS : {(plantDetails?.remarks) ? plantDetails?.remarks : ''}</b></h4>
                  </> : ''}
                </td>
                <td colSpan={4} className={'ta-b'} style={{ textAlign: 'left' }}>
                  <div className='stamp-and-print'>

                    <b>Signature & Date For:</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <h4>{exporterData?.name}</h4><br />
                    <h4>AUTHORISED SIGNATORY</h4>
                  </div>
                </td>
              </tr>
            </table> */}
          </body>
        </html>
      ) : (
        <Card
          title={
            <span
              style={{
                color: 'black',
                borderColor: 'black',
                borderStyle: 'initial',
                height: '100',
              }}
            >
              PLANT PACKING LIST
            </span>
          }
          // extra={<> <Button href="/#/document-register" style={{color:'black'}}>Back</Button></>}
          style={{ textAlign: 'center' }}
          headStyle={{ backgroundColor: '#69c0ff' }}
        >
          <span style={{ paddingTop: '10px', textAlign: 'center' }}>
            <Spin />
          </span>
        </Card>
      )}
    </>
  );
}

export default PostPlantPackingList;
