전체 실적 통계(매출/수당) 복구
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user