Anyone with a code snippet for grouping same items...
# advancedpdf
l
Anyone with a code snippet for grouping same items as one line item in the pdf template and summing up the quantity and amount? Just want to have a starting point for grouping items. Thanks.
That's an example of grouping by class but should be straightforward enough to adapt to item
s
It’s easiest/best if you sort the list by the element you’ll be grouping on, that way, they will all be consecutive, and you can look for changes to the field as an indicator of when to switch.
👍 1
l
Thank you both for the file and tip!
@michoel is it possible to present the item just once? For example, if my invoice has 2 lines in the UI: Service Item A 100 qty Service Item A -5 qty I would like to show it as one liner in the pdf: Service Item A 95 qty I think the code you shared still presents all lines but add a subtotal line per group of item?
m
Sure, you can adapt the technique from my snippet but only print the "subtotal"