]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Модификация метода analyzeHistory
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 29 May 2025 09:50:35 +0000 (12:50 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 29 May 2025 09:50:35 +0000 (12:50 +0300)
erp24/services/StorePlanService.php

index a1f346f5d3aa1a7e99aedf2882670db88b4a9353..5757b9b27f1c626cadd9fc0372fa45e013a83daf 100755 (executable)
@@ -392,33 +392,36 @@ class StorePlanService
      *         'without_history' => [...],
      * ]
      */
-    private static function analyzeHistory($salesHistory, $periods)
+    private static function analyzeHistory(array $salesHistory, array $periods)
     {
         $productsWithHistory    = [];
         $productsWithoutHistory = [];
 
-        foreach ($salesHistory as $guid => $monthsData) {
+        foreach ($salesHistory as $guid => $info) {
+            $monthsData    = $info['data'];
+            $metaFields    = [
+                'category'    => $info['category'],
+                'subcategory' => $info['subcategory'],
+                'species'     => $info['species'],
+            ];
             $hasHistoryInAllPeriods = true;
-            $weeklySalesData = [];
+            $weeklySalesData        = [];
 
             foreach ($periods as $periodKey => $periodData) {
                 $weeksCount = count($periodData['weeks']);
 
                 if (!isset($monthsData[$periodKey])) {
                     $hasHistoryInAllPeriods = false;
-                    // Заполняем пустыми значениями столько недель, сколько их есть в периоде.
                     $weekData = array_fill(0, $weeksCount, 0);
                 } else {
-                    $weekData = [];
+                    $weekData    = [];
                     $activeWeeks = 0;
 
-                    for ($weekIndex = 0; $weekIndex < $weeksCount; $weekIndex++) {
-                        $salesCount = isset($monthsData[$periodKey][$weekIndex]) ? $monthsData[$periodKey][$weekIndex] : 0;
-                        $weekData[$weekIndex] = $salesCount;
-                        if ($weekIndex == 4) {
-                            continue; //пропускаем 5 неполную неделю в учете активных продаж
-                        }
-                        if ($salesCount > 0) {
+                    for ($i = 0; $i < $weeksCount; $i++) {
+                        $count = $monthsData[$periodKey][$i] ?? 0;
+                        $weekData[$i] = $count;
+
+                        if ($i < 4 && $count > 0) {
                             $activeWeeks++;
                         }
                     }
@@ -427,18 +430,20 @@ class StorePlanService
                         $hasHistoryInAllPeriods = false;
                     }
                 }
+
                 $weeklySalesData[$periodKey] = $weekData;
             }
 
-            $productData = [
-                'guid'         => $guid,
-                'weekly_sales' => $weeklySalesData,
-            ];
+            $item = array_merge(
+                ['guid' => $guid],
+                $metaFields,
+                ['weekly_sales' => $weeklySalesData]
+            );
 
             if ($hasHistoryInAllPeriods) {
-                $productsWithHistory[] = $productData;
+                $productsWithHistory[] = $item;
             } else {
-                $productsWithoutHistory[] = $productData;
+                $productsWithoutHistory[] = $item;
             }
         }