diff --git a/app/Models/Sales/SalesScenarioChecklist.php b/app/Models/Sales/SalesScenarioChecklist.php index 97f8d1df..65d261a2 100644 --- a/app/Models/Sales/SalesScenarioChecklist.php +++ b/app/Models/Sales/SalesScenarioChecklist.php @@ -188,15 +188,29 @@ public static function getSimpleProgress(int $tenantId, string $scenarioType): a $steps = config($configKey, []); $total = 0; + $validCheckpointKeys = []; + + // config에 정의된 유효한 체크포인트만 수집 foreach ($steps as $step) { - $total += count($step['checkpoints'] ?? []); + foreach ($step['checkpoints'] ?? [] as $checkpoint) { + $total++; + $validCheckpointKeys[] = "{$step['id']}_{$checkpoint['id']}"; + } } - // 완료된 체크포인트 수 (DB에서 조회) - $completed = self::where('tenant_id', $tenantId) + // 완료된 체크포인트 수 (config에 존재하는 것만 카운트) + $checkedItems = self::where('tenant_id', $tenantId) ->where('scenario_type', $scenarioType) ->where('is_checked', true) - ->count(); + ->get(); + + $completed = 0; + foreach ($checkedItems as $item) { + $key = "{$item->step_id}_{$item->checkpoint_id}"; + if (in_array($key, $validCheckpointKeys)) { + $completed++; + } + } $percentage = $total > 0 ? round(($completed / $total) * 100) : 0;