From 79437cd0ec6cbe1bf4080f55e7d72da378cc209f Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 17 Jun 2025 12:55:40 +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 | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index be0724f0..c05754d4 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -212,27 +212,26 @@ class AutoPlannogrammaController extends BaseController $quantity = $value['quantity']; $value['title'] = []; + // Skip if store_id is not in forecast + if (!isset($forecast[$storeId])) { + continue; + } + foreach (['offline', 'marketplace', 'online'] as $channel) { - // Ищем forecast по store и каналу + // Initialize channel data in title + $value['title'][$channel] = []; $channelData = $forecast[$storeId][$channel] ?? []; - // 1. Если есть share — сохраняем отдельно if (isset($channelData['share']) && is_numeric($channelData['share'])) { - $value['title'][$channel . '_share'] = round($quantity * $channelData['share'], 2); + $value['title'][$channel] = round($quantity * $channelData['share'], 2); } - // 2. Если есть подтипы (любые ключи, кроме 'share') - $details = array_filter( - $channelData, - fn($k) => $k !== 'share', - ARRAY_FILTER_USE_KEY - ); - - if (!empty($details)) { + if (isset($productData['product_id']) && isset($forecast[$storeId][$productData['product_id']][$channel])) { + $details = $forecast[$storeId][$productData['product_id']][$channel]; $total = array_sum($details); $value['title'][$channel] = [ - 'total' => round($quantity * $total, 2), - 'details' => $details, + round($quantity * $total, 2), + 'details' => array_map(fn($val) => round($val, 2), $details), ]; } } -- 2.39.5