]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Merge branch 'develop' into feature_zozirova_erp-360_autoplannogramma_build
authormarina <m.zozirova@gmail.com>
Mon, 16 Jun 2025 12:36:19 +0000 (15:36 +0300)
committermarina <m.zozirova@gmail.com>
Mon, 16 Jun 2025 12:36:19 +0000 (15:36 +0300)
# Conflicts:
# erp24/controllers/AutoPlannogrammaController.php

1  2 
erp24/controllers/AutoPlannogrammaController.php

index feb9caceba11e1d6d1e0e3c66730d0f64a379918,20066d0f6944a86373983736ab1aff542c57a985..a3a78609270faf2719f3ac6bfbb3bfee803882d0
@@@ -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);
  
              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;
 +    }
++
  }