]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Вычисление цели по виду
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 6 May 2025 09:07:05 +0000 (12:07 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 6 May 2025 09:07:05 +0000 (12:07 +0300)
erp24/controllers/AutoPlannogrammaController.php
erp24/services/AutoPlannogrammaService.php
erp24/views/auto-plannogramma/control-species.php

index 2ba5a77566e2502a46d4a3c17d2e5ef15faa6c62..0e45f48ce67bf0873d23d845b23b0b4d778212bf 100644 (file)
@@ -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,
index 0cf0498f3605bd00c321b2929de980ce978b4d7a..04c22ab2d42fd5fa26e03ffcc2ab25b8af6554db 100644 (file)
@@ -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) {
index f3c2b4ddef2cb798641bc0c8222e2e8183258f51..2ecafb347785119278748129c7fcff1e66cbec61 100644 (file)
@@ -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;
                         <th>Вид товара</th>
                         <th>Сумма</th>
                         <th>Доля недели</th>
+                        <th>Цель недели</th>
                     </tr>
                     </thead>
                     <tbody>
@@ -122,6 +124,14 @@ use yii_app\records\Products1c;
                                     )
                                     : '-' ?>
                             </td>
+                            <td>
+                                <?= isset($weeksGoalResult[$weekNum])
+                                    ? Yii::$app->formatter->asPercent(
+                                        $weeksGoalResult[$weekNum][$row['category']][$row['subcategory']][$row['species']],
+                                        2
+                                    )
+                                    : '-' ?>
+                            </td>
                         </tr>
                     <?php endforeach; ?>
                     </tbody>