-- 권순경(supiadan) 1월 체크리스트 인센티브 확인

-- 1. 사용자 ID 확인
SELECT id, username, role FROM users WHERE username = 'supiadan';
-- 예상: id = 1

-- 2. 2026년 1월 체크리스트 레코드 확인
SELECT 
    id,
    record_date,
    shift,
    status,
    earned_incentive,
    submitted_at,
    owner_approved_at
FROM performance_records
WHERE user_id = 1
  AND record_date BETWEEN '2026-01-01' AND '2026-01-31'
ORDER BY record_date DESC;

-- 3. 급여 계산에 포함되는 레코드 (owner_approved만)
SELECT 
    id,
    record_date,
    shift,
    status,
    earned_incentive
FROM performance_records
WHERE user_id = 1
  AND status = 'owner_approved'
  AND record_date BETWEEN '2026-01-01' AND '2026-01-31';

-- 4. 인센티브 합계 계산
SELECT 
    SUM(earned_incentive) as total_incentive
FROM performance_records
WHERE user_id = 1
  AND status = 'owner_approved'
  AND record_date BETWEEN '2026-01-01' AND '2026-01-31';

-- 5. 상태별 통계
SELECT 
    status,
    COUNT(*) as count,
    SUM(earned_incentive) as total
FROM performance_records
WHERE user_id = 1
  AND record_date BETWEEN '2026-01-01' AND '2026-01-31'
GROUP BY status;
