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 PlantPackingListProps {
  saleOrderId: number;
  compId?: string
}

export function PlantPackingList(props: PlantPackingListProps) {
  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 [mainData, setMainData] = useState<any[]>([]);
  const globalPriceService = new GlobalPriceChartService();
  const [conditionRes, setConditionRes] = useState([]);

  let totalCases = 0;
  let totalLbWeight = 0;
  let totalGrossWeight = 0;
  let totalAmount = 0;
  let lbPouchWeight;
  let kgPouchWeight;
  let totalAm = 0;
  let antiDumping;
  let fob;
  let grossWeightInKg;
  let frozenWeightInKg;
  let finalTotalQuantity=0
  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) => {
        console.log(saleOrderId);
        if (res.status) {
          setPlantDetails(res.data);
          const request = new ConditionsRequest();
          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.netWeight=
          salOrderService.getConditionsBasedLogistics(request).then((res) => {
            if (res.status) {
              console.log("Buyer:", res.data[0]?.Buyer);
              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 = '';
  let netWeightInKgs = 0;
  let netWeightInLbs = 0;
    if (normalOrder) {
    if (plantDetails?.lotCode) {
      lotNo = 'LOT NO. ' + plantDetails?.lotCode + ', ';
    }
    if (plantDetails?.buyerPoNo) {
      RefNo = 'REF NO. ' + plantDetails?.buyerPoNo;
    }
    lotRefString = lotNo + RefNo;
  }
  // return 'test';
  let spanVal = 0;
  let adjustSpan = 0;
  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));
  }

  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);

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

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

    lhsContent.push(
      <>
        <b>Exporter:</b> <br />
        <h4>
          {exporterData?.company ? exporterData?.company : ''}
          <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 : ''}
          </>
        )
      ) : (
        <></>
      );
    }

    {
      conditionRes?.[0]?.importerDetails === true ? (
        lhsContent.push(
          <>
            <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
              : ''}
          </>
        )
      ) : (
        <></>
      );
    }


    rhsContent.push(
      <>
        <b>Invoice No: </b>
        {plantDetails?.invoiceNumber}
      </>
    );

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

    rhsContent.push(
      <>
        <b>Place Of Supply: </b>{' '}
        {(plantDetails?.saleOrderItems[0]?.destinationDetails
          ? (plantDetails?.shipmentTerms ? plantDetails?.shipmentTerms : '') +
            ',' +
            plantDetails?.saleOrderItems[0]?.destinationDetails?.toUpperCase()
          : '') +
          ',' +
          (plantDetails?.country ? plantDetails?.country : '')}
      </>
    );

    rhsContent.push(
      <>
        <b>Tax is payable On Reverse Charge : NO</b>
      </>
    );

    // rhsContent.push(
    //   <>
    //     <b>GST NO: </b>
    //     {exporterData?.GSTNumber}
    //   </>
    // );

    rhsContent.push(
      <>
        <b>
          Exporter's Ref
          <br />
          IE Code{' '}
        </b>{' '}
        {exporterData?.ieCode}
      </>
    );

    // {
    //   conditionRes?.[0]?.duplicateBuyer === true ? (
        rhsContent.push(
          <>
          {/* {plantDetails?.consigneeAddress || plantDetails?.consignee ? ( */}
          <b>{plantDetails?.endCustomerName != "HIGH LINER FOODS INC" ? !conditionRes?.[0]?.duplicateBuyer? "BUYER :" :" ULTIMATE Buyer:": "SHIP TO:"} </b>
        {/* ) : (
            <b>Buyer & Consignee:</b>
          )
          } */}
          {/* <br />
          {conditionRes?.[0]?.duplicateBuyerAddress}
        </> */}
        <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>{plantDetails?.endCustomerName === "HIGH LINER FOODS INC" ? "Ship To:" : "Buyer:"}</b>

    //     ) : (
    //       <b>Buyer & Consignee:</b>
    //     )}
    //     <br />
    //     {plantDetails?.endCustomerName}
    //     {plantDetails?.endCustomerName ? ':' : ''}
    //     <br />
    //     {plantDetails?.saleOrderItems[0]?.buyerAddress?.split(',')}
    //     <br />
    //     {plantDetails?.country ? plantDetails?.country : ''}
    //   </>
    // );
    console.log(
      rhsContent,
      'rhssssssssss000000000000000000000000000000000000000000000000'
    );

    {
      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}
      </>
    );
    {
      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));

  let lhsCount = lhsContent.length;
  let rhsCount = rhsContent.length;
  const lhsRowSpanMap = new Map<number, number>();
  const lhsRowSpanCopyMap = new Map<number, number>();
  const blockSpanSize = Math.round(rhsCount / lhsCount);
  const 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,5 
    lhsRowSpanCopyMap.set(rowNumber, blockSpanSize);//1 ,5 
    fulfilledCount = blockSpanSize;//5
  } else {
    const remaing = rhsCount - fulfilledCount;//9-5=4
    const breakDownVal = Math.round( remaing / lhsCount);//4/3=1
    lhsRowSpanMap.set(rowNumber, breakDownVal);//1,5 | 2,1
    lhsRowSpanCopyMap.set(rowNumber, breakDownVal);//1 ,5 | 2,1
    fulfilledCount =blockSpanSize+ breakDownVal;
    
  }
    index++;//1
    rowNumber++;//2
    lhsCount--;//1
  }

  // lhsRowSpanMap.set(1, blockSpanSize + blockSpanSizeRem);
  // lhsRowSpanCopyMap.set(1, blockSpanSize + blockSpanSizeRem);
  let lhsPrintingRowNumber = 1;
  let lhsPrintingIndexNumber = 0;
  let totalNetAmount=0


  return (
    <>
      {/* <span style={{alignContent:'left', backgroundColor:'red'}}>
            <ReactHTMLTableToExcel
              id="test-table-xls-button"
              className="download-table-xls-button"
              table="table-to-xls"
              filename="PlantPackingList"
              sheet="PlantPackingList"
              buttonText="Get Excel" />
          </span> */}
      {plantDetails ? (
        <html>
          <head></head>
          <br />
          <body id={props.compId} className={'stylesInfo print-layout'}>
            <br></br>
            <table
              className={'ta-b stylesInfo'}
              style={{ width: '100%' }}
              id="table-to-xls"
            >
              <tr>
                <td
                  className={'ta-b'}
                  colSpan={10}
                  style={{
                    textAlign: 'center',
                    fontSize: '14px',
                    lineHeight: '12px',
                    paddingTop: '15px',
                  }}
                >
                  <h1 >PACKING LIST</h1>
                </td>
              </tr>
              {rhsContent.map((r, i) => {
                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('innnnnnnnnnnnn');
                  lhsPrintingIndexNumber++;
                  lhsPrintingRowNumber++;
                }
                console.log(currRowSpanConsumption, 'pppppppppp');

                return (
                  <>
                    <tr>
                      <td
                        colSpan={5}
                        className={'ta-b'}
                        rowSpan={currRowSpanConsumption}
                        style={{
                          display:
                            currRowSpanConsumption === currRowSpanReducedCons
                              ? ''
                              : 'none',
                        }}
                      >
                        {lhsContent[lhsPrintingIndexNumber]}
                      </td>
                      <td className={'ta-b'} colSpan={5}>
                        {r}
                      </td>
                    </tr>
                  </>
                );
              })}
              {/* <tr>
                <td className={'ta-b'} colSpan={4} rowSpan={6}>
                  <b>Exporter:</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 />
                  <h4 style={{ display: 'inline' }}>GSTIN: </h4>{exporterData?.GSTNumber}
                  <br />
                  <h4 style={{ display: 'inline' }}>USFDA REGN NO: </h4>{exporterData?.usfdaRegNo}
                </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> */}
              {/* {(plantDetails?.saleOrderItems[0]?.destinationDetails ? (plantDetails?.saleOrderItems[0]?.destinationDetails)?.toUpperCase() + "," : '') + (plantDetails?.country ? plantDetails?.country : '')}                  <br/> */}
              {/* <b>Tax is payable On Reverse Charge: no</b> */}
              {/* </td>
              </tr> */}
              {/* <tr>
              {plantDetails?.consigneeAddress != undefined|| plantDetails?.consignee!=null?
              ( <td className={'ta-b'} colSpan={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={5}>
                  <b>Exporter's Ref<br />
                    IE Code </b> {exporterData?.ieCode}
                </td> 
              </tr> */}
              {/* <tr>
                {conditionRes?.[0]?.duplicateBuyer === true ?(<>
                  <td className={'ta-b'} colSpan={5}>
              <b> Buyer & Consignee:</b><br />
                  {conditionRes?.[0]?.duplicateBuyerAddress}
                </td>
                </>):(<>
                
              <td className={'ta-b'} colSpan={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> */}
              {/* {plantDetails?.htsInfo?.length>0?
            <tr>
            <td className={'ta-b'} colSpan={5}><b>HTS Code : </b>{plantDetails?.htsInfo.map((e)=>e.htsCode).join(',')}</td>
            </tr>
            :<></>} */}

              {/* <tr>
                <td className={'ta-b'} colSpan={5}>
                    <b>{conditionRes?.[0]?.terms}</b>
                    {plantDetails?.deliveryTerms}
                </td>
                </tr> */}

              <tr>
                <td
                  className={'ta-b'}
                  colSpan={10}
                  style={{
                    textAlign: 'center',
                    fontSize: '16px',
                    lineHeight: '10px',
                    paddingTop: '20px',
                  }}
                >
                  <b>{conditionRes?.[0]?.poLabel} : </b> {plantDetails.custPoNo}{' '}
                  <b>Date : </b>{' '}
                  {moment(plantDetails.actualEdl).format('DD-MM-YYYY')}
                </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'} colSpan={2} style={{textAlign:"center"}}>
                  <b>
                    {conditionRes?.[0]?.destinationDetails
                      ? conditionRes?.[0]?.destinationDetails
                      : ''}
                  </b>
                </td>
                <td className={'ta-b'} colSpan={3} style={{textAlign:"center"}}>
                  <b>Terms & Payments</b>
                </td>
                <td className={'ta-b'} style={{textAlign:"center"}}>
                  <b>Origin Of Goods</b>
                </td>
              </tr>
              <tr>
                <td className={'ta-b'} style={{textAlign:"center"}}>
                  &nbsp;
                  {/* {plantDetails?.vesselName?.toUpperCase()} */}
                  </td>
                <td className={'ta-b'} style={{textAlign:"center"}}>
                  {/* {' '} */}
                   &nbsp;
                  {/* {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={2}>
                  {(plantDetails?.saleOrderItems[0]?.destinationDetails
                    ? plantDetails?.saleOrderItems[0]?.destinationDetails?.toUpperCase()
                    : '') +
                    ',' +
                    (plantDetails?.country ? plantDetails?.country : '')}
                </td>
                <td className={'ta-b'} style={{textAlign:"center"}} colSpan={3}>
                  {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>
                </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>
                <td className={'ta-b'} style={{textAlign:"center"}}>
                  <b>No.Of Cartons</b>
                </td>
                <td
                  className={'ta-b'}
                  colSpan={3}
                  style={{ textAlign: 'center', borderBottom: '0px' }}
                >
                  <b>
                    {' '}
                    Quantity{' '}<br/>
                    {conditionRes?.[0]?.quantityUom === true
                      ? ' ( IN LBS ) '
                      : ' ( IN KGS ) '}
                  </b>
                </td>{' '}
                <td className={'ta-b'} colSpan={1}>
                  <b>Remarks</b>
                </td>
                {/* <td className={'ta-b'}><b>Amount in USD</b></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));
                  // 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 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>
                    </>
                  )
                }
                )
              } */}
              {
                // 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;
                    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));
                        } // converting to kg
                        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.price).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
                        ? ( conditionRes?.[0]?.quantityUom === true?
                          invUnitPrice = Number(r.price ? r.price : 0).toFixed(2):
                          invUnitPrice = (Number(r.price ? r.price : 0)*Number(2.20462)).toFixed(2)
                        )
                        : ( conditionRes?.[0]?.quantityUom === true?
                          invUnitPrice = Number(r.revisedPrice ? r.revisedPrice : 0).toFixed(2):
                          invUnitPrice = (Number(r.revisedPrice ? r.revisedPrice : 0)*Number(2.20462)).toFixed(2)
                        );
                    }
                    totalLbWeight += Number(finalNetWeight);
                    totalAmount += Number(
                      Number(invUnitPrice) * Number(finalNetWeight)
                    );
                    totalNetAmount += Number(r.netAmount);
                    finalTotalQuantity+=Number(r.quatity)
                    return (
                      <tr key={index}>
                        {plantDetails?.modeOfExport === ModeOfExportEnum.FLIGHT ? (
                          <td className="ta-b" style={{ textAlign: "center" }}>
                            {r.marksAndNo}
                          </td>
                        ) : (
                        <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>

                        <td className={'ta-b'} style={{textAlign:"center"}}>{r.noOfCases}</td>
                        <td className={'ta-b'} style={{textAlign:"center"}} colSpan={3}>
                        {/* {r.netAmount} */}

                          {finalNetWeight
                            ? Number(finalNetWeight).toLocaleString(undefined, {
                                minimumFractionDigits: 3,
                                maximumFractionDigits: 3,
                              })
                            : 0}
                        </td>
                        {/* <td className={'ta-b'} style={{textAlign:"center"}}>{invUnitPrice}</td> */}
                        <td className={'ta-b'} rowSpan={totalContainersRowSpan}
                          style={{
                            display:
                              totalContainersRowSpan-- == copiedContainerRowSpan
                                ? ''
                                : 'none',
                          }}>
                          {r.code.map((e) => e.code).join(',')}
                          {/* {g.code.map((e)=>e.code).join(',')} */}
                          {/* {Number(Number(invUnitPrice) * Number(finalNetWeight))?.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })} */}
                        </td>
                      </tr>
                    );
                  });
                })
              }
              <tr>
                <td className={'ta-b'}>
                  <b>Net Weight</b>
                </td>


                {conditionRes?.[0]?.lbParam == true ? (
                  <td className={'ta-b'}>
                    {Number(netWeightInLbs).toLocaleString('en-US', {
    minimumFractionDigits: 2,
    maximumFractionDigits: 2
  })}
                    (LBS)
                  </td>
                ) : (
                  <td className={'ta-b'}></td>
                )}
                <td className={'ta-b'}>
                {Number(netWeightInKgs).toLocaleString('en-US', {
    minimumFractionDigits: 2,
    maximumFractionDigits: 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'} style={{textAlign:'center'}}>
                      <b>Total</b>
                    </td>
                    <td className={'ta-b'} style={{ textAlign: 'center' }}>
                      {totalCases}
                    </td>
                    <td className={'ta-b'} style={{ textAlign: 'center' }} colSpan={3}>
                    {Number(totalLbWeight)?.toLocaleString(
                        CrrencySymbols.find(
                          (item) =>
                            item.name ==
                            plantDetails?.saleOrderItems[0]?.currencyDetails
                        )?.locale,
                        { minimumFractionDigits: 2, maximumFractionDigits: 2 }
                      )}
                    </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>
                ) : (
                ' '
                )}
                {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'} style={{ textAlign: 'center' }}>
                      
                    </td>
                    <td className={'ta-b'} style={{ textAlign: 'center' }} colSpan={3}></td>
                    {/* <td className={'ta-b'} style={{ textAlign: 'center' }}></td> */}
                    <td className={'ta-b'} style={{ textAlign: 'center' }}></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={2}
                        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'}></td> */}
                      <td className={'ta-b'}></td>
                      <td className="ta-b"></td>
                    </>
                  )}
                  <td
                    className={'ta-b'}
                    colSpan={3}></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 colSpan={3}></td></>
                ) : (
                  <>
                    <td className={'ta-b'} style={{textAlign:'center'}}><b>Total</b></td>
                  
                    <td className={'ta-b'}style={{textAlign:'center'}}>{totalCases}</td>
                    {plantDetails?.saleOrderItems[0]?.grossWeightPerKg ||
                    plantDetails?.isItem === true ? (
                      <td className={'ta-b'} colSpan={3} style={{textAlign:'center'}}>
                        {Number(totalLbWeight)?.toLocaleString(
                        CrrencySymbols.find(
                          (item) =>
                            item.name ==
                            plantDetails?.saleOrderItems[0]?.currencyDetails
                        )?.locale,
                        { minimumFractionDigits: 2, maximumFractionDigits: 2 }
                      )}
                      </td>
                    ) : (
                      <>
                        <td className={'ta-b'} colSpan={3} style={{textAlign:'center'}}>
                        {Number(totalLbWeight)?.toLocaleString(
                        CrrencySymbols.find(
                          (item) =>
                            item.name ==
                            plantDetails?.saleOrderItems[0]?.currencyDetails
                        )?.locale,
                        { minimumFractionDigits: 2, maximumFractionDigits: 2 }
                      )}
                      </td>
                      </>
                      
                    )}
                    {/* {totalLbWeight
                        ? Number(totalLbWeight)?.toLocaleString(undefined, {
                            minimumFractionDigits: 3,
                            maximumFractionDigits: 3,
                          })
                        : 0} */}

                    {/* <td className={'ta-b'}></td> */}
                    {/* <td className={'ta-b'}> 
                      {Number(totalAmount)?.toLocaleString(CrrencySymbols.find(item => item.name == plantDetails?.saleOrderItems[0]?.currencyDetails)?.locale, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
                      </td> */}
                  </>
                )}
                {/* <td
                  className={'ta-b'}
                  
                >
                &nbsp;
                </td> */}
                
                <td className={'ta-b'} colSpan={2}>
                Temp : {plantDetails?.temperaturee}
                </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> */}
              {/* </table>
          <table style={{width:'100%'}} id="table-to-xls"> */}

              {/* <tr>
                <td style={{ width: '20%' }} className={'ta-b'}></td>
                <td style={{ textAlign: 'center', width: '20%', borderBottom: '0px' }} className={'ta-b'}>
                  <h4>IN LBS</h4>
                </td>
                <td style={{ textAlign: 'center', width: '20%', borderBottom: '0px' }} className={'ta-b'}>
                  <h4>IN KGS</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>
                <td style={{ textAlign: 'right', width: '20%', borderTop: '0px', borderBottom: '0px' }} className={'ta-b'}>
                  <h4>{(Math.round(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 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
                  className={'ta-b'}
                  colSpan={10}
                >
                  <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>
              <tr>
                <td
                  className={'ta-b'}
                  colSpan={10}
                  style={{ fontSize: '14px', paddingTop: '15px' }}
                >
                  <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>
              {plantDetails.remarks && plantDetails.remarks !== '' ? (
  <tr>
    <td
      className={'ta-b'}
      colSpan={10}
      style={{ fontSize: '14px', paddingTop: '15px' }}
    >
      <p>
        <b>{plantDetails.remarks}</b>
      </p>
    </td>
  </tr>
) : null}


              <tr>
                <td colSpan={4} id="inputText">
                  {' '}
                  <div style={{paddingLeft:"8px"}}> 
                    <b>Declaration</b>
                  </div>
                  <div style={{paddingLeft:"8px"}}>
                  {conditionRes?.[0]?.declaration}
                  </div>
                  {plantDetails?.remarks != null ? (
                    <>
                      <h4>
                        <b>
                          REMARKS :{' '}
                          {plantDetails?.remarks ? plantDetails?.remarks : ''}
                        </b>
                      </h4>
                    </>
                  ) : (
                    ''
                  )}
                </td>
                <td
                  colSpan={6}
                  className={'ta-b'}
                  style={{textAlign:"center"}}
                >
                  <div>
                    for {' '}<b>{exporterData?.company}</b>
                    <br />
                    <br /><br /><br />
                    <b>AUTHORISED SIGNATORY</b>
                  </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 PlantPackingList;
