]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавляем актуальность в расчет
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 20 Aug 2025 14:50:58 +0000 (17:50 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 20 Aug 2025 14:50:58 +0000 (17:50 +0300)
erp24/services/AutoPlannogrammaService.php

index 1b59010a8dc55ca09c97caec4aac2ef1b95ee819..8bf204345523e1eebc1bf27bfbcf52e7fd0352f9 100644 (file)
@@ -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])) {