0

I'd like to group each department together to create a summary.

For example if i have the following data in an invoice on the line level:

  • Dept/Amount/ship/tax/total:
  • 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

i'd like it to print like:

  • Dept/Amount/ship/tax/total:
  • A1/50/0/0/50
  • A2/45/0/0/45
  • A3/50/0/0/50
  • A4/45/0/0/45
  • total/190/0/0/190

Here is what I have so far, but it does not group them:

`<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>`
  • Making such calculations is not what a template engine is for. I don't know Netsuite, but can't it group the items before they are exposed to the template? – ddekany Feb 04 '20 at 22:22

1 Answers1

2

Basically you do this by looping over all your items for each department.

See How to remove duplicate elements in a array using freemarker?

for a bit of discussion about this and then where that says "Do something with ${groupId}" you'd do something like:

<#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.
bknights
  • 14,408
  • 2
  • 18
  • 31
  • It seems like the dept_total is not working as it returns "0" - the initial assignment. Do you know what would make it behave that way? This is part of my code using your above help: `<#assign dept_total = 0> <#list record.item as dept_item> <#assign line_dept = item.memo> <#if line_dept == groupId> <#assign dept_total =+ dept_item.amount>#if>#list> ${item.memo} ${dept_total} $0.00 $0.00 ${dept_total} ` – netsuite_beginner Feb 18 '20 at 18:17
  • from what you posted you have `=+` instead of `+=`. I'd expect that to throw an error though. – bknights Feb 18 '20 at 19:32