Proforma invoice from the sales order.

Jira Code: ME-189

Customized solution for printing the proforma invoice from sales order by adding a custom button and render the PDF using the suitelet script. It also includes the concept of integrated items.

Advanced PDF Template -Normal Proforma Invoice

<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
<head>
  <link name="NotoSans" type="font" subtype="truetype" src="${nsfont.NotoSans_Regular}" src-bold="${nsfont.NotoSans_Bold}" src-italic="${nsfont.NotoSans_Italic}" src-bolditalic="${nsfont.NotoSans_BoldItalic}" bytes="2" />
  <#if .locale == "zh_CN">
    <link name="NotoSansCJKsc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKsc_Regular}" src-bold="${nsfont.NotoSansCJKsc_Bold}" bytes="2" />
  <#elseif .locale == "zh_TW">
    <link name="NotoSansCJKtc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKtc_Regular}" src-bold="${nsfont.NotoSansCJKtc_Bold}" bytes="2" />
  <#elseif .locale == "ja_JP">
    <link name="NotoSansCJKjp" type="font" subtype="opentype" src="${nsfont.NotoSansCJKjp_Regular}" src-bold="${nsfont.NotoSansCJKjp_Bold}" bytes="2" />
  <#elseif .locale == "ko_KR">
    <link name="NotoSansCJKkr" type="font" subtype="opentype" src="${nsfont.NotoSansCJKkr_Regular}" src-bold="${nsfont.NotoSansCJKkr_Bold}" bytes="2" />
  <#elseif .locale == "th_TH">
    <link name="NotoSansThai" type="font" subtype="opentype" src="${nsfont.NotoSansThai_Regular}" src-bold="${nsfont.NotoSansThai_Bold}" bytes="2" />
  </#if>
    <macrolist>
        <macro id="nlheader">
            <table width="100%"><tr><td align="left" style="padding-top:-10px;"> 
                              <img src="https://system.netsuite.com/core/media/media.nl?id=4406&c=5318034_SB1&h=d6cfe6693b342d031655" style="padding-left:-5px;width:220px;height:80px" />
             <p style="padding-top:-10px;" ><b>${companyInformation.companyName}</b></p>
             <p align="left" font-size="9" style="padding-top:-10px;">1826/II/23 New Amarnath Building</p>
  <p align="left" font-size="9" style="padding-top:-10px;">Bhagirath Palace</p>
  <p align="left" font-size="9" style="padding-top:-10px;">Chandni Chowk Delhi 110006</p>
  <p align="left" font-size="9" style="padding-top:-10px;">India</p>
             <p align="left" font-size="9" style="padding-top:-10px;"><b>GSTIN:</b> 07AAJPK0556E1ZX</p>
             <p align="left" font-size="9" style="padding-top:-10px;"><b>State Code:</b> 07</p>
                <p align="left" font-size="9" style="padding-top:-10px;"><b>Email:</b> sales@manglamelectricals.com</p>
             
             </td><td align="right"><span class="title">Proforma Invoice</span>
             <p font-size="10">PI-${record.tranid}</p> <p font-size="10"><b> Date:</b> ${record.trandate}</p></td></tr> </table>
        </macro>
        <macro id="nlfooter">
            <table style="width: 100%; font-size: 8pt;"><tr>
  <td style="padding: 0;"><barcode codetype="code128" showtext="true" value="${record.tranid}"/></td>
  <td align="right" style="padding: 0;"><pagenumber/> of <totalpages/></td>
  </tr></table>
        </macro>
    </macrolist>
    <style type="text/css">* {
    <#if .locale == "zh_CN">
      font-family: NotoSans, NotoSansCJKsc, sans-serif;
    <#elseif .locale == "zh_TW">
      font-family: NotoSans, NotoSansCJKtc, sans-serif;
    <#elseif .locale == "ja_JP">
      font-family: NotoSans, NotoSansCJKjp, sans-serif;
    <#elseif .locale == "ko_KR">
      font-family: NotoSans, NotoSansCJKkr, sans-serif;
    <#elseif .locale == "th_TH">
      font-family: NotoSans, NotoSansThai, sans-serif;
    <#else>
      font-family: NotoSans, sans-serif;
    </#if>
    }
    table {
      font-size: 9pt;
      table-layout: fixed;
    }
        th {
            font-weight: bold;
            font-size: 8pt;
            vertical-align: middle;
            padding: 5px 6px 3px;
            background-color: #e3e3e3;
            color: #333333;
        }
        td {
            padding: 4px 6px;
        }
    td p { align:left }
        span.title {
            font-size: 28pt;
        }
       .invoicebox
      {
        border:1px; border-color:#000000; margin-top:2px;width:211px;padding-bottom:0px;padding-top:1px;min-height:100px;max-height:100px;
      }
      
