From: Vladimir Fomichev Date: Tue, 17 Jun 2025 11:13:25 +0000 (+0300) Subject: Рассчет в кроне X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=b21a6c77a6ce98b95839edd450d74c15cda506b8;p=erp24_rep%2Fyii-erp24%2F.git Рассчет в кроне --- diff --git a/erp24/commands/CronController.php b/erp24/commands/CronController.php index 8392ff48..9aa5e1bb 100644 --- a/erp24/commands/CronController.php +++ b/erp24/commands/CronController.php @@ -1590,12 +1590,22 @@ class CronController extends Controller 'plan_date' => $planDate ]); + $writeOffsForecast = $service->getWeeklyProductsWriteoffsForecast($month, $year, $store->id); + $this->stdout("Рассчитана автопланограмма для магазина {$store->name}\n", BaseConsole::FG_GREEN); } catch (\Throwable $e) { $this->stderr("Ошибка при расчёте прогноза: {$e->getMessage()}\n", BaseConsole::FG_RED); Yii::error("Ошибка при расчёте прогноза: " . $e->getMessage(), __METHOD__); continue; } + $writeOffsForecastMap = []; + foreach ($writeOffsForecast as $itemForecast) { + $itemWeek = $itemForecast['week']; + $itemGuid = $itemForecast['product_id']; + $writeoffsForecast = $itemForecast['forecast']; + $writeOffsForecastMap[$itemWeek][$itemGuid] = $writeoffsForecast; + + } foreach ($forecast as $item) { $model = new Autoplannogramma(); @@ -1608,6 +1618,11 @@ class CronController extends Controller $model->quantity_forecast = $item['forecast_week_pieces']; $model->is_archive = false; $model->capacity_type = 1; + if (isset($writeOffsForecastMap[$item['week']]) && isset($writeOffsForecastMap[$item['week']][$item['product_id']])) { + $model->writeoffs_forecast = $writeOffsForecastMap[$item['week']][$item['product_id']]; + } else { + $model->writeoffs_forecast = 0; + } if (!$model->save()) { $errors = [];