]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Корректировка общего отчета и подсчтета недель
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 8 Dec 2025 06:56:58 +0000 (09:56 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 8 Dec 2025 06:56:58 +0000 (09:56 +0300)
erp24/api3/core/services/ReportService.php

index 11555bb5768124c1798b58a0ed7a2a0134d8462b..1f0e71c4af1ea2b328e92c86b1987bc225337c9b 100644 (file)
@@ -432,16 +432,8 @@ class ReportService
                 ];
             }
 
-            // Подсчет должностей на смене для этого дня
+            // Подсчет должностей на смене для этого дня (используется для информации по дню)
             $employeePositionsOnShift = $this->countEmployeesByPosition($timetables, $positionMap);
-            
-            // Суммируем для общего отчета
-            foreach ($employeePositionsOnShift as $positionName => $count) {
-                if (!isset($totalEmployeePositionsOnShift[$positionName])) {
-                    $totalEmployeePositionsOnShift[$positionName] = 0;
-                }
-                $totalEmployeePositionsOnShift[$positionName] += $count;
-            }
 
             $adminPayrollDaysMonth = AdminPayrollDays::find()->select(["FLOOR(SUM(day_payroll)) as total", "store_id"])
                 ->where(['>=', 'date', date("Y-m-01", strtotime($currentDate))])
@@ -886,6 +878,16 @@ class ReportService
                 $totalEmployeeSkillsScore = round(array_sum($totalEmployeeSkillsScores) / count($totalEmployeeSkillsScores), 1);
             }
 
+            // Агрегируем сотрудников по магазинам без дедупликации
+            $totalEmployeePositionsOnShift = [];
+            $totalEmployeeCountOnShift = 0;
+            foreach ($report["stores"] as $storeData) {
+                $totalEmployeeCountOnShift += $storeData["employee_count_on_shift"];
+                foreach ($storeData["employee_positions_on_shift"] as $positionName => $count) {
+                    $totalEmployeePositionsOnShift[$positionName] = ($totalEmployeePositionsOnShift[$positionName] ?? 0) + $count;
+                }
+            }
+
             $report['total'] = [
                 "sale_total" => $storeSaleTotalTotal,
                 "sale_quantity" => $storeSaleQuantityTotal,
@@ -912,9 +914,9 @@ class ReportService
                 "total_wrap_per_day" => $totalWrapPerDayTotal,
                 "total_services_per_day" => $totalServicePerDayTotal,
                 "total_potted_per_day" => $totalPottedPerDayTotal,
-                "employee_positions_on_shift" => $employeePositionsOnShift,
+                "employee_positions_on_shift" => $totalEmployeePositionsOnShift,
                 "employee_skills_score" => $totalEmployeeSkillsScore,
-                "employee_count_on_shift" => count($timetables),
+                "employee_count_on_shift" => $totalEmployeeCountOnShift,
             ];
 
             // Создаем итоговый массив для дня с правильным порядком полей
@@ -1369,6 +1371,16 @@ class ReportService
                 $total["total_services_per_day"] = ($total["total_services_per_day"] ?? 0) + ($totalServicePerDayTotal[$store_id] ?? 0);
                 $total["total_potted_per_day"] = ($total["total_potted_per_day"] ?? 0) + ($totalPottedPerDayTotal[$store_id] ?? 0);
             }
+
+            // Суммы по всем магазинам без дедупликации сотрудников
+            $totalEmployeePositionsOnShift = [];
+            foreach ($stores as $storeData) {
+                foreach ($storeData['data']['employee_positions_on_shift'] as $position => $count) {
+                    $totalEmployeePositionsOnShift[$position] = ($totalEmployeePositionsOnShift[$position] ?? 0) + $count;
+                }
+            }
+            $totalEmployeeCountOnShift = array_sum($employeeCount);
+
             $total["sale_avg"] = $total["sale_quantity"] > 0 ? floor($total["sale_total"] / $total["sale_quantity"]) : 0;
             $total["total_write_offs_per_date_percent"] = $total["sale_total"] > 0 ? floor($total["total_write_offs_per_date"] / $total["sale_total"] * 100) : 0;
             $total["total_write_offs_per_month_percent"] = $total["sale_month_total"] > 0 ? floor($total["total_write_offs_per_month"] / $total["sale_month_total"] * 100) : 0;
@@ -1377,8 +1389,8 @@ class ReportService
             $total["employee_sale_avg"] = $employeeCountTotal > 0 ? floor($total["sale_total"] / $employeeCountTotal) : 0;
             $total["conversion"] = $total["visitors_quantity"] > 0 ? floor($total["sale_quantity"] / $total["visitors_quantity"] * 100) : 0;;
             $total["bonus_user_per_sale_percent"] = $total["sale_quantity"] > 0 ? floor($total["bonus_user_count"] / $total["sale_quantity"] * 100) : 0;
-            $total["employee_positions_on_shift"] = $employeePositionsOnShift;
-            $total["employee_count_on_shift"] = count($weekEmployees);
+            $total["employee_positions_on_shift"] = $totalEmployeePositionsOnShift;
+            $total["employee_count_on_shift"] = $totalEmployeeCountOnShift;
 
             $report = [
                 "date_from" => $dateStartEnd[0],