</style>
</head>
<body header="nlheader" header-height="20%" footer="nlfooter" footer-height="20pt" padding="0.5in 0.5in 0.5in 0.5in" size="Letter">
   <#assign currency={"US Dollar":"$", "Euro" :"€", "British pound" :"£", "Indian Rupee" :"₹"}>
    <table style="width: 100%; margin-top: 10px;"><tr>
  <td colspan="3" style="font-size: 8pt;  font-weight: bold; color: #333333;padding-right:-5px;">${record.billaddress@label}</td>
  <td colspan="3" style="font-size: 8pt;  font-weight: bold; color: #333333;padding-right:-5px;">${record.shipaddress@label}</td>
  </tr>
  <tr>
  <td colspan="3" style="padding-right:-5px;padding-top:-3px;">${record.billaddress}</td>
  <td colspan="3" style="padding-right:-5px;padding-top:-3px;">${record.shipaddress}</td>
  </tr></table>
  <p  font-size="9" style="padding-left:7px;padding-top:-8px;"> <b>Ph.No. :</b> ${record.entity.phone}</p>
  <p  font-size="9" style="padding-left:7px;padding-top:-5px;"><b>Email:</b> ${record.entity.email}</p>
  <#if record.otherrefnum?has_content><p  font-size="9" style="padding-left:7px;padding-top:-5px;">Reference to your PO#   <b> ${record.otherrefnum} </b>Dated:   <b>${record.custbody3}</b></p></#if>
     
       <#assign count = 0>
  <#list record.item as item>
	<#if item.itemtype?contains("Group") >
       <#assign count = 1>
      </#if>
    </#list> 
    
<#if record.item?has_content && count = 0>
<#assign index = 0>
<table font-size="7" class="itemtable" style="width: 100%; margin-top: 10px;"><!-- start items --><#list record.item as item><#if item_index==0>
<thead>
  <tr>
  <th colspan="4">Sl.No.</th>
      <th colspan="16"><p align="left">Item Code Description</p></th>
      <th colspan="8"><p align="left">HSN/SAC</p></th>
       <th colspan="6"><p align="left">UOM</p></th>
    <th align="center" colspan="5">Qty</th>
  <th align="right" colspan="12">${item.rate@label}</th>
  <th align="right" colspan="12">${item.amount@label}</th>
  <th align="right" colspan="8" style="padding: 10px 6px; white-space: nowrap;">${item.taxrate@label}</th>
  <th align="right" colspan="12" style="padding: 10px 6px; white-space: nowrap;">${item.taxamount@label}</th>
  <th align="right" colspan="12" style="padding: 10px 6px; white-space: nowrap;">${item.grossamt@label}</th>
  </tr>
</thead>
  </#if>
<#if item.itemtype != 'OthCharge'><#if item.custcol_jj_substitute_item?contains("Yes")><tr><td colspan="4"><#assign index=index+1>${index}</td>
  <td colspan="16" line-height="150%"><span class="itemname">${item.custcol_jj_me102_substitute_item}</span><#if item.inventorydetail?has_content ><br/>${item.inventorydetail}</#if><br />${item.custcol_jj_me102_substitute_item_des}</td>
  <td colspan="8"><#if item.custcol_in_hsn_code?has_content>${item.custcol_in_hsn_code?keep_before(" ")}<#else>${item.custcol_in_hsn_code}</#if></td>
  <td colspan="6">${item.units}</td>
    <td align="center" colspan="5">${item.quantity}</td>
  <td align="right" colspan="12">${item.rate}</td>
  <td align="right" colspan="12">${item.amount}</td>
  <td align="right" colspan="8">${item.taxrate}</td>
  <td align="right" colspan="12">${item.taxamount}</td>
  <td align="right" colspan="12">${item.grossamt}</td>
  </tr> <#else><tr>
  <td colspan="4"><#assign index=index+1>${index}</td>
  <td colspan="16" line-height="150%"><span class="itemname">${item.item}</span><#if item.inventorydetail?has_content ><br/>${item.inventorydetail}</#if><br />${item.description}</td>
  <td colspan="8"><#if item.custcol_in_hsn_code?has_content>${item.custcol_in_hsn_code?keep_before(" ")}<#else>${item.custcol_in_hsn_code}</#if></td>
  <td colspan="6">${item.units}</td>
    <td align="center" colspan="5">${item.quantity}</td>
  <td align="right" colspan="12">${item.rate}</td>
  <td align="right" colspan="12">${item.amount}</td>
  <td align="right" colspan="8">${item.taxrate}</td>
  <td align="right" colspan="12">${item.taxamount}</td>
  <td align="right" colspan="12">${item.grossamt}</td>
  </tr></#if></#if>
  </#list><!-- end items --></table>

<hr /></#if>
<#if record.item?has_content && count = 1>
<#assign index = 0>
<table font-size="7" class="itemtable" style="width: 100%; margin-top: 10px;"><!-- start items --><#list record.item as item><#if item_index==0>
<thead>
  <tr>
  <th colspan="4">Sl.No.</th>
      <th colspan="16"><p align="left">Item Code Description</p></th>
      <th colspan="8"><p align="left">HSN/SAC</p></th>
       <th colspan="6"><p align="left">UOM</p></th>
    <th align="center" colspan="5">Qty</th>
  <th align="right" colspan="12">${item.rate@label}</th>
  <th align="right" colspan="12">${item.amount@label}</th>
  <th align="right" colspan="8" style="padding: 10px 6px; white-space: nowrap;">${item.taxrate@label}</th>
  <th align="right" colspan="12" style="padding: 10px 6px; white-space: nowrap;">${item.taxamount@label}</th>
  <th align="right" colspan="12" style="padding: 10px 6px; white-space: nowrap;">${item.grossamt@label}</th>
  </tr>
</thead>
  </#if>
