From: fomichev Date: Tue, 13 May 2025 10:04:36 +0000 (+0300) Subject: Вывод доп данных X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=8b6916091d17ea1dd0fa197db6fb186f1e35b892;p=erp24_rep%2Fyii-erp24%2F.git Вывод доп данных --- diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index ffd94059..13a38e85 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -238,7 +238,7 @@ class AutoPlannogrammaController extends BaseController $weeksData = []; $weeksShareResult = []; $weeksGoalResult = []; - + $monthCategoryShareResult = []; if ($model->load(Yii::$app->request->post()) && $model->validate()) { $filters = []; @@ -264,20 +264,7 @@ class AutoPlannogrammaController extends BaseController ); } - $monthResult = $service->getMonthSpeciesShareOrWriteOffDate( - $dateFrom, - $dateTo, - $filters, - null, - $model->type - ); - $speciesMonthTotals = []; - foreach ($monthResult as $monthRow) { - $speciesMonthTotals[$monthRow['store_id']] - [$monthRow['category']] - [$monthRow['subcategory']] - [$monthRow['species']] = $monthRow['total_sum'] ; - } + $monthSpeciesGoals = $service->calculateFullGoalChain($filters); $monthSpeciesGoalsMap = []; @@ -285,70 +272,92 @@ class AutoPlannogrammaController extends BaseController $monthSpeciesGoalsMap[$monthSpeciesGoal['store_id']] [$monthSpeciesGoal['category']] [$monthSpeciesGoal['subcategory']] - [$monthSpeciesGoal['species']] = $monthSpeciesGoal['goal'] ; // переименовать + [$monthSpeciesGoal['species']] = $monthSpeciesGoal['goal'] ; } - foreach (range(1, 5) as $ind) { - $weekStart = date("Y-m-d 00:00:00", strtotime("+" . (($ind - 1) * 7) . ' days', strtotime($dateFrom))); - $weekEnd = date("Y-m-d 23:59:59", strtotime("+" . ($ind * 7 - 1) . ' days', strtotime($dateFrom))); - if ($weekEnd > $dateTo) { - $weekEnd = $dateTo; + + + $weeksShareResult = $service->getHistoricalWeeklySpeciesShare($model->month, $filters, null, 'writeOffs'); + $weeksData = $service->calculateWeeklySpeciesGoals($weeksShareResult['weeksData'], $monthSpeciesGoals) ; + + $datePlan = $filters['plan_date']; + $monthCategoryShare = $service->getMonthCategoryShareOrWriteOffWeighted($datePlan, $filters, null, $filters['type']); + $monthCategoryGoal = $service->getMonthCategoryGoal($monthCategoryShare, $datePlan, $filters); + foreach ($monthCategoryShare as $sid => $cats) { + foreach($cats as $cat) { + $monthCategoryShareResult[$sid][$cat['category']]['total_sum_cat'] = $cat['total_sum_cat']; + $monthCategoryShareResult[$sid][$cat['category']]['share_of_total'] = $cat['share_of_total']; } - if ($weekStart > $dateTo) { - continue; + + } + //var_dump($monthCategoryShareResult); die(); + $monthSubcategoryShare = $service->getMonthSubcategoryShareOrWriteOffWeighted($datePlan, $filters, null, $filters['type']); + $monthSubcategoryGoal = $service->getMonthSubcategoryGoal($monthSubcategoryShare, $monthCategoryGoal); + + if ($filters['type'] === 'writeOffs') { + $salesSubShare = $service->getMonthSubcategoryShareOrWriteOffWeighted($datePlan, $filters, null, 'sales'); + $salesSubGoal = $service->getMonthSubcategoryGoal($salesSubShare, $monthCategoryGoal); + + $catGoalMap = []; + foreach ($monthCategoryGoal as $row) { + $catGoalMap[$row['category']] = $row['goal']; } - $weekResult = $service->getMonthSpeciesShareOrWriteOffDate( - $weekStart, - $weekEnd, - $filters, - null, - $model->type - ); - $weeksData[$ind] = $weekResult; - if (!$weekResult) { - continue; + $salesSubGoalMap = []; + foreach ($salesSubGoal as $row) { + $salesSubGoalMap[$row['category']][$row['subcategory']] = $row['goal']; } - $weeksShareResult[$ind] = []; - $weeksGoalResult[$ind] = []; - foreach ($weekResult as $weekRow) { - $monthSum = $speciesMonthTotals - [$weekRow['store_id']] - [$weekRow['category']] - [$weekRow['subcategory']] - [$weekRow['species']] ?? null; - - $monthGoal = $monthSpeciesGoalsMap - [$weekRow['store_id']] - [$weekRow['category']] - [$weekRow['subcategory']] - [$weekRow['species']] ?? null; - - - if ($monthSum) { - $weeksShareResult[$ind] - [$weekRow['category']] - [$weekRow['subcategory']] - [$weekRow['species']] = $weekRow['total_sum'] / $monthSum; - } - if ($monthSum && $monthGoal) { - $weeksGoalResult[$ind] - [$weekRow['category']] - [$weekRow['subcategory']] - [$weekRow['species']] = ($weekRow['total_sum'] / $monthSum) * $monthGoal; - } + foreach ($monthSubcategoryShare as &$row) { + $cat = $row['category']; + $sub = $row['subcategory']; - } + $writeShare = $row['percent_of_month']; + $writeGoal = ($catGoalMap[$cat] ?? 0) * $writeShare; + $saleGoal = $salesSubGoalMap[$cat][$sub] ?? 0; + + if ($saleGoal > 0 && $writeGoal > 0.1 * $saleGoal) { + $row['share'] = 0.1; + } + } + unset($row); + $monthSubcategoryGoal = $service->getMonthSubcategoryGoal($monthSubcategoryShare, $monthCategoryGoal); } - $weeksShareResult = $service->getHistoricalWeeklySpeciesShare($model->month, $filters, null, 'writeOffs'); - $weeksData = $service->calculateWeeklySpeciesGoals($weeksShareResult['weeksData'], $monthSpeciesGoals) ; + $monthSpeciesShare = $service->getMonthSpeciesShareOrWriteOffWeighted($datePlan, $datePlan, $filters, null, $filters['type']); + $monthSpeciesGoal = $service->getMonthSpeciesGoalDirty($monthSpeciesShare, $monthSubcategoryGoal); + if ($filters['type'] === 'writeOffs') { + $salesSpecShare = $service->getMonthSpeciesShareOrWriteOffWeighted($datePlan, $datePlan, $filters, null, 'sales'); + $salesSpecGoal = $service->getMonthSpeciesGoalDirty($salesSpecShare, $monthSubcategoryGoal); + $subGoalMap = []; + foreach ($monthSubcategoryGoal as $row) { + $subGoalMap[$row['category']][$row['subcategory']] = $row['goal']; + } + $salesSpecGoalMap = []; + foreach ($salesSpecGoal as $row) { + $salesSpecGoalMap[$row['category']][$row['subcategory']][$row['species']] = $row['goal']; + } + foreach ($monthSpeciesShare as &$row) { + $cat = $row['category']; + $sub = $row['subcategory']; + $spec = $row['species']; + $writeShare = $row['percent_of_month']; + $writeGoal = ($subGoalMap[$cat][$sub] ?? 0) * $writeShare; + $saleGoal = $salesSpecGoalMap[$cat][$sub][$spec] ?? 0; + + if ($saleGoal > 0 && $writeGoal > 0.1 * $saleGoal) { + $row['share'] = 0.1; + } + } + unset($row); + + $monthSpeciesGoal = $service->getMonthSpeciesGoalDirty($monthSpeciesShare, $monthSubcategoryGoal); + } @@ -361,7 +370,7 @@ class AutoPlannogrammaController extends BaseController 'model' => $model, 'result' => $monthResult, 'weeksData' => $weeksData, - //'monthGoal' => $monthSpeciesGoalsMap, + 'monthCategoryShare' => $monthCategoryShareResult, // 'weeksGoalResult' => $weeksGoalResult, 'totals' => $totals, 'storeList' => $storeList, diff --git a/erp24/services/AutoPlannogrammaService.php b/erp24/services/AutoPlannogrammaService.php index cbf87ff6..310deaa0 100644 --- a/erp24/services/AutoPlannogrammaService.php +++ b/erp24/services/AutoPlannogrammaService.php @@ -177,9 +177,7 @@ var_dump($totals); die(); $start = date('Y-m-01 00:00:00', strtotime("-{$offsetMonths} months", $baseMonth)); $end = date('Y-m-t 23:59:59', strtotime($start)); - $monthStoreTotals = $this->getStoreTotals( - $storeIds, $start, $productFilter, $type, $end - ); + $q = (new Query()) ->select([ @@ -223,28 +221,33 @@ var_dump($totals); die(); $sum = (float)$r['month_sum'] * $w; $weightedSums[$sid][$cat] = ($weightedSums[$sid][$cat] ?? 0) + $sum; } - foreach ($monthStoreTotals as $sid => $monthStoreTotal) { - $monthStoreTotalsWeighted[$sid] = ($monthStoreTotalsWeighted[$sid] ?? 0) + ($monthStoreTotal * $w); - - } } $result = []; foreach ($weightedSums as $storeId => $cats) { $grand = array_sum($cats) ?: 1; + + $unlabeledSum = $cats[''] ?? 0; + $labeledCount = count($cats) - (isset($cats['']) ? 1 : 0); + + $distribution = $labeledCount > 0 ? $unlabeledSum / $labeledCount : 0; + foreach ($cats as $category => $weightedSum) { + if ($category === '') { + continue; + } + + $adjustedSum = $weightedSum + $distribution; + $result[$storeId][] = [ 'category' => $category, 'total_sum_cat' => $weightedSum, - 'total_sum_store' => $monthStoreTotalsWeighted[$storeId], - 'query_total_sum_store' => $grand, - 'share_of_total' => round($weightedSum / $grand, 4), - 'share_of_total_control' => round($weightedSum / $monthStoreTotalsWeighted[$storeId], 4), + 'total_sum_store' => $grand, + 'share_of_total' => round($adjustedSum / $grand, 4), ]; } } - return $result; } diff --git a/erp24/views/auto-plannogramma/control-species.php b/erp24/views/auto-plannogramma/control-species.php index a92d97b2..50acfe62 100644 --- a/erp24/views/auto-plannogramma/control-species.php +++ b/erp24/views/auto-plannogramma/control-species.php @@ -81,7 +81,7 @@ use yii_app\records\Products1c; - + formatter->asPercent($monthCategoryShare[$row['category']]['share_of_total'], 2) ?> formatter->asDecimal($row['total_sum'], 2) ?> @@ -108,7 +108,7 @@ use yii_app\records\Products1c; - + storeId][$r['category']]['total_sum_cat'] ?> formatter->asPercent($monthCategoryShare[$model->storeId][$r['category']]['share_of_total'], 2) ?> неделя - начало