전체 실적 통계(매출/수당) 복구

This commit is contained in:
2026-01-04 22:38:54 +09:00
parent 848958da5f
commit 651a80018a
2 changed files with 37 additions and 9 deletions

View File

@@ -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) {

View File

@@ -483,8 +483,7 @@
<main className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8 space-y-12">
<div className="flex items-center justify-between">
<div>
<h2 className="text-3xl font-extrabold text-slate-900 tracking-tight">지능형 영업 통합 관리</h2>
<p className="text-red-500 font-bold mt-2 text-xl underline animate-pulse"> 현재 에이전트의 수정사항이 반영된 화면입니다 (V3) </p>
<h2 className="text-3xl font-extrabold text-slate-900 tracking-tight">운영자 화면</h2>
<p className="text-slate-500 mt-2 text-lg">모든 테넌트 계약과 영업 자산을 중앙에서 제어합니다.</p>
</div>
<button
@@ -1342,15 +1341,14 @@
{/* 패키지 카드 그리드 */}
<div className="mt-8">
<div className="flex items-center justify-between mb-4 p-4 bg-blue-50 border-2 border-blue-200 rounded-2xl">
<h4 className="text-xl font-black text-blue-900">[V3-DEBUG] 패키지 관리</h4>
<div className="flex items-center justify-between mb-4 p-4 bg-slate-50 rounded-xl border border-slate-200">
<h4 className="text-lg font-bold text-slate-800">패키지 품목 관리</h4>
<button
onClick={() => handleAddItem('package')}
className="px-6 py-3 bg-red-600 text-white rounded-xl text-lg font-black hover:bg-red-700 transition-all shadow-lg flex items-center gap-2"
id="add-package-btn-debug"
className="px-4 py-2 bg-blue-600 text-white rounded-lg text-sm font-bold hover:bg-blue-700 transition-colors shadow-sm flex items-center gap-2"
>
<span className="text-2xl">+</span>
패키지 품목 등록하기
<LucideIcon name="plus" className="w-4 h-4" />
패키지 추가
</button>
</div>