<#if item.itemtype != 'OthCharge'><#if item.itemtype !='Group' && item.itemtype !='EndGroup'  && item.custcol_jj_me71_show_item?string=="Yes" ><#if item.custcol_jj_substitute_item?contains("Yes")><tr><td colspan="4"><#assign index=index+1>${index}</td>
  <td colspan="16" line-height="150%"><span class="itemname">${item.custcol_jj_me102_substitute_item}</span><#if item.inventorydetail?has_content ><br/>${item.inventorydetail}</#if><br />${item.custcol_jj_me102_substitute_item_des}</td>
  <td colspan="8"><#if item.custcol_in_hsn_code?has_content>${item.custcol_in_hsn_code?keep_before(" ")}<#else>${item.custcol_in_hsn_code}</#if></td>
  <td colspan="6">${item.units}</td>
    <td align="center" colspan="5">${item.quantity}</td>
  <td align="right" colspan="12">${item.rate}</td>
  <td align="right" colspan="12">${item.amount}</td>
  <td align="right" colspan="8">${item.taxrate}</td>
  <td align="right" colspan="12">${item.taxamount}</td>
  <td align="right" colspan="12">${item.grossamt}</td>
  </tr> <#else><tr>
  <td colspan="4"><#assign index=index+1>${index}</td>
  <td colspan="16" line-height="150%"><span class="itemname">${item.item}</span><#if item.inventorydetail?has_content ><br/>${item.inventorydetail}</#if><br />${item.description}</td>
  <td colspan="8"><#if item.custcol_in_hsn_code?has_content>${item.custcol_in_hsn_code?keep_before(" ")}<#else>${item.custcol_in_hsn_code}</#if></td>
  <td colspan="6">${item.units}</td>
    <td align="center" colspan="5">${item.quantity}</td>
  <td align="right" colspan="12">${item.rate}</td>
  <td align="right" colspan="12">${item.amount}</td>
  <td align="right" colspan="8">${item.taxrate}</td>
  <td align="right" colspan="12">${item.taxamount}</td>
  <td align="right" colspan="12">${item.grossamt}</td>
  </tr></#if></#if></#if>
  </#list><!-- end items --></table>

<hr /></#if>

  
  <#assign chargeAmt = 0>
  <#list record.item as item>
	<#if item.itemtype =='OthCharge' >
       <#assign chargeAmt = chargeAmt + item.amount>
      </#if>
    </#list>

  

<table style="page-break-inside: avoid; width: 100%; margin-top: 10px;"><tr>
  <td colspan="4"> </td>
  <td align="right" style="font-weight: bold; color: #333333;">${record.subtotal@label}</td>
  <td align="right"><#if chargeAmt !=0 ><#assign subchargeAmt = record.subtotal - chargeAmt>${currency[record.currency]}${subchargeAmt?string["0.00"]}<#else>${record.subtotal}</#if></td>
  </tr>
  <#list record.item as item>
   <#if item.itemtype =='OthCharge' >
       <tr>
  <td colspan="4"> </td>
  <td align="right" style="font-weight: bold; color: #333333;">${item.item}</td>
  <td align="right">${item.amount}</td>
    </tr>
      </#if>
    </#list>



   <#if record.taxtotal2?has_content >
   <tr>
  <td colspan="4"> </td>
  <td align="right" style="font-weight: bold; color: #333333;">IGST</td>
  <td align="right">${currency[record.currency]}${record.taxtotal2}</td>
    </tr></#if>
   <#if record.taxtotal5?has_content >
  <tr>
  <td colspan="4"> </td>
  <td align="right" style="font-weight: bold; color: #333333;">UTGST</td>
  <td align="right">${currency[record.currency]}${record.taxtotal5}</td>
     </tr></#if>
   <#if record.taxtotal3?has_content >
  <tr>
  <td colspan="4"> </td>
  <td align="right" style="font-weight: bold; color: #333333;">CGST</td>
  <td align="right">${currency[record.currency]}${record.taxtotal3}</td>
     </tr></#if>
  <!--<tr>
  <td colspan="4"> </td>
  <td align="right" style="font-weight: bold; color: #333333;">${record.taxtotal@label}</td>
  <td align="right">${record.taxtotal}</td>
  </tr>-->
    <tr>
  <td colspan="4"> </td>
  <td align="right" style="font-weight: bold; color: #333333;">Round Off</td>
      <td align="right"><#assign round = record.total?round ><#assign round = round - record.total >${currency[record.currency]}${round?string["##0.00"]}</td>
  </tr>
  <tr style="background-color: #e3e3e3; line-height: 200%;">
  <td background-color="#ffffff" colspan="4"> </td>
  <td align="right" style="font-weight: bold; color: #333333;">${record.total@label}</td>
  <td align="right">${record.total}</td>
  </tr></table>
  <p  font-size="9" style="padding-left:7px;padding-top:-8px;"><b>Note:</b>  </p> <p  font-size="9" style="padding-left:7px;padding-top:-8px;"> Kindly send / deposit the above amount of <b>${record.total} </b>in any branch of HDFC Bank in favour of
  Manglam Electricals </p><p font-size="9" style="padding-left:7px;padding-top:-8px;"><b> A/c No  00032210006409 </b>of the same amount.</p>
    <br/>
  <table align="right" class="invoicebox"><tr><td><p align="left" >For Manglam Electricals</p></td></tr><tr><td><p align="right"></p></td></tr><tr><td><p align="right"></p></td></tr><tr><td><p align="right">Authorised Signatory </p></td></tr></table>
