From: Vladimir Fomichev Date: Tue, 17 Jun 2025 11:31:59 +0000 (+0300) Subject: Merge branch 'feature_zozirova_erp-360_autoplannogramma_build' into feature_zozirova_... X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=b2499dac3b3adab9a6865d7465a51232e61a637b;p=erp24_rep%2Fyii-erp24%2F.git Merge branch 'feature_zozirova_erp-360_autoplannogramma_build' into feature_zozirova_erp-360_autoplannogramma_build_tooltips # Conflicts: # erp24/services/AutoPlannogrammaService.php --- b2499dac3b3adab9a6865d7465a51232e61a637b diff --cc erp24/services/AutoPlannogrammaService.php index 705ac472,9b3cb761..27c6572d --- a/erp24/services/AutoPlannogrammaService.php +++ b/erp24/services/AutoPlannogrammaService.php @@@ -2839,52 -2848,18 +2848,62 @@@ class AutoPlannogrammaServic ]; } } - return $weeklyForecasts; - } + $grouped = []; + foreach ($weeklyForecasts as $item) { + $storeItem = (int)$item['store_id']; + $guid = (string)$item['product_guid']; + $group = (string)$item['matrix_group']; + $type = (string)$item['type']; + $forecastValue = (float)$item['week_forecast']; + $grouped[$storeItem][$guid][$type][$group] = $forecastValue; + } + + return $grouped; + } + public function getWeeklyProductsWriteoffsForecast($month, $year, $storeId = null, $weekNumber = null) + { + $weeksProductForecast = []; + $filters = []; + + $dateFrom = date("Y-m-d 00:00:00", strtotime(sprintf('%04d-%02d-01', $year, $month))); + $monthYear = date("m-Y", strtotime($dateFrom)); + $filters['store_id'] = $storeId; + $filters['type'] = self::TYPE_WRITE_OFFS; + $filters['plan_date'] = $dateFrom; + + $monthSpeciesGoals = $this->calculateFullGoalChain($filters); + $monthSpeciesGoalsMap = []; + foreach ($monthSpeciesGoals as $monthSpeciesGoal) { + $monthSpeciesGoalsMap[$monthSpeciesGoal['store_id']] + [$monthSpeciesGoal['category']] + [$monthSpeciesGoal['subcategory']] + [$monthSpeciesGoal['species']] = $monthSpeciesGoal['goal']; + } + + $weeksShareResult = $this->getHistoricalWeeklySpeciesShare($monthYear, $filters, null, 'writeOffs'); + $weeksData = $this->calculateWeeklySpeciesGoals($weeksShareResult, $monthSpeciesGoals); + + foreach ($weeksData as $r) { + $forecasts = $this->calculateWeekForecastSpeciesProducts($r['category'], $r['subcategory'], $r['species'], $r['store_id'], $r['weekly_goal']); + + foreach ($forecasts as $forecast) { + $weeksProductForecast[] = [ + 'category' => $forecast['category'] ?? '', + 'subcategory' => $forecast['subcategory'] ?? '', + 'species' => $forecast['species'] ?? '', + 'product_id' => $forecast['product_id'] ?? '', + 'name' => $forecast['name'] ?? '', + 'price' => $forecast['price'] ?? '', + 'goal' => $forecast['goal'] ?? 0, + 'forecast' => $forecast['forecast'] ?? 0, + 'week' => $r['week'], + ]; + } + } + + return $weeksProductForecast; + } + }