From f522dc6779a6ab5922058a1d620b672c615c258b Mon Sep 17 00:00:00 2001 From: fomichev Date: Thu, 5 Jun 2025 17:12:39 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF?= =?utf8?q?=D0=BE=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81?= =?utf8?q?=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../AutoPlannogrammaController.php | 140 ++++++++++++++++ erp24/views/auto-plannogramma/test.php | 153 ++++++++++++++++++ 2 files changed, 293 insertions(+) create mode 100644 erp24/views/auto-plannogramma/test.php diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index de5b59e3..95389b6c 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -1617,4 +1617,144 @@ class AutoPlannogrammaController extends BaseController } + public function actionTest() + { + $request = Yii::$app->request; + + $filters = [ + 'category' => 'Срезка', + 'subcategory' => 'Розы' ?? null, + 'species' => 'Роза' ?? null, + 'store_id' => 2 ?? [], + 'year' => 2025, + 'month' => 5, + 'type' => 'sales', + ]; + + $stores = ArrayHelper::map( + CityStore::findAll(['visible' => CityStore::IS_VISIBLE]), + 'id', + 'name' + ); + // var_dump($stores);die(); + $dataProvider = new ArrayDataProvider([ + 'allModels' => [], + 'pagination' => ['pageSize' => 100], + ]); + $flatData =[]; + $bouquetSpeciesForecast = []; + // Обработка даты на год и месяц + if (!empty($filters['year']) && !empty($filters['month'])) { + $filters['plan_date'] = $filters['year'] . '-' . str_pad($filters['month'], 2, '0', STR_PAD_LEFT) . '-01'; + // var_dump( $filters['plan_date']); die(); + $service = new AutoPlannogrammaService(); +//$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'], + $filters['year'], + $filters['category'], + $filters['subcategory'], + $filters['species'] + ); + + $noHistoryProductData = $service->calculateSpeciesForecastForProductsWithoutHistory($filters['plan_date'], $filters); + + $productSalesShare = StorePlanService::calculateProductSalesShareProductsWithHistory( + $filters['store_id'], + $filters['month'], + $result['with_history'] + ); + + $productSalesForecast = $service->calculateProductForecastInPiecesProductsWithHistory( + $filters['store_id'], + $filters['month'], + $productSalesShare, + $goals, + $filters['subcategory'], + $filters['category'], + $filters['species'] + ); + + $matrixForecast = MatrixBouquetForecast::find() + ->where(['year' => $filters['year'], 'month' => $filters['month']]) + ->asArray() + ->all(); + $matrixGroups = array_unique(ArrayHelper::getColumn($matrixForecast, 'group')); + $bouquetForecast = StorePlanService::getBouquetSpiecesMonthGoalFromForecast($filters['month'], $filters['year'], $filters['store_id'], $matrixGroups); + $speciesData = $bouquetForecast['final']; + foreach ($speciesData as $store_id => $categoryData) { + foreach ($categoryData as $category => $subcategoryData) { + foreach ($subcategoryData as $subcategory => $species) { + foreach ($species as $speciesInd => $row) { + $bouquetSpeciesForecast[] = [ + 'category' => $category, + 'subcategory' => $subcategory, + 'store_id' => $store_id, + 'species' => $speciesInd, + 'goal' => $row + ]; + } + } + } + + } + $cleanedSpeciesGoals = $service->subtractSpeciesGoals($goals, $bouquetSpeciesForecast, $noHistoryProductData); + + + $salesProductForecastShare = $service->calculateProductForecastShare($noHistoryProductData, $productSalesForecast); + + $productForecastSpecies = $service->calculateProductSalesBySpecies($salesProductForecastShare, $cleanedSpeciesGoals); + + + $weeklySales = $service->getHistoricalSpeciesShareByWeek($filters['plan_date'], $filters); + + $weeklySalesForecast = $service->calculateWeeklyProductForecastPieces($productForecastSpecies, $weeklySales); + + + + + $flatData = array_filter($weeklySalesForecast, function ($row) use ($filters) { + foreach ($filters as $key => $value) { + if (empty($value)) continue; + if (!isset($row[$key])) continue; + + if (stripos((string)$row[$key], (string)$value) === false) { + return false; + } + } + return true; + }); + + $dataProvider = new ArrayDataProvider([ + 'allModels' => $flatData, + 'pagination' => ['pageSize' => 100], + ]); + } + return $this->render('test', [ + 'dataProvider' => $dataProvider, + 'data' => $flatData, + 'filters' => $filters, + 'stores' => $stores + ]); + } + + } diff --git a/erp24/views/auto-plannogramma/test.php b/erp24/views/auto-plannogramma/test.php new file mode 100644 index 00000000..e37d7713 --- /dev/null +++ b/erp24/views/auto-plannogramma/test.php @@ -0,0 +1,153 @@ + name */ + +// Группируем данные: category > subcategory > species > product_id +$grouped = []; +foreach ($data as $row) { + $cat = $row['category']; + $sub = $row['subcategory']; + $sp = $row['species']; + $pid = $row['product_id']; + $sid = $row['store_id']; + + $grouped[$cat][$sub][$sp][$pid]['values'][$sid] = $row['forecast_week_pieces']; + $grouped[$cat][$sub][$sp][$pid]['product_id'] = $pid; +} + +$storeHasData = []; +foreach ($grouped as $cat => $subcats) { + foreach ($subcats as $sub => $species) { + foreach ($species as $sp => $products) { + foreach ($products as $p) { + foreach ($p['values'] as $storeId => $v) { + $storeHasData[$storeId] = true; + } + } + } + } +} +?> + +
+

Автопланограмма

+ + + + +
+
+
+ $storeName): ?> + +
+ + + $subcategories): ?> +
▶
+ $__) echo '
'; ?> + + $speciesList): ?> + + $__) echo '
'; ?> + + $products): ?> + + $__) echo '
'; ?> + + $info): ?> + + $storeName): ?> + + + + + + + + +
+
+
+ + + + -- 2.39.5