I am trying to group the lines by item and sum up the quantity and amount (at least in the meantime).
This code below works except that the header is repeated every new item.
If anyone would be able to explain what this list directive and and the ifs mean based on their placement in the code, that'd would be appreciated and probably help me update it, so that the headers won't be repeated anymore. Thanks.
<#if record.item?has_content>
<#assign previousItem = “”>
<#list record.item?sort_by(‘item’) as item>
<#if item.item != previousItem>
<#assign currentItem = item.item>
<#assign amount = 0>
<#assign quantity = 0>
<table class=“itemtable” style=“width: 100%; margin-top: 10px;“>
<thead>
<tr>
<th align=“center” colspan=“3">${item.quantity@label}</th>
<th colspan=“12”>${item.item@label}</th>
<th colspan=“3">${item.options@label}</th>
<th align=“right” colspan=“4">${item.rate@label}</th>
<th align=“right” colspan=“4">${item.amount@label}</th>
</tr>
</thead>
<#list record.item?sort_by(‘item’) as item>
<#if item.item == currentItem> <#assign subtotal = subtotal + item.amount>
<#assign quantity = quantity + item.quantity>
</#if>
</#list>
<tr>
<td align=“center” colspan=“3" line-height=“150%“>${quantity}</td>
<td colspan=“12”><span class=“itemname”>${item.item}</span><br /></td>
<td colspan=“3”>${item.options}</td>
<td align=“right” colspan=“4”>${item.rate}</td>
<td align=“right” colspan=“4”>${amount?string.currency}</td>
</tr>
</table>
</#if>
<#assign previousItem = item.item>
</#list>
<hr />
</#if>