fix: 登记线下签署日期时同步创建 EsignRecord
登记签署日期后,签署记录 Tab 中也能看到这条记录。 创建一条 status=COMPLETED 的线下手签 EsignRecord, 避免已签合同在签署记录中无痕可查。 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -206,7 +206,7 @@ router.post('/sign-date', async (req: AuthRequest, res: Response, next: NextFunc
|
||||
}
|
||||
const contract = await prisma.laborContract.findFirst({
|
||||
where: { id: contractId, orgId: req.user!.orgId },
|
||||
select: { id: true, signMethod: true, employee: { select: { name: true } } },
|
||||
select: { id: true, signMethod: true, contractType: true, employeeId: true, employee: { select: { name: true } } },
|
||||
})
|
||||
if (!contract) {
|
||||
return res.status(404).json({ success: false, error: { code: 'NOT_FOUND', message: '合同不存在' } })
|
||||
@@ -218,10 +218,35 @@ router.post('/sign-date', async (req: AuthRequest, res: Response, next: NextFunc
|
||||
if (isNaN(parsedDate.getTime())) {
|
||||
return res.status(400).json({ success: false, error: { code: 'VALIDATION_ERROR', message: '签署日期格式无效' } })
|
||||
}
|
||||
// 更新合同签署日期
|
||||
await prisma.laborContract.update({
|
||||
where: { id: contractId },
|
||||
data: { signDate: parsedDate },
|
||||
})
|
||||
// 同时创建一条已完成的线下手签 EsignRecord,使签署记录 Tab 可见
|
||||
const existingRecord = await prisma.eSignRecord.findFirst({
|
||||
where: { contractId, status: 'COMPLETED' },
|
||||
select: { id: true },
|
||||
})
|
||||
if (!existingRecord) {
|
||||
await prisma.eSignRecord.create({
|
||||
data: {
|
||||
orgId: req.user!.orgId,
|
||||
contractId,
|
||||
employeeId: contract.employeeId,
|
||||
scene: 'CONTRACT',
|
||||
signMethod: 'PAPER',
|
||||
documentTitle: `${contract.contractType}合同线下签署登记`,
|
||||
status: 'COMPLETED',
|
||||
completedAt: parsedDate,
|
||||
signedAt: parsedDate,
|
||||
signedLocation: null,
|
||||
initiatedBy: req.user!.id,
|
||||
createdBy: req.user!.id,
|
||||
remark: 'HR 登记线下签署日期',
|
||||
},
|
||||
})
|
||||
}
|
||||
await auditLog(req, 'SIGN_DATE', 'CONTRACT', contractId, { employeeName: contract.employee.name, signDate: parsedDate.toISOString() })
|
||||
res.json({ success: true, data: { message: '签署日期已登记', signDate: parsedDate.toISOString() } })
|
||||
} catch (err) { next(err) }
|
||||
|
||||
@@ -242,7 +242,13 @@ router.get('/', authMiddleware, async (req: AuthRequest, res, next) => {
|
||||
riskLevel: contractInfo.riskLevel,
|
||||
socialInsuranceStatus: (() => {
|
||||
const sr = (e as any).socialInsRecords?.[0]
|
||||
if (!sr) return null
|
||||
// 劳务协议/实习协议:不缴纳社保,返回 null(前端显示"—")
|
||||
const isNoSocialContract = latestContract && ['LABOR', 'INTERNSHIP'].includes(latestContract.contractType)
|
||||
if (isNoSocialContract) return null
|
||||
if (!sr) {
|
||||
// 在职且应缴社保但无社保记录 → 待办理
|
||||
return 'PENDING'
|
||||
}
|
||||
// endMonth 为 null 表示在保,否则已停保
|
||||
if (sr.endMonth) return 'SUSPENDED'
|
||||
return 'ACTIVE'
|
||||
|
||||
Reference in New Issue
Block a user