From a537cfa29fd89ae8354a828e618a1c196166966e Mon Sep 17 00:00:00 2001 From: fomichev Date: Tue, 6 May 2025 12:07:05 +0300 Subject: [PATCH] =?utf8?q?=D0=92=D1=8B=D1=87=D0=B8=D1=81=D0=BB=D0=B5=D0=BD?= =?utf8?q?=D0=B8=D0=B5=20=D1=86=D0=B5=D0=BB=D0=B8=20=D0=BF=D0=BE=20=D0=B2?= =?utf8?q?=D0=B8=D0=B4=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../AutoPlannogrammaController.php | 43 ++++++++++++++++--- erp24/services/AutoPlannogrammaService.php | 5 ++- .../auto-plannogramma/control-species.php | 10 +++++ 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index 2ba5a775..0e45f48c 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -237,18 +237,21 @@ class AutoPlannogrammaController extends BaseController $totals = []; $weeksData = []; $weeksShareResult = []; + $weeksGoalResult = []; if ($model->load(Yii::$app->request->post()) && $model->validate()) { $filters = []; - if ($model->storeId) { - $filters['store_id'] = $model->storeId; - } - list($m, $y) = explode('-', $model->month); $dateFrom = date("Y-m-d 00:00:00", strtotime(sprintf('%04d-%02d-01', $y, $m))); $dateTo = date("Y-m-t 23:59:59", strtotime($dateFrom)); + if ($model->storeId) { + $filters['store_id'] = $model->storeId; + $filters['type'] = $model->type; + $filters['plan_date'] = $dateFrom; + } + $service = new AutoPlannogrammaService(); if ($model->storeId) { @@ -276,6 +279,15 @@ class AutoPlannogrammaController extends BaseController [$monthRow['species']] = $monthRow['total_sum'] ; } + $monthSpeciesGoals = $service->calculateFullGoalChain($filters); + $monthSpeciesGoalsMap = []; + foreach ($monthSpeciesGoals as $monthSpeciesGoal) { + $monthSpeciesGoalsMap[$monthSpeciesGoal['store_id']] + [$monthSpeciesGoal['category']] + [$monthSpeciesGoal['subcategory']] + [$monthSpeciesGoal['product_name']] = $monthSpeciesGoal['goal'] ; // переименовать + } + foreach (range(1, 5) as $ind) { $weekStart = date("Y-m-d 00:00:00", strtotime("+" . (($ind - 1) * 7) . ' days', strtotime($dateFrom))); @@ -297,7 +309,9 @@ class AutoPlannogrammaController extends BaseController if (!$weekResult) { continue; } + $weeksShareResult[$ind] = []; + $weeksGoalResult[$ind] = []; foreach ($weekResult as $weekRow) { $monthSum = $speciesMonthTotals [$weekRow['store_id']] @@ -305,6 +319,13 @@ class AutoPlannogrammaController extends BaseController [$weekRow['subcategory']] [$weekRow['species']] ?? null; + $monthGoal = $monthSpeciesGoalsMap + [$weekRow['store_id']] + [$weekRow['category']] + [$weekRow['subcategory']] + [$weekRow['species']] ?? null; + + if ($monthSum) { $weeksShareResult[$ind] [$weekRow['category']] @@ -312,6 +333,13 @@ class AutoPlannogrammaController extends BaseController [$weekRow['species']] = $weekRow['total_sum'] / $monthSum; } + if ($monthSum && $monthGoal) { + $weeksGoalResult[$ind] + [$weekRow['category']] + [$weekRow['subcategory']] + [$weekRow['species']] = ($weekRow['total_sum'] / $monthSum) * $monthGoal; + } + } } @@ -320,13 +348,18 @@ class AutoPlannogrammaController extends BaseController $weeksData = $weeksShareResult['weeksData']; $weeksShareResult = $weeksShareResult['weeksShare']; - } + + + + } +var_dump($monthSpeciesGoalsMap); die(); return $this->render('control-species', [ 'model' => $model, 'result' => $monthResult, 'weeksData' => $weeksData, 'weeksShareResult' => $weeksShareResult, + 'weeksGoalResult' => $weeksGoalResult, 'totals' => $totals, 'storeList' => $storeList, 'monthsList' => $monthsList, diff --git a/erp24/services/AutoPlannogrammaService.php b/erp24/services/AutoPlannogrammaService.php index 0cf0498f..04c22ab2 100644 --- a/erp24/services/AutoPlannogrammaService.php +++ b/erp24/services/AutoPlannogrammaService.php @@ -351,11 +351,12 @@ class AutoPlannogrammaService $monthCategoryShare = $this->getMonthCategoryShareOrWriteOff($dateFromForCategory, $filters); $monthCategoryGoal = $this->getMonthCategoryGoal($monthCategoryShare, $datePlan, $filters); - + var_dump($monthCategoryShare); die(); $monthSubcategoryShare = $this->getMonthSubcategoryShareOrWriteOff($dateFrom, $filters); $monthSubcategoryGoal = $this->getMonthSubcategoryGoal($monthSubcategoryShare, $monthCategoryGoal); - $monthSpeciesShare = $this->getMonthSpeciesShareOrWriteOff($dateFrom, $filters); + //$monthSpeciesShare = $this->getMonthSpeciesShareOrWriteOff($dateFrom, $filters); + $monthSpeciesShare = $this->getMonthSpeciesShareOrWriteOffDate($dateFrom, $datePlan, $filters, null, $filters['type']); $monthSpeciesGoal = $this->getMonthSpeciesGoalDirty($monthSpeciesShare, $monthSubcategoryGoal); $filtered = array_filter($monthSpeciesGoal, function ($row) use ($filters) { diff --git a/erp24/views/auto-plannogramma/control-species.php b/erp24/views/auto-plannogramma/control-species.php index f3c2b4dd..2ecafb34 100644 --- a/erp24/views/auto-plannogramma/control-species.php +++ b/erp24/views/auto-plannogramma/control-species.php @@ -15,6 +15,7 @@ use yii_app\records\Products1c; /* @var $totals array */ /* @var $weeksData array */ /* @var $weeksShareResult array */ +/* @var $weeksGoalResult array */ ?> @@ -105,6 +106,7 @@ use yii_app\records\Products1c; Вид товара Сумма Доля недели + Цель недели @@ -122,6 +124,14 @@ use yii_app\records\Products1c; ) : '-' ?> + + formatter->asPercent( + $weeksGoalResult[$weekNum][$row['category']][$row['subcategory']][$row['species']], + 2 + ) + : '-' ?> + -- 2.39.5