]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Вывод 9 шага
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 21 May 2025 09:24:20 +0000 (12:24 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 21 May 2025 09:24:20 +0000 (12:24 +0300)
erp24/controllers/AutoPlannogrammaController.php
erp24/services/AutoPlannogrammaService.php
erp24/services/StorePlanService.php
erp24/views/auto-plannogramma/8.php
erp24/views/auto-plannogramma/9.php

index e6410cdb1aaaae2750e493a1ef83dd2476bbdb17..48ecc5eb2200874b7143deefed8236aa4753ce00 100644 (file)
@@ -728,9 +728,9 @@ class AutoPlannogrammaController extends BaseController
             }
             //var_dump($bouquetSpeciesForecast); die();
             $noHistoryProductData = $service->calculateSpeciesForecastForProductsWithoutHistory($filters['plan_date'], $filters);
-            var_dump($noHistoryProductData); die();
-            $cleanedSpeciesGoals = $service->subtractSpeciesGoals($data, $bouquetSpeciesForecast, $noHistoryProductData);
 
+            $cleanedSpeciesGoals = $service->subtractSpeciesGoals($data, $bouquetSpeciesForecast, $noHistoryProductData);
+            //var_dump($cleanedSpeciesGoals); die();
 
             $flatData = array_filter($cleanedSpeciesGoals, function ($row) use ($filters) {
                 foreach ($filters as $key => $value) {
index e41516a55a936caba330782319a9a43d85fd7777..38bc39d2213dfc82612f67a384d50161e375f2a3 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace yii_app\services;
 
+use Yii;
 use yii\db\Expression;
 use yii\db\Query;
 use yii\helpers\ArrayHelper;
@@ -565,6 +566,7 @@ class AutoPlannogrammaService
      */
     public function calculateSpeciesForecastForProductsWithoutHistory($dateFrom, $filters): array
     {
+        $t0 = hrtime(true);
         // Получение ID видимых магазинов
         $storeIds = array_map(fn($store) => $store->id, $this->getVisibleStores());
 
@@ -580,7 +582,10 @@ class AutoPlannogrammaService
         $year = $date->format('Y');
 
         $result = [];
+        $initTime = (hrtime(true) - $t0) / 1e6; // миллисекунды
+        Yii::warning( "Init (getVisibleStores + filters): {$initTime} ms\n");
         foreach ($storeIds as $storeId) {
+            $t1 = hrtime(true);
             $histResult = StorePlanService::calculateHistoricalShare(
                 $storeId,
                 $month,
@@ -589,34 +594,41 @@ class AutoPlannogrammaService
                 $subcategory,
                 $species
             );
+            $dur = (hrtime(true) - $t1) / 1e6;
+            Yii::warning( "calculateHistoricalShare for store {$storeId}: {$dur} ms\n");
 
             $productsWithoutHistory = $histResult['without_history'] ?? [];
-
             if (empty($productsWithoutHistory)) {
                 continue;
             }
 
+            // ——————— WEIGHTED SALES ————————
+            $t2 = hrtime(true);
             $weightedResults = StorePlanService::calculateWeightedSalesForProductsWithoutHistory(
-                $storeId,
-                $month,
-                $year,
-                $productsWithoutHistory
+                $storeId, $month, $year, $productsWithoutHistory
             );
-
+            $dur = (hrtime(true) - $t2) / 1e6;
+            Yii::warning("calculateWeightedSalesForProductsWithoutHistory for store {$storeId}: {$dur} ms\n");
 
             if (empty($weightedResults)) {
                 continue;
             }
 
+            // ——————— COST CALCULATION ————————
+            $t3 = hrtime(true);
             $costs = StorePlanService::calculateCostForProductsWithoutHistory(
                 $storeId, $month, $year, $weightedResults
             );
+            $dur = (hrtime(true) - $t3) / 1e6;
+            Yii::warning( "calculateCostForProductsWithoutHistory for store {$storeId}: {$dur} ms\n");
 
             if (!empty($costs)) {
                 $result = array_merge($result, $costs);
             }
         }
 
+        $totalTime = (hrtime(true) - $t0) / 1e6;
+        Yii::warning( "Total calculateSpeciesForecastForProductsWithoutHistory: {$totalTime} ms\n");
 
         return $result;
     }
@@ -629,8 +641,8 @@ class AutoPlannogrammaService
         return $mapped;
     }
 
-    public function subtractSpeciesGoals(array $data, array $forecast, array $noHistory): array {
-        $forecastMap = $this->mapGoalsBySpecies($forecast);
+    public function subtractSpeciesGoals(array $data, array $bouquetForecast, array $noHistory): array {
+        $bouquetForecastMap = $this->mapGoalsBySpecies($bouquetForecast);
         $noHistoryMap = $this->mapGoalsBySpecies($noHistory);
         $result = [];
 
@@ -641,10 +653,10 @@ class AutoPlannogrammaService
             $species = $row['species'];
             $originalGoal = $row['goal'];
 
-            $forecastGoal = $forecastMap[$storeId][$category][$subcategory][$species] ?? 0;
+            $bouquetForecastGoal = $bouquetForecastMap[$storeId][$category][$subcategory][$species] ?? 0;
             $noHistoryGoal = $noHistoryMap[$storeId][$category][$subcategory][$species] ?? 0;
 
-            $cleanGoal = $originalGoal - $forecastGoal - $noHistoryGoal;
+            $cleanGoal = $originalGoal - ($bouquetForecastGoal + $noHistoryGoal);
 
 
             $result[] = [
@@ -652,6 +664,9 @@ class AutoPlannogrammaService
                 'category' => $category,
                 'subcategory' => $subcategory,
                 'species' => $species,
+                'dirtyGoal' => $originalGoal,
+                'bouquetGoal' => $bouquetForecastGoal,
+                'noHistoryGoal' => $noHistoryGoal,
                 'goal' => $cleanGoal
             ];
         }
index e505ea5c2b52f5c14a2f4745c6acfbb74a28b631..200f810ed1e332393614136f98ccbf5a426a2c42 100755 (executable)
@@ -4,6 +4,7 @@ namespace yii_app\services;
 
 use DateTime;
 use yii\db\Expression;
+use yii\db\Query;
 use yii\helpers\ArrayHelper;
 use yii_app\records\BouquetComposition;
 use yii_app\records\BouquetCompositionMatrixTypeHistory;
@@ -630,10 +631,10 @@ class StorePlanService
                     'species'     => $sp,
                     'month'       => $selectedMonth,
                     'year'        => $selectedYear,
-                    'sum'         => 0.0,
+                    'goal'         => 0.0,
                 ];
             }
-            $accumulator[$key]['sum'] += $cost;
+            $accumulator[$key]['goal'] += $cost;
         }
 
         return array_values($accumulator);
