const moment = require("moment");

const LOGOS = {
  1: "../../../../public/data/logos/mbs-logo.png",
  3: "../../../../public/data/logos/rni-logo.png",
  4: "../../../../public/data/logos/pv-logo.jpg",
  5: "../../../../public/data/logos/kf-logo.png",
};

/* eslint-disable no-useless-escape */
function formatNumber(num) {
  return Number(num || 0).toLocaleString("id-ID");
}

module.exports = {
  html: (param) => {
    const styles = {
      thTopLeft: "border:2px solid #000000;",
      thTop: "border-top:2px solid #000000;border-right:2px solid #000000;border-bottom:2px solid #000000;",
      thLine: "border-right:2px solid #000000;border-bottom:2px solid #000000;",
      tdLine: "border-right:2px solid #000000;border-bottom:2px solid #000000;",
      tdLineLeft: "border-left:2px solid #000000;border-right:2px solid #000000;border-bottom:2px solid #000000;",
      img: "width:100px;height:auto;",
      title: "text-align:center;font-size:18px;font-weight:bold;text-decoration:underline;",
      thLineLeft: "border-left:2px solid #000000;border-right:2px solid #000000;border-bottom:2px solid #000000;",
    };

    const logo = LOGOS[param?.distributor?.id] || "";

    const formatNumberWithCommas = (number) => {
      return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    };

    // MBS
    if (param?.distributor?.id === 1) {
      return `<!DOCTYPE html>
      <html>
      <body>
           <table width="100%" border="0" cellSpacing="1" cellPadding="1">
                           <tr>
                               <td>
                                   <table width="100%" border="0" cellSpacing="1" cellPadding="3">
                                       <tr>
                                           <td colSpan="8">
                                               <table width="100%" border="0" cellSpacing="1" cellPadding="3">
                                                <tr>
                                                    <td align="left" style="width: 8%">
                                                        <img src=${logo} alt="Logo" style="${styles.img}"/>
                                                    </td>
                                                    <td style="${styles.title}">
                                                        <h3>USULAN DISKON PRODUK</h3>
                                                        ${
                                                          param && param?.workflow?.status === "Approved"
                                                            ? `<h4>${param.doc_no}</h4>`
                                                            : `<h5>${param.doc_no} - (${param.workflow?.status})</h5>`
                                                        }
                                                    </td>
                                                </tr>
                                            </table>
                                           </td>
                                       </tr>
           
                                       <tr>
                                           <td width="20px">&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td width="20px">&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td width="20px">&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td width="20px">&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td width="20px">&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td width="20px">&nbsp;</td>
                                       </tr>
           
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td>Kode Pelanggan</td>
                                           <td>:</td>
                                           <td>${
                                             param?.distributoroutlet ? param?.distributoroutlet?.code : "-"
                                           }&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td rowSpan="4" valign="top">
                                               &nbsp;
                                           </td>
                                           <td width="20px">&nbsp;</td>
                                       </tr>
           
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td width="100px">Nama Pelanggan</td>
                                           <td>:</td>
                                           <td width="60%">${param?.outlet?.display_name}&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td width="100px">Principal</td>
                                           <td>:</td>
                                           <td width="550px">&nbsp;PT. SATYA ABADI PHARMA</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td width="20px">&nbsp;</td>
                                       </tr>
           
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td>Type</td>
                                           <td>:</td>
                                           <td>${param?.outlet?.outlettype?.display_name || "-"}&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td rowSpan="4" valign="top">
                                               &nbsp;
                                           </td>
                                           <td width="20px">&nbsp;</td>
                                       </tr>
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td>Area Distributor</td>
                                           <td>:</td>
                                           <td>${param?.distributorbranch?.display_name}&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td rowSpan="4" valign="top">
                                               &nbsp;
                                           </td>
                                           <td width="20px">&nbsp;</td>
                                       </tr>
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td>Masa Berlaku</td>
                                           <td>:</td>
                                           <td>
                                               ${param?.from_date} s/d ${param?.to_date}&nbsp;
                                           </td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                       </tr>
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td>Pembayaran</td>
                                           <td>:</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                       </tr>
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td width="20px">&nbsp;</td>
                                       </tr>
                                   </table>
                               </td>
                           </tr>
                           <tr>
                               <td>
                                   <table width="100%" cellSpacing="0" cellPadding="3">
                                       <tr>
                                           <th style="${styles.thTopLeft}" rowSpan="2">
                                               NO.
                                           </th>
                                           <th style="${styles.thTop}" rowSpan="2">
                                               JUMLAH UNIT
                                           </th>
                                           <th style="${styles.thTop}" colSpan="3">
                                               PRODUK
                                           </th>
                                           <th style="${styles.thTop}" colSpan="2">
                                               DISKON (%)
                                           </th>
                                           <th style="${styles.thTop}" rowSpan="2">
                                               HARGA SATUAN
                                               (HNA)
                                           </th>
                                           <th style="${styles.thTop}" rowSpan="2">
                                               JUMLAH HNA (Rp)
                                           </th>
           
                                       </tr>
                                       <tr>
                                           <th style="${styles.thLine}">KODE</th>
                                           <th style="${styles.thLine}">NAMA</th>
                                           <th style="${styles.thLine}">KEMASAN</th>
                                           <th style="${styles.thLine}">DIST</th>
                                           <th style="${styles.thLine}">PRINCIPAL</th>
                                       </tr>
                                       ${param?.udpproducts?.map(
                                         (item, index) =>
                                           `
                                          <tr key=${index}>
                                               <td style="${styles.tdLineLeft}" align="center">
                                                   &nbsp;${index + 1}.
                                               </td>
                                               <td style="${styles.tdLine}" align="center">
                                                   &nbsp;${item?.quantity || 0}
                                               </td>
                                              
                                               <td style="${styles.tdLine}" align="right">
                                                   &nbsp;
                                               </td>
                                               <td style="${styles.tdLine}">&nbsp;${item?.item?.display_name || ""}</td>
                                               <td style="${styles.tdLine}">&nbsp;${item?.stock_uom || ""}</td>
                                               <td style="${styles.tdLine}" align="center">
                                                   &nbsp;${item?.disc_distributor || 0}
                                               </td>
                                               <td style="${styles.tdLine}" align="center">
                                                   &nbsp;${item?.disc_principal || 0}
                                               </td>
                                               <td style="${styles.tdLine}" align="right">
                                                   &nbsp;${formatNumberWithCommas(item?.item_price || 0)}
                                               </td>
                                               <td style="${styles.tdLine}" align="right">
                                                   &nbsp; ${formatNumberWithCommas(item?.total || 0)}
                                               </td>
                                           </tr>
                                        `
                                       )}
                                   </table>
                               </td>
                           </tr>
                           <tr>
                               <td>&nbsp;</td>
                           </tr>
                           <tr>
                               <td>
                                   <b>
                                       <u>Keterangan</u> : ${param?.note}
                                   </b>
                               </td>
                           </tr>
                           <tr>
                               <td>&nbsp;</td>
                           </tr>
                      
                           <tr>
                               <td>
                                   <table width="100%">
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td width="280px">&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td width="280px" align="center">
                                               Jakarta, ${moment(param.creation).format("yyyy-MM-DD")}
                                           </td>
                                           <td>&nbsp;</td>
                                       </tr>
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td align="center" style="fontWeight: 'bold';">
                                               Diminta oleh (Principal):
                                               <br />
                                               MR/Supervisor/Area Sales Manager
                                           </td>
                                           <td>&nbsp;</td>
                                           <td align="center" style="fontWeight: 'bold';">
                                               Disetujui (Kantor Pusat ${param?.distributor?.display_name})
                                           </td>
                                           <td>&nbsp;</td>
                                       </tr>
                                       <tr style="height: '40px';">
                                           <td>&nbsp;</td>
                                           <td align="center">
                                               Proposed by ${param?.territory?.display_name} <br />
                                               ${
                                                 param?.workflow?.workflowapprovers[0]?.status === "Approved"
                                                   ? "Approved by " +
                                                     param?.workflow?.workflowapprovers[0]?.territory?.employees[0]
                                                       ?.employee_name
                                                   : "Not Approved Yet"
                                               } <br />
                                               ${
                                                 param?.workflow?.workflowapprovers[1]?.status === "Approved"
                                                   ? "Approved by " +
                                                     param?.workflow?.workflowapprovers[1]?.territory?.employees[0]
                                                       ?.employee_name
                                                   : "Not Approved Yet"
                                               } <br />
                                           </td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                       </tr>
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td>
                                               <hr />
                                           </td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                       </tr>
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td align="center" style="fontWeight: 'bold'; whiteSpace: 'nowrap';">
                                               Disetujui (Kantor Pusat PT. Satya Abadi Pharma) :
                                           </td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                       </tr>
                                       <tr style="height: '40px';">
                                           <td>&nbsp;</td>
                                           <td align="center">
                                               ${
                                                 param?.workflow?.workflowapprovers[2]?.status === "Approved"
                                                   ? "Approved by " +
                                                     param?.workflow?.workflowapprovers[2]?.territory?.employees[0]
                                                       ?.employee_name
                                                   : "Not Approved Yet"
                                               }&nbsp;
                                           </td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                       </tr>
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td>
                                               <hr />
                                           </td>
                                           <td>&nbsp;</td>
                                           <td>
                                               <hr />
                                           </td>
                                           <td>&nbsp;</td>
                                       </tr>
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td align="center" style="fontWeight: 'bold';">
                                               Bagian Sales & Marketing
                                           </td>
                                           <td>&nbsp;</td>
                                           <td align="center" style="fontWeight: 'bold';">
                                               Bagian Operasional
                                           </td>
                                           <td>&nbsp;</td>
                                       </tr>
                                   </table>
                               </td>
                           </tr>
                       </table>
      </body>
      </html>
      `;
    }

    // PV
    if (param?.distributor?.id === 4) {
      return `<!DOCTYPE html>
      <html>
      <body>
           <table width="100%" border="0" cellSpacing="1" cellPadding="1">
                        <tr>
                            <td>
                                <table width="100%" border="0" cellSpacing="1" cellPadding="3">
                                    <tr>
                                        <td colSpan="8">
                                            <table width="100%" border="0" cellSpacing="1" cellPadding="3">
                                                <tr>
                                                    <td align="left" style="width: 8%">
                                                        <img src=${logo} alt="Logo" style="${styles.img}"/>
                                                    </td>
                                                    <td style="${styles.title}">
                                                        <h3>USULAN DISKON PRODUK</h3>
                                                        ${
                                                          param && param?.workflow?.status === "Approved"
                                                            ? `<h4>${param.doc_no}</h4>`
                                                            : `<h5>${param.doc_no} - (${param.workflow?.status})</h5>`
                                                        }
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
        
                                    <tr>
                                        <td width="20px">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td width="20px">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td width="20px">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td width="20px">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td width="20px">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td width="20px">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td width="100px">Pelanggan</td>
                                        <td>:</td>
                                        <td width="60%">${param.outlet?.display_name}&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td width="100px">Principal</td>
                                        <td>:</td>
                                        <td width="550px">&nbsp;PT. SATYA ABADI PHARMA</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td width="20px">&nbsp;</td>
                                    </tr>
        
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td>Type</td>
                                        <td>:</td>
                                        <td>${param.outlet?.outlettype?.display_name}&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td rowSpan="4" valign="top">
                                            &nbsp;
                                        </td>
                                        <td width="20px">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td>Area Distributor</td>
                                        <td>:</td>
                                        <td>${param.distributorbranch?.display_name}&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td rowSpan="4" valign="top">
                                            &nbsp;
                                        </td>
                                        <td width="20px">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td>Masa Berlaku</td>
                                        <td>:</td>
                                        <td>
                                            ${param.from_date} s/d ${param.to_date}&nbsp;
                                        </td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td>Pembayaran</td>
                                        <td>:</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td width="20px">&nbsp;</td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <table width="100%" cellSpacing="0" cellPadding="3">
                                    <tr>
                                        <th style="${styles.thTopLeft}" rowSpan="2">
                                            NO.
                                        </th>
                                        <th style="${styles.thTop}" rowSpan="2">
                                            JUMLAH UNIT
                                        </th>
                                        <th style="${styles.thTop}" rowSpan="2">
                                            KEMASAN
                                        </th>
                                        <th style="${styles.thTop}" rowSpan="2">
                                            PRODUK
                                        </th>
                                        <th style="${styles.thTop}" rowSpan="2">
                                            BONUS UNIT
                                        </th>
                                        <th style="${styles.thTop}" colSpan="2">
                                            DISKON (%)
                                        </th>
                                        <th style="${styles.thTop}" rowSpan="2">
                                            HARGA SATUAN (HNA)
                                        </th>
                                        <th style="${styles.thTop}" rowSpan="2">
                                            JUMLAH HNA (Rp)
                                        </th>
                                    </tr>
                                    <tr>
                                        <th style="${styles.thLine}">DIST</th>
                                        <th style="${styles.thLine}">PRINCIPAL</th>
                                    </tr>
                                    ${param.udpproducts?.map(
                                      (item, index) =>
                                        `<tr key=${index}>
                                            <td style="${styles.tdLineLeft}" align="center">
                                                &nbsp;${index + 1}.
                                            </td>
                                            <td style="${styles.tdLine}" align="center">
                                                &nbsp;${item?.quantity || 0}
                                            </td>
                                            <td style="${styles.tdLine}">&nbsp;${item?.stock_uom || ""}</td>
        
                                            <td style="${styles.tdLine}">&nbsp;${item?.item?.display_name || ""}</td>
                                            <td style="${styles.tdLine}" align="right">
                                                &nbsp;
                                            </td>
                                            <td style="${styles.tdLine}" align="center">
                                                &nbsp;${item?.disc_distributor || 0}
                                            </td>
                                            <td style="${styles.tdLine}" align="center">
                                                &nbsp;${item?.disc_principal || 0}
                                            </td>
                                            <td style="${styles.tdLine}" align="right">
                                                &nbsp;${formatNumberWithCommas(item?.item_price || 0)}
                                            </td>
                                            <td style="${styles.tdLine}" align="right">
                                                &nbsp; ${formatNumberWithCommas(item?.total || 0)}
                                            </td>
                                        </tr>`
                                    )}
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>
                                <b>
                                    <u>Keterangan</u> : ${param.note}
                                </b>
                            </td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>
                                <table width="100%">
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td width="280px">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td width="280px" align="center">
                                            Jakarta, ${moment(param.creation).format("yyyy-MM-DD")}
                                        </td>
                                        <td>&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td align="center" style="fontWeight: 'bold';">
                                            Diminta oleh (Principal):
                                            <br />
                                            MR/Supervisor/Area Sales Manager
                                        </td>
                                        <td>&nbsp;</td>
                                        <td align="center" style="fontWeight: 'bold';">
                                            Disetujui (Kantor Pusat ${param.distributor?.display_name})
                                        </td>
                                        <td>&nbsp;</td>
                                    </tr>
                                    <tr style="height: '40px';">
                                        <td>&nbsp;</td>
                                        <td align="center">
                                            Proposed by ${param.territory?.display_name} <br />
                                            ${
                                              param.workflow?.workflowapprovers[0]?.status === "Approved"
                                                ? "Approved by " +
                                                  param.workflow?.workflowapprovers[0]?.territory?.employees[0]
                                                    ?.employee_name
                                                : "Not Approved Yet"
                                            } <br />
                                            ${
                                              param.workflow?.workflowapprovers[1]?.status === "Approved"
                                                ? "Approved by " +
                                                  param.workflow?.workflowapprovers[1]?.territory?.employees[0]
                                                    ?.employee_name
                                                : "Not Approved Yet"
                                            } <br />
                                        </td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td>
                                            <hr />
                                        </td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td align="center" style="fontWeight: 'bold'; whiteSpace: 'nowrap';">
                                            Disetujui (Kantor Pusat PT. Satya Abadi Pharma) :
                                        </td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                    </tr>
                                    <tr style="height: '40px';">
                                        <td>&nbsp;</td>
                                        <td align="center">
                                            ${
                                              param.workflow?.workflowapprovers[2]?.status === "Approved"
                                                ? "Approved by " +
                                                  param.workflow?.workflowapprovers[2]?.territory?.employees[0]
                                                    ?.employee_name
                                                : "Not Approved Yet"
                                            }&nbsp;
                                        </td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td>
                                            <hr />
                                        </td>
                                        <td>&nbsp;</td>
                                        <td>
                                            <hr />
                                        </td>
                                        <td>&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td align="center" style="fontWeight: 'bold';">
                                            Bagian Sales & Marketing
                                        </td>
                                        <td>&nbsp;</td>
                                        <td align="center" style="fontWeight: 'bold';">
                                            Bagian Operasional
                                        </td>
                                        <td>&nbsp;</td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
      </body>
      </html>
      `;
    }

    // KFTD
    if (param?.distributor?.id === 5) {
      return `<!DOCTYPE html>
      <html>
      <body>
           <table width="100%" border="0" cellSpacing="1" cellPadding="1">
                           <tr>
                               <td>
                                   <table width="100%" border="0" cellSpacing="1" cellPadding="3">
                                       <tr>
                                           <td colSpan="8">
                                               <table width="100%" border="0" cellSpacing="1" cellPadding="3">
                                                   <tr>
                                                    <td align="left" style="width: 8%">
                                                        <img src=${logo} alt="Logo" style="${styles.img}"/>
                                                    </td>
                                                    <td style="${styles.title}">
                                                        <h3>USULAN DISKON PRODUK</h3>
                                                        ${
                                                          param && param?.workflow?.status === "Approved"
                                                            ? `<h4>No Register : ${param.doc_no}</h4>`
                                                            : `<h5>No Register :${param.doc_no} - (${param.workflow?.status})</h5>`
                                                        }
                                                    </td>
                                                </tr>
                                               </table>
                                           </td>
                                       </tr>
           
                                       <tr>
                                           <td width="20px">&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td width="20px">&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td width="20px">&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td width="20px">&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td width="20px">&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td width="20px">&nbsp;</td>
                                       </tr>
           
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td>Cabang</td>
                                           <td>:</td>
                                           <td>${param?.distributorbranch?.display_name}&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td rowSpan="4" valign="top">
                                               &nbsp;
                                           </td>
                                           <td width="20px">&nbsp;</td>
                                       </tr>
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td width="100px">Nama Pelanggan</td>
                                           <td>:</td>
                                           <td width="60%">${param?.outlet?.display_name}&nbsp;</td>
                                           <td>&nbsp;</td>
                                       </tr>
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td>Kode Pelanggan</td>
                                           <td>:</td>
                                           <td>${
                                             param?.outlet?.distributoroutlets?.length > 0
                                               ? param?.outlet?.distributoroutlets[0]?.code
                                               : "-"
                                           }&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td rowSpan="4" valign="top">
                                               &nbsp;
                                           </td>
                                           <td width="20px">&nbsp;</td>
                                       </tr>
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td>Alamat Pelanggan</td>
                                           <td>:</td>
                                           <td>${
                                             param?.outlet?.distributoroutlets?.length > 0
                                               ? param?.outlet?.distributoroutlets[0]?.address
                                               : "-"
                                           }&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td rowSpan="4" valign="top">
                                               &nbsp;
                                           </td>
                                           <td width="20px">&nbsp;</td>
                                       </tr>
           
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td>Type</td>
                                           <td>:</td>
                                           <td>${param?.outlet?.outlettype?.display_name || "-"}&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td rowSpan="4" valign="top">
                                               &nbsp;
                                           </td>
                                           <td width="20px">&nbsp;</td>
                                       </tr>
           
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td>Periode Berlaku</td>
                                           <td>:</td>
                                           <td>
                                               ${param?.from_date} s/d ${param?.to_date}&nbsp;
                                           </td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                       </tr>
                                       <tr>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td>&nbsp;</td>
                                           <td width="20px">&nbsp;</td>
                                       </tr>
                                   </table>
                               </td>
                           </tr>
                           <tr>
                               <td>
                                   <table width="100%" cellSpacing="0" cellPadding="3" border-collapse="collapse">
                                       <tr>
                                           <th style="${styles.thTopLeft}" rowSpan="2">
                                               NO.
                                           </th>
                                           <th style="${styles.thTop}" colSpan="2" rowSpan="2">
                                               NAMA ITEM PRODUK
                                           </th>
                                           <th style="${styles.thTop}" colSpan="3">
                                               SALES
                                           </th>
           
                                           <th style="${styles.thTop}" rowSpan="2">
                                               TOTAL DISKON %
                                           </th>
                                           <th style="${styles.thTop}" colSpan="2">
                                               BEBAN DISKON
                                           </th>
                                       </tr>
                                       <tr>
                                           <th style="${styles.thLine}">UNIT SALES</th>
                                           <th style="${styles.thLine}">HNA</th>
                                           <th style="${styles.thLine}">Rp.</th>
                                           <th style="${styles.thLine}">PT. KF</th>
                                           <th style="${styles.thLine}">PT. SAP</th>
                                       </tr>
                                       ${param?.udpproducts?.map(
                                         (item, index) =>
                                           ` <tr key=${index}>
                                               <td style="${styles.tdLineLeft}" align="center">
                                                   &nbsp;${index + 1}.
                                               </td>
                                               <td style="${styles.tdLine}" colSpan="2">&nbsp;${
                                             item?.item?.display_name || ""
                                           }</td>
           
                                               <td style="${styles.tdLine}">&nbsp;${item?.stock_uom || ""}</td>
                                               <td style="${styles.tdLine}" align="right">
                                                   &nbsp;${formatNumberWithCommas(item?.item_price || 0)}
                                               </td>
                                               <td style="${styles.tdLine}" align="right">
                                                   &nbsp; ${formatNumberWithCommas(item?.total || 0)}
                                               </td>
                                               <td style="${styles.tdLine}" align="center">
                                                   &nbsp;${
                                                     (Number(item?.disc_distributor) || 0) +
                                                     (Number(item?.disc_principal) || 0)
                                                   }
                                               </td>
                                               <td style="${styles.tdLine}" align="center">
                                                   &nbsp;${item?.disc_distributor || 0}
                                               </td>
                                               <td style="${styles.tdLine}" align="center">
                                                   &nbsp;${item?.disc_principal || 0}
                                               </td>
                                           </tr>
                                        `
                                       )}
                                   </table>
                               </td>
                           </tr>
           
                           <tr>
                               <td>&nbsp;</td>
                               <td>&nbsp;</td>
                               <td>&nbsp;</td>
                           </tr>
                           <tr>
                               <td>
                                   <table width="100%" cellSpacing="0" cellPadding="3" border-collapse="collapse">
                                       <tr>
                                           <th style="${styles.thTopLeft}" colSpan="4">
                                               DIAJUKAN.
                                           </th>
                                           <th style="${styles.thTop}" colSpan="4">
                                               DISETUJUI
                                           </th>
                                       </tr>
                                       <tr style="height: '80px';" align="center">
                                           <td style="${styles.thLineLeft}" colSpan="2">&nbsp;</td>
                                           <td style="${styles.thLine}" colSpan="2">Propose by ${
        param?.territory?.display_name
      } </td>
                                           <td style="${styles.thLine}" colSpan="2">&nbsp;</td>
                                           <td style="${styles.thLine}" colSpan="2"> ${
        param?.workflow?.workflowapprovers[0]?.status === "Approved"
          ? "Approved by " + param?.workflow?.workflowapprovers[0]?.territory?.employees[0]?.employee_name
          : "Waiting for Approval " + param?.workflow?.workflowapprovers[0]?.territory?.display_name
      } <br />
                                               ${
                                                 param?.workflow?.workflowapprovers[1]?.status === "Approved"
                                                   ? "Approved by " +
                                                     param?.workflow?.workflowapprovers[1]?.territory?.employees[0]
                                                       ?.employee_name
                                                   : "Waiting for Approval " +
                                                     param?.workflow?.workflowapprovers[1]?.territory?.display_name
                                               } <br /></td>
                                       </tr>
                                       <tr style="height: '80px';" align="center">
                                           <td style="${
                                             styles.thLineLeft
                                           }" colSpan="2" valign="bottom"> Kacab. PT Kimia Farma</td>
                                           <td style="${
                                             styles.thLine
                                           }" colSpan="2" valign="bottom">MR / SPV PT. SAP (Cabang)</td>
                                           <td style="${
                                             styles.thLine
                                           }" colSpan="2" valign="bottom">Manager Principal PT. KF</td>
                                           <td style="${
                                             styles.thLine
                                           }" colSpan="2" valign="bottom">Sales Manager PT. SAP</td>
                                       </tr>
                                   </table>
                               </td>
                           </tr>
                           <tr>
                               <td>&nbsp;</td>
                           </tr>
                           <tr>
                               <td>
                                   <b>
                                       <u>Keterangan</u> : ${param?.note}
                                   </b>
                               </td>
                           </tr>
                           <tr>
                               <td>&nbsp;</td>
                           </tr>
                       </table>
      </body>
      </html>
      `;
    }
  },
};
