$storeId = (int)$storeId;
+ $startDate = date('Y-m-d', strtotime($startDate));
+ $endDate = date('Y-m-d 23:59:59', strtotime($endDate));
+
$salesRecords = Sales::find()
->select(['id', 'date'])
- ->where(['store_id' => $storeId, 'operation' => 'Продажа'])
+ ->where(['store_id' => $storeId, 'operation' => Sales::OPERATION_SALE])
->andWhere(['>=', 'date', $startDate])
->andWhere(['<=', 'date', $endDate])
->asArray()
->all();
- $startDate = date('Y-m-d', strtotime($startDate));
- $endDate = date('Y-m-d', strtotime($endDate));
- $endDatePlusThreeWeeks = date('Y-m-d', strtotime($endDate . ' +3 weeks'));
+ $endDatePlusThreeWeeks = date('Y-m-d 23:59:59', strtotime($endDate . ' +3 weeks'));
$returnedSales = Sales::find()
->select(['sales_check'])
- ->where(['store_id' => $storeId, 'operation' => 'Возврат'])
+ ->where(['store_id' => $storeId, 'operation' => Sales::OPERATION_RETURN])
->andWhere(['>=', 'date', $startDate])
->andWhere(['<=', 'date', $endDatePlusThreeWeeks]) // $endDate + 3 недели
->andWhere(['is not', 'sales_check', null]) // Проверяем, что поле sales_check не пустое
$quantity = (float)$product['quantity'];
$checkDate = date('Y-m-d', strtotime($saleDates[$product['check_id']]));
- if (isset($selfCostsMap[$productId][$checkDate])) {
- $totalSum += $selfCostsMap[$productId][$checkDate] * $quantity;
+ // Логирование отсутствующих данных о себестоимости
+ if (!isset($selfCostsMap[$productId][$checkDate])) {
+
+ Yii::info("Не найдена себестоимость для продукта $productId на дату $checkDate", __METHOD__);
+
+
+ InfoLogService::setInfoLog(__FILE__, __LINE__, 'SelfCostProduct', "error_id_100: Продукт $productId на дату $checkDate не имеет себестоимости");
+
+
+ $price = 0.0;
+ } else {
+ $price = $selfCostsMap[$productId][$checkDate];
}
+
+
+ $totalSum += $price * $quantity;
}
+
return $totalSum;
}