From: marina Date: Mon, 16 Jun 2025 12:36:19 +0000 (+0300) Subject: Merge branch 'develop' into feature_zozirova_erp-360_autoplannogramma_build X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=2eef370fc63a8cda0b8af1461e3c7bffea40b46c;p=erp24_rep%2Fyii-erp24%2F.git Merge branch 'develop' into feature_zozirova_erp-360_autoplannogramma_build # Conflicts: # erp24/controllers/AutoPlannogrammaController.php --- 2eef370fc63a8cda0b8af1461e3c7bffea40b46c diff --cc erp24/controllers/AutoPlannogrammaController.php index feb9cace,20066d0f..a3a78609 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@@ -922,36 -909,35 +922,35 @@@ class AutoPlannogrammaController extend $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); @@@ -1716,17 -1704,18 +1710,18 @@@ 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'], ]; } } @@@ -1756,24 -1745,53 +1751,74 @@@ ]); } + 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; + } ++ }