]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Прогноз товаров с историей
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 27 May 2025 07:04:39 +0000 (10:04 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 27 May 2025 07:04:39 +0000 (10:04 +0300)
erp24/controllers/AutoPlannogrammaController.php
erp24/services/AutoPlannogrammaService.php

index 42663b598d61543a688611f1f4de54e687db641b..a3360580f05d6d95847cf31e02a4949f390b61cf 100644 (file)
@@ -686,7 +686,24 @@ class AutoPlannogrammaController extends BaseController
             //var_dump($filters); die();
             $service = new AutoPlannogrammaService();
             $data = $service->calculateSpeciesForecastForProductsWithoutHistory($filters['plan_date'], $filters);
-            $goals = $service->calculateFullGoalChain($filters);
+            //$goals = $service->calculateFullGoalChain($filters);
+            $monthCategoryShare = $service->getMonthCategoryShareOrWriteOff($filters['plan_date'], $filters);
+            $monthCategoryGoal = $service->getMonthCategoryGoal($monthCategoryShare, $filters['plan_date']);
+            $monthSubcategoryShare = $service->getMonthSubcategoryShareOrWriteOff($filters['plan_date'], $filters);
+            $monthSubcategoryGoal = $service->getMonthSubcategoryGoal($monthSubcategoryShare, $monthCategoryGoal);
+            $monthSpeciesShare = $service->getMonthSpeciesShareOrWriteOff($filters['plan_date'], $filters);
+            $goals = $service->getMonthSpeciesGoalDirty($monthSpeciesShare, $monthSubcategoryGoal);
+
+            if ($filters['type'] == AutoPlannogrammaService::TYPE_WRITE_OFFS) {
+                $monthCategoryWriteOffsShare = $service->getMonthCategoryShareOrWriteOff($filters['plan_date'], $filters, $filters['type']);
+                $monthCategoryWriteOffsGoal = $service->getMonthCategoryGoal($monthCategoryWriteOffsShare, $filters['plan_date'], $filters['type']);
+                $monthSubcategoryWriteOffsShare = $service->getMonthSubcategoryShareOrWriteOff($filters['plan_date'], $filters, $filters['type']);
+                $monthSubcategoryWriteOffsGoals = $service->getMonthSubcategoryGoal($monthSubcategoryWriteOffsShare, $monthCategoryWriteOffsGoal, $filters['type']);
+                $monthSpeciesWriteOffShare = $service->getMonthSpeciesShareOrWriteOff($filters['plan_date'], $filters, $filters['type']);
+                $goals = $service->getMonthSpeciesGoalDirty($monthSpeciesWriteOffShare, $monthSubcategoryWriteOffsGoals, $filters['type'], $data);
+            }
+
+
             $result = StorePlanService::calculateHistoricalShare(
                 $filters['store_id'],
                 $filters['month'],
@@ -709,9 +726,17 @@ class AutoPlannogrammaController extends BaseController
                 $result['with_history']
             );
 
+            $productSalesForecast = $service->calculateProductForecastInPieces(
+                $filters['store_id'],
+                $filters['month'],
+                $filters['category'],
+                $filters['subcategory'],
+                $filters['species'],
+                $productSalesShare,
+                $goals
+            );
 
-
-            var_dump($productSalesShare); die();
+            var_dump($productSalesForecast); die();
 
 
 
index e3bf11c6fa7d7137593278d50cbd27da794995f8..5bbd5840e8dc9ab41838adac4a04ab41cd5867b2 100644 (file)
@@ -825,4 +825,77 @@ class AutoPlannogrammaService
         return $result;
     }
 
+    public static function calculateProductForecastInPieces(
+        int $storeId,
+        string $month,
+        string $category,
+        string $subcategory,
+        string $species,
+        array $productSalesShare,
+        array $speciesGoals
+    ): 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) {
+            return [];
+        }
+
+        $region = CityStoreParams::find()
+            ->where(['store_id' => $storeId])
+            ->select('address_region')
+            ->scalar();
+
+        if (!$region) {
+            $cityId = CityStore::find()->select('city_id')->where(['id' => $storeId])->scalar();
+            $region = ($cityId == 1)
+                ? BouquetComposition::REGION_MSK
+                : BouquetComposition::REGION_NN;
+        }
+
+        foreach ($productSalesShare as $productId => $data) {
+            $share = $data['share'] ?? 0.0;
+
+            if ($share <= 0.0) {
+                continue;
+            }
+
+            $priceRecord = PricesDynamic::find()
+                ->where([
+                    'product_id' => $productId,
+                    'region_id' => $region,
+                    'active' => 1,
+                ])
+                ->one();
+
+            if (!$priceRecord || $priceRecord->price <= 0) {
+                continue;
+            }
+
+            $forecastSum = $goal * $share;
+            $forecastCount = $forecastSum / $priceRecord->price;
+
+            $result[] = [
+                'product_id' => $productId,
+                'goal_share' => round($forecastSum, 2),
+                'price' => $priceRecord->price,
+                'forecast_pieces' => round($forecastCount),
+            ];
+        }
+
+        return $result;
+    }
+
 }
\ No newline at end of file