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

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