From a03c01f97a394d90193b3dc840760494380fdda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Mon, 2 Feb 2026 11:29:02 +0900 Subject: [PATCH] =?UTF-8?q?fix:=EC=9C=A0=EC=B9=98=20=ED=8C=8C=ED=8A=B8?= =?UTF-8?q?=EB=84=88=20=ED=98=84=ED=99=A9=20=EC=B4=9D=20=EA=B3=84=EC=95=BD?= =?UTF-8?q?=20=EA=B1=B4=EC=88=98=EB=A5=BC=20=EA=B0=80=EC=9E=85=EB=B9=84=20?= =?UTF-8?q?=EA=B8=B0=EC=A4=80=EC=9C=BC=EB=A1=9C=20=EA=B3=84=EC=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 계약 성사(STATUS_CONVERTED) 기준 대신 가입비(registration_fee > 0) 기준으로 변경 - 예상 수당이 표시되면 총 계약 건수도 함께 표시되도록 수정 Co-Authored-By: Claude Opus 4.5 --- .../Sales/SalesDashboardController.php | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/Sales/SalesDashboardController.php b/app/Http/Controllers/Sales/SalesDashboardController.php index 947329d9..427047fc 100644 --- a/app/Http/Controllers/Sales/SalesDashboardController.php +++ b/app/Http/Controllers/Sales/SalesDashboardController.php @@ -441,10 +441,17 @@ private function calculatePartnerSummaryStats(array $partnerIds, int $currentUse // 하위 파트너들이 등록한 총 영업권(명함) 수 $totalProspects = TenantProspect::whereIn('registered_by', $partnerIds)->count(); - // 하위 파트너들의 계약 성사 건수 - $totalConversions = TenantProspect::whereIn('registered_by', $partnerIds) - ->where('status', TenantProspect::STATUS_CONVERTED) - ->count(); + // 예상 수당 계산을 위해 먼저 가입비 정보 조회 + $prospectIds = TenantProspect::whereIn('registered_by', $partnerIds)->pluck('id')->toArray(); + $managementIds = SalesTenantManagement::whereIn('tenant_prospect_id', $prospectIds)->pluck('id')->toArray(); + $totalRegistrationFee = SalesContractProduct::whereIn('management_id', $managementIds)->sum('registration_fee'); + + // 하위 파트너들의 계약 건수 (가입비가 설정된 건수) + $contractedManagementCount = SalesContractProduct::whereIn('management_id', $managementIds) + ->where('registration_fee', '>', 0) + ->distinct('management_id') + ->count('management_id'); + $totalConversions = $contractedManagementCount; // 확정 수당 (SalesCommission에서) $confirmedCommission = SalesCommission::where('manager_user_id', $currentUserId) @@ -452,11 +459,6 @@ private function calculatePartnerSummaryStats(array $partnerIds, int $currentUse $query->whereIn('user_id', $partnerIds); }) ->sum('manager_commission'); - - // 예상 수당: 하위 파트너들이 등록한 가망고객의 가입비 × 5% - $prospectIds = TenantProspect::whereIn('registered_by', $partnerIds)->pluck('id')->toArray(); - $managementIds = SalesTenantManagement::whereIn('tenant_prospect_id', $prospectIds)->pluck('id')->toArray(); - $totalRegistrationFee = SalesContractProduct::whereIn('management_id', $managementIds)->sum('registration_fee'); $expectedFromFee = (int)($totalRegistrationFee * 0.05); // 최종 예상 수당 (확정 + 예상 중 큰 값)