From 201ad9565da1851fc79a4a505875a8b57158001b Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Fri, 25 Jul 2025 13:28:51 +0300 Subject: [PATCH] =?utf8?q?=D0=A0=D0=B0=D1=81=D1=87=D0=B5=D1=82=20=D0=BF?= =?utf8?q?=D0=BE=20=D0=BA=D0=B0=D1=82=D0=B5=D0=B3=D0=BE=D1=80=D0=B8=D1=8F?= =?utf8?q?=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/commands/CronController.php | 23 ++++++++++++------- .../AutoPlannogrammaController.php | 4 +--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/erp24/commands/CronController.php b/erp24/commands/CronController.php index 088667e4..c3bbeac9 100644 --- a/erp24/commands/CronController.php +++ b/erp24/commands/CronController.php @@ -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']; diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index a5e2df8e..bd97ce38 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -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); -- 2.39.5