Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Varun-Tandon14/021359ae52722cc22b2aa7b3017ef2eb to your computer and use it in GitHub Desktop.
Save Varun-Tandon14/021359ae52722cc22b2aa7b3017ef2eb to your computer and use it in GitHub Desktop.
Display item wise tax in Tax Invoice for ERPNext. The report is formatted for landscape orientation with repeating header and footer for each page. Please customize as per your requirements. For more clarity on the output format, look at the image below.
<!--
Description:
Display itemwise GST (as applicable) in the items table for ERPNext
The report is formatted for landscape orientation with repeating header
and footer for each page. Please customize as per your requirements.
For more clarity on the output format, look at the image below.
Tetsed version- ERPNext: v14.63.0 (version-14)
References:
1) https://github.com/rtdany10/erpnext_print_format
2) https://github.com/umaepoch/epochapp/blob/master/GST_Sales_Invoice.txt
-->
<!-- <meta name="pdfkit-orientation" content="Landscape"/> -->
<style>
.print-format {
margin-left:0mm;
margin-top:0mm;
margin-right:0mm;
margin-bottom:0mm;
height: 100vh;
width: 100vh;
}
.print-format table, .print-format table-bordered {
table-layout: auto;
border-collapse: collapse;
padding: 0mm;
margin-left:0mm;
margin-top:0mm;
margin-right:0mm;
margin-bottom:4mm;
font-size: xx-small;
width: 100%;
}
.print-format td {
page-break-inside: avoid ;
white-space: nowrap;
overflow: visible;
padding: 0mm;
font-size: xx-small;
}
</style>
{% macro header_continue_item_table() %}
<div class="container-fluid" style="min-width: 100% !important; font-size: 9px; top: 0;" id="header">
<div class="row d-flex align-items-end justify-content-end" style="padding-top: 0mm;">
{{your_header}}
</div>
<table class="table table-bordered text-wrap" style="overflow-x: hidden;">
<thead>
<tr class="table-info" style="font-weight: bold;">
<td style="width:6%;">Sr</td>
<td style="width:48%;">Item Name</td>
<td style="width:3%;">HSN/SAC</td>
<td style="width:10%;">Qty</td>
<td style="width:10%;">Price List Rate</td>
<td style="width:5%;">Discount </td>
<td style="width:14%;">Rate</td>
<td style="width:14%;">Amount</td>
{% if sgst_applicable_flag -%}
<td style="width:5%;">SGST Rate</td>
<td style="width:14%;">SGST Amount</td>
{%- endif -%}
{% if cgst_applicable_flag -%}
<td style="width:5%;">CGST Rate</td>
<td style="width:14%;">CGST Amount</td>
{%- endif -%}
{% if igst_applicable_flag -%}
<td style="width:5%;">IGST Rate</td>
<td style="width:14%;">IGST Amount</td>
{%- endif -%}
<td style="width:14%;"> Amt with Tax</td>
</tr>
</thead>
<tbody>
{% endmacro %}
{% macro footer_continue_item_table() %}
</tbody>
</table>
</div>
<!-- Our first container was closed here. It has height of 210mm -->
<div class="container-fluid" style="min-width: 100% !important; font-size: 9px; bottom: 0 !important;" id="footer">
{{your_footer}}
</div>
{% endmacro %}
{% set pr = [1] %}
{% set lines = [0] %}
{% set max_characters_per_table_line = 38 %}
{% set page_height_in_lines = 28 %}
{% set tot_cgst_amount = [] %}
{% set tot_sgst_amount = [] %}
{% set tot_igst_amount = [] %}
{% set cgst_applicable_flag = [] %}
{% set sgst_applicable_flag = [] %}
{% set igst_applicable_flag = [] %}
{% set cgst_percentage_amount_dict = {} %}
{% set sgst_percentage_amount_dict = {} %}
{% set igst_percentage_amount_dict = {} %}
{% set grand_total = {"qty":0.0, "price_list_rate": 0.0, "amount":0.0, "cgst_amt":0.0, "sgst_amt":0.0, "igst_amt":0.0, "amt_with_tax": 0.0} %}
{%- for row in doc.taxes -%}
{% if row.tax_amount > 0 %}
{% if "CGST" in row.description.split() %}
{% if cgst_applicable_flag.append(1) %}{% endif %}
{% set _ = cgst_percentage_amount_dict.update(json.loads(row.item_wise_tax_detail)) %}
{%- endif -%}
{% if "SGST" in row.description.split() %}
{% if sgst_applicable_flag.append(1) %}{% endif %}
{% set _ = sgst_percentage_amount_dict.update(json.loads(row.item_wise_tax_detail)) %}
{%- endif -%}
{% if "IGST" in row.description.split() %}
{% if igst_applicable_flag.append(1) %}{% endif %}
{% set _ = igst_percentage_amount_dict.update(json.loads(row.item_wise_tax_detail)) %}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{{ header_continue_item_table() }}
{%- for row in doc.items -%}
{% set row_amt_with_tax = row.amount %}
{% if cgst_applicable_flag -%}
{% set temp_cgst_amt = grand_total["cgst_amt"] + cgst_percentage_amount_dict[row.item_code][1] | float | round(2) %}
{% set row_amt_with_tax = row_amt_with_tax + cgst_percentage_amount_dict[row.item_code][1]%}
{%- endif -%}
{% if sgst_applicable_flag -%}
{% set temp_sgst_amt = grand_total["sgst_amt"] + sgst_percentage_amount_dict[row.item_code][1] | float | round(2) %}
{% set row_amt_with_tax = row_amt_with_tax + sgst_percentage_amount_dict[row.item_code][1] %}
{%- endif -%}
{% if igst_applicable_flag -%}
{% set temp_igst_amt = grand_total["igst_amt"] + igst_percentage_amount_dict[row.item_code][1] | float | round(2) %}
{% set row_amt_with_tax = row_amt_with_tax + igst_percentage_amount_dict[row.item_code][1] %}
{%- endif -%}
{% set temp_qty = grand_total["qty"] + row.qty %}
{% set temp_amount = grand_total["amount"] + row.amount %}
{% set temp_price_list_rate = grand_total["price_list_rate"] + row.price_list_rate %}
{% set temp_amt_with_tax = grand_total["amt_with_tax"] + row_amt_with_tax %}
{% set check = grand_total.update({"qty": temp_qty, "price_list_rate": temp_price_list_rate, "amount": temp_amount, "cgst_amt":temp_cgst_amt, "sgst_amt":temp_sgst_amt, "igst_amt":temp_igst_amt, "amt_with_tax": temp_amt_with_tax}) %}
{% if lines[-1] %} {% endif %}
{% if lines.append( lines[-1] + 1 +((row.description|length / max_characters_per_table_line)|int)) %}{% endif %}
{% if (row.description|length % max_characters_per_table_line) > 0 %}
{% if lines[-1] %} {% endif %}
{% if lines.append( lines[-1] + 1 ) %}{% endif %}
{% endif %}
{% if (lines[-1]/page_height_in_lines) <= pr[-1] %}
<tr class="table-info">
<td>{{ row.idx }}</td>
<td>{{ row.get_formatted("item_name", doc) }}</td>
<td>{{ row.get_formatted("gst_hsn_code", doc) }}</td>
<td>{{ row.get_formatted("qty", doc) }} {{ row.uom or ''}}</td>
<td>{{ row.get_formatted("price_list_rate", doc) }}</td>
<td>{{ row.get_formatted("discount_percentage", doc) }}</td>
<td>{{ row.get_formatted("rate", doc) }}</td>
<td>{{ row.get_formatted("amount", doc) }}</td>
{% if sgst_applicable_flag -%}
<td>{{ sgst_percentage_amount_dict[row.item_code][0] | float | round(2) }}%</td>
<td>{{"₹ {:,.2f}".format(sgst_percentage_amount_dict[row.item_code][1]) }}</td>
{%- endif -%}
{% if cgst_applicable_flag -%}
<td>{{ cgst_percentage_amount_dict[row.item_code][0] | float | round(2) }}%</td>
<td>{{"₹ {:,.2f}".format(cgst_percentage_amount_dict[row.item_code][1]) }}</td>
{%- endif -%}
{% if igst_applicable_flag -%}
<td>{{ igst_percentage_amount_dict[row.item_code][0] | float | round(2) }}%</td>
<td>{{"₹ {:,.2f}".format(igst_percentage_amount_dict[row.item_code][1]) }}</td>
{%- endif -%}
<td>{{"₹ {:,.2f}".format(row_amt_with_tax) }}</td>
</tr>
{% else %}
{{ footer_continue_item_table() }}
<div style="page-break-before: always;"></div>
{% if pr[-1] %} {% endif %}
{% if pr.append( pr[-1] + 1 ) %}{% endif %}
{{ header_continue_item_table() }}
<tr class="table-info">
<td>{{ row.idx }}</td>
<td>{{ row.get_formatted("item_name", doc) }}</td>
<td>{{ row.get_formatted("gst_hsn_code", doc) }}</td>
<td>{{ row.get_formatted("qty", doc) }} {{ row.uom or ''}}</td>
<td>{{ row.get_formatted("price_list_rate", doc) }}</td>
<td>{{ row.get_formatted("discount_percentage", doc) }}</td>
<td>{{ row.get_formatted("rate", doc) }}</td>
<td>{{ row.get_formatted("amount", doc) }}</td>
{% if sgst_applicable_flag -%}
<td>{{ sgst_percentage_amount_dict[row.item_code][0] | float | round(2) }}%</td>
<td>{{"₹ {:,.2f}".format(sgst_percentage_amount_dict[row.item_code][1]) }}</td>
{%- endif -%}
{% if cgst_applicable_flag -%}
<td>{{ cgst_percentage_amount_dict[row.item_code][0] | float | round(2) }}%</td>
<td>{{"₹ {:,.2f}".format(cgst_percentage_amount_dict[row.item_code][1]) }}</td>
{%- endif -%}
{% if igst_applicable_flag -%}
<td>{{ igst_percentage_amount_dict[row.item_code][0] | float | round(2) }}%</td>
<td>{{"₹ {:,.2f}".format(igst_percentage_amount_dict[row.item_code][1]) }}</td>
{%- endif -%}
<td>{{"₹ {:,.2f}".format(row_amt_with_tax ) }}</td>
</tr>
{% endif %}
{%- endfor -%}
<tr style="font-weight: bold;">
<td style="width:6%;"></td>
<td style="width:48%;">Total</td>
<td style="width:3%;"></td>
<td style="width:10%;">{{ grand_total["qty"] }}</td>
<td style="width:10%;"></td>
<td style="width:5%;"> </td>
<td style="width:14%;"></td>
<td style="width:14%;">{{"₹ {:,.2f}".format(grand_total["amount"]) }}</td>
{% if sgst_applicable_flag -%}
<td style="width:5%;"></td>
<td style="width:14%;">{{"₹ {:,.2f}".format(grand_total["sgst_amt"]) }}</td>
{%- endif -%}
{% if cgst_applicable_flag -%}
<td style="width:5%;"></td>
<td style="width:14%;">{{"₹ {:,.2f}".format(grand_total["cgst_amt"]) }}</td>
{%- endif -%}
{% if igst_applicable_flag -%}
<td style="width:5%;"></td>
<td style="width:14%;">{{"₹ {:,.2f}".format(grand_total["igst_amt"]) }}</td>
{%- endif -%}
<td style="width:14%;"> {{"₹ {:,.2f}".format(grand_total["amt_with_tax"]) }}</td>
</tr>
</tbody>
</table>
{{ footer_continue_item_table() }}
@Varun-Tandon14
Copy link
Author

item_wise_tax_report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment