Customizations in GST Compatible Print format Item Table

Hi Community , here is our print format Item table customized based on suggestions and tables created by our ERPNext community members. This is almost compatible with standard GST template but missing a few details.
If we make this as standard table , it will help other members too.
This is the code

                      <table class="table-striped" style="table-layout: auto;">
<tbody>
    <colgroup>
        <col>
        <col>
        <col>
    </colgroup>
    <tr>
        <th style="color:#3394DC;">Sr</th>
        <th style="color:#3394DC;">Product Details</th>
        <th style="color:#3394DC;">HSN/SAC</th>
        <th class="text-right" style="color:#3394DC;">Qty</th>
        <th class="text-right" style="color:#3394DC;">Unit Rate</th>
        <th class="text-right" style="color:#3394DC;">CGST</th>
        <th class="text-right" style="color:#3394DC;">SGST</th>
        <th class="text-right" style="color:#3394DC;">IGST</th>
        <th class="text-right" style="color:#3394DC;">Taxable Amount</th>
    </tr>
    {% set cgst_rate = [] -%}
    {% set sgst_rate = [] -%}
    {% set igst_rate = [] -%}
    {% set cgst_account_head = [] -%}
    {% set sgst_account_head = [] -%}
    {% set igst_account_head = [] -%}
    {% set tot_cgst_amount = [] %}
    {% set tot_sgst_amount = [] %}
    {% set grand_total = {"qty":0.0, "amount":0.0, "cgst_amt":0.0, "sgst_amt":0.0, "igst_amt":0.0} %}
    {%- for row in doc.taxes -%}
    {% if 'CGST' in row.account_head -%}
    {% set _ = cgst_account_head.append(row.account_head) %}
    {% set _ = cgst_rate.append(row.rate) %}
    {%- endif -%}
    {% if 'SGST' in row.account_head -%}
    {% set _ = sgst_account_head.append(row.account_head) %}
    {% set _ = sgst_rate.append(row.rate) %}	
    {%- endif -%}
    {% if 'IGST' in row.account_head -%}
    {% set _ = igst_account_head.append(row.account_head) %}
    {% set _ = igst_rate.append(row.rate) %}
    {%- endif -%}
    {%- endfor -%}
    {%- for row in doc.items -%}
    <tr>
        {% set cgst_amt = [] -%}
        {% set sgst_amt = [] -%}
        {% set igst_amt = [] -%}
        {% set it_cgst_rate = [] -%}
        {% set it_sgst_rate = [] -%}
        {% set it_igst_rate = [] -%}
        {% set rate_found_item = 0 -%}
        {%- set item_record = frappe.get_doc("Item", row.item_code) -%}
        {% for item_tax in item_record.taxes %}
        {% if item_tax.tax_type == igst_account_head[0] %}	
        {% set _ = it_igst_rate.append(item_tax.tax_rate) %}
        {% set _ = igst_amt.append(row.amount * it_igst_rate[0] / 100) -%}
        {% set rate_found_item = 1 -%}
        {% endif %}		
        {% if item_tax.tax_type == sgst_account_head[0] %}
        {% set _ = it_sgst_rate.append(item_tax.tax_rate) %}
        {% set _ = sgst_amt.append(row.amount * it_sgst_rate[0] / 100) -%}
        {% set rate_found_item = 1 -%}
        {% endif %}	
        {% if item_tax.tax_type == cgst_account_head[0] %}
        {% set _ = it_cgst_rate.append(item_tax.tax_rate) %}
        {% set _ = cgst_amt.append(row.amount * it_cgst_rate[0] / 100) -%}
        {% set rate_found_item = 1 -%}
        {% endif %}		
        {% endfor %}	
        {% if rate_found_item == 0 %}
        {% if cgst_rate[0] -%}
        {% set _ = cgst_amt.append((row.amount * cgst_rate[0])/100) -%}
        {% set _= it_cgst_rate.append(cgst_rate[0]) -%}
        {% set rate_found_inv = 1 -%}
        {%- endif -%}
        {% if sgst_rate[0] -%}
        {% set _ = sgst_amt.append((row.amount * sgst_rate[0])/100) -%}
        {% set _= it_sgst_rate.append(sgst_rate[0]) -%}
        {%- endif -%}
        {% if igst_rate[0] -%}
        {% set _ = igst_amt.append((row.amount * igst_rate[0])/100) -%}
        {% set _= it_igst_rate.append(igst_rate[0]) -%}
        {% set rate_found_inv = 1 -%}
        {%- endif -%}
        {% endif %}
        {% if not it_cgst_rate[0] %}
        {% set _ = it_cgst_rate.append(0) %}
        {% set _ = cgst_amt.append(0) %}
        {% endif %}
        {% if not it_sgst_rate[0] %}
        {% set _ = it_sgst_rate.append(0) %}
        {% set _ = sgst_amt.append(0) %}
        {% endif %}
        {% if not it_igst_rate[0] %}
        {% set _ = it_igst_rate.append(0) %}
        {% set _ = igst_amt.append(0) %}
        {% endif %}
        {% set temp_cgst_amt = grand_total["cgst_amt"] + cgst_amt[0] %}
        {% set temp_sgst_amt = grand_total["sgst_amt"] + sgst_amt[0] %}
        {% set temp_igst_amt = grand_total["igst_amt"] + igst_amt[0] %}
        {% set temp_qty = grand_total["qty"] + row.qty %}
        {% set temp_amount = grand_total["amount"] + row.amount %}
        {% set check = grand_total.update({"qty": temp_qty, "amount": temp_amount, "cgst_amt":temp_cgst_amt, "sgst_amt":temp_sgst_amt, "igst_amt":temp_igst_amt}) %}
        <td style="width: auto;"><font size = "1">{{ row.idx }}</font></td>
        <td style="width: auto;"><strong><font size = "2">
            {% if row.item_code != row.item_name -%}</strong>
            <b>{{ row.item_code}}</b><br>
            {%- endif %}
            {{ row.item_name }}
            </font>
        </td>
        <td style="width: auto;"><strong><font size = "1.5">{{ row.gst_hsn_code }}</font></strong></td>
        <td style="width: auto; text-align: right;"><font size = "2">{{ row.qty }}</font></td>
        <td style="width: auto; text-align: right;"><strong><font size = "2">{{
            row.get_formatted("rate", doc) }}</font></strong>
        </td>
        <td style="width: auto; text-align: right;"><strong><font size = "2">{{
            "₹ {:,.2f}".format(cgst_amt[0])  }}<br><small>{{
            it_cgst_rate[0] }}%</small></font></strong>
        </td>
        <td style="width: auto; text-align: right;"><strong><font size = "2">{{
            "₹ {:,.2f}".format(sgst_amt[0])  }}<br><small>{{
            it_sgst_rate[0] }}%</small></font></strong>
        </td>
        <td style="width: auto; text-align: right;"><strong><font size = "2">{{
            "₹ {:,.2f}".format(igst_amt[0])  }}</strong><br><strong><small>{{
            it_igst_rate[0] }}%</small></strong></font>
        </td>
        <td style="width: 14%; text-align: right;" class="amount"><font size = "2"><strong>{{
            row.get_formatted("amount", doc) }}</strong></font>
        </td>
    </tr>
    {%- endfor -%}
</tbody>

Output is

1.Now, we have to add a Total Amount coloumn after Taxable amount coloumn, this coloumn displays the amount including Taxable Amount+ Taxes.
2.A footer row for total , which calculates all the row fields.

2 Likes

Hello @vimal0777

This will work only if GST account head is same.
It is not working if we have CGST 2% and CGST 6% as separate account head in chart of account.

Can you send mockup/ Microsoft Word template for GST Tax Invoice?

Thanks,
Sam