</body>
</pdf>

Advanced PDF Template -Integrated Proforma Invoice

<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
<head>
  <link name="NotoSans" type="font" subtype="truetype" src="${nsfont.NotoSans_Regular}" src-bold="${nsfont.NotoSans_Bold}" src-italic="${nsfont.NotoSans_Italic}" src-bolditalic="${nsfont.NotoSans_BoldItalic}" bytes="2" />
  <#if .locale == "zh_CN">
    <link name="NotoSansCJKsc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKsc_Regular}" src-bold="${nsfont.NotoSansCJKsc_Bold}" bytes="2" />
  <#elseif .locale == "zh_TW">
    <link name="NotoSansCJKtc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKtc_Regular}" src-bold="${nsfont.NotoSansCJKtc_Bold}" bytes="2" />
  <#elseif .locale == "ja_JP">
    <link name="NotoSansCJKjp" type="font" subtype="opentype" src="${nsfont.NotoSansCJKjp_Regular}" src-bold="${nsfont.NotoSansCJKjp_Bold}" bytes="2" />
  <#elseif .locale == "ko_KR">
    <link name="NotoSansCJKkr" type="font" subtype="opentype" src="${nsfont.NotoSansCJKkr_Regular}" src-bold="${nsfont.NotoSansCJKkr_Bold}" bytes="2" />
  <#elseif .locale == "th_TH">
    <link name="NotoSansThai" type="font" subtype="opentype" src="${nsfont.NotoSansThai_Regular}" src-bold="${nsfont.NotoSansThai_Bold}" bytes="2" />
  </#if>
    <macrolist>
        <macro id="nlheader">
            <table width="100%"><tr><td align="left" style="padding-top:-10px;"> 
                              <img src="https://system.netsuite.com/core/media/media.nl?id=4406&c=5318034_SB1&h=d6cfe6693b342d031655" style="padding-left:-5px;width:220px;height:80px" />
             <p style="padding-top:-10px;" ><b>${companyInformation.companyName}</b></p>
             <p align="left" font-size="9" style="padding-top:-10px;">1826/II/23 New Amarnath Building</p>
  <p align="left" font-size="9" style="padding-top:-10px;">Bhagirath Palace</p>
  <p align="left" font-size="9" style="padding-top:-10px;">Chandni Chowk Delhi 110006</p>
  <p align="left" font-size="9" style="padding-top:-10px;">India</p>
             <p align="left" font-size="9" style="padding-top:-10px;"><b>GSTIN:</b> 07AAJPK0556E1ZX</p>
             <p align="left" font-size="9" style="padding-top:-10px;"><b>State Code:</b> 07</p>
                <p align="left" font-size="9" style="padding-top:-10px;"><b>Email:</b> sales@manglamelectricals.com</p>
             
             </td><td align="right"><span class="title">Proforma Invoice</span>
             <p font-size="10">PI-${record.tranid}</p> <p font-size="10"><b> Date:</b> ${record.trandate}</p></td></tr> </table>
        </macro>
        <macro id="nlfooter">
            <table style="width: 100%; font-size: 8pt;"><tr>
  <td style="padding: 0;"><barcode codetype="code128" showtext="true" value="${record.tranid}"/></td>
  <td align="right" style="padding: 0;"><pagenumber/> of <totalpages/></td>
  </tr></table>
        </macro>
    </macrolist>
    <style type="text/css">* {
    <#if .locale == "zh_CN">
      font-family: NotoSans, NotoSansCJKsc, sans-serif;
    <#elseif .locale == "zh_TW">
      font-family: NotoSans, NotoSansCJKtc, sans-serif;
    <#elseif .locale == "ja_JP">
      font-family: NotoSans, NotoSansCJKjp, sans-serif;
    <#elseif .locale == "ko_KR">
      font-family: NotoSans, NotoSansCJKkr, sans-serif;
    <#elseif .locale == "th_TH">
      font-family: NotoSans, NotoSansThai, sans-serif;
    <#else>
      font-family: NotoSans, sans-serif;
    </#if>
    }
    table {
      font-size: 9pt;
      table-layout: fixed;
    }
        th {
            font-weight: bold;
            font-size: 8pt;
            vertical-align: middle;
            padding: 5px 6px 3px;
            background-color: #e3e3e3;
            color: #333333;
        }
        td {
            padding: 4px 6px;
        }
    td p { align:left }
        span.title {
            font-size: 28pt;
        }
       .invoicebox
      {
        border:1px; border-color:#000000; margin-top:2px;width:211px;padding-bottom:0px;padding-top:1px;min-height:100px;max-height:100px;
      }
      
</style>
</head>
<body header="nlheader" header-height="20%" footer="nlfooter" footer-height="20pt" padding="0.5in 0.5in 0.5in 0.5in" size="Letter">
  <#assign currency={"US Dollar":"$", "Euro" :"€", "British pound" :"£", "Indian Rupee" :"₹"}>
    <table style="width: 100%; margin-top: 10px;"><tr>
  <td colspan="3" style="font-size: 8pt;  font-weight: bold; color: #333333;padding-right:-5px;">${record.billaddress@label}</td>
  <td colspan="3" style="font-size: 8pt;  font-weight: bold; color: #333333;padding-right:-5px;">${record.shipaddress@label}</td>
  </tr>
  <tr>
  <td colspan="3" style="padding-right:-5px;padding-top:-3px;">${record.billaddress}</td>
  <td colspan="3" style="padding-right:-5px;padding-top:-3px;">${record.shipaddress}</td>
  </tr></table>
  <p  font-size="9" style="padding-left:7px;padding-top:-8px;"> <b>Ph.No. :</b> ${record.entity.phone}</p>
  <p  font-size="9" style="padding-left:7px;padding-top:-5px;"><b>Email:</b> ${record.entity.email}</p>
  <#if record.otherrefnum?has_content><p  font-size="9" style="padding-left:7px;padding-top:-5px;">Reference to your PO#   <b> ${record.otherrefnum} </b>Dated:   <b>${record.custbody3}</b></p></#if>
