From 55ec011ae487567309e610a2956006f4fdacfe6a Mon Sep 17 00:00:00 2001 From: fomichev Date: Thu, 29 May 2025 12:50:35 +0300 Subject: [PATCH] =?utf8?q?=D0=9C=D0=BE=D0=B4=D0=B8=D1=84=D0=B8=D0=BA=D0=B0?= =?utf8?q?=D1=86=D0=B8=D1=8F=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20anal?= =?utf8?q?yzeHistory?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/services/StorePlanService.php | 41 ++++++++++++++++------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/erp24/services/StorePlanService.php b/erp24/services/StorePlanService.php index a1f346f5..5757b9b2 100755 --- a/erp24/services/StorePlanService.php +++ b/erp24/services/StorePlanService.php @@ -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; } } -- 2.39.5