@@ -714,6 +715,24 @@ class StorePlanService
             $salesValues[] = (int)$sales;
         }
 
+       /* $rows = (new Query())
+            ->select(['sp.product_id', 'cnt' => 'COUNT(*)'])
+            ->from(['s' => 'sales'])
+            ->innerJoin(['sp' => 'sales_products'], 's.id = sp.check_id')
+            ->where(['sp.product_id' => $similarProductIds])
+            ->andWhere(['s.store_id' => $storeId])
+            ->andWhere(['between', 's.date', $startDate . ' 00:00:00', $endDate . ' 23:59:59'])
+            ->andWhere(['not', ['s.order_id' => ['','0']]])
+            ->groupBy('sp.product_id')
+            ->indexBy('product_id')
+            ->all();*/
+
+ //var_dump($similarProductIds, $storeId, $startDate, $endDate);die();
+//        $salesValues = [];
+//        foreach ($similarProductIds as $id) {
+//            $salesValues[] = isset($rows[$id]) ? (int)$rows[$id]['cnt'] : 0;
+//        }
+
         $nonZeroSales = array_filter($salesValues, function($val) {
             return $val > 0;
         });
index aa89abba6d2dc7abd08c47bad7bee4c237fce570..885a80ed45d238d6173b7fe8de5d26c02c222c17 100644 (file)
@@ -102,7 +102,7 @@ $columns = [
     ['attribute' => 'category', 'label' => 'Категория'],
     ['attribute' => 'subcategory', 'label' => 'Подкатегория'],
     ['attribute' => 'species', 'label' => 'Тип'],
-    ['attribute' => 'sum', 'label' => 'Сумма', 'format' => ['decimal', 2]],
+    ['attribute' => 'goal', 'label' => 'Сумма', 'format' => ['decimal', 2]],
 ];
 
 
index 620d8198a1b0fa021485d8ceb1676a7a97984886..5ae0593e974c6a0341c64b5817b5566a5e81bad3 100644 (file)
@@ -102,7 +102,10 @@ $columns = [
     ['attribute' => 'category', 'label' => 'Категория'],
     ['attribute' => 'subcategory', 'label' => 'Подкатегория'],
     ['attribute' => 'species', 'label' => 'Тип'],
-    ['attribute' => 'goal', 'label' => 'Сумма', 'format' => ['decimal', 2]],
+    ['attribute' => 'dirtyGoal', 'label' => 'Неочищенная цель', 'format' => ['decimal', 2]],
+    ['attribute' => 'bouquetGoal', 'label' => 'Цель букета', 'format' => ['decimal', 2]],
+    ['attribute' => 'noHistoryGoal', 'label' => 'Товары без истории', 'format' => ['decimal', 2]],
+    ['attribute' => 'goal', 'label' => 'Очищенная цель', 'format' => ['decimal', 2]],
 ];