I am trying to group the lines by item and sum up ...
# advancedpdf
l
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>
j
Your <table> definition and <thead> are too late in the code. They need to be before you start looping through the lines (which is
<#list record.item?sort_by('item') as item>
)
you can do clever stuff with testing if it's line 1, but advancedpdf error checking isn't that sophisticated so can get upset about missing starting and ending tags
n
You need to condition code the <thead>, should be able to do it on index to check if it's 0.
✔️ 1
l
Thank you! I just added a condition code at index = 0 like you said.
👍 1