From 0a3342230d152f1c5c5d18f60a954359d1e7fe77 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Fri, 26 Sep 2025 17:04:52 +0300 Subject: [PATCH] =?utf8?q?=D0=A2=D0=B5=D1=81=D1=82=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/services/AutoPlannogrammaService.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/erp24/services/AutoPlannogrammaService.php b/erp24/services/AutoPlannogrammaService.php index d7f86ceb..16077d7c 100644 --- a/erp24/services/AutoPlannogrammaService.php +++ b/erp24/services/AutoPlannogrammaService.php @@ -1973,7 +1973,7 @@ private function buildCategoryGoals(array $rawGoals, bool $subtractMatrix, int $ } $isGoalExists = isset($goalsMap[$storeId][$cat][$sub][$spec]); $goal = $goalsMap[$storeId][$cat][$sub][$spec] ?? 0; - if ($goal !== 0) { + if ($isGoalExists) { $forecastSum = $goal * $share; } else { $forecastSum = $avgWeightedSumm; @@ -2059,6 +2059,7 @@ private function buildCategoryGoals(array $rawGoals, bool $subtractMatrix, int $ 'product_id' => $item['product_id'], 'forecast_pieces' => (float)$item['forecast_pieces'], 'history_status' => 'With history', + 'is_goal_exists' => $item['is_goal_exists'] ]; } @@ -2132,6 +2133,7 @@ private function buildCategoryGoals(array $rawGoals, bool $subtractMatrix, int $ $pid = $p['product_id']; $forecastPieces = (float)$p['forecast_pieces']; $historyStatus = $p['history_status']; + $goalExistsFlag = $p['is_goal_exists'] ?? 1; $summ = $productSumms[$pid] ?? 0.0; if ($totalSumm > 0) { @@ -2145,6 +2147,7 @@ private function buildCategoryGoals(array $rawGoals, bool $subtractMatrix, int $ 'forecast_pieces' => $forecastPieces, 'share' => $share, 'history_status' => $historyStatus, + 'is_goal_exists' => $goalExistsFlag, ]); } } @@ -2213,9 +2216,15 @@ private function buildCategoryGoals(array $rawGoals, bool $subtractMatrix, int $ ]); $cleanGoal = $goalsMap[$key] ?? 0; - $productSales = $shareItem['share'] * $cleanGoal; + $goalExistsFlag = $shareItem['is_goal_exists']; + if ($goalExistsFlag) { + $productSales = $shareItem['share'] * $cleanGoal; + $productSalesPieces = round($productSales / $price, 2); + } else { + $productSales = $shareItem['forecast_pieces'] * $price; + $productSalesPieces = $shareItem['forecast_pieces']; + } - $productSalesPieces = round($productSales / $price, 2); $result[] = [ 'store_id' => $shareItem['store_id'], @@ -2547,9 +2556,9 @@ private function buildCategoryGoals(array $rawGoals, bool $subtractMatrix, int $ $cleanedSpeciesGoals = $this->subtractSpeciesGoals($goals, [], []); $salesProductForecastShare = $this->calculateProductForecastShare($noHistoryProductData, $historyProductData); - var_dump($salesProductForecastShare); die(); - $productForecastSpecies = $this->calculateProductSalesBySpecies($salesProductForecastShare, $cleanedSpeciesGoals); + $productForecastSpecies = $this->calculateProductSalesBySpecies($salesProductForecastShare, $cleanedSpeciesGoals); + var_dump($productForecastSpecies); die(); $weeklySales = $this->getHistoricalSpeciesShareByWeek($filters['plan_date'], $filters); $weeklySalesForecast = $this->calculateWeeklyProductForecastPieces($productForecastSpecies, $weeklySales, $filters); -- 2.39.5