import prisma from '../src/lib/prisma'

async function main() {
  // 查看已发布的7条工资条明细
  const published = await prisma.$queryRaw<any[]>`
    SELECT p."employeeId", e.name, e.department,
           p."baseSalary", p."overtimePay", p.allowance, p.deduction, p.bonus,
           p."totalPay", p."socialEmp", p."housingEmp", p.tax, p."netPay",
           p."publishStatus", p.status, p.month
    FROM "Payslip" p
    JOIN "Employee" e ON p."employeeId" = e.id
    WHERE p.month='2026-08' AND p."publishStatus" = 'PUBLISHED'
    ORDER BY e.name
  `
  console.log('=== 已发布工资条（7条）===')
  for (const p of published) {
    console.log(`${p.name} | ${p.department} | base=${p.baseSalary} total=${p.totalPay} net=${p.netPay} social=${p.socialEmp} housing=${p.housingEmp} tax=${p.tax}`)
  }

  // 查看未发布的23条
  const unpublished = await prisma.$queryRaw<any[]>`
    SELECT e.name, e.department,
           p."totalPay", p."netPay", p."publishStatus"
    FROM "Payslip" p
    JOIN "Employee" e ON p."employeeId" = e.id
    WHERE p.month='2026-08' AND p."publishStatus" IS NULL
    ORDER BY e.name
  `
  console.log('\n=== 未发布工资条（23条）===')
  for (const p of unpublished) {
    console.log(`${p.name} | ${p.department} | total=${p.totalPay} net=${p.netPay}`)
  }

  await prisma.$disconnect()
}
main()
