diff --git a/salesmanagement/api/get_performance.php b/salesmanagement/api/get_performance.php index 1b9e37a..82096f3 100644 --- a/salesmanagement/api/get_performance.php +++ b/salesmanagement/api/get_performance.php @@ -232,7 +232,37 @@ try { return $stats; } - $totalStats = calculateTotalStats($pdo, $rootUserId, $rootUserId, 0); + if ($userRole === 'operator' && !isset($_GET['target_id'])) { + // 운영자가 특정 대상을 지정하지 않은 경우 전체 시스템 통계 반환 + $stmt = $pdo->query(" + SELECT + COALESCE(SUM(contract_amount), 0) as total_sales, + COALESCE(SUM(commission_amount), 0) / 1.0 as total_comm, -- 매니저 수당 + COUNT(*) as total_count + FROM sales_tenant_products + "); + $tpData = $stmt->fetch(PDO::FETCH_ASSOC); + + $stmt = $pdo->query(" + SELECT + COALESCE(SUM(amount), 0) as total_sales, + COALESCE(SUM(amount) * 0.25, 0) as total_comm, -- 영업수당(20%) + 관리수당(5%) 추정치 + COUNT(*) as total_count + FROM sales_record + WHERE status = 'completed' + "); + $srData = $stmt->fetch(PDO::FETCH_ASSOC); + + // 영업수당 계산 (sales_tenant_products 기준): 모든 건에 대해 최소 25% (영업 20 + 관리 5) 지급된다고 가정하거나 + // 혹은 DB에 기록된 실제 지급액이 있다면 그것을 사용해야 함. 여기서는 단순 합산. + $totalStats = [ + 'totalSales' => $tpData['total_sales'] + $srData['total_sales'], + 'totalCommission' => $tpData['total_comm'] + ($tpData['total_sales'] * 0.25) + $srData['total_comm'], + 'totalCount' => $tpData['total_count'] + $srData['total_count'] + ]; + } else { + $totalStats = calculateTotalStats($pdo, $rootUserId, $rootUserId, 0); + } // 역할별 수당 합계 계산 (현재 기간 트리 기반) function summarizeCommissions($node, &$summary) { diff --git a/salesmanagement/index.php b/salesmanagement/index.php index 586231c..5c7ccd6 100644 --- a/salesmanagement/index.php +++ b/salesmanagement/index.php @@ -483,8 +483,7 @@
-

지능형 영업 통합 관리

-

※ 현재 에이전트의 수정사항이 반영된 화면입니다 (V3) ※

+

운영자 화면

모든 테넌트 계약과 영업 자산을 중앙에서 제어합니다.