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

- 创建员工时劳务/实习协议跳过社保公积金记录创建
- 重新入职时同样判断合同类型
- 编辑员工时若最新合同为劳务/实习,强制基数为0并关闭在保记录
- 月度办理列表过滤劳务/实习协议员工
This commit is contained in:
freedakgmail
2026-08-18 07:20:58 +08:00
parent c24cc68cd8
commit 66ae5ff21f
+46 -6
View File
@@ -433,6 +433,8 @@ export async function createEmployee(orgId: string, userId: string, data: any) {
}, },
}) })
// 劳务/实习协议不创建社保公积金记录
if (!isNoSocialContract) {
await tx.employeeSocialInsRecord.create({ await tx.employeeSocialInsRecord.create({
data: { data: {
orgId, orgId,
@@ -460,6 +462,7 @@ export async function createEmployee(orgId: string, userId: string, data: any) {
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,6 +617,8 @@ export async function rehireEmployee(orgId: string, userId: string, id: string,
}, },
}) })
// 劳务/实习协议不创建社保公积金记录
if (!isNoSocialContract) {
// 创建新社保缴费记录 // 创建新社保缴费记录
await prisma.employeeSocialInsRecord.create({ await prisma.employeeSocialInsRecord.create({
data: { data: {
@@ -639,6 +646,7 @@ export async function rehireEmployee(orgId: string, userId: string, id: string,
city: data.city || employee.city || '北京', city: data.city || employee.city || '北京',
}, },
}) })
}
// 创建新薪资记录 // 创建新薪资记录
await prisma.salaryChangeRecord.create({ await prisma.salaryChangeRecord.create({
@@ -792,12 +800,44 @@ 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 || '北京'
// 查询最新合同类型,劳务/实习协议强制基数为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) 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 || '北京'
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) 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
if (data.education !== undefined) updateData.education = data.education if (data.education !== undefined) updateData.education = data.education