Can anyone direct me to the right direction on how...
# advancedpdf
l
Can anyone direct me to the right direction on how to group the transaction lines in the item table based on multiple fields? For example, if two or more transaction lines have the same values in the Item, Class and Memo fields, they should be presented as one line in the pdf, and the amounts should be summed up. I think I have a bit knowledge when it comes to grouping by a single field like item though. Do I need to concatenate those fields and use that to group the results?
d
I would recommend just checking each field instead of concatenating. Do you want to group only consecutive lines or any line on the transaction that matches? If any line, it may be easiest to sort the items first (see SO answer for "double sorting"):
<#list record.item?sort_by('memo')?sort_by('class')?sort_by('item') as item>
If only consecutive lines, you just list the items as normal Then you can check if subsequent items have the same value:
You then also need to skip the subsequent lines. For your use case, you can just do the same check against the previous line (see line 3 in above example) Make sure you first check you're not on the first line (?is_first)
l
Hi David, thank you! This is very helpful as usual. I will try this. And yes, it is for any line and not just consecutive lines.
d
just wanted to say my above example would never print the last line facepalm Need to change it to this (moved the </#if> up and moved the <#assign summedAmount> out to the top)