$filters['month'],
$filters['year'],
$goals,
- $productSalesShare,
- $filters['category'],
- $filters['subcategory'],
- $filters['species']
+ $productSalesShare
);
-/* $matrixForecast = MatrixBouquetForecast::find()
- ->where(['year' => $filters['year'], 'month' => $filters['month']])
- ->asArray()
- ->all();
- $matrixGroups = array_unique(ArrayHelper::getColumn($matrixForecast, 'group'));
- $bouquetForecast = StorePlanService::getBouquetSpiecesMonthGoalFromForecast($filters['month'], $filters['year'], $filters['store_id'], $matrixGroups);
- $speciesData = $bouquetForecast['final'];
- foreach ($speciesData as $store_id => $categoryData) {
- foreach ($categoryData as $category => $subcategoryData) {
- foreach ($subcategoryData as $subcategory => $species) {
- foreach ($species as $speciesInd => $row) {
- $bouquetSpeciesForecast[] = [
- 'category' => $category,
- 'subcategory' => $subcategory,
- 'store_id' => $store_id,
- 'species' => $speciesInd,
- 'goal' => $row
- ];
- }
- }
- }
+
+
+ /* $matrixForecast = MatrixBouquetForecast::find()
+ ->where(['year' => $filters['year'], 'month' => $filters['month']])
+ ->asArray()
+ ->all();
+ $matrixGroups = array_unique(ArrayHelper::getColumn($matrixForecast, 'group'));
+ $bouquetForecast = StorePlanService::getBouquetSpiecesMonthGoalFromForecast($filters['month'], $filters['year'], $filters['store_id'], $matrixGroups);
+ $speciesData = $bouquetForecast['final'];
+ foreach ($speciesData as $store_id => $categoryData) {
+ foreach ($categoryData as $category => $subcategoryData) {
+ foreach ($subcategoryData as $subcategory => $species) {
+ foreach ($species as $speciesInd => $row) {
+ $bouquetSpeciesForecast[] = [
+ 'category' => $category,
+ 'subcategory' => $subcategory,
+ 'store_id' => $store_id,
+ 'species' => $speciesInd,
+ 'goal' => $row
+ ];
+ }
+ }
+ }
- }
- $cleanedSpeciesGoals = $service->subtractSpeciesGoals($goals, $bouquetSpeciesForecast, $noHistoryProductData);*/
+ }
+ $cleanedSpeciesGoals = $service->subtractSpeciesGoals($goals, $bouquetSpeciesForecast, $noHistoryProductData);*/
$salesProductForecastShare = $service->calculateProductForecastShare($noHistoryProductData, $productSalesForecast);
foreach ($weeksData as $r) {
$forecasts = $service->calculateWeekForecastSpeciesProducts($r['category'], $r['subcategory'], $r['species'], $r['store_id'], $r['weekly_goal']);
+
foreach ($forecasts as $forecast) {
$weeksProductForecast[] = [
- 'category' => $forecast['category'] ?? '',
+ 'category' => $forecast['category'] ?? '',
'subcategory' => $forecast['subcategory'] ?? '',
- 'species' => $forecast['species'] ?? '',
- 'product_id' => $forecast['product_id'] ?? '',
- 'name' => $forecast['name'] ?? '',
- 'price' => $forecast['price'] ?? '',
- 'goal' => $forecast['goal'] ?? 0,
- 'forecast' => $forecast['forecast'] ?? 0,
- 'week' => $r['week'],
+ 'species' => $forecast['species'] ?? '',
+ 'product_id' => $forecast['product_id'] ?? '',
+ 'name' => $forecast['name'] ?? '',
+ 'price' => $forecast['price'] ?? '',
+ 'goal' => $forecast['goal'] ?? 0,
+ 'forecast' => $forecast['forecast'] ?? 0,
+ 'week' => $r['week'],
];
}
}
]);
}
+ public function actionWeeklyBouquetProductsForecast()
+ {
+ Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
+
+ $request = Yii::$app->request;
+ $storeIdRequest = $request->get('storeId');
+ $monthRequest = $request->get('month');
+ $yearRequest = $request->get('year');
+ $weekRequest = $request->get('week');
+
+ if (!$monthRequest || !$yearRequest || $weekRequest === null) {
+ return ['success' => false, 'message' => 'Нет параметров'];
+ }
+
+ $service = new AutoPlannogrammaService();
+ $result = $service->getWeeklyBouquetProductsForecast($monthRequest, $yearRequest, $storeIdRequest);
+
+ if (!is_array($result)) {
+ return ['success' => false, 'message' => 'Ошибка структуры данных'];
+ }
+
+ $grouped = [];
+
+ foreach ($result as $item) {
+ $weekItem = (int) $item['week'];
+ $storeItem = (int) $item['store_id'];
+ $guid = (string) $item['product_guid'];
+ $group = (string) $item['matrix_group'];
+ $type = (string) $item['type'];
+ $forecastValue = (float) $item['week_forecast'];
+
+ $grouped[$weekItem][$storeItem][$guid][$type][$group] = $forecastValue;
+ }
+
+
+ if ($weekRequest !== null) {
+ $week = (int) $weekRequest;
+ $grouped = isset($grouped[$week]) ? [$week => $grouped[$week]] : [];
+ }
+
+ return [
+ 'success' => true,
+ 'data' => $grouped,
+ ];
+
+
+ }
+
+
+ public function actionGetSubcategories(string $category, int $year, int $week): array
+ {
+ Yii::$app->response->format = Response::FORMAT_JSON;
+
+ $data = Autoplannogramma::find()
+ ->alias('a')
+ ->leftJoin('products_1c_nomenclature p', 'a.product_id = p.id')
+ ->where(['p.category' => $category])
+ ->andWhere(['a.year' => $year])
+ ->andWhere(['a.week' => $week])
+ ->select([
+ 'p.subcategory as name',
+ new \yii\db\Expression("CASE WHEN COUNT(a.id) > 0 THEN 1 ELSE 0 END AS hasData")
+ ])
+ ->groupBy('p.subcategory')
+ ->asArray()
+ ->all();
+
+ return $data;
+ }
++
}