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

index c05754d4f9c0ddf0dc03da305a87d24d9e61fc3d..bf947d5b505c16b62788c132af35146dc8333f12 100644 (file)
@@ -212,20 +212,20 @@ 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) {
-                    // Initialize channel data in title
-                    $value['title'][$channel] = [];
                     $channelData = $forecast[$storeId][$channel] ?? [];
 
+                    // Prioritize share if it exists
                     if (isset($channelData['share']) && is_numeric($channelData['share'])) {
                         $value['title'][$channel] = round($quantity * $channelData['share'], 2);
+                        continue; // Skip product-specific data if share exists
                     }
 
+                    // Use product-specific forecast if available
                     if (isset($productData['product_id']) && isset($forecast[$storeId][$productData['product_id']][$channel])) {
                         $details = $forecast[$storeId][$productData['product_id']][$channel];
                         $total = array_sum($details);
@@ -233,6 +233,8 @@ class AutoPlannogrammaController extends BaseController
                             round($quantity * $total, 2),
                             'details' => array_map(fn($val) => round($val, 2), $details),
                         ];
+                    } else {
+                        $value['title'][$channel] = []; // Empty if neither share nor details exist
                     }
                 }
             }