From: Vladimir Fomichev Date: Fri, 25 Jul 2025 10:28:51 +0000 (+0300) Subject: Расчет по категориям X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=201ad9565da1851fc79a4a505875a8b57158001b;p=erp24_rep%2Fyii-erp24%2F.git Расчет по категориям --- 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);