fix: 劳务协议人员社保基数为0时仍按基本工资计算的bug

根因:socialInsBase || baseSalary 中 0 是 falsy,导致基数为0
的劳务协议/实习人员回退到基本工资计算社保。

修复:改为 nullish check(!= null),区分"明确设置为0"
和"未设置(null)":
- socialInsBase = 0 → 用 0(劳务协议不交社保)
- socialInsBase = null → 用 baseSalary(回退)
- socialInsBase = 5000 → 用 5000(核定基数)

涉及文件:
- payroll.service.ts calcBatchEntry + prePayrollCheck
- payroll.routes.ts 旧版薪资计算

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
selfrelease
2026-08-16 15:12:07 +08:00
parent 54d138cc73
commit 2f1e339413
2 changed files with 7 additions and 7 deletions
+2 -2
View File
@@ -596,8 +596,8 @@ router.post('/tax-preview', async (req: AuthRequest, res: Response, next: NextFu
])
const emp = employee || { socialInsBase: baseSalary, housingFundBase: baseSalary }
const socialBase = emp.socialInsBase || baseSalary
const housingBase = emp.housingFundBase || baseSalary
const socialBase = emp.socialInsBase != null ? emp.socialInsBase : baseSalary
const housingBase = emp.housingFundBase != null ? emp.housingFundBase : baseSalary
// 计算社保公积金
let socialEmp = 0, housingEmp = 0
+5 -5
View File
@@ -233,9 +233,9 @@ export async function calcBatchEntry(
})
}
// 社保基数:优先用员工核定基数,否则用基本工资
const socialBase = employee.socialInsBase || inputs.baseSalary
const housingBase = employee.housingFundBase || inputs.baseSalary
// 社保基数:优先用员工核定基数(含0,劳务协议人员基数为0不交社保),未设置时回退到基本工资
const socialBase = employee.socialInsBase != null ? employee.socialInsBase : inputs.baseSalary
const housingBase = employee.housingFundBase != null ? employee.housingFundBase : inputs.baseSalary
let socialEmp = 0, socialOrg = 0, housingEmp = 0, housingOrg = 0
@@ -689,7 +689,7 @@ export async function prePayrollCheck(orgId: string, batchId: string): Promise<P
// 1. 社保基数是否在上下限范围内
if (socialConfig) {
for (const entry of entries) {
const base = entry.employee.socialInsBase || entry.baseSalary
const base = entry.employee.socialInsBase != null ? entry.employee.socialInsBase : entry.baseSalary
if (base < socialConfig.baseMin || base > socialConfig.baseMax) {
checks.push({
code: 'SOCIAL_BASE_OUT_OF_RANGE',
@@ -707,7 +707,7 @@ export async function prePayrollCheck(orgId: string, batchId: string): Promise<P
// 2. 公积金基数是否在上下限范围内
if (housingConfig) {
for (const entry of entries) {
const base = entry.employee.housingFundBase || entry.baseSalary
const base = entry.employee.housingFundBase != null ? entry.employee.housingFundBase : entry.baseSalary
if (base < housingConfig.baseMin || base > housingConfig.baseMax) {
checks.push({
code: 'HOUSING_BASE_OUT_OF_RANGE',