From: marina Date: Tue, 17 Jun 2025 09:46:22 +0000 (+0300) Subject: ERP-360 Сборка страницы автопм X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=71512770d676d71780ab261a5fcad7e9e2249d1f;p=erp24_rep%2Fyii-erp24%2F.git ERP-360 Сборка страницы автопм --- diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index 86b297bc..d1fe4a72 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -205,7 +205,7 @@ class AutoPlannogrammaController extends BaseController ], ], ]; - + foreach ($result as &$productData) { foreach ($productData['values'] as &$value) { $storeId = $value['store_id']; @@ -213,26 +213,36 @@ class AutoPlannogrammaController extends BaseController $value['title'] = []; foreach (['offline', 'marketplace', 'online'] as $channel) { - // Если по этому магазину и каналу есть просто share — умножаем - if (isset($forecast[$storeId][$channel]['share'])) { + // 1. Обработка доли (share) + if ( + isset($forecast[$storeId][$channel]['share']) && + is_numeric($forecast[$storeId][$channel]['share']) + ) { $share = $forecast[$storeId][$channel]['share']; - $value['title'][$channel] = round($quantity * $share, 2); + $value['title'][$channel . '_share'] = round($quantity * $share, 2); } - // Если по этому магазину и каналу есть список с продуктами — просто копируем + // 2. Обработка подтипов if ( isset($forecast[$storeId][$channel]) && - is_array($forecast[$storeId][$channel]) && - !isset($forecast[$storeId][$channel]['share']) // чтобы не дублировать + is_array($forecast[$storeId][$channel]) ) { - $value['title'][$channel] = $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, + ]; + } } } } } - - return array_values($result); }