<#assign netsuiteItems = [
	{"id" : "itemIdA", "sku": "skuA", "amount": 1.00},
	{"id" : "itemIdB", "sku": "skuB", "amount": 2.00},
	{"id" : "itemIdC", "sku": "skuA", "amount": 3.00},
	{"id" : "itemIdD", "sku": "skuB", "amount": 4.00},
	{"id" : "itemIdE", "sku": "skuA", "amount": 5.00},
	{"id" : "itemIdF", "sku": "skuB", "amount": 6.00},
	{"id" : "itemIdG", "sku": "skuA", "amount": 7.00},
	{"id" : "itemIdH", "sku": "skuB", "amount": 8.00}
]>

<#function getConsolidatedItems items consolidateByFieldId>
	
	<#assign sortedItems = items?sort_by(consolidateByFieldId)>
	<#assign consolidatedItems = []>

	<#assign amount = 0>

	<#list 0..items?size-1 as i>

	    <#assign amount = amount + sortedItems[i].amount>

	    <#if i == (sortedItems?size-1) || sortedItems[i].sku != sortedItems[i+1].sku>
	       <#assign consolidatedItems = consolidatedItems + [{"sku": sortedItems[i].sku, "amount": amount}]>
	       <#assign amount = 0 >
	    </#if>
	</#list>

	<#return consolidatedItems>
</#function>

<#macro displayConsolidatedItems consolidatedItems>

	<#list consolidatedItems as item>
  		${item.sku} - ${item.amount}
	</#list>
</#macro>

<#macro addConsolidatedItemsToTable consolidatedItems>

	<#list consolidatedItems as item>
  		<!-- Add Consolidated Items To Table -->
	</#list>
</#macro>


<#assign consolidatedItems = getConsolidatedItems(netsuiteItems "sku")>

<@displayConsolidatedItems consolidatedItems />

<@addConsolidatedItemsToTable consolidatedItems />
