From 03e40c6f5672d16738dc2fd4e5c696b9602ee6fd Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Mon, 28 Jul 2025 15:33:49 +0300 Subject: [PATCH] =?utf8?q?=D0=A0=D0=B0=D1=81=D1=87=D0=B5=D1=82=20=D0=BF?= =?utf8?q?=D0=BB=D0=B0=D0=BD=D0=BE=D0=B3=D1=80=D0=B0=D0=BC=20=D0=B8=D0=B7?= =?utf8?q?=20=D0=B2=D0=B5=D0=B1=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5?= =?utf8?q?=D0=B9=D1=81=D0=B0=20-=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?utf8?q?=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../AutoPlannogrammaController.php | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index bd97ce38..45db5b4c 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -1763,8 +1763,17 @@ class AutoPlannogrammaController extends BaseController $writeOffsForecast = $service->getWeeklyProductsWriteoffsForecast($month, $year, $forecast, $store_id); $salesForecast = $service->getWeeklyBouquetProductsSalesForecast($month, $year, $store_id); + $weeks = array_unique(array_column($forecast, 'week')); + $productIds = array_unique(array_column($forecast, 'product_id')); + $existing = Autoplannogramma::find() - ->where(['month' => $month, 'year' => $year, 'store_id' => $store_id, 'week' => array_unique(array_column($forecast, 'week'))]) + ->where([ + 'month' => $month, + 'year' => $year, + 'store_id' => $store_id, + ]) + ->andWhere(['in', 'week', $weeks]) + ->andWhere(['in', 'product_id', $productIds]) ->indexBy(fn($r) => $r->week . '_' . $r->product_id) ->all(); @@ -1772,13 +1781,14 @@ class AutoPlannogrammaController extends BaseController foreach ($forecast as $item) { $key = $item['week'] . '_' . $item['product_id']; $model = $existing[$key] ?? new Autoplannogramma(); + $quantity = (float)($item['forecast_week_pieces'] ?? 0); $productId = $item['product_id']; $week = $item['week']; - $details = []; $total = $quantity; + if (!empty($writeOffsForecast[$productId][$week]['writeOffs'])) { $wo = $writeOffsForecast[$productId][$week]['writeOffs']; $details['writeOffs']['quantity'] = $wo; @@ -1786,6 +1796,7 @@ class AutoPlannogrammaController extends BaseController } else { $details['writeOffs']['quantity'] = 0; } + foreach (['offline', 'online', 'marketplace'] as $type) { $block = ['share' => 0, 'quantity' => 0, 'groups' => []]; if (isset($salesForecast[$store_id][$productId][$type]) && is_array($salesForecast[$store_id][$productId][$type])) { @@ -1799,6 +1810,7 @@ class AutoPlannogrammaController extends BaseController } $details[$type] = $block; } + $details['forecast'] = ['quantity' => $quantity]; $total = (float)sprintf('%.2f', $total); @@ -1815,8 +1827,10 @@ class AutoPlannogrammaController extends BaseController 'modify' => null, 'total' => ceil($total), ], false); - $model->save(); + if (!$model->save()) { + Yii::error("Ошибка сохранения планограммы: " . json_encode($model->errors), __METHOD__); + } $rows[] = [ 'week' => $week, @@ -1827,6 +1841,7 @@ class AutoPlannogrammaController extends BaseController ]; } + } catch (Throwable $e) { Yii::error($e->getMessage(), __METHOD__); throw $e; -- 2.39.5