]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Тест 2
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 26 Sep 2025 14:04:52 +0000 (17:04 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 26 Sep 2025 14:04:52 +0000 (17:04 +0300)
erp24/services/AutoPlannogrammaService.php

index d7f86cebdca47e10780cda139d18d879cbfed67b..16077d7ca51ed3995d8144b60f49d32b251a23bf 100644 (file)
@@ -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);