I need total amount minus total wth

Hello everyone,

Below are my codes:

My table:

</tr>
{% for items in doc.references %} {% set result = frappe.get_all("Purchase Invoice Item", filters={'parent': items.reference_name}, fields=['item_name', 'qty', 'rate', 'amount']) %} {% for item in result %}
    </tr>
  {% endfor %}
{% endfor %}
Sr. No Type Name Due Date Item Name Qty Rate Amount Outstanding Allocated
{{ loop.index }} {{ items.reference_doctype }} {{ items.reference_name }} {{ items.due_date }} {{ item.item_name }} {{ item.qty }} {{ item.rate }} {{ item.amount }} {{ items.outstanding_amount }} {{ items.allocated_amount }}

My total wth:

{% set total_wth_amount = [0] %}

{% for items in doc.references %}

{%	set result=frappe.db.get_value("Purchase Invoice Item",filters={'parent':items.reference_name},fieldname=['rate','qty','amount','item_name'],as_dict=true) %}

{% if result.item_name == "Rent" or result.item_name == "Science TextBook" or result.item_name == "WTH item" %}
    {% set wth_rate = 5 %}
{% else %}
    {% set wth_rate = 0 %}
{% endif %}

{% if wth_rate > 0 %}
    {% set wth_amount = result.amount * (wth_rate / 100) %}
    {% if total_wth_amount.append(total_wth_amount.pop() + wth_amount) %}{% endif %}
{% endif %}

{% endfor %}

Total withheld tax amount is:
{{ frappe.format_value(total_wth_amount.pop(), {‘fieldtype’:
‘Currency’, ‘options’: ‘TZS’}) }}


So i need the total amount in my table minus the total wth

Anyone assist?

Regards

Please apply it.

{% set total_amount = 0 %}
{% set total_wth_amount = 0 %}

<table>
  <tr>
    <th>Sr. No</th>
    <th>Type</th>
    <th>Name</th>
    <th>Due Date</th>
    <th>Item Name</th>
    <th>Qty</th>
    <th>Rate</th>
    <th>Amount</th>
    <th>Outstanding</th>
    <th>Allocated</th>
  </tr>
  {% for items in doc.references %}
    {% set result = frappe.get_all("Purchase Invoice Item", filters={'parent': items.reference_name}, fields=['item_name', 'qty', 'rate', 'amount']) %}
    {% for item in result %}
      <tr>
        <td>{{ loop.index }}</td>
        <td>{{ items.reference_doctype }}</td>
        <td>{{ items.reference_name }}</td>
        <td>{{ items.due_date }}</td>
        <td>{{ item.item_name }}</td>
        <td>{{ item.qty }}</td>
        <td>{{ item.rate }}</td>
        <td>{{ item.amount }}</td>
        <td>{{ items.outstanding_amount }}</td>
        <td>{{ items.allocated_amount }}</td>
      </tr>
      {% set total_amount = total_amount + item.amount %}
      {% if item.item_name == "Rent" or item.item_name == "Science TextBook" or item.item_name == "WTH item" %}
        {% set wth_rate = 5 %}
      {% else %}
        {% set wth_rate = 0 %}
      {% endif %}
      {% if wth_rate > 0 %}
        {% set wth_amount = item.amount * (wth_rate / 100) %}
        {% set total_wth_amount = total_wth_amount + wth_amount %}
      {% endif %}
    {% endfor %}
  {% endfor %}
</table>

<p>Total amount: {{ frappe.format_value(total_amount, {'fieldtype': 'Currency', 'options': 'TZS'}) }}</p>
<p>Total withheld tax amount: {{ frappe.format_value(total_wth_amount, {'fieldtype': 'Currency', 'options': 'TZS'}) }}</p>
<p>Total amount after withholding tax: {{ frappe.format_value(total_amount - total_wth_amount, {'fieldtype': 'Currency', 'options': 'TZS'}) }}</p>

check the field name and again check the concept. i just provided the sample code and reference. now you have to apply the logic.