raw materials fix
This commit is contained in:
@@ -138,7 +138,7 @@ if (!isset($_GET['ajaxAction'])) {
|
|||||||
getComponents3($_POST['ids']);
|
getComponents3($_POST['ids']);
|
||||||
break;
|
break;
|
||||||
case 'getRawMaterials':
|
case 'getRawMaterials':
|
||||||
echo getRawMaterials($_POST['ids'], $_POST['type']);;
|
getRawMaterials2($_POST['ids'], $_POST['type']);;
|
||||||
break;
|
break;
|
||||||
case 'saveProductDescription':
|
case 'saveProductDescription':
|
||||||
saveProductDescription($_GET['itemId'], $_GET['description']);
|
saveProductDescription($_GET['itemId'], $_GET['description']);
|
||||||
@@ -300,7 +300,8 @@ function getRawMaterials2($ids, $type)
|
|||||||
if ($type == 'sales') {
|
if ($type == 'sales') {
|
||||||
$productsQuery = "SELECT si.ecmproduct_id, SUM(si.quantity) as quantity
|
$productsQuery = "SELECT si.ecmproduct_id, SUM(si.quantity) as quantity
|
||||||
FROM ecmsaleitems AS si
|
FROM ecmsaleitems AS si
|
||||||
WHERE si.id IN ('" . $idsString . "')";
|
WHERE si.id IN ('" . $idsString . "')
|
||||||
|
GROUP BY si.id";
|
||||||
$prows = $db->query($productsQuery);
|
$prows = $db->query($productsQuery);
|
||||||
while ($p = $db->fetchByAssoc($prows)) {
|
while ($p = $db->fetchByAssoc($prows)) {
|
||||||
$prod = array();
|
$prod = array();
|
||||||
@@ -312,18 +313,9 @@ function getRawMaterials2($ids, $type)
|
|||||||
$products = $ids;
|
$products = $ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
$grouppedProducts = array_reduce($products, function ($carry, $item) {
|
|
||||||
if (isset($carry[$item['ecmproduct_id']])) {
|
|
||||||
$carry[$item['ecmproduct_id']]['productQty'] += $item['quantity'];
|
|
||||||
} else {
|
|
||||||
$carry[$item['ecmproduct_id']] = $item;
|
|
||||||
}
|
|
||||||
return $carry;
|
|
||||||
});
|
|
||||||
|
|
||||||
$rawMaterialsData = array();
|
$rawMaterialsData = array();
|
||||||
|
|
||||||
foreach ($grouppedProducts as $product) {
|
foreach ($products as $product) {
|
||||||
$rawMaterialsData = array_merge(
|
$rawMaterialsData = array_merge(
|
||||||
$rawMaterialsData,
|
$rawMaterialsData,
|
||||||
getProductRawMaterials($product['ecmproduct_id'], $product['quantity'])
|
getProductRawMaterials($product['ecmproduct_id'], $product['quantity'])
|
||||||
@@ -389,7 +381,7 @@ function getRawMaterials2($ids, $type)
|
|||||||
$row['stockAddress'] = (!empty($product['stock_addresses'])) ? $product['stock_addresses'] : "";
|
$row['stockAddress'] = (!empty($product['stock_addresses'])) ? $product['stock_addresses'] : "";
|
||||||
$response[] = $row;
|
$response[] = $row;
|
||||||
}
|
}
|
||||||
return json_encode($response);
|
echo json_encode($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRawMaterials($ids, $cids)
|
function getRawMaterials($ids, $cids)
|
||||||
|
|||||||
Reference in New Issue
Block a user