}
$price = ArrayHelper::map(Prices::find()->select(['product_id', 'price'])->where(['product_id' => array_keys($products)])->all(), 'product_id', 'price');
$storeEIT = ExportImportTable::find()->select(['entity_id'])->where(['entity' => 'city_store', 'export_val' => $storeGuid, 'export_id' => 1])->one();
- $selfCost = ArrayHelper::map(
- SelfCostProductDynamic::find()
- ->select(['product_guid', 'price'])
- ->where(['product_guid' => array_keys($products), 'store_id' => $storeEIT->entity_id])
- ->andWhere(new Expression(":d BETWEEN date_from AND date_to", [':d' => date('Y-m-d', strtotime($shiftDate))]))
- ->orderBy(['date_from' => SORT_DESC])
- ->all(),
- 'product_guid', 'price'
- );
+ $selfCost = [];
+ if ($storeEIT && $storeEIT->entity_id) {
+ $selfCost = ArrayHelper::map(
+ SelfCostProductDynamic::find()
+ ->select(['product_guid', 'price'])
+ ->where(['product_guid' => array_keys($products), 'store_id' => $storeEIT->entity_id])
+ ->andWhere(new Expression(":d BETWEEN date_from AND date_to", [':d' => date('Y-m-d', strtotime($shiftDate))]))
+ ->orderBy(['date_from' => SORT_DESC])
+ ->all(),
+ 'product_guid', 'price'
+ );
+ }
// $a = [['a' => 1, 'b' => 2, 'c' => 3], ['a' => 1, 'b' => 5, 'c' => 4], ['a' => 1, 'b' => 7, 'c' => 5],];
// var_dump(ArrayHelper::map($a, 'a', 'b')); die;
// result: array(1) { [1]=> int(7) }
- $loadDataShiftRemains = [];
+
+ // Фильтруем товары без себестоимости из списка
+ $productGuidsFiltered = [];
foreach ($productGuids as $key => $name) {
+ // Проверяем наличие себестоимости (не пустая и больше 0)
+ if (isset($selfCost[$key]) && $selfCost[$key] !== '' && $selfCost[$key] !== null && $selfCost[$key] > 0) {
+ $productGuidsFiltered[$key] = $name;
+ }
+ }
+
+ $loadDataShiftRemains = [];
+ foreach ($productGuidsFiltered as $key => $name) {
$loadDataShiftRemains[] = [
'product_guid' => $key, 'retail_price' => $price[$key] ?? '',
'self_cost' => $selfCost[$key] ?? '',
'fact_and_1c_diff' => 0, 'remains_1c' => $balance[$key] ?? ''
];
}
+
+ // Обновляем productGuids отфильтрованным списком
+ $productGuids = $productGuidsFiltered;
return compact('loadDataShiftRemains', 'productGuids');
}