From 64ad639c8921187cd734b99c38f72062606d3228 Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 17 Jun 2025 15:19:33 +0300 Subject: [PATCH] =?utf8?q?ERP-360=20=D0=A1=D0=B1=D0=BE=D1=80=D0=BA=D0=B0?= =?utf8?q?=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B=20=D0=B0?= =?utf8?q?=D0=B2=D1=82=D0=BE=D0=BF=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/commands/CronController.php | 36 ++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/erp24/commands/CronController.php b/erp24/commands/CronController.php index 8392ff48..bfc58c15 100644 --- a/erp24/commands/CronController.php +++ b/erp24/commands/CronController.php @@ -1597,17 +1597,37 @@ class CronController extends Controller continue; } + $existingRecords = []; + $records = Autoplannogramma::find() + ->where([ + 'month' => $month, + 'year' => $year, + 'store_id' => $store->id, + ]) + ->andWhere(['week' => array_unique(array_column($forecast, 'week'))]) + ->all(); + + foreach ($records as $record) { + $existingRecords[$record->week . '_' . $record->product_id] = $record; + } + foreach ($forecast as $item) { - $model = new Autoplannogramma(); - $model->month = $month; - $model->year = $year; - $model->week = $item['week']; - $model->product_id = $item['product_id']; - $model->store_id = $item['store_id']; + $key = $item['week'] . '_' . $item['product_id']; + $model = $existingRecords[$key] ?? null; + + if (!$model) { + $model = new Autoplannogramma(); + $model->month = $month; + $model->year = $year; + $model->week = $item['week']; + $model->product_id = $item['product_id']; + $model->store_id = $item['store_id']; + $model->is_archive = false; + $model->capacity_type = 1; + } + $model->quantity = $item['forecast_week_pieces']; $model->quantity_forecast = $item['forecast_week_pieces']; - $model->is_archive = false; - $model->capacity_type = 1; if (!$model->save()) { $errors = []; -- 2.39.5