Hello,
I'm trying to group the invoice lines by Category and Amount. This means that for each category I'd like to display the total amount for that category. Below is my FreeMarker code:
<#assign categoryTotals = {}> <!-- create an empty map to hold category totals -->
<#list record.item as item> <!-- loop through each line item -->
<#assign category = item.custcol_subof_category?string> <!-- get the category value for the current line item -->
<#assign amount = item.amount> <!-- get the amount value for the current line item -->
<!-- custcol_subof_category is the custom column line field on the invocie -->
<#if categoryTotals[category]??> <!-- if the category is already in the map, add the amount to its total -->
<#assign categoryTotals[category] = categoryTotals[category] + amount>
<#else> <!-- if the category is not in the map, initialize its total to the amount -->
<#assign categoryTotals[category] = amount>
</#if>
</#list>
<!-- display the output in a table -->
<table>
<tr>
<th>Category</th>
<th>Amount</th>
</tr>
<#list categories as category> <!-- loop through each category in the list -->
<tr>
<td>${category}</td>
<td>${categoryTotals[category]?string("0.00")}</td> <!-- display the total for that category -->
</tr>
</#list>
</table>
But I get the following error for the following line:
<#assign categoryTotals[category] = categoryTotals[category] + amount>
Encountered "[", but was expecting one of:
"="
"+="
"-="
"*="
"/="
"%="
"++"
"--"
"in"
">"