<#assign index = 0>
<#if record.item?has_content>
 <table font-size="7" class="itemtable" style="width: 100%; margin-top: 10px;">
                        <!-- start items -->
                        <#list items.items as item>
                            <#if item_index==0>
                                <thead>
                                    <tr>
                                        <th colspan="4">Sl.No.</th>
                                        <th colspan="16"><p style="text-align:left">
                                          Item Code Description
                                          </p></th>
                                        <th colspan="8">
                                            <p align="left">HSN/SAC</p>
                                        </th>
                                        <th colspan="6">
                                            <p align="left">UOM</p>
                                        </th>
                                        <th align="center" colspan="5">Qty</th>
                                        <th align="right" colspan="12">Rate</th>
                                        <th align="right" colspan="12">Amount</th>
                                        <th align="right" colspan="8" style="padding: 10px 6px; white-space: nowrap;">Tax Rate</th>
                                        <th align="right" colspan="12" style="padding: 10px 6px; white-space: nowrap;">Tax Amount</th>
                                        <th align="right" colspan="12" style="padding: 10px 6px; white-space: nowrap;">Gross Amount</th>
                                    </tr>
                                </thead>
                            </#if>
                            <tr>
                                <td colspan="4">
                                    <#assign index=index+1>${index}
                                </td>
                                <td colspan="16" line-height="150%"><b>${item.item}</b><br />${item.components}<br />${item.description}
                                </td>
                                <td colspan="8">${item.hsncode}</td>
                                <td colspan="6">${item.unit}</td>
                                <td align="center" colspan="5">${item.quantity}</td>
                                <td align="right" colspan="12">${currency[record.currency]} ${item.rate}</td>
                                <td align="right" colspan="12">${currency[record.currency]} ${item.amount}</td>
                                <td align="right" colspan="8">${item.taxrate}</td>
                                <td align="right" colspan="12">${currency[record.currency]} ${item.taxamount}</td>
                                <td align="right" colspan="12"> ${currency[record.currency]} ${item.grossamt}</td>
                            </tr>
                        </#list><!-- end items -->
                    </table>
<hr style="width: 100%; color: #d3d3d3; background-color: #d3d3d3; height: 1px;" /></#if>
  
   <#assign chargeAmt = 0>
  <#list record.item as item>
	<#if item.itemtype =='OthCharge' >
       <#assign chargeAmt = chargeAmt + item.amount>
      </#if>
    </#list>


<table style="page-break-inside: avoid; width: 100%; margin-top: 10px;"><tr>
  <td colspan="4"> </td>
  <td align="right" style="font-weight: bold; color: #333333;">${record.subtotal@label}</td>
  <td align="right"><#if chargeAmt !=0 ><#assign subchargeAmt = record.subtotal - chargeAmt>${currency[record.currency]}${subchargeAmt?string["0.00"]}<#else>${record.subtotal}</#if></td>
  </tr>
    
    <#list record.item as item>
   <#if item.itemtype =='OthCharge' >
       <tr>
  <td colspan="4"> </td>
  <td align="right" style="font-weight: bold; color: #333333;">${item.item}</td>
  <td align="right">${item.amount}</td>
    </tr>
      </#if>
    </#list>

 
   <#if record.taxtotal2?has_content >
   <tr>
  <td colspan="4"> </td>
  <td align="right" style="font-weight: bold; color: #333333;">IGST</td>
  <td align="right">${currency[record.currency]}${record.taxtotal2}</td>
    </tr></#if>
   <#if record.taxtotal5?has_content >
  <tr>
  <td colspan="4"> </td>
  <td align="right" style="font-weight: bold; color: #333333;">UTGST</td>
  <td align="right">${currency[record.currency]}${record.taxtotal5}</td>
     </tr></#if>
   <#if record.taxtotal3?has_content >
  <tr>
  <td colspan="4"> </td>
  <td align="right" style="font-weight: bold; color: #333333;">CGST</td>
  <td align="right">${currency[record.currency]}${record.taxtotal3}</td>
     </tr></#if>

    <tr>
  <td colspan="4"> </td>
  <td align="right" style="font-weight: bold; color: #333333;">Round Off</td>
      <td align="right"><#assign round = record.total?round ><#assign round = round - record.total >${currency[record.currency]} ${round?string["##0.00"]}</td>
  </tr>
  <tr style="background-color: #e3e3e3; line-height: 200%;">
  <td background-color="#ffffff" colspan="4"> </td>
  <td align="right" style="font-weight: bold; color: #333333;">${record.total@label}</td>
  <td align="right">${record.total}</td>
  </tr></table>
  <p  font-size="9" style="padding-left:7px;padding-top:-8px;"><b>Note:</b>  </p> <p  font-size="9" style="padding-left:7px;padding-top:-8px;"> Kindly send / deposit the above amount of <b>${record.total} </b>in any branch of HDFC Bank in favour of
  Manglam Electricals </p><p font-size="9" style="padding-left:7px;padding-top:-8px;"><b> A/c No  00032210006409 </b>of the same amount.</p>
    <br/>
  <table align="right" class="invoicebox"><tr><td><p align="left" >For Manglam Electricals</p></td></tr><tr><td><p align="right"></p></td></tr><tr><td><p align="right"></p></td></tr><tr><td><p align="right">Authorised Signatory </p></td></tr></table>
