]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-360 Сборка страницы автопм
authormarina <m.zozirova@gmail.com>
Tue, 17 Jun 2025 13:42:42 +0000 (16:42 +0300)
committermarina <m.zozirova@gmail.com>
Tue, 17 Jun 2025 13:42:42 +0000 (16:42 +0300)
erp24/services/AutoPlannogrammaService.php

index c71df1bbe7e58d79b221a5bd70ab3e76bbd8bb3c..101ce93ec871f3f4499482207fdda128abf118f0 100644 (file)
@@ -2857,18 +2857,41 @@ class AutoPlannogrammaService
         }
 
         $grouped = [];
+        $grouped = [];
+        $salesShares = [];
+
+        $plans = SalesWriteOffsPlan::find()
+            ->where(['month' => $month, 'year' => $year])
+            ->indexBy('store_id')
+            ->asArray()
+            ->all();
+        if ($plans) {
+            foreach ($plans as $storeId => $plan) {
+                $total = $plan['total_sales_plan'];
+                $offline = $plan['offline_sales_plan'];
+                $online = $plan['online_sales_shop_plan'];
+                $market = $plan['online_sales_marketplace_plan'];
+                $salesShares[$storeId]['offline'] = round($offline / $total, 4);
+                $salesShares[$storeId]['online'] = round($online / $total, 4);
+                $salesShares[$storeId]['marketplace'] = round($market / $total, 4);
+            }
+        }
+
         foreach ($weeklyForecasts as $item) {
             $storeItem = (int)$item['store_id'];
             $guid = (string)$item['product_guid'];
             $group = (string)$item['matrix_group'];
             $type = (string)$item['type'];
             $forecastValue = (float)$item['week_forecast'];
-
+            if (isset($salesShares[$storeItem]) && isset($salesShares[$storeItem][$type])) {
+                $grouped[$storeItem][$type]['share'] = $salesShares[$storeItem][$type];
+            }
             $grouped[$storeItem][$guid][$type][$group] = $forecastValue;
         }
 
         return $grouped;
     }
+
     public function getWeeklyProductsWriteoffsForecast($month, $year, $storeId = null, $weekNumber = null)
     {
         $weeksProductForecast = [];