diff --git a/app/Services/StatisticsService.php b/app/Services/StatisticsService.php index 1db71f6..058f487 100644 --- a/app/Services/StatisticsService.php +++ b/app/Services/StatisticsService.php @@ -151,9 +151,6 @@ class StatisticsService $departmentsPlans = $this->planCalculator->calculate($allDeptIds, $startDate, $endDate); - $grandRecipientPlan = collect($departmentsPlans)->sum('cumulative_plan'); - $grandProgressPlan = collect($departmentsPlans)->sum('actual_year_to_date'); - foreach ($departments as $typeName => $deptList) { $groupedData[$typeName] = []; $totalsByType[$typeName] = $this->initTypeTotals(); @@ -322,13 +319,18 @@ class StatisticsService // KPI за предыдущий аналогичный период (для бейджей тренда) $grandTotals['previous'] = $this->calculatePreviousKpis($allDeptIds, $startDate, $endDate, $bedsTotal); + // План/факт именно за выбранный период (а не с начала года), тот же принцип, + // что и в "Норма"/"Выбыло" на странице Штаба (PlanCalculator::period_plan vs outcome). + $recipientPlan = collect($departmentsPlans)->sum('period_plan'); + $recipientProgress = $grandTotals['outcome_sum']; + return [ 'data' => $this->buildFinalData($groupedData, $totalsByType), 'totalsByType' => $totalsByType, 'grandTotals' => $grandTotals, 'recipientPlanOfYear' => [ - 'plan' => $grandRecipientPlan, // Сумма планов по периоду - 'progress' => $grandProgressPlan, // Сумма фактов по периоду + 'plan' => $recipientPlan, + 'progress' => $recipientProgress, ], ]; }