Item Grouping in PDF based on the Estimate customer in the Item line

Grouping based on Estimate customer in which we don’t print discount lines. The discount amount and tax will be deducted from the item to which the discount item is associated with

<table class="itemtable" style="width: 100%; margin-top: 10px;"><!-- start items --><#list record.item?sort_by("custcol_estimate_customer") as item><#if item_index==0>
<thead style="width: 100%;">
	<tr>
    <th align="left" colspan="11" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">Estimate Customer</th> 
	<th align="left" colspan="13" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${item.description@label}</th>
	<th align="center" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${record.custbodyinvoice_legal_statement_mf_12.custrecord_mf_pdfinv_quantity@label}</th>
	<th align="right" colspan="6" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${record.custbodyinvoice_legal_statement_mf_12.custrecord_mf_pdfinv_unitprice@label}</th>
    <th align="right" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${record.custbodyinvoice_legal_statement_mf_12.custrecord_mf_pdfinv_taxrate@label}</th>
	<th align="right" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${record.custbodyinvoice_legal_statement_mf_12.custrecord_mf_pdfinv_taxamt@label}</th>
	<th align="right" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${record.custbodyinvoice_legal_statement_mf_12.custrecord_mf_pdfinv_amount@label}</th>
	</tr>

</thead>
  
</#if>
 
<tr>
  <#if item.custcol_jj_item_id != 414> 
    <#if item.custcol_estimate_customer == "" >
      <td> </td>
      <#else>
   <#if item.custcol_estimate_customer != Estimatecustomer>
     		<td align="left" colspan="11" style="font-family:Verdana,Geneva,sans-serif; font-size:11px; border:1; border-color:#ffffff;">${item.custcol_estimate_customer?keep_after(" ")}</td>
     			<#assign Estimatecustomer = item.custcol_estimate_customer>
		</#if>
                  </#if>
        </#if>
</tr>


         <tr>
    <#assign subName = subsidiary.name>
    <#if  subName == "Compusoft US LLC">
       <#assign Taxrate = "0%">
      <#else/>	
      <#assign Taxrate = item.taxrate1>	
      </#if>	
    	
    <#if item.rate?contains("-")>
      <#assign DiscountedRate1 = item.amount + item.custcol_sf_discount_amount>
      <#assign rate = DiscountedRate1?string(",##0.00")>	
      <#else>	
        <#assign DiscountedRate2 = item.amount + item.custcol_sf_discount_amount>
         <#assign rate =  DiscountedRate2?string(",##0.00; roundingMode=halfEven")>	
      </#if>	


        <#if  subName == "Compusoft US LLC">	
       	<#assign tax = "0.00">	
             <#else/>	
                 <#if item.tax1amt?contains("-")>	
                   <#assign taxamt1 = item.custcol_sf_discount_amount * item.taxrate1>
                   <#assign discountedtax = item.tax1amt + taxamt1 >
           <#assign tax = discountedtax?string(",##0.00")>	
          <#else/>	
              <#assign taxamt2 = item.custcol_sf_discount_amount * item.taxrate1>
                   <#assign discountedtax = item.tax1amt + taxamt2 >
           <#assign tax = discountedtax?string(",##0.00; roundingMode=halfEven")>	
          </#if>	
             </#if>	


             <#if  subName == "Compusoft US LLC">	
                <#assign total = item.amount + item.custcol_sf_discount_amount>	
               <#else/>	
             <#if item.grossamt?contains("-")>
               <#assign taxamt1 = item.custcol_sf_discount_amount * item.taxrate1>
               <#assign grossamount1 = item.grossamt + taxamt1 +  item.custcol_sf_discount_amount>
                <#assign total = grossamount1?string(",##0.00")>	
               <#else/>
                  <#assign taxamt2 = item.custcol_sf_discount_amount * item.taxrate1>
                  <#assign grossamount2 = item.grossamt + taxamt2 +  item.custcol_sf_discount_amount>
               <#assign total = grossamount2?string(",##0.00; roundingMode=halfEven")>	
               </#if>	
                    </#if>	
      
    			
               <#if item.custcol_jj_item_id != 414>
                 <td colspan="11">&nbsp;</td>
               <td align="left" colspan="13" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${item.description}</td>	
	<td align="center" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${item.custcol_jj_sf_qty}</td>	
	<td align="right" colspan="6" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${rate}</td>	
    <td align="right" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${Taxrate}</td>	
	<td align="right" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${tax}</td>	
	<td align="right" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${total}</td>	
                 </#if>
                 </tr>
	</#list><!-- end items --></table>

Grouping based on Estimate customer and also printing the discount lines. For that first, we added the Estimate customer name in a long text field separated by a comma via script. And then will iterate through these values for grouping


     <#assign length = 0>
   <#list record.item as item>
     <#assign length=length+1>
     </#list>
     
<#if record.custbody_grouped_sales_order == true >
    <!--<#if record.item?has_content> -->
    
                  <#assign currency={"USD":"USD","EUR":"€","GBP":"£","CAD":"CAD","CHF":"CHF","AUD":"AUD","NZD":"NZD","NOK":"NOK","DKK":"DKK","SEK":"SEK","ZAR":"R","CZK":"CZK"}>
