]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Прогноз товаров без истории
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 26 May 2025 15:12:23 +0000 (18:12 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 26 May 2025 15:12:23 +0000 (18:12 +0300)
erp24/controllers/AutoPlannogrammaController.php
erp24/services/StorePlanService.php

index 6a1c9b7d8a36bf859e5cd949f4fabcc6e59b3a62..8b1947e291f518995176b4c4a41815e96cfecb7e 100644 (file)
@@ -695,13 +695,14 @@ class AutoPlannogrammaController extends BaseController
                 $filters['subcategory'],
                 $filters['species']
             );
-            // var_dump($result); die();
+
             $withoutHistoryResults = StorePlanService::calculateMedianSalesForProductsWithoutHistoryExtended(
                 $filters['store_id'],
                 $filters['month'],
                 $filters['year'],
                 $result['without_history']
             );
+            var_dump($data); die();
             $productSalesShare = StorePlanService::calculateProductSalesShare(
                 $filters['store_id'],
                 $filters['month'],
index 9d71f8b57e6c943ddfad085d50b5d0ce29b8e153..fbc186250491c66b464db585ce63fc10d96987c7 100755 (executable)
@@ -677,47 +677,51 @@ class StorePlanService
         int   $selectedMonth,
         int   $selectedYear,
         array $medianProductsWithoutHistory
-    ): array
-    {
+    ): array {
+        $accumulator  = [];
+        $prices        = [];
+        $guidToGroup   = [];
 
-        $accumulator = [];
-       // var_dump($productsWithoutHistory); die();
-        foreach ($medianProductsWithoutHistory as $guid => $info) {
-            $quantity = (float)$info;
-            if ($quantity <= 0) {
-                continue;
-            }
 
-            // цена за два месяца назад
+        foreach ($medianProductsWithoutHistory as $guid => $qty) {
+            $q = (float)$qty;
+            if ($q <= 0) continue;
+
             $price = self::getPriceForProductAtOffsetMonthWeekly(
-                $guid,
-                $selectedYear,
-                $selectedMonth,
-                $storeId,
-                2
+                $guid, $selectedYear, $selectedMonth, $storeId, 2
             );
+            $prices[$guid] = $price;
 
-            $cost = $quantity * $price;
-
-            /** @var Products1cNomenclature $nom */
             $nom = Products1cNomenclature::findOne($guid);
             $cat = $nom->category    ?? '';
             $sub = $nom->subcategory ?? '';
             $sp  = $nom->species     ?? '';
+            $groupKey = implode('|', [$cat,$sub,$sp]);
+            $guidToGroup[$guid] = $groupKey;
 
-            $key = implode('|', [$cat, $sub, $sp]);
-            if (!isset($accumulator[$key])) {
-                $accumulator[$key] = [
+            if (!isset($accumulator[$groupKey])) {
+                $accumulator[$groupKey] = [
                     'store_id'    => $storeId,
                     'category'    => $cat,
                     'subcategory' => $sub,
                     'species'     => $sp,
                     'month'       => $selectedMonth,
                     'year'        => $selectedYear,
-                    'goal'         => 0.0,
+                    'goal'        => 0.0,
+                    'forecasts'   => [],
                 ];
             }
-            $accumulator[$key]['goal'] += $cost;
+            $accumulator[$groupKey]['goal'] += $q * $price;
+        }
+
+        foreach ($medianProductsWithoutHistory as $guid => $_) {
+            $groupKey = $guidToGroup[$guid];
+            $goal     = $accumulator[$groupKey]['goal'];
+            $price    = $prices[$guid] ?? 0.0;
+            $accumulator[$groupKey]['forecasts'][$guid] =
+                $price > 0.0
+                    ? ($goal / $price)
+                    : 0.0;
         }
 
         return array_values($accumulator);