fix: 专项附加扣除改为5项明细分类(子女教育、赡养老人、住房、继续教育、婴幼儿照护)

- 后端 GET /profile 返回最新月份的专项附加扣除明细记录
- 后端 PUT /profile 保存明细到 SpecialDeductionRecord 表(当前月份 upsert)
- 前端5项明细输入框 + 合计实时计算 + 备注字段
- 与管理端社保>专项附加扣除 Tab 数据结构一致
This commit is contained in:
freedakgmail
2026-08-17 19:16:26 +08:00
parent 88b0fcdc7d
commit 76a49985f1
2 changed files with 138 additions and 16 deletions
+49 -4
View File
@@ -903,6 +903,21 @@ router.get('/profile', portalAuth, async (req: any, res, next) => {
}
}
// 查询最新月份的专项附加扣除明细
const latestDeductionRecord = await (prisma as any).specialDeductionRecord.findFirst({
where: { employeeId, orgId },
orderBy: { month: 'desc' },
})
const latestDeduction = latestDeductionRecord ? {
month: latestDeductionRecord.month,
children: latestDeductionRecord.children || 0,
elderly: latestDeductionRecord.elderly || 0,
housing: latestDeductionRecord.housing || 0,
education: latestDeductionRecord.education || 0,
infant: latestDeductionRecord.infant || 0,
remark: latestDeductionRecord.remark || '',
} : null
res.json({
success: true,
data: {
@@ -925,6 +940,7 @@ router.get('/profile', portalAuth, async (req: any, res, next) => {
employeeNo: emp.employeeNo || '',
femaleWorkerType: emp.femaleWorkerType || '',
specialDeduction: emp.specialDeduction ?? 0,
specialDeductionDetail: latestDeduction,
},
})
} catch (err) { next(err) }
@@ -940,7 +956,7 @@ router.put('/profile', portalAuth, async (req: any, res, next) => {
const {
emergencyContact, emergencyPhone, address,
bankAccount, bankName, education, city,
specialDeduction,
specialDeductionDetail,
} = req.body
// 构建更新数据(仅允许员工自行编辑的字段)
@@ -955,9 +971,38 @@ router.put('/profile', portalAuth, async (req: any, res, next) => {
if (bankAccount !== undefined && bankAccount) {
updateData.bankAccount = encrypt(bankAccount)
}
// 专项附加扣除(子女教育、赡养老人等,员工自行填报)
if (specialDeduction !== undefined) {
updateData.specialDeduction = Number(specialDeduction) || 0
// 专项附加扣除明细保存到 SpecialDeductionRecord 表(当前月份)
if (specialDeductionDetail && typeof specialDeductionDetail === 'object') {
const now = new Date()
const currentMonth = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`
const { children, elderly, housing, education: dedEducation, infant, remark } = specialDeductionDetail
const total = (Number(children) || 0) + (Number(elderly) || 0) + (Number(housing) || 0) + (Number(dedEducation) || 0) + (Number(infant) || 0)
await (prisma as any).specialDeductionRecord.upsert({
where: { employeeId_month: { employeeId, month: currentMonth } },
create: {
orgId, employeeId, month: currentMonth,
amount: total,
children: Number(children) || 0,
elderly: Number(elderly) || 0,
housing: Number(housing) || 0,
education: Number(dedEducation) || 0,
infant: Number(infant) || 0,
remark: remark || null,
createdBy: employeeId,
},
update: {
amount: total,
children: Number(children) || 0,
elderly: Number(elderly) || 0,
housing: Number(housing) || 0,
education: Number(dedEducation) || 0,
infant: Number(infant) || 0,
remark: remark || null,
},
})
// 同步便捷字段
updateData.specialDeduction = total
}
await prisma.employee.update({ where: { id: employeeId }, data: updateData })