From 485e54ecbaa309f8120e27fa279380eb9c209a40 Mon Sep 17 00:00:00 2001 From: fomichev Date: Thu, 22 May 2025 15:43:36 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B8=D0=BC=D0=B5=D0=BD?= =?utf8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE?= =?utf8?q?=D0=B4=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/services/AutoPlannogrammaService.php | 200 ++++++++++----------- 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/erp24/services/AutoPlannogrammaService.php b/erp24/services/AutoPlannogrammaService.php index 7a67d262..73f129aa 100644 --- a/erp24/services/AutoPlannogrammaService.php +++ b/erp24/services/AutoPlannogrammaService.php @@ -351,107 +351,7 @@ var_dump($totals); die(); return $result; } - public function calculateFullGoalChainWeighted(array $filters): array - { - $datePlan = $filters['plan_date']; - $dateFromForCategory = (new \DateTime($datePlan))->modify('-12 months')->format('Y-m-d'); - $dateFrom = (new \DateTime($datePlan))->modify('-3 months')->format('Y-m-d'); - - $monthCategoryShare = $this->getMonthCategoryShareOrWriteOffWeighted($datePlan, $filters, null, $filters['type']); - $monthCategoryGoal = $this->getMonthCategoryGoal($monthCategoryShare, $datePlan, $filters); - $monthSubcategoryShare = $this->getMonthSubcategoryShareOrWriteOffWeighted($datePlan, $filters, null, $filters['type']); - $monthSubcategoryGoal = $this->getMonthSubcategoryGoal($monthSubcategoryShare, $monthCategoryGoal); - - if ($filters['type'] === 'writeOffs') { - $salesSubShare = $this->getMonthSubcategoryShareOrWriteOffWeighted($datePlan, $filters, null, 'sales'); - $salesSubGoal = $this->getMonthSubcategoryGoal($salesSubShare, $monthCategoryGoal); - - $catGoalMap = []; - foreach ($monthCategoryGoal as $row) { - $catGoalMap[$row['category']] = $row['goal']; - } - $salesSubGoalMap = []; - foreach ($salesSubGoal as $row) { - $salesSubGoalMap[$row['category']][$row['subcategory']] = $row['goal']; - } - - - 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 = $this->getMonthSubcategoryGoal($monthSubcategoryShare, $monthCategoryGoal); - } - - $monthSpeciesShare = $this->getMonthSpeciesShareOrWriteOffWeighted($datePlan, $datePlan, $filters, null, $filters['type']); - $monthSpeciesGoal = $this->getMonthSpeciesGoalDirty($monthSpeciesShare, $monthSubcategoryGoal); - if ($filters['type'] === 'writeOffs') { - $salesSpecShare = $this->getMonthSpeciesShareOrWriteOffWeighted($datePlan, $datePlan, $filters, null, 'sales'); - $salesSpecGoal = $this->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 = $this->getMonthSpeciesGoalDirty($monthSpeciesShare, $monthSubcategoryGoal); - } - // var_dump($monthSpeciesGoal); - // die(); - $filtered = array_filter($monthSpeciesGoal, function ($row) use ($filters) { - foreach ($filters as $key => $value) { - if ($value === null || $value === '') { - continue; - } - - if (!array_key_exists($key, $row)) { - continue; - } - - if (is_numeric($row[$key]) && is_numeric($value)) { - if ((float)$row[$key] !== (float)$value) { - return false; - } - } else { - if (stripos((string)$row[$key], (string)$value) === false) { - return false; - } - } - } - return true; - }); - - return array_values($filtered); - } @@ -1145,6 +1045,106 @@ var_dump($totals); die(); } + public function calculateFullGoalChainWeighted(array $filters): array + { + $datePlan = $filters['plan_date']; + $dateFromForCategory = (new \DateTime($datePlan))->modify('-12 months')->format('Y-m-d'); + $dateFrom = (new \DateTime($datePlan))->modify('-3 months')->format('Y-m-d'); + + $monthCategoryShare = $this->getMonthCategoryShareOrWriteOffWeighted($datePlan, $filters, null, $filters['type']); + $monthCategoryGoal = $this->getMonthCategoryGoal($monthCategoryShare, $datePlan, $filters); + $monthSubcategoryShare = $this->getMonthSubcategoryShareOrWriteOffWeighted($datePlan, $filters, null, $filters['type']); + $monthSubcategoryGoal = $this->getMonthSubcategoryGoal($monthSubcategoryShare, $monthCategoryGoal); + + if ($filters['type'] === 'writeOffs') { + $salesSubShare = $this->getMonthSubcategoryShareOrWriteOffWeighted($datePlan, $filters, null, 'sales'); + $salesSubGoal = $this->getMonthSubcategoryGoal($salesSubShare, $monthCategoryGoal); + + $catGoalMap = []; + foreach ($monthCategoryGoal as $row) { + $catGoalMap[$row['category']] = $row['goal']; + } + $salesSubGoalMap = []; + foreach ($salesSubGoal as $row) { + $salesSubGoalMap[$row['category']][$row['subcategory']] = $row['goal']; + } + + + 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 = $this->getMonthSubcategoryGoal($monthSubcategoryShare, $monthCategoryGoal); + } + + $monthSpeciesShare = $this->getMonthSpeciesShareOrWriteOffWeighted($datePlan, $datePlan, $filters, null, $filters['type']); + $monthSpeciesGoal = $this->getMonthSpeciesGoalDirty($monthSpeciesShare, $monthSubcategoryGoal); + if ($filters['type'] === 'writeOffs') { + $salesSpecShare = $this->getMonthSpeciesShareOrWriteOffWeighted($datePlan, $datePlan, $filters, null, 'sales'); + $salesSpecGoal = $this->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 = $this->getMonthSpeciesGoalDirty($monthSpeciesShare, $monthSubcategoryGoal); + } + // var_dump($monthSpeciesGoal); + // die(); + $filtered = array_filter($monthSpeciesGoal, function ($row) use ($filters) { + foreach ($filters as $key => $value) { + if ($value === null || $value === '') { + continue; + } + + if (!array_key_exists($key, $row)) { + continue; + } + + if (is_numeric($row[$key]) && is_numeric($value)) { + if ((float)$row[$key] !== (float)$value) { + return false; + } + } else { + if (stripos((string)$row[$key], (string)$value) === false) { + return false; + } + } + } + return true; + }); + + return array_values($filtered); + } } -- 2.39.5