0
我想在銷售訂單中對相同名稱的項目進行分組,併合並報表中的價格金額。在javascript中分組項目(netsuite)
例如, 銷售訂單
Item A 100usd
Item A 100usd
Item A 100usd
Item A 100usd
在我要總結的所有項目和展示項目A的總價格作爲一個行報告: 項目A 400USD
我知道我應該使用循環和數組做到這一點,但它似乎並沒有工作。
//scan through all lines
for(i=1;...){
item[i]=getitemforline(i);
itemprice[i]=getitempriceforline(i);
}
//check current line one by one for any duplicates, and sum up itemprice if there is
for(k=1;...){
for(i=1;i<k;i++){
currentitem[k] = getitemforcurrentline(k);
currentitemprice[k] = getitempriceforcurrentline(k);
if(currentitem[k] == item[i]){
itemprice[i] = itemprice[i] + currentitemprice[k];
}
}
print(itemw[i]+itemprice[i]);
}
這是非常模糊 - 目前數據的結構是什麼? getitemforline()和其他函數返回什麼? – nnnnnn
數據結構採用NetSuite數據庫表格格式。 Getlineforitem(i,price)返回特定行的值。 – user1033038
函數名稱只是僞代碼,並不代表確切的函數名稱。 – user1033038