]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Правки по товарам c истории
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 30 May 2025 15:19:52 +0000 (18:19 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 30 May 2025 15:19:52 +0000 (18:19 +0300)
erp24/controllers/AutoPlannogrammaController.php
erp24/services/AutoPlannogrammaService.php
erp24/services/StorePlanService.php

index 991e6ca5020fbbfe5ad4711b865d3e684f2fa4fd..a1d024d1c10fa0a196b8e71a2b4ac6f6856b8650 100644 (file)
@@ -906,14 +906,14 @@ class AutoPlannogrammaController extends BaseController
             $productSalesForecast = $service->calculateProductForecastInPiecesProductsWithHistory(
                 $filters['store_id'],
                 $filters['month'],
-                $filters['category'],
-                $filters['subcategory'],
-                $filters['species'],
                 $productSalesShare,
-                $goals
+                $goals,
+                $filters['subcategory'],
+                $filters['category'],
+                $filters['species']
             );
 
-            $matrixForecast = MatrixBouquetForecast::find()
+/*            $matrixForecast = MatrixBouquetForecast::find()
                 ->where(['year' => $filters['year'], 'month' => $filters['month']])
                 ->asArray()
                 ->all();
@@ -936,14 +936,14 @@ class AutoPlannogrammaController extends BaseController
                 }
 
             }
-            $cleanedSpeciesGoals = $service->subtractSpeciesGoals($goals, $bouquetSpeciesForecast, $noHistoryProductData);
+            $cleanedSpeciesGoals = $service->subtractSpeciesGoals($goals, $bouquetSpeciesForecast, $noHistoryProductData);*/
 
 
             $salesProductForecastShare = $service->calculateProductForecastShare($noHistoryProductData, $productSalesForecast);
 
            // $productForecastSpecies = $service->calculateProductSalesBySpecies($salesProductForecastShare, $cleanedSpeciesGoals);
 
-            //var_dump($salesProductForecastShare); die();
+            var_dump($productSalesForecast); die();
 
 
 
@@ -1037,11 +1037,11 @@ class AutoPlannogrammaController extends BaseController
             $productSalesForecast = $service->calculateProductForecastInPiecesProductsWithHistory(
                 $filters['store_id'],
                 $filters['month'],
-                $filters['category'],
-                $filters['subcategory'],
-                $filters['species'],
                 $productSalesShare,
-                $goals
+                $goals,
+                $filters['subcategory'],
+                $filters['category'],
+                $filters['species']
             );
 
             $matrixForecast = MatrixBouquetForecast::find()
index dec3bf92ccde3857cdd9fd0d1c4983be070a2c10..c27a7a6c0aa49f30e4c712a9ba5ac1c70de0d137 100644 (file)
@@ -1471,38 +1471,26 @@ var_dump($yearData); die();
         return $result;
     }
 
-    public static function calculateProductForecastInPiecesProductsWithHistory(
+    public function calculateProductForecastInPiecesProductsWithHistory(
         int $storeId,
         string $month,
-        string $category,
-        string $subcategory,
-        string $species,
         array $productSalesShare,
-        array $speciesGoals
+        array $speciesGoals,
+        string $subcategory = null,
+        string $category = null,
+        string $species = null
     ): array {
         $result = [];
 
-        $goal = null;
-        foreach ($speciesGoals as $item) {
-            if (
-                $item['store_id'] == $storeId &&
-                $item['category'] == $category &&
-                $item['subcategory'] == $subcategory &&
-                $item['species'] == $species
-            ) {
-                $goal = $item['goal'];
-                break;
-            }
-        }
-
-        if ($goal === null) {
+        if (empty($speciesGoals)) {
             return [];
         }
 
+        $goalsMap = $this->mapGoalsBySpecies($speciesGoals);
+
         $region = CityStoreParams::find()
             ->where(['store_id' => $storeId])
-            ->select('address_region')
-            ->scalar();
+            ->one()->address_region ?? null;
 
         if (!$region) {
             $cityId = CityStore::find()->select('city_id')->where(['id' => $storeId])->scalar();
@@ -1529,7 +1517,7 @@ var_dump($yearData); die();
             if (!$priceRecord || $priceRecord->price <= 0) {
                 continue;
             }
-
+            $goal = $goalsMap[$data['store_id']][$data['category']][$data['subcategory']][$data['species']];
             $forecastSum = $goal * $share;
 
             $forecastCount = $forecastSum / $priceRecord->price;
@@ -1540,10 +1528,10 @@ var_dump($yearData); die();
                 'goal_share' => round($forecastSum, 2),
                 'price' => $priceRecord->price,
                 'forecast_pieces' => round($forecastCount),
-                'store_id' => $storeId,
-                'category' => $category,
-                'subcategory' => $subcategory,
-                'species' => $species,
+                'store_id' => $data['store_id'],
+                'category' => $data['category'],
+                'subcategory' => $data['subcategory'],
+                'species' => $data['species'],
             ];
         }
 
index b99448cd801b55801a8e522004a19c65c94bb91d..6afc6054e0c9cd3c0ae4e7428bbfc1740572ab62 100755 (executable)
@@ -989,7 +989,7 @@ class StorePlanService
 
         $productsData = [];
         $globalTotal = 0;
-
+       // var_dump($productsWithHistory); die();
         foreach ($productsWithHistory as $product) {
             $guid = $product['guid'];
             $result = self::processProductWithHistory($storeId, $product, $weightedPeriods);
@@ -1045,6 +1045,10 @@ class StorePlanService
         }
 
         return [
+            'store_id' => $storeId,
+            'category' => $product['category'],
+            'subcategory' => $product['subcategory'],
+            'species' => $product['species'],
             'monthlySales'    => $monthlySales,
             'monthlyWeighted' => $monthlyWeighted,
             'weightedSum'     => $weightedSum,