]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавление проверки на 10%
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 12 May 2025 15:20:46 +0000 (18:20 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 12 May 2025 15:20:46 +0000 (18:20 +0300)
erp24/services/AutoPlannogrammaService.php

index 5926c844c2516db356a8c5ff0eae6e4e9562df8b..5eeba658d00ecb7e41beda88468710bbd28c950f 100644 (file)
@@ -567,17 +567,69 @@ var_dump($totals); die();
         $monthSubcategoryShare = $this->getMonthSubcategoryShareOrWriteOffWeighted($datePlan, $filters, null, $filters['type']);
         $monthSubcategoryGoal = $this->getMonthSubcategoryGoal($monthSubcategoryShare, $monthCategoryGoal);
 
-        if ($filters['type'] == 'writeOffs') {
-            $monthCategorySalesShare = $this->getMonthCategoryShareOrWriteOffWeighted($datePlan, $filters, null, 'sales');
-            $monthCategorySalesGoal = $this->getMonthCategoryGoal($monthCategorySalesShare, $datePlan, $filters);
-            $monthSubcategorySalesShare = $this->getMonthSubcategoryShareOrWriteOffWeighted($datePlan, $filters, null, 'sales');
-            $monthSubcategorySalesGoal = $this->getMonthSubcategoryGoal($monthSubcategorySalesShare, $monthCategorySalesGoal);
+        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['share'];
 
+                $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['share'];
+                $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) {