【问题标题】:How can I group a list in an advanced pdf/html sheet in netsuite/freemarker?如何在 netsuite/freemarker 的高级 pdf/html 工作表中对列表进行分组?
【发布时间】:2020-05-20 16:29:24
【问题描述】:

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

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

  • 部门/金额/船/税/总计:
  • A1/15/0/0/15
  • A1/30/0/0/30
  • A1/5/0/0/5
  • A2/45/0/0/45
  • A3/50/0/0/50
  • A4/45/0/0/45

我希望它打印如下:

  • 部门/金额/船/税/总计:
  • A1/50/0/0/50
  • A2/45/0/0/45
  • A3/50/0/0/50
  • A4/45/0/0/45
  • 总计/190/0/0/190

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

`<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>`

【问题讨论】:

  • 进行这样的计算不是模板引擎的用途。我不知道 Netsuite,但它不能在项目暴露给模板之前对其进行分组吗?

标签: netsuite freemarker


【解决方案1】:

基本上,您通过遍历每个部门的所有项目来做到这一点。

How to remove duplicate elements in a array using freemarker?

对此进行一些讨论,然后在“使用 ${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.

【讨论】:

  • dept_total 似乎不起作用,因为它返回“0” - 初始分配。你知道是什么让它表现得那样吗?这是我使用上述帮助的代码的一部分:&lt;#assign dept_total = 0&gt; &lt;#list record.item as dept_item&gt; &lt;#assign line_dept = item.memo&gt; &lt;#if line_dept == groupId&gt; &lt;#assign dept_total =+ dept_item.amount&gt;&lt;/#if&gt;&lt;/#list&gt; &lt;tr&gt;&lt;td width="32%"&gt;${item.memo}&lt;/td&gt; &lt;td width="20%"&gt;${dept_total}&lt;/td&gt; &lt;td width="17%"&gt;$0.00&lt;/td&gt; &lt;td width="14%"&gt;$0.00&lt;/td&gt; &lt;td width="17%"&gt;${dept_total}&lt;/td&gt; &lt;/tr&gt;
  • 从您发布的内容来看,您拥有=+ 而不是+=。我希望这会引发错误。
猜你喜欢
  • 2020-07-18
  • 2019-07-18
  • 2014-05-08
  • 2017-10-17
  • 2019-11-09
  • 1970-01-01
  • 2016-09-09
  • 2020-03-13
  • 2020-01-11
相关资源
最近更新 更多