<#assign customers = record.custbody_jj_estimate_cus_array?split(",") >
<table class="itemtable" style="width: 100%; margin-top: 10px;"><!-- start items -->
<thead>
	<tr>
    <th align="left" colspan="11" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">Estimate Customer</th> 
	<th align="left" colspan="13" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">Description</th>
	<th align="center" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${record.custbodyinvoice_legal_statement_mf_12.custrecord_mf_pdfinv_quantity@label}</th>
	<th align="right" colspan="6" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${record.custbodyinvoice_legal_statement_mf_12.custrecord_mf_pdfinv_unitprice@label}</th>
    <th align="right" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${record.custbodyinvoice_legal_statement_mf_12.custrecord_mf_pdfinv_taxrate@label}</th>
	<th align="right" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${record.custbodyinvoice_legal_statement_mf_12.custrecord_mf_pdfinv_taxamt@label}</th>
	<th align="right" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${record.custbodyinvoice_legal_statement_mf_12.custrecord_mf_pdfinv_amount@label}</th>
	</tr>

</thead>


    <#list customers as customer>
  <tr><td align="left" colspan="11" style="font-family:Verdana,Geneva,sans-serif; font-size:11px; border:1; border-color:#ffffff;">${customer?keep_after(" ")}</td></tr>
 <#list record.item as item>
 

    <#if customer == item.custcol_estimate_customer >
      <tr>    
    <#assign subName = subsidiary.name>
    <#if  subName == "Compusoft US LLC">
       <#assign Taxrate = "0%">
      <#else/>	
      <#assign Taxrate = item.taxrate1>	
      </#if>	
    	
    <#if item.rate?contains("-")>
      <#assign DiscountedRate1 = item.amount>
      <#assign rate = DiscountedRate1?string(",##0.00")>	
      <#else>	
        <#assign DiscountedRate2 = item.amount>
         <#assign rate =  DiscountedRate2?string(",##0.00; roundingMode=halfEven")>	
      </#if>	
        	
        <#if  subName == "Compusoft US LLC">	
       	<#assign tax = "0.00">	
             <#else/>	
                 <#if item.tax1amt?contains("-")>	
           <#assign tax = item.tax1amt?string(",##0.00")>	
          <#else/>	
           <#assign tax = item.tax1amt?string(",##0.00; roundingMode=halfEven")>	
          </#if>	
             </#if>	
             <#if  subName == "Compusoft US LLC">	
                <#assign total = item.amount>	
               <#else/>	
             <#if item.grossamt?contains("-")>	
                <#assign total = item.grossamt?string(",##0.00")>	
               <#else/>	
               <#assign total = item.grossamt?string(",##0.00; roundingMode=halfEven")>	
               </#if>	
                    </#if>	
   
      
               <td colspan="11"></td>
               <td align="left" colspan="13" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${item.description}</td>	
	<td align="center" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${item.custcol_jj_sf_qty} </td>	
	<td align="right" colspan="6" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${rate}</td>	
    <td align="right" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${Taxrate}</td>	
	<td align="right" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${tax}</td>	
	<td align="right" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${total}</td>	
</tr>
              <#if length &gt; item_index+1 || length == item_index+1>  
                <#if record.item[item_index+1].custcol_jj_item_id == 414 && customer == item.custcol_estimate_customer >  
                        <tr>    
    <#assign subName = subsidiary.name>
    <#if  subName == "Compusoft US LLC">
       <#assign Taxrate = "0%">
      <#else/>	
      <#assign Taxrate = record.item[item_index+1].taxrate1>	
      </#if>	
         
    	<#if record.item[item_index+1].amount?contains("-")>	
      <#assign rate = record.item[item_index+1].amount?string(",##0.00")>	
      <#else/>	
         <#assign rate = record.item[item_index+1].amount?string(",##0.00; roundingMode=halfEven")>	
      </#if>	
        	
	
        	
        <#if  subName == "Compusoft US LLC">	
       	<#assign tax = "0.00">	
             <#else/>	
                 <#if record.item[item_index+1].tax1amt?contains("-")>	
           <#assign tax = record.item[item_index+1].tax1amt?string(",##0.00")>	
          <#else/>	
           <#assign tax = record.item[item_index+1].tax1amt?string(",##0.00; roundingMode=halfEven")>	
          </#if>	
             </#if>	
             <#if  subName == "Compusoft US LLC">	
                <#assign total = record.item[item_index+1].amount>	
               <#else/>	
             <#if record.item[item_index+1].grossamt?contains("-")>	
                <#assign total = record.item[item_index+1].grossamt?string(",##0.00")>	
               <#else/>	
               <#assign total = record.item[item_index+1].grossamt?string(",##0.00; roundingMode=halfEven")>	
               </#if>	
                    </#if>
   
      
               <td colspan="11"></td>
               <td align="left" colspan="13" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${record.item[item_index+1].description}</td>	
	<td align="center" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px"> ${record.item[item_index+1].custcol_jj_sf_qty}</td>	
	<td align="right" colspan="6" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${rate}</td>	
    <td align="right" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${Taxrate}</td>	
	<td align="right" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${tax}</td>	
	<td align="right" colspan="4" style="font-family:Verdana,Geneva,sans-serif; font-size:11px">${total}</td>	
</tr>
                  </#if>
                  </#if>
               </#if>
	</#list><!-- end items -->
               	
                   </#list>
          </table>

Leave a comment

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