Below is an array of objects:
const lineItems = [
{
"lineNumber": "0",
"item": "1496",
"itemDesc": "wertyuiasdfghj",
"qualityReceiptHold": "N",
"quantity": 10,
"quantityUOM": "Unit",
"batchNumber": "LO123678",
"receivedQty": 5,
"shippedQty": 10,
"itemCode": "Packagetest1"
},
{
"lineNumber": "1",
"item": "1496",
"itemDesc": "wertyuiasdfghj",
"qualityReceiptHold": "N",
"quantity": 40,
"quantityUOM": "Unit",
"batchNumber": "LO123678",
"receivedQty": 4,
"shippedQty": 20,
"itemCode": "Packagetest1"
},
{
"lineNumber": "2",
"item": "1496",
"itemDesc": "wertyuiasdfghj",
"qualityReceiptHold": "N",
"quantity": 10,
"quantityUOM": "Unit",
"receivedQty": 5,
"shippedQty": 30,
"itemCode": "Packagetest1"
},
{
"lineNumber": "3",
"item": "1496",
"itemDesc": "wertyuiasdfghj",
"qualityReceiptHold": "N",
"quantity": 10,
"quantityUOM": "Unit",
"receivedQty": 10,
"shippedQty": 30,
"itemCode": "Packagetest1"
}
];
Desired output:
[
{
"lineNumber": "0",
"item": "1496",
"itemDesc": "wertyuiasdfghj",
"qualityReceiptHold": "N",
"quantity": 50,
"quantityUOM": "Unit",
"batchNumber": "LO123678",
"receivedQty": 9,
"shippedQty": 30,
"itemCode": "Packagetest1"
},
{
"lineNumber": "2",
"item": "1496",
"itemDesc": "wertyuiasdfghj",
"qualityReceiptHold": "N",
"quantity": 20,
"quantityUOM": "Unit",
"receivedQty": 15,
"shippedQty": 60,
"itemCode": "Packagetest1"
}
]
The code provides the sum of properties like quantity, receivedQty and shippedQty based on grouping of batchNumber and item value. It correctly groups the first two items by batchNumber and item, but not the last two based on item value only.
groupedVariantLineItems() {
// Code for grouping variants
}
The current code correctly outputs the first two line items grouped by batchNumber, but not the last two. Adjustments are needed for correct grouping based on item value.