From: fomichev Date: Thu, 29 May 2025 09:50:35 +0000 (+0300) Subject: Модификация метода analyzeHistory X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=55ec011ae487567309e610a2956006f4fdacfe6a;p=erp24_rep%2Fyii-erp24%2F.git Модификация метода analyzeHistory --- 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; } }