fix: 劳务/实习协议员工从根源不创建社保公积金记录

- 创建员工时劳务/实习协议跳过社保公积金记录创建
- 重新入职时同样判断合同类型
- 编辑员工时若最新合同为劳务/实习,强制基数为0并关闭在保记录
- 月度办理列表过滤劳务/实习协议员工
This commit is contained in:
freedakgmail
2026-08-18 07:20:58 +08:00
parent c24cc68cd8
commit 66ae5ff21f
+100 -60
View File
@@ -433,33 +433,36 @@ export async function createEmployee(orgId: string, userId: string, data: any) {
}, },
}) })
await tx.employeeSocialInsRecord.create({ // 劳务/实习协议不创建社保公积金记录
data: { if (!isNoSocialContract) {
orgId, await tx.employeeSocialInsRecord.create({
employeeId: emp.id, data: {
startMonth: socialInsStartMonth, orgId,
endMonth: null, employeeId: emp.id,
base: socialInsBase, startMonth: socialInsStartMonth,
changeType: 'ONBOARDING', endMonth: null,
createdBy: userId, base: socialInsBase,
city: data.city || '北京', changeType: 'ONBOARDING',
accountId: data.socialAccountId || null, createdBy: userId,
}, city: data.city || '北京',
}) accountId: data.socialAccountId || null,
},
})
await tx.employeeHousingFundRecord.create({ await tx.employeeHousingFundRecord.create({
data: { data: {
orgId, orgId,
employeeId: emp.id, employeeId: emp.id,
startMonth: housingFundStartMonth, startMonth: housingFundStartMonth,
endMonth: null, endMonth: null,
base: housingFundBase, base: housingFundBase,
changeType: 'ONBOARDING', changeType: 'ONBOARDING',
createdBy: userId, createdBy: userId,
city: data.city || '北京', city: data.city || '北京',
accountId: data.housingAccountId || null, accountId: data.housingAccountId || null,
}, },
}) })
}
await tx.salaryChangeRecord.create({ await tx.salaryChangeRecord.create({
data: { data: {
@@ -555,12 +558,14 @@ export async function rehireEmployee(orgId: string, userId: string, id: string,
const performanceSalaryNum = data.performanceSalary != null ? Number(data.performanceSalary) : (employee.performanceSalary ? Number(decrypt(employee.performanceSalary)) || 0 : 0) const performanceSalaryNum = data.performanceSalary != null ? Number(data.performanceSalary) : (employee.performanceSalary ? Number(decrypt(employee.performanceSalary)) || 0 : 0)
const newMonthlySalary = data.baseSalary != null ? baseSalaryNum + performanceSalaryNum : salaryNum const newMonthlySalary = data.baseSalary != null ? baseSalaryNum + performanceSalaryNum : salaryNum
const city = data.city || employee.city || '北京' const city = data.city || employee.city || '北京'
const rawSocialInsBase = data.socialInsBase != null ? Number(data.socialInsBase) : salaryNum // 劳务协议/实习协议:不缴纳社保公积金
const rawHousingFundBase = data.housingFundBase != null ? Number(data.housingFundBase) : salaryNum const isNoSocialContract = data.contract && ['LABOR', 'INTERNSHIP'].includes(data.contract.contractType)
const socialInsBase = await clampSocialInsBase(orgId, rawSocialInsBase, city) const rawSocialInsBase = isNoSocialContract ? 0 : (data.socialInsBase != null ? Number(data.socialInsBase) : salaryNum)
const housingFundBase = await clampHousingFundBase(orgId, rawHousingFundBase, city) const rawHousingFundBase = isNoSocialContract ? 0 : (data.housingFundBase != null ? Number(data.housingFundBase) : salaryNum)
const socialInsStartMonth = data.socialInsStartMonth || newHireMonth const socialInsBase = isNoSocialContract ? 0 : await clampSocialInsBase(orgId, rawSocialInsBase, city)
const housingFundStartMonth = data.housingFundStartMonth || newHireMonth const housingFundBase = isNoSocialContract ? 0 : await clampHousingFundBase(orgId, rawHousingFundBase, city)
const socialInsStartMonth = isNoSocialContract ? '' : (data.socialInsStartMonth || newHireMonth)
const housingFundStartMonth = isNoSocialContract ? '' : (data.housingFundStartMonth || newHireMonth)
const prevHireMonth = prevMonth(newHireMonth) const prevHireMonth = prevMonth(newHireMonth)
// 关闭旧社保缴费记录 // 关闭旧社保缴费记录
@@ -612,33 +617,36 @@ export async function rehireEmployee(orgId: string, userId: string, id: string,
}, },
}) })
// 创建社保缴费记录 // 劳务/实习协议不创建社保公积金记录
await prisma.employeeSocialInsRecord.create({ if (!isNoSocialContract) {
data: { // 创建新社保缴费记录
orgId, await prisma.employeeSocialInsRecord.create({
employeeId: id, data: {
startMonth: socialInsStartMonth, orgId,
endMonth: null, employeeId: id,
base: socialInsBase, startMonth: socialInsStartMonth,
changeType: 'REHIRE', endMonth: null,
createdBy: userId, base: socialInsBase,
city: data.city || employee.city || '北京', changeType: 'REHIRE',
}, createdBy: userId,
}) city: data.city || employee.city || '北京',
},
})
// 创建新公积金缴费记录 // 创建新公积金缴费记录
await prisma.employeeHousingFundRecord.create({ await prisma.employeeHousingFundRecord.create({
data: { data: {
orgId, orgId,
employeeId: id, employeeId: id,
startMonth: housingFundStartMonth, startMonth: housingFundStartMonth,
endMonth: null, endMonth: null,
base: housingFundBase, base: housingFundBase,
changeType: 'REHIRE', changeType: 'REHIRE',
createdBy: userId, createdBy: userId,
city: data.city || employee.city || '北京', city: data.city || employee.city || '北京',
}, },
}) })
}
// 创建新薪资记录 // 创建新薪资记录
await prisma.salaryChangeRecord.create({ await prisma.salaryChangeRecord.create({
@@ -792,11 +800,43 @@ export async function updateEmployee(orgId: string, id: string, data: any) {
if (data.isWorkInjured !== undefined) updateData.isWorkInjured = data.isWorkInjured if (data.isWorkInjured !== undefined) updateData.isWorkInjured = data.isWorkInjured
if (data.socialInsBase !== undefined) { if (data.socialInsBase !== undefined) {
const city = data.city || employee.city || '北京' const city = data.city || employee.city || '北京'
updateData.socialInsBase = await clampSocialInsBase(orgId, Number(data.socialInsBase), city) // 查询最新合同类型,劳务/实习协议强制基数为0
const latestContract = await prisma.laborContract.findFirst({
where: { employeeId: id },
orderBy: { createdAt: 'desc' },
select: { contractType: true },
})
const isNoSocial = latestContract && ['LABOR', 'INTERNSHIP'].includes(latestContract.contractType)
if (isNoSocial) {
updateData.socialInsBase = 0
// 关闭在保社保记录
const nowMonth = new Date().toISOString().slice(0, 7)
await prisma.employeeSocialInsRecord.updateMany({
where: { employeeId: id, endMonth: null },
data: { endMonth: nowMonth, changeType: 'TERMINATION' },
})
} else {
updateData.socialInsBase = await clampSocialInsBase(orgId, Number(data.socialInsBase), city)
}
} }
if (data.housingFundBase !== undefined) { if (data.housingFundBase !== undefined) {
const city = data.city || employee.city || '北京' const city = data.city || employee.city || '北京'
updateData.housingFundBase = await clampHousingFundBase(orgId, Number(data.housingFundBase), city) const latestContract = await prisma.laborContract.findFirst({
where: { employeeId: id },
orderBy: { createdAt: 'desc' },
select: { contractType: true },
})
const isNoSocial = latestContract && ['LABOR', 'INTERNSHIP'].includes(latestContract.contractType)
if (isNoSocial) {
updateData.housingFundBase = 0
const nowMonth = new Date().toISOString().slice(0, 7)
await prisma.employeeHousingFundRecord.updateMany({
where: { employeeId: id, endMonth: null },
data: { endMonth: nowMonth, changeType: 'TERMINATION' },
})
} else {
updateData.housingFundBase = await clampHousingFundBase(orgId, Number(data.housingFundBase), city)
}
} }
if (data.specialDeduction !== undefined) updateData.specialDeduction = data.specialDeduction if (data.specialDeduction !== undefined) updateData.specialDeduction = data.specialDeduction
if (data.city !== undefined) updateData.city = data.city if (data.city !== undefined) updateData.city = data.city