From: fomichev Date: Tue, 27 May 2025 07:04:39 +0000 (+0300) Subject: Прогноз товаров с историей X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=a9f0b8c941f035f03550241a28d85eb1f0661bfd;p=erp24_rep%2Fyii-erp24%2F.git Прогноз товаров с историей --- 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