From a9f0b8c941f035f03550241a28d85eb1f0661bfd Mon Sep 17 00:00:00 2001 From: fomichev Date: Tue, 27 May 2025 10:04:39 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D1=80=D0=BE=D0=B3=D0=BD=D0=BE=D0=B7=20?= =?utf8?q?=D1=82=D0=BE=D0=B2=D0=B0=D1=80=D0=BE=D0=B2=20=D1=81=20=D0=B8?= =?utf8?q?=D1=81=D1=82=D0=BE=D1=80=D0=B8=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../AutoPlannogrammaController.php | 31 +++++++- erp24/services/AutoPlannogrammaService.php | 73 +++++++++++++++++++ 2 files changed, 101 insertions(+), 3 deletions(-) diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index 42663b59..a3360580 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -686,7 +686,24 @@ class AutoPlannogrammaController extends BaseController //var_dump($filters); die(); $service = new AutoPlannogrammaService(); $data = $service->calculateSpeciesForecastForProductsWithoutHistory($filters['plan_date'], $filters); - $goals = $service->calculateFullGoalChain($filters); + //$goals = $service->calculateFullGoalChain($filters); + $monthCategoryShare = $service->getMonthCategoryShareOrWriteOff($filters['plan_date'], $filters); + $monthCategoryGoal = $service->getMonthCategoryGoal($monthCategoryShare, $filters['plan_date']); + $monthSubcategoryShare = $service->getMonthSubcategoryShareOrWriteOff($filters['plan_date'], $filters); + $monthSubcategoryGoal = $service->getMonthSubcategoryGoal($monthSubcategoryShare, $monthCategoryGoal); + $monthSpeciesShare = $service->getMonthSpeciesShareOrWriteOff($filters['plan_date'], $filters); + $goals = $service->getMonthSpeciesGoalDirty($monthSpeciesShare, $monthSubcategoryGoal); + + if ($filters['type'] == AutoPlannogrammaService::TYPE_WRITE_OFFS) { + $monthCategoryWriteOffsShare = $service->getMonthCategoryShareOrWriteOff($filters['plan_date'], $filters, $filters['type']); + $monthCategoryWriteOffsGoal = $service->getMonthCategoryGoal($monthCategoryWriteOffsShare, $filters['plan_date'], $filters['type']); + $monthSubcategoryWriteOffsShare = $service->getMonthSubcategoryShareOrWriteOff($filters['plan_date'], $filters, $filters['type']); + $monthSubcategoryWriteOffsGoals = $service->getMonthSubcategoryGoal($monthSubcategoryWriteOffsShare, $monthCategoryWriteOffsGoal, $filters['type']); + $monthSpeciesWriteOffShare = $service->getMonthSpeciesShareOrWriteOff($filters['plan_date'], $filters, $filters['type']); + $goals = $service->getMonthSpeciesGoalDirty($monthSpeciesWriteOffShare, $monthSubcategoryWriteOffsGoals, $filters['type'], $data); + } + + $result = StorePlanService::calculateHistoricalShare( $filters['store_id'], $filters['month'], @@ -709,9 +726,17 @@ class AutoPlannogrammaController extends BaseController $result['with_history'] ); + $productSalesForecast = $service->calculateProductForecastInPieces( + $filters['store_id'], + $filters['month'], + $filters['category'], + $filters['subcategory'], + $filters['species'], + $productSalesShare, + $goals + ); - - var_dump($productSalesShare); die(); + var_dump($productSalesForecast); die(); diff --git a/erp24/services/AutoPlannogrammaService.php b/erp24/services/AutoPlannogrammaService.php index e3bf11c6..5bbd5840 100644 --- a/erp24/services/AutoPlannogrammaService.php +++ b/erp24/services/AutoPlannogrammaService.php @@ -825,4 +825,77 @@ class AutoPlannogrammaService return $result; } + public static function calculateProductForecastInPieces( + int $storeId, + string $month, + string $category, + string $subcategory, + string $species, + array $productSalesShare, + array $speciesGoals + ): 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) { + return []; + } + + $region = CityStoreParams::find() + ->where(['store_id' => $storeId]) + ->select('address_region') + ->scalar(); + + if (!$region) { + $cityId = CityStore::find()->select('city_id')->where(['id' => $storeId])->scalar(); + $region = ($cityId == 1) + ? BouquetComposition::REGION_MSK + : BouquetComposition::REGION_NN; + } + + foreach ($productSalesShare as $productId => $data) { + $share = $data['share'] ?? 0.0; + + if ($share <= 0.0) { + continue; + } + + $priceRecord = PricesDynamic::find() + ->where([ + 'product_id' => $productId, + 'region_id' => $region, + 'active' => 1, + ]) + ->one(); + + if (!$priceRecord || $priceRecord->price <= 0) { + continue; + } + + $forecastSum = $goal * $share; + $forecastCount = $forecastSum / $priceRecord->price; + + $result[] = [ + 'product_id' => $productId, + 'goal_share' => round($forecastSum, 2), + 'price' => $priceRecord->price, + 'forecast_pieces' => round($forecastCount), + ]; + } + + return $result; + } + } \ No newline at end of file -- 2.39.5