From: fomichev Date: Fri, 30 May 2025 15:19:52 +0000 (+0300) Subject: Правки по товарам c истории X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=0289425c15c104e96fa486969a0037707b75b437;p=erp24_rep%2Fyii-erp24%2F.git Правки по товарам c истории --- diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index 991e6ca5..a1d024d1 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -906,14 +906,14 @@ class AutoPlannogrammaController extends BaseController $productSalesForecast = $service->calculateProductForecastInPiecesProductsWithHistory( $filters['store_id'], $filters['month'], - $filters['category'], - $filters['subcategory'], - $filters['species'], $productSalesShare, - $goals + $goals, + $filters['subcategory'], + $filters['category'], + $filters['species'] ); - $matrixForecast = MatrixBouquetForecast::find() +/* $matrixForecast = MatrixBouquetForecast::find() ->where(['year' => $filters['year'], 'month' => $filters['month']]) ->asArray() ->all(); @@ -936,14 +936,14 @@ class AutoPlannogrammaController extends BaseController } } - $cleanedSpeciesGoals = $service->subtractSpeciesGoals($goals, $bouquetSpeciesForecast, $noHistoryProductData); + $cleanedSpeciesGoals = $service->subtractSpeciesGoals($goals, $bouquetSpeciesForecast, $noHistoryProductData);*/ $salesProductForecastShare = $service->calculateProductForecastShare($noHistoryProductData, $productSalesForecast); // $productForecastSpecies = $service->calculateProductSalesBySpecies($salesProductForecastShare, $cleanedSpeciesGoals); - //var_dump($salesProductForecastShare); die(); + var_dump($productSalesForecast); die(); @@ -1037,11 +1037,11 @@ class AutoPlannogrammaController extends BaseController $productSalesForecast = $service->calculateProductForecastInPiecesProductsWithHistory( $filters['store_id'], $filters['month'], - $filters['category'], - $filters['subcategory'], - $filters['species'], $productSalesShare, - $goals + $goals, + $filters['subcategory'], + $filters['category'], + $filters['species'] ); $matrixForecast = MatrixBouquetForecast::find() diff --git a/erp24/services/AutoPlannogrammaService.php b/erp24/services/AutoPlannogrammaService.php index dec3bf92..c27a7a6c 100644 --- a/erp24/services/AutoPlannogrammaService.php +++ b/erp24/services/AutoPlannogrammaService.php @@ -1471,38 +1471,26 @@ var_dump($yearData); die(); return $result; } - public static function calculateProductForecastInPiecesProductsWithHistory( + public function calculateProductForecastInPiecesProductsWithHistory( int $storeId, string $month, - string $category, - string $subcategory, - string $species, array $productSalesShare, - array $speciesGoals + array $speciesGoals, + string $subcategory = null, + string $category = null, + string $species = null ): array { $result = []; - $goal = null; - foreach ($speciesGoals as $item) { - if ( - $item['store_id'] == $storeId && - $item['category'] == $category && - $item['subcategory'] == $subcategory && - $item['species'] == $species - ) { - $goal = $item['goal']; - break; - } - } - - if ($goal === null) { + if (empty($speciesGoals)) { return []; } + $goalsMap = $this->mapGoalsBySpecies($speciesGoals); + $region = CityStoreParams::find() ->where(['store_id' => $storeId]) - ->select('address_region') - ->scalar(); + ->one()->address_region ?? null; if (!$region) { $cityId = CityStore::find()->select('city_id')->where(['id' => $storeId])->scalar(); @@ -1529,7 +1517,7 @@ var_dump($yearData); die(); if (!$priceRecord || $priceRecord->price <= 0) { continue; } - + $goal = $goalsMap[$data['store_id']][$data['category']][$data['subcategory']][$data['species']]; $forecastSum = $goal * $share; $forecastCount = $forecastSum / $priceRecord->price; @@ -1540,10 +1528,10 @@ var_dump($yearData); die(); 'goal_share' => round($forecastSum, 2), 'price' => $priceRecord->price, 'forecast_pieces' => round($forecastCount), - 'store_id' => $storeId, - 'category' => $category, - 'subcategory' => $subcategory, - 'species' => $species, + 'store_id' => $data['store_id'], + 'category' => $data['category'], + 'subcategory' => $data['subcategory'], + 'species' => $data['species'], ]; } diff --git a/erp24/services/StorePlanService.php b/erp24/services/StorePlanService.php index b99448cd..6afc6054 100755 --- a/erp24/services/StorePlanService.php +++ b/erp24/services/StorePlanService.php @@ -989,7 +989,7 @@ class StorePlanService $productsData = []; $globalTotal = 0; - + // var_dump($productsWithHistory); die(); foreach ($productsWithHistory as $product) { $guid = $product['guid']; $result = self::processProductWithHistory($storeId, $product, $weightedPeriods); @@ -1045,6 +1045,10 @@ class StorePlanService } return [ + 'store_id' => $storeId, + 'category' => $product['category'], + 'subcategory' => $product['subcategory'], + 'species' => $product['species'], 'monthlySales' => $monthlySales, 'monthlyWeighted' => $monthlyWeighted, 'weightedSum' => $weightedSum,