From: Vladimir Fomichev Date: Wed, 20 Aug 2025 14:50:58 +0000 (+0300) Subject: Добавляем актуальность в расчет X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=ae6faae0f704e6b9d703028584fee2610bb8dfb1;p=erp24_rep%2Fyii-erp24%2F.git Добавляем актуальность в расчет --- diff --git a/erp24/services/AutoPlannogrammaService.php b/erp24/services/AutoPlannogrammaService.php index 1b59010a..8bf20434 100644 --- a/erp24/services/AutoPlannogrammaService.php +++ b/erp24/services/AutoPlannogrammaService.php @@ -1328,10 +1328,22 @@ private function buildCategoryGoals(array $rawGoals, bool $subtractMatrix, int $ public function calculateWeeklyProductForecastPieces( array $productForecastSpecies, - array $weeklySales + array $weeklySales, + array $filters ): array { - + $date = $filters['year'] . '-' . str_pad($filters['month'], 2, '0', STR_PAD_LEFT) . '-01'; + $df = (new \DateTime($date)) + ->setTime(0, 0, 0)->format('Y-m-d H:i:s'); + $dt = (new \DateTime($date)) + ->modify('last day of this month')->setTime(23, 59, 59) + ->format('Y-m-d H:i:s'); + $actualProducts = Products1cNomenclatureActuality::find() + ->select(['guid']) + ->where(['<=', 'date_from', $df]) + ->andWhere(['>=', 'date_to', $dt]) + ->asArray() + ->column(); $forecastMap = []; foreach ($productForecastSpecies as $item) { $sid = $item['store_id']; @@ -1369,7 +1381,9 @@ private function buildCategoryGoals(array $rawGoals, bool $subtractMatrix, int $ foreach ($productsInSpec as $pid => $piecesMon) { $forecastWeekPieces = round($piecesMon * $wShare, 2); - + if (!in_array($pid, $actualProducts)) { + continue; + } $result[] = [ 'week' => $week, 'store_id' => $sid, @@ -2509,7 +2523,7 @@ private function buildCategoryGoals(array $rawGoals, bool $subtractMatrix, int $ $weeklySales = $this->getHistoricalSpeciesShareByWeek($filters['plan_date'], $filters); - $weeklySalesForecast = $this->calculateWeeklyProductForecastPieces($productForecastSpecies, $weeklySales); + $weeklySalesForecast = $this->calculateWeeklyProductForecastPieces($productForecastSpecies, $weeklySales, $filters); return $weeklySalesForecast; } @@ -3253,11 +3267,10 @@ private function buildCategoryGoals(array $rawGoals, bool $subtractMatrix, int $ $baseGroup = $groupsArr[0]; $storeItem = (int)$item['store_id']; $guid = (string)$item['product_guid']; - $group = $baseGroup; if (!in_array($guid, $actualProducts)) { - continue; + continue; } - $group = (string)$item['matrix_group']; + $group = $baseGroup; $type = (string)$item['type']; $forecastValue = (float)$item['week_forecast']; if (isset($salesShares[$storeItem]) && isset($salesShares[$storeItem][$type])) {