]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Расчет по категориям
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 25 Jul 2025 10:28:51 +0000 (13:28 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 25 Jul 2025 10:28:51 +0000 (13:28 +0300)
erp24/commands/CronController.php
erp24/controllers/AutoPlannogrammaController.php

index 088667e44afbbb4df3561a69efcc0f58c1b3b978..c3bbeac9323e9eb32863e69711c8e168704f1a22 100644 (file)
@@ -27,6 +27,7 @@ use yii_app\records\LPTrackerApi;
 use yii_app\records\MatrixBouquetForecast;
 use yii_app\records\Product1cReplacement;
 use yii_app\records\Products1c;
+use yii_app\records\Products1cNomenclature;
 use yii_app\records\ReplacementInvoice;
 use yii_app\records\ReplacementInvoiceProducts;
 use yii_app\records\MarketplaceOrder1cStatuses;
@@ -1593,14 +1594,14 @@ class CronController extends Controller
     public function actionAutoplannogrammaCalculate(): void
     {
         $date = new DateTime();
-        $date->modify('+0 months');
+        $date->modify('+2 months');
         $planDate = $date->format('Y-m-01');
         $month = (int)$date->format('m');
         $year = (int)$date->format('Y');
 
         $service = new AutoPlannogrammaService();
         $stores = CityStore::find()->where(['visible' => CityStore::IS_VISIBLE])->all();
-
+        $categories = Products1cNomenclature::find()->select('category')->distinct()->andWhere(['not in', 'category', ['', 'букет', 'сборка', 'сервис']])->column();
         $this->stdout("Начало расчетов автопланограммы для $planDate\n", BaseConsole::FG_GREEN);
 
         foreach ($stores as $store) {
@@ -1617,8 +1618,14 @@ class CronController extends Controller
                     'species' => null,
                     'plan_date' => $planDate
                 ];
-                $this->stdout("Рассчитана автопланограмма для магазина " .  json_encode($forecastParams, JSON_UNESCAPED_UNICODE) . "\n", BaseConsole::FG_GREEN);
-                $forecast = $service->calculateFullForecastForWeek($forecastParams);
+                $this->stdout("Параметры расчета " .  json_encode($forecastParams, JSON_UNESCAPED_UNICODE) . "\n", BaseConsole::FG_GREEN);
+                $forecasts = [];
+                foreach ($categories as $category) {
+                    $forecastParams['category'] = $category;
+                    $forecast = $service->calculateFullForecastForWeek($forecastParams);
+                    $forecasts = array_merge($forecasts, $forecast);
+                }
+
                 $logDir = Yii::getAlias('@runtime/logs/autoplannogramma');
                 if (!is_dir($logDir)) {
                     mkdir($logDir, 0755, true);
@@ -1626,10 +1633,10 @@ class CronController extends Controller
                 $file = $logDir . '/forecast_store_' . $store->id . '_' . date('Ymd_His') . '.json';
                 file_put_contents(
                     $file,
-                    json_encode($forecast, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
+                    json_encode($forecasts, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
                 );
                 $this->stdout("Forecast сохранён в $file\n", BaseConsole::FG_BLUE);
-                $writeOffsForecast = $service->getWeeklyProductsWriteoffsForecast($month, $year, $forecast, $store->id);
+                $writeOffsForecast = $service->getWeeklyProductsWriteoffsForecast($month, $year, $forecasts, $store->id);
                 $salesForecast = $service->getWeeklyBouquetProductsSalesForecast($month, $year, $store->id);
 
                 $this->stdout("Рассчитана автопланограмма для магазина {$store->name}\n", BaseConsole::FG_GREEN);
@@ -1639,12 +1646,12 @@ class CronController extends Controller
                         'month' => $month,
                         'year' => $year,
                         'store_id' => $store->id,
-                        'week' => array_unique(array_column($forecast, 'week'))
+                        'week' => array_unique(array_column($forecasts, 'week'))
                     ])
                     ->indexBy(fn($record) => $record->week . '_' . $record->product_id)
                     ->all();
 
-                foreach ($forecast as $item) {
+                foreach ($forecasts as $item) {
                     $key = $item['week'] . '_' . $item['product_id'];
                     $model = $existingRecords[$key] ?? new Autoplannogramma();
                     $productId = $item['product_id'];
index a5e2df8ebd554936f773d0b55f85cbc4524400bb..bd97ce38ae797879e64fecf20b941231e1f1e656 100644 (file)
@@ -1358,8 +1358,7 @@ class AutoPlannogrammaController extends BaseController
 
             $service = new AutoPlannogrammaService();
             //$goals = $service->calculateFullGoalChain($filters);
-            $forecast = $service->calculateFullForecastForWeek($filters);
-            var_dump( $forecast); die();
+            //$forecast = $service->calculateFullForecastForWeek($filters);
             $monthCategoryShare = $service->getMonthCategoryShareOrWriteOff($filters['plan_date'], $filters);
             $monthCategoryGoal = $service->getMonthCategoryGoal($monthCategoryShare, $filters['plan_date']);
             $monthSubcategoryShare = $service->getMonthSubcategoryShareOrWriteOff($filters['plan_date'], $filters);
@@ -1761,7 +1760,6 @@ class AutoPlannogrammaController extends BaseController
 
             try {
                 $forecast = $service->calculateFullForecastForWeek($params);
-                //var_dump($forecast);die();
                 $writeOffsForecast = $service->getWeeklyProductsWriteoffsForecast($month, $year, $forecast, $store_id);
                 $salesForecast = $service->getWeeklyBouquetProductsSalesForecast($month, $year, $store_id);