如何在 netsuite/freemarker 中的高级 pdf/html sheet 中对列表进行分组?

How can I group a list in an advanced pdf/html sheet in netsuite/freemarker?

我想将每个部门组合在一起创建一个摘要。

例如,如果我在行级别的发票中有以下数据:

我希望它打印成这样:

这是我目前所拥有的,但没有对它们进行分组:

`<table style="width: 100%; margin-top: 10px;">
    <thead>
    <tr>
        <td border-bottom="1px solid black" width="32%">Department</td>
        <td border-bottom="1px solid black" width="20%">Merchandise Amount</td>
        <td border-bottom="1px solid black" width="17%">Del./Sve. Amount</td>
        <td border-bottom="1px solid black" width="14%">Tax Amount</td>
        <td border-bottom="1px solid black" width="17%">Total Inv. Amount</td>
    </tr>
    </thead>
<#list record.line?sort as item><#assign i = 0>
<#assign memo_check = ["A1", "A2", "A3", "A4", "A5", "A6", "A7"]/>
<#if memo_check[i] != item.memo>
    <!--DO NOTHING-->
</#if>
<#assign i += 1>
    <tr>
        <td width="32%">${item.memo}</td>
        <td width="20%">${item.amount}</td>
        <td width="17%">0.00</td>
        <td width="14%">0.00</td>
        <td width="17%">${item.amount}</td>
    </tr>
</#list>
</table>`

基本上,您可以通过遍历每个部门的所有项目来完成此操作。

How to remove duplicate elements in a array using freemarker?

对此进行一些讨论,然后在那里说 "Do something with ${groupId}" 你会做类似的事情:

<#assign dept_total = 0>

<#list record.item as dept_item>
    <#assign line_dept = dept_item.memo>
    <#if line_dept == groupId>
    <#assign dept_total = dept_total + dept_item.amount>
    ... // any other calculations
</#list>
... // use the dept_total etc
// then the outer loop will find the next unique dept.