raw materials fix

This commit is contained in:
Michał Zieliński
2025-09-08 10:59:33 +02:00
parent cbf5645912
commit 64a63d5748

View File

@@ -138,7 +138,7 @@ if (!isset($_GET['ajaxAction'])) {
getComponents3($_POST['ids']);
break;
case 'getRawMaterials':
echo getRawMaterials($_POST['ids'], $_POST['type']);;
getRawMaterials2($_POST['ids'], $_POST['type']);;
break;
case 'saveProductDescription':
saveProductDescription($_GET['itemId'], $_GET['description']);
@@ -300,7 +300,8 @@ function getRawMaterials2($ids, $type)
if ($type == 'sales') {
$productsQuery = "SELECT si.ecmproduct_id, SUM(si.quantity) as quantity
FROM ecmsaleitems AS si
WHERE si.id IN ('" . $idsString . "')";
WHERE si.id IN ('" . $idsString . "')
GROUP BY si.id";
$prows = $db->query($productsQuery);
while ($p = $db->fetchByAssoc($prows)) {
$prod = array();
@@ -312,18 +313,9 @@ function getRawMaterials2($ids, $type)
$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();
foreach ($grouppedProducts as $product) {
foreach ($products as $product) {
$rawMaterialsData = array_merge(
$rawMaterialsData,
getProductRawMaterials($product['ecmproduct_id'], $product['quantity'])
@@ -389,7 +381,7 @@ function getRawMaterials2($ids, $type)
$row['stockAddress'] = (!empty($product['stock_addresses'])) ? $product['stock_addresses'] : "";
$response[] = $row;
}
return json_encode($response);
echo json_encode($response);
}
function getRawMaterials($ids, $cids)