-<?
+<?php
+
+global $orderStoresArrayRelation_in, $whereInProductsId, $data_up;
+
$date_id=$db::getValue("SELECT date_id FROM store_products_fact order by date_id DESC LIMIT 1");
-$store_products_fact=$db::getRows("SELECT product_id,quantity, store_id,color FROM store_products_fact WHERE quantity>0
+if ($whereInProductsId != " in ()") {
+ $store_products_fact = $db::getRows("SELECT product_id,quantity, store_id,color FROM store_products_fact WHERE quantity>0
AND date_id=?
AND store_id $orderStoresArrayRelation_in
-AND product_id $whereInProductsId",[$date_id]);
-foreach($store_products_fact as $row) {
- $data_up[$row["product_id"]][$row["store_id"]][$row["color"]] +=$row["quantity"];
- $data_up[$row["product_id"]][0][$row["color"]] +=$row["quantity"];
+AND product_id $whereInProductsId", [$date_id]);
+
+ foreach ($store_products_fact as $row) {
+ $data_up[$row["product_id"]][$row["store_id"]][$row["color"]] = ($data_up[$row["product_id"]][$row["store_id"]][$row["color"]] ?? 0) + $row["quantity"];
+ $data_up[$row["product_id"]][0][$row["color"]] = ($data_up[$row["product_id"]][0][$row["color"]] ?? 0) + $row["quantity"];
+ }
}
\ No newline at end of file