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

index 86b297bce38fa292abe2a18ccc033819eda8bb60..d1fe4a721f6072a00c945b3941628caccbc68a68 100644 (file)
@@ -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);
     }