I have sorted an item table in an invoice, and I w...
# advancedpdf
l
I have sorted an item table in an invoice, and I wanted to add a sequence number (1, 2, 3, etc.). I can’t rely on the UI because the items are already sorted out in the advanced pdf template. I tried ${item_index + 1} but it’s not sequential.
s
do you have just one item table or multiple ones?
l
Multiple item tables. Each table must have sequence numbers starting at 1. I’ve also tried storing it in a variable and add 1 for every loop but it shows 1 for all items in a table.
s
If each table must start at 1, then it's much easier than counting up across all multiple item tables (I've done both though). For your case, there's a lot of stackoverflow links on how to do this. If you created the variable but it shows as 1 everytime then you are not properly 'incrementing' the variable
l
<#assign totalAddlItems = 0>
<table class="itemtable" style="width: 100%; margin-top: 10px;"><!-- start items --><#assign sequenceNumber = 1><#list record.item as item><#if item_index==0>
<thead>
<tr>
<th colspan="1">Item#</th>
<th colspan="4">Memo</th>
<th align="right" colspan="2">Quantity</th>
<th align="right" colspan="2">Rate</th>
<th align="right" colspan="2">Amount (ex GST)</th>
</tr>
</thead>
</#if><#if item.quantity?has_content && !item.quantityordered?has_content && !item.custcol_pr_pcst?has_content><#assign totalAddlItems = totalAddlItems + item.amount><tr>
<td colspan="1">${sequenceNumber}</td>
<td colspan="4">${item.description}</td>
<td align="right" colspan="2">${item.quantity}</td>
<td align="right" colspan="2">${item.rate}</td>
<td align="right" colspan="2">${item.amount}</td>
</tr>
</#if><#assign sequenceNumber = sequenceNumber + 1>
<!-- end items --></#list></table>
<table style="width: 100%;"><#assign totalItemse = totalAddlItems><tr>
<td colspan="3">&nbsp;</td>
<td align="right" colspan="12">Total Additional Items</td>
<td align="right" colspan="4">$${totalItemse?string(",##0.00")}</td>
</tr></table>
<br /> </#if>
Weirdly it uses the index in the UI. For example, I have 3 items in this table, and the sequence numbers are 1, 7, and 8 which is their sequence in the UI
s
try <#assign sequenceNumber += sequenceNumber + 1>
l
From 1, 7, 8, it went to 1, 127, 255. Just doesn’t make sense to me
d
use ?filter and ?counter i've changed a few things here, can talk through later them if you want
👀 1
c
In the code you shared, the increment is outside of the IF that is conditionally displaying. Is that what you intend?
l
Thank you all. And @David B, that worked. I just had to fix the last closing “if”. Thank you for your help as always. I’ve learned new functions in your code as well.
d
good catch on the missing close tag @CD using
?counter
instead of an incremented variable *sorry, just noticed that there is one,
totalAddlItems
, which Luis is using to get the total amount of the filtered items.