From 2979deac14a1efc8b7ded5cd01903a7d51de78dd Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 17 Jun 2025 12:48:58 +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 --- .../AutoPlannogrammaController.php | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index d1fe4a72..be0724f0 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -213,31 +213,27 @@ class AutoPlannogrammaController extends BaseController $value['title'] = []; foreach (['offline', 'marketplace', 'online'] as $channel) { - // 1. Обработка доли (share) - if ( - isset($forecast[$storeId][$channel]['share']) && - is_numeric($forecast[$storeId][$channel]['share']) - ) { - $share = $forecast[$storeId][$channel]['share']; - $value['title'][$channel . '_share'] = round($quantity * $share, 2); + // Ищем forecast по store и каналу + $channelData = $forecast[$storeId][$channel] ?? []; + + // 1. Если есть share — сохраняем отдельно + if (isset($channelData['share']) && is_numeric($channelData['share'])) { + $value['title'][$channel . '_share'] = round($quantity * $channelData['share'], 2); } - // 2. Обработка подтипов - if ( - isset($forecast[$storeId][$channel]) && - is_array($forecast[$storeId][$channel]) - ) { - // Исключаем случай, когда это просто ['share' => ...] - $subtypes = $forecast[$storeId][$channel]; - $subtypesWithoutShare = array_filter($subtypes, fn($k) => $k !== 'share', ARRAY_FILTER_USE_KEY); - - if (!empty($subtypesWithoutShare)) { - $total = array_sum($subtypesWithoutShare); - $value['title'][$channel] = [ - 'total' => round($quantity * $total, 2), - 'details' => $subtypesWithoutShare, - ]; - } + // 2. Если есть подтипы (любые ключи, кроме 'share') + $details = array_filter( + $channelData, + fn($k) => $k !== 'share', + ARRAY_FILTER_USE_KEY + ); + + if (!empty($details)) { + $total = array_sum($details); + $value['title'][$channel] = [ + 'total' => round($quantity * $total, 2), + 'details' => $details, + ]; } } } -- 2.39.5