@Kartive_lfc, Try this
<table class="table table-bordered table-condensed">
<thead>
<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>
</thead>
{% for items in doc.references %}
<tr>
<td>{{ items.idx }} </td>
<td>{{ items.reference_doctype }} </td>
<td>{{ items.reference_name }} </td>
<td>{{ items.due_date }} </td>
{% set result=frappe.db.get_value("Purchase Invoice Item",filters={'parent':items.reference_name},fieldname=['rate','qty','amount','item_name'],as_dict=true) %}
<td>{{ result.item_name }} </td>
<td>{{ result.qty }} </td>
<td>{{ result.rate }} </td>
<td>{{ result.amount }} </td>
<td>{{ items.outstanding_amount }} </td>
<td>{{ items.allocated_amount }} </td>
</tr>
{% endfor %}
</table>
I hope this solves your problem.