</body>
</pdf>

Suitelet

/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 * @NModuleScope SameAccount
 */
/**
 * Script Description: PDF Creation 
 */
/*******************************************************************************
 * * ME * *
 * **************************************************************************
 * Date:13/3/19
 * Script name: ME JJ SL Print Invoice
 * Script id: customscript_jj_sl_print_invoice
 * 
 ******************************************************************************/
define(['N/file', 'N/render', 'N/record', 'N/search', 'N/config', 'N/file', 'N/encode'], function (file, render, record, search, config, file, encode) {
    /**
     * Definition of the Suitelet script trigger point.
     *
     * @param {Object} context
     * @param {ServerRequest} context.request - Encapsulation of the incoming request
     * @param {ServerResponse} context.response - Encapsulation of the Suitelet response
     * @Since 2015.2
     */
    function onRequest(context) {
        try {
            var internalId = context.request.parameters.intenalId;
            var objRecord = record.load({
                type: "salesorder",
                id: internalId
            });
        
            var mainitem = objRecord.getValue({
                fieldId: 'custbody_jj_main_item_print',

            });

            var items = [];
            var length = objRecord.getLineCount({ sublistId: 'item' });
            //log.debug("line", length)
            var itemgroup_count = 0;
            for (var i = 0; i < length; i++) {
                var itemtype = objRecord.getSublistValue({
                    sublistId: 'item',
                    fieldId: 'itemtype',
                    line: i
                });

               

                if (itemtype == 'Group' && mainitem == false)
                    itemgroup_count++;
            }


            if (itemgroup_count > 0) {
                log.debug("integrated item")
                var myFile = render.create();

                var template = 135;
                myFile.setTemplateById(template);


                myFile.addRecord({
                    templateName: 'record',
                    record: objRecord
                });


                var quantity, amount, rate, grossamt, taxref, hsncode;
                for (var i = 0; i < length; i++) {
                    var itemtype = objRecord.getSublistValue({
                        sublistId: 'item',
                        fieldId: 'itemtype',
                        line: i
                    });
                    //log.debug("itemtype", itemtype + "i");

                    if (itemtype == 'Group') {
                        quantity = objRecord.getSublistValue({ sublistId: 'item', fieldId: 'quantity', line: i });
                        var component_items = [];
                        for (var j = i + 1; j < length; j++) {
                            var itemtype_new = objRecord.getSublistValue({
                                sublistId: 'item',
                                fieldId: 'itemtype',
                                line: j
                            });
                            if (itemtype_new == 'EndGroup') {
                                amount = objRecord.getSublistValue({ sublistId: 'item', fieldId: 'amount', line: j });
                                rate = parseFloat(amount / quantity).toFixed(2);
                                grossamt = objRecord.getSublistValue({ sublistId: 'item', fieldId: 'grossamt', line: j });

                                break;
                            } else if(itemtype != 'OthCharge') {

                                // get hsn code of component item
                                hsncode = objRecord.getSublistText({ sublistId: 'item', fieldId: 'custcol_in_hsn_code', line: j });

                                taxref = objRecord.getSublistValue({ sublistId: 'item', fieldId: 'taxdetailsreference', line: j });

                                var show_item = objRecord.getSublistValue({ sublistId: 'item', fieldId: 'custcol_jj_me71_show_item', line: j });
                                if (show_item != true)
                                    continue;
                                var is_substitute = objRecord.getSublistValue({ sublistId: 'item', fieldId: 'custcol_jj_substitute_item', line: j });
                                if (is_substitute == true)
                                    component_items.push(objRecord.getSublistValue({ sublistId: 'item', fieldId: 'custcol_jj_me102_substitute_item', line: j }));
                                else
                                    component_items.push(objRecord.getSublistText({ sublistId: 'item', fieldId: 'item', line: j }));
                            }
                        }
                        var component_arr = ' ';
                        for (var k = 0; k < component_items.length; k++) {
                            if (k == 0)
                                component_arr = component_items[k];

                            else
                                component_arr = component_arr + ',' + component_items[k];
                        }
                        //log.debug("component_arr", component_arr);
                        /*items.push({
                           components: component_arr});*/
                        if ((hsncode != '') && (hsncode != null) && (hsncode != undefined)) {
                            var lineNumber = objRecord.findSublistLineWithValue({
                                sublistId: 'taxdetails',
                                fieldId: 'taxdetailsreference',
                                value: taxref
                            });
                            log.debug("lineNumber", lineNumber)
                            var taxrate = objRecord.getSublistText({ sublistId: 'taxdetails', fieldId: 'taxrate', line: lineNumber });
                            var taxrate1 = objRecord.getSublistValue({ sublistId: 'taxdetails', fieldId: 'taxrate', line: lineNumber });
                            var taxamount = parseFloat((amount * taxrate1) / 100).toFixed(2);

                            var hsncode_arr = hsncode.split(" ");
                            //log.debug("hsncode_arr",hsncode_arr)
                            hsncode = hsncode_arr[0];
                        }

                        var is_substitute = objRecord.getSublistValue({ sublistId: 'item', fieldId: 'custcol_jj_substitute_item', line: i });
                                if (is_substitute == true){








                        items.push({
                            item: objRecord.getSublistText({ sublistId: 'item', fieldId: 'custcol_jj_me102_substitute_item', line: i }),
                            description: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'custcol_jj_me102_substitute_item_des', line: i }),
                            quantity: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'quantity', line: i }),
                            unit: 'each',
                            hsncode: hsncode,
                            taxrate: taxrate,
                            taxamount: taxamount,
                            rate: rate,
                            amount: amount,
                            grossamt: grossamt,
                            components: component_arr
                        });
                        log.debug("component_items", component_items);


                    }else{


                        items.push({
                            item: objRecord.getSublistText({ sublistId: 'item', fieldId: 'item', line: i }),
                            description: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'description', line: i }),
                            quantity: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'quantity', line: i }),
                            unit: 'each',
                            hsncode: hsncode,
                            taxrate: taxrate,
                            taxamount: taxamount,
                            rate: rate,
                            amount: amount,
                            grossamt: grossamt,
                            components: component_arr
                        });
                        log.debug("component_items", component_items);



                    }

                        i = j;

                    } else if (itemtype == 'EndGroup') {
                        continue;
                    } else if(itemtype != 'OthCharge') {
                        var hsncode = objRecord.getSublistText({ sublistId: 'item', fieldId: 'custcol_in_hsn_code', line: i });
                        var taxrate;
                        if ((hsncode != '') && (hsncode != null) && (hsncode != undefined)) {
                            var hsncode_arr = hsncode.split(" ");
                            //log.debug("hsncode_arr",hsncode_arr)
                            hsncode = hsncode_arr[0];
                            var taxref = objRecord.getSublistValue({ sublistId: 'item', fieldId: 'taxdetailsreference', line: i });
                            var lineNumber = objRecord.findSublistLineWithValue({
                                sublistId: 'taxdetails',
                                fieldId: 'taxdetailsreference',
                                value: taxref
                            });

                            taxrate = objRecord.getSublistText({ sublistId: 'taxdetails', fieldId: 'taxrate', line: lineNumber });
                        }
                        var is_substitute = objRecord.getSublistValue({ sublistId: 'item', fieldId: 'custcol_jj_substitute_item', line: i });
                        if (is_substitute == true){

                        items.push({
                            item: objRecord.getSublistText({ sublistId: 'item', fieldId: 'custcol_jj_me102_substitute_item', line: i }),
                            description: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'custcol_jj_me102_substitute_item_des', line: i }),
                            quantity: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'quantity', line: i }),
                            unit: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'units_display', line: i }),
                            hsncode: hsncode,
                            taxrate: taxrate,
                            taxamount: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'taxamount', line: i }),
                            grossamt: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'grossamt', line: i }),
                            rate: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'rate', line: i }),
                            amount: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'amount', line: i })
                        });

                    }else{


                        items.push({
                            item: objRecord.getSublistText({ sublistId: 'item', fieldId: 'item', line: i }),
                            description: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'description', line: i }),
                            quantity: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'quantity', line: i }),
                            unit: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'units_display', line: i }),
                            hsncode: hsncode,
                            taxrate: taxrate,
                            taxamount: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'taxamount', line: i }),
                            grossamt: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'grossamt', line: i }),
                            rate: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'rate', line: i }),
                            amount: objRecord.getSublistValue({ sublistId: 'item', fieldId: 'amount', line: i })
                        });





                    }









                    }

                }

                log.debug("items", items)



                myFile.addCustomDataSource({
                    format: render.DataSource.JSON,
                    alias: "items",
                    data: JSON.stringify({ items: items })
                });
                var invoicePdf = myFile.renderAsPdf();
                context.response.writeFile(invoicePdf, true);


            } else {
                log.debug("normal itm")
                var recId = context.request.parameters.intenalId;
                log.debug("recId", recId)
              

                var myFile = render.create();
                var template = 139;
                myFile.setTemplateById(template);
                log.debug('myfile',myFile)
                var objRecord = record.load({
                    type: record.Type.SALES_ORDER,
                    id: recId
                });
                log.debug('error normal print');

                myFile.addRecord({
                    templateName: 'record',
                    record: objRecord
                });
                
                var transactionFile = myFile.renderAsPdf();

                context.response.writeFile(transactionFile, true);


            }
        } catch (er) {
            log.debug('error', er)
        }
    }
    return {
        onRequest: onRequest
    };
});

