]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-360 Сборка страницы автопм
authormarina <m.zozirova@gmail.com>
Tue, 17 Jun 2025 09:48:58 +0000 (12:48 +0300)
committermarina <m.zozirova@gmail.com>
Tue, 17 Jun 2025 09:48:58 +0000 (12:48 +0300)
erp24/controllers/AutoPlannogrammaController.php

index d1fe4a721f6072a00c945b3941628caccbc68a68..be0724f0c4f084a1769957bbe74c0e58d79f45f4 100644 (file)
@@ -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,
+                        ];
                     }
                 }
             }