From: Vladimir Fomichev Date: Mon, 28 Jul 2025 12:33:49 +0000 (+0300) Subject: Расчет планограм из вебинтерфейса - обновление X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=03e40c6f5672d16738dc2fd4e5c696b9602ee6fd;p=erp24_rep%2Fyii-erp24%2F.git Расчет планограм из вебинтерфейса - обновление --- 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;