From: marina Date: Tue, 17 Jun 2025 09:48:58 +0000 (+0300) Subject: ERP-360 Сборка страницы автопм X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=2979deac14a1efc8b7ded5cd01903a7d51de78dd;p=erp24_rep%2Fyii-erp24%2F.git ERP-360 Сборка страницы автопм --- 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, + ]; } } }