If the tax type is IGST, we should display the IGST. If the tax type is not IGST, both SGST and CGST should be displayed.
You can use the provided sample code to display either IGST or both CGST and SGST along with their respective values.


<#-- Find matching tax details -->
<#list record.taxdetails as tax_detail>
<#if tax_detail.taxdetailsreference == tax_details_ref>
<#assign taxable_value = tax_detail.taxbasis?replace("[^0-9.]", "", "r")?number!0>
<#assign tax_rate = tax_detail.taxrate!0>
<#assign tax_type = tax_detail.taxtype?string!"" /> <!-- Safely assign tax_type -->
<#assign tax_amount = tax_detail.taxamount?replace("[^0-9.]", "", "r")?number!0>
<#if tax_type=="CGST">
<#assign cgsttax_amount = tax_detail.taxamount?replace("[^0-9.]", "", "r")?number!0>
</#if>
<#if tax_type=="SGST">
<#assign sgsttax_amount = tax_detail.taxamount?replace("[^0-9.]", "", "r")?number!0>
</#if>
</#if>
</#list>
<#-- Accumulate totals based on tax type -->
<#assign total_taxable_value += taxable_value>
<#if tax_type == "IGST">
<#assign total_igst_amount += tax_amount>
<#assign total_tax_amount += tax_amount>
<#elseif tax_type == "CGST">
<#assign total_cgst_amount += cgsttax_amount>
<#assign total_tax_amount += tax_amount>
<#elseif tax_type == "SGST">
<#assign total_sgst_amount += sgsttax_amount>
<#assign total_tax_amount += tax_amount>
</#if>
<#if item.custcol_in_hsn_code?has_content>
<#assign hsn_code = item.custcol_in_hsn_code?substring(0, item.custcol_in_hsn_code?index_of(" "))>
<#else>
<#assign hsn_code = " ">
</#if>
<#if cgsttax_amount?has_content>
<#assign cgsttax_amount = cgsttax_amount>
<#else>
<#assign cgsttax_amount = 0>
</#if>
<#if sgsttax_amount?has_content>
<#assign sgsttax_amount = sgsttax_amount>
<#else>
<#assign sgsttax_amount = 0>
</#if>
<#assign processed_items += [{
"hsn_code": hsn_code,
"taxable_value": taxable_value,
"tax_rate": tax_rate,
"tax_amount": tax_amount,
"cgst_amount":cgsttax_amount,
"sgst_amount":sgsttax_amount,
"tax_type": tax_type
}]>
</#list>
<!-- Render the table -->
<table border="1" style="border-collapse: collapse; width: 100%; text-align: center;">
<thead>
<tr>
<th rowspan="2" style="text-align: center; vertical-align: middle; border: 1px solid #000;">HSN/SAC</th>
<th rowspan="2" style="text-align: center; vertical-align: middle; border: 1px solid #000;">Taxable Value</th>
<!-- Conditional Header Based on Tax Type -->
<#if record.taxdetails?has_content && record.taxdetails[0].taxtype == "IGST">
<th colspan="2" style="align: center; text-align: center; vertical-align: middle; border: 1px solid #000;">IGST</th>
<#else>
<th colspan="2" style="align: center; text-align: center; vertical-align: middle; border: 1px solid #000;">CGST</th>
<th colspan="2" style="align: center; text-align: center; vertical-align: middle; border: 1px solid #000;">SGST/UTGST</th>
</#if>
<th rowspan="2" style="text-align: center; vertical-align: middle; border: 1px solid #000;">Total Tax Amount</th>
</tr>
<tr>
<!-- Sub-Headers -->
<#if record.taxdetails?has_content && record.taxdetails[0].taxtype == "IGST">
<th style="text-align: center; border: 1px solid #000;">Rate</th>
<th style="text-align: center; border: 1px solid #000;">Amount</th>
<#else>
<th style="text-align: center; border: 1px solid #000;">Rate</th>
<th style="text-align: center; border: 1px solid #000;">Amount</th>
<th style="text-align: center; border: 1px solid #000;">Rate</th>
<th style="text-align: center; border: 1px solid #000;">Amount</th>
</#if>
</tr>
</thead>
<tbody>
<#list processed_items as processed_item>
<tr>
<td style="border: 1px solid #000;">${processed_item.hsn_code}</td>
<td style="border: 1px solid #000;">${processed_item.taxable_value?string(",##0.00")}</td>
<!-- Render Tax Type Details -->
<#if processed_item.tax_type == "IGST">
<td style="border: 1px solid #000;">${processed_item.tax_rate}</td>
<td style="border: 1px solid #000;">${processed_item.tax_amount?string(",##0.00")}</td>
<td style="border: 1px solid #000;">${processed_item.tax_amount?string(",##0.00")}</td>
<#else>
<td style="border: 1px solid #000;">${processed_item.tax_rate}</td>
<td style="border: 1px solid #000;">${(processed_item.cgst_amount)?string(",##0.00")}</td>
<td style="border: 1px solid #000;">${processed_item.tax_rate}</td>
<td style="border: 1px solid #000;">${(processed_item.sgst_amount)?string(",##0.00")}</td>
<td style="border: 1px solid #000;">${(processed_item.cgst_amount+processed_item.sgst_amount)?string(",##0.00")}</td>
</#if>
</tr>
</#list>
</tbody>
<tfoot>
<tr>
<td colspan="1" style="text-align: right; font-weight: bold; border: 1px solid #000;">Total:</td>
<td style="font-weight: bold; border: 1px solid #000;">${total_taxable_value?string(",##0.00")}</td>
<!-- Conditional rendering for IGST -->
<#if record.taxdetails?has_content && record.taxdetails[0].taxtype == "IGST">
<td style="font-weight: bold; border: 1px solid #000;"></td>
<td style="font-weight: bold; border: 1px solid #000;">${record.taxtotal2}</td>
<td style="font-weight: bold; border: 1px solid #000;">${total_igst_amount?string(",##0.00")}</td>
<#else>
<!-- Render columns for CGST and SGST -->
<td style="font-weight: bold; border: 1px solid #000;"></td>
<td style="font-weight: bold; border: 1px solid #000;">${record.taxtotal3}</td>
<td style="border: 1px solid #000;"></td>
<td style="font-weight: bold; border: 1px solid #000;">${record.taxtotal4}</td>
<td style="font-weight: bold; border: 1px solid #000;">${record.taxtotal}</td>
</#if>
</tr>
</tfoot>
</table>