User Event

/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */

/**
 * 
 */

/*******************************************************************************
 * * ME * *
 * **************************************************************************
 * Date:01/03/19
 * 
 * Author : Jobin and Jismi IT Services LLP
 * Script Description: This script defines disabling buttons, adding buttons and on save actions in SO
 * Script name: ME-71 JJ UE SO Actions
 * Script id: customscript_me71_jj_ue_so_actions
 * Deployment id: customdeploy_me71_jj_ue_so_actions
 * 
 ******************************************************************************/

define(['N/search','N/record'],

function(search,record) {
	   
    /**
     * Function definition to be triggered before record is loaded.
     *
     * @param {Object} scriptContext
     * @param {Record} scriptContext.newRecord - New record
     * @param {string} scriptContext.type - Trigger type
     * @param {Form} scriptContext.form - Current form
     * @Since 2015.2
     */
    function beforeLoad(scriptContext) {
    	
    	try {
    		if (scriptContext.type == 'view') {
    		var custRec=scriptContext.form;
    		var recId=scriptContext.newRecord.id;
			log.debug({    
				title: 'recId',
                details: recId
            });
			
			//Getting the SO fields
			var soRecDtls = search.lookupFields({
                type: record.Type.SALES_ORDER,
                id: recId,
                columns: ['customform']
            });
			
			var customForm=null;
			
			if(soRecDtls.customform[0]!=null && soRecDtls.customform[0]!="" && soRecDtls.customform[0]!=undefined){       
				customForm=soRecDtls.customform[0].value;
			}
			
				custRec.clientScriptFileId = 969;
			//If SO form is Integrated SO form
			if(customForm==168){
				
			
				
					    			
             					 //Set Delivery Challan button
		    	    			custRec.addButton({
		    	    				id:'custpage_so_send_to_assembler_btn',
		    	    				label:'Delivery Challan',
		    	    				functionName:'deliveryChellan' 
		    	    			});
              					

		    	    			//Set annexture Invoice button
		    	    			/*custRec.addButton({
		    	    				id:'custpage_so_send_to_annexture',
		    	    				label:'Annexure',
		    	    				functionName:'annexure' 
		    	    			});*/


		    	    			//Set SO print button
		    	    			custRec.addButton({
		    	    				id:'custpage_salesorder_print',
		    	    				label:'Print Sales Order',
		    	    				functionName:'printSalesOrder' 
		    	    			});

			}//Set Proforma Invoice button
		    	    			custRec.addButton({
		    	    				id:'custpage_so_send_to_assembler_btn',
		    	    				label:'Proforma Invoice',
		    	    				functionName:'proformaInvoice' 
		    	    			});
    		}
    		
		} catch (e) {
			log.debug(e.name,e.message);
		}

    }

 

    return {
        beforeLoad: beforeLoad
      
    };
    
});

Client Script

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */

define(['N/currentRecord','N/url','N/https'],

function(currentRecord,url,https) {
    
    /**
     * Function to be executed after page is initialized.
     *
     * @param {Object} scriptContext
     * @param {Record} scriptContext.currentRecord - Current form record
     * @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
     *
     * @since 2015.2
     */
    function pageInit(scriptContext) {
    	try {
    		console.log('in');

		} catch (e) {
			console.log(e.name, e.message);
		}


    }

    

    
    function deliveryChellan()
    {
    	try{
    		  var currentRec = currentRecord.get();
              var id = currentRec.id;
    		console.log('id',id);
    		//Setting the url of the suitelet script 
            var output = url.resolveScript({
                scriptId: 'customscript_me_82_jj_sl_delivery_chella',
                deploymentId: 'customdeploy_me_82_jj_sl_delivery_chella',
                returnExternalUrl: false,
            }) + '&recId=' + id;

       
            //Opens url on a new Window
          newWindow = window.open(output);
    		
    	}
    	catch (e) {
			console.log(e.name, e.message);
		}

    }


function annexure()
    {
        try{
              var currentRec = currentRecord.get();
              var id = currentRec.id;
            console.log('id',id);
            //Setting the url of the suitelet script 
            var output = url.resolveScript({
                scriptId: 'customscript_jj_me_117_sl_annexure',
                deploymentId: 'customdeploy_jj_me_117_sl_annexure',
                returnExternalUrl: false,
            }) + '&recId=' + id;

       
            //Opens url on a new Window
          newWindow = window.open(output);
            
        }
        catch (e) {
            console.log(e.name, e.message);
        }

    }

function proformaInvoice()
    {console.log('inn');
        try{
             var recID = currentRecord.get().id;
           console.log("recID", recID);
            var parameterObj = {
                intenalId: recID
            };
            //Setting the url of the suitelet script 
            var output = url.resolveScript({
                scriptId: 'customscript_me_print_proforma_invoice',
                deploymentId: 'customdeploy_me_print_proforma_invoice',
                 params: parameterObj
            }) 

       
            //Opens url on a new Window
          newWindow = window.open(output);
            
        }
        catch (e) {
            console.log(e.name, e.message);
        }

    }

  function printSalesOrder()
    {console.log('inn');
        try{
             var recID = currentRecord.get().id;
           console.log("recID", recID);
            var parameterObj = {
                intenalId: recID
            };
            //Setting the url of the suitelet script 
            var output = url.resolveScript({
                scriptId: 'customscript_me_printintegrateditem_so',
                deploymentId: 'customdeploy_sl_printintegrateditem_so',
                 params: parameterObj
            }) 

       
            //Opens url on a new Window
          newWindow = window.open(output);
            
        }
        catch (e) {
            console.log(e.name, e.message);
        }

    }


  return {
        pageInit: pageInit,
        deliveryChellan : deliveryChellan,
       annexure:annexure,
       proformaInvoice:proformaInvoice,
       printSalesOrder:printSalesOrder
    };
    
});

Leave a comment

Your email address will not be published. Required fields are marked *