文件下载地址:https://wenshushu.vip/pan/index.php?id=36 提取码:7bf9
/**
* 个税模拟器 - 纯JS计算模拟系统
* 阿里云社区风格示例
*
* 功能说明:
* 1. 支持居民个人综合所得年度汇算清缴模拟
* 2. 支持月度工资薪金预扣预缴模拟
* 3. 支持年终奖单独计税/合并计税对比
* 4. 支持专项附加扣除(子女教育、继续教育、大病医疗、住房贷款利息、住房租金、赡养老人、3岁以下婴幼儿照护)
*
* 注意:本代码仅供学习参考,实际个税计算以国家税务总局政策为准。
*/
// ==================== 个税税率表 ====================
/**
* 居民个人综合所得年度税率表(适用于汇算清缴)
* 级数 | 全年应纳税所得额 | 税率 | 速算扣除数
*/
const ANNUAL_TAX_BRACKETS = [
{ level: 1, min: 0, max: 36000, rate: 0.03, deduction: 0 },
{ level: 2, min: 36000, max: 144000, rate: 0.10, deduction: 2520 },
{ level: 3, min: 144000, max: 300000, rate: 0.20, deduction: 16920 },
{ level: 4, min: 300000, max: 420000, rate: 0.25, deduction: 31920 },
{ level: 5, min: 420000, max: 660000, rate: 0.30, deduction: 52920 },
{ level: 6, min: 660000, max: 960000, rate: 0.35, deduction: 85920 },
{ level: 7, min: 960000, max: Infinity, rate: 0.45, deduction: 181920 }
];
/**
* 居民个人工资薪金所得预扣预缴税率表(按月累计)
* 级数 | 累计预扣预缴应纳税所得额 | 预扣率 | 速算扣除数
*/
const MONTHLY_TAX_BRACKETS = [
{ level: 1, min: 0, max: 36000, rate: 0.03, deduction: 0 },
{ level: 2, min: 36000, max: 144000, rate: 0.10, deduction: 2520 },
{ level: 3, min: 144000, max: 300000, rate: 0.20, deduction: 16920 },
{ level: 4, min: 300000, max: 420000, rate: 0.25, deduction: 31920 },
{ level: 5, min: 420000, max: 660000, rate: 0.30, deduction: 52920 },
{ level: 6, min: 660000, max: 960000, rate: 0.35, deduction: 85920 },
{ level: 7, min: 960000, max: Infinity, rate: 0.45, deduction: 181920 }
];
/**
* 年终奖单独计税税率表(按月换算)
* 级数 | 全月应纳税所得额 | 税率 | 速算扣除数
*/
const ANNUAL_BONUS_BRACKETS = [
{ level: 1, min: 0, max: 3000, rate: 0.03, deduction: 0 },
{ level: 2, min: 3000, max: 12000, rate: 0.10, deduction: 210 },
{ level: 3, min: 12000, max: 25000, rate: 0.20, deduction: 1410 },
{ level: 4, min: 25000, max: 35000, rate: 0.25, deduction: 2660 },
{ level: 5, min: 35000, max: 55000, rate: 0.30, deduction: 4410 },
{ level: 6, min: 55000, max: 80000, rate: 0.35, deduction: 7160 },
{ level: 7, min: 80000, max: Infinity, rate: 0.45, deduction: 15160 }
];
// ==================== 基础参数 ====================
/** 基本减除费用(起征点) */
const BASIC_DEDUCTION = 5000; // 每月
/** 社保公积金个人缴纳比例(默认值,可自定义) */
const DEFAULT_SOCIAL_INSURANCE_RATES = {
pension: 0.08, // 养老保险
medical: 0.02, // 医疗保险
unemployment: 0.005, // 失业保险
housingFund: 0.12 // 住房公积金
};
/** 专项附加扣除标准(每月) */
const SPECIAL_ADDITIONAL_DEDUCTIONS = {
childEducation: 2000, // 子女教育(每个子女)
continuingEducation: 400, // 继续教育(学历教育)
continuingEducationCert: 3600, // 继续教育(职业资格,年度)
housingLoan: 1000, // 住房贷款利息
housingRent: 1500, // 住房租金(一线城市)
elderlySupport: 3000, // 赡养老人(独生子女)
infantCare: 2000 // 3岁以下婴幼儿照护(每个婴幼儿)
};
// ==================== 工具函数 ====================
/**
* 根据应纳税所得额和税率表计算税额
* @param {number} taxableIncome - 应纳税所得额
* @param {Array} brackets - 税率表
* @returns {Object} 税额计算结果
*/
function calculateTaxByBrackets(taxableIncome, brackets) {
if (taxableIncome <= 0) {
return { tax: 0, rate: 0, deduction: 0, level: 0 };
}
for (const bracket of brackets) {
if (taxableIncome > bracket.min && taxableIncome <= bracket.max) {
const tax = taxableIncome * bracket.rate - bracket.deduction;
return {
tax: Math.max(0, Math.round(tax * 100) / 100),
rate: bracket.rate,
deduction: bracket.deduction,
level: bracket.level
};
}
}
// 超过最高级距
const last = brackets[brackets.length - 1];
const tax = taxableIncome * last.rate - last.deduction;
return {
tax: Math.max(0, Math.round(tax * 100) / 100),
rate: last.rate,
deduction: last.deduction,
level: last.level
};
}
/**
* 计算社保公积金个人缴纳部分
* @param {number} salary - 月工资
* @param {Object} rates - 缴纳比例
* @param {number} base - 缴纳基数(默认等于工资)
* @returns {Object} 各项社保公积金金额
*/
function calculateSocialInsurance(salary, rates = DEFAULT_SOCIAL_INSURANCE_RATES, base = null) {
const insuranceBase = base !== null ? base : salary;
const pension = insuranceBase * rates.pension;
const medical = insuranceBase * rates.medical;
const unemployment = insuranceBase * rates.unemployment;
const housingFund = insuranceBase * rates.housingFund;
const total = pension + medical + unemployment + housingFund;
return {
pension: Math.round(pension * 100) / 100,
medical: Math.round(medical * 100) / 100,
unemployment: Math.round(unemployment * 100) / 100,
housingFund: Math.round(housingFund * 100) / 100,
total: Math.round(total * 100) / 100
};
}
/**
* 计算专项附加扣除月度总额
* @param {Object} options - 各项扣除选项
* @returns {number} 月度专项附加扣除总额
*/
function calculateSpecialAdditionalDeduction(options = {}) {
let total = 0;
// 子女教育(每个子女2000元/月)
if (options.childEducation && options.childEducation.count > 0) {
total += SPECIAL_ADDITIONAL_DEDUCTIONS.childEducation * options.childEducation.count;
}
// 继续教育(学历教育400元/月,职业资格年度3600元)
if (options.continuingEducation) {
if (options.continuingEducation.type === 'degree') {
total += SPECIAL_ADDITIONAL_DEDUCTIONS.continuingEducation;
} else if (options.continuingEducation.type === 'cert') {
// 职业资格按年度扣除,分摊到月
total += SPECIAL_ADDITIONAL_DEDUCTIONS.continuingEducationCert / 12;
}
}
// 住房贷款利息(1000元/月)
if (options.housingLoan) {
total += SPECIAL_ADDITIONAL_DEDUCTIONS.housingLoan;
}
// 住房租金(根据城市级别)
if (options.housingRent) {
const cityLevel = options.housingRent.cityLevel || 'first';
const rentMap = {
first: 1500, // 一线城市
second: 1100, // 二线城市
third: 800 // 三线及以下
};
total += rentMap[cityLevel] || 1500;
}
// 赡养老人(独生子女3000元/月,非独生子女分摊)
if (options.elderlySupport) {
if (options.elderlySupport.isOnlyChild) {
total += SPECIAL_ADDITIONAL_DEDUCTIONS.elderlySupport;
} else {
// 非独生子女分摊,每人不超过1500元/月
const share = options.elderlySupport.share || 1500;
total += Math.min(share, 1500);
}
}
// 3岁以下婴幼儿照护(每个婴幼儿2000元/月)
if (options.infantCare && options.infantCare.count > 0) {
total += SPECIAL_ADDITIONAL_DEDUCTIONS.infantCare * options.infantCare.count;
}
return Math.round(total * 100) / 100;
}
// ==================== 核心计算类 ====================
/**
* 个税模拟器类
*/
class TaxSimulator {
constructor(config = {}) {
this.socialInsuranceRates = config.socialInsuranceRates || DEFAULT_SOCIAL_INSURANCE_RATES;
this.socialInsuranceBase = config.socialInsuranceBase || null;
this.specialAdditionalDeduction = config.specialAdditionalDeduction || {};
this.basicDeduction = config.basicDeduction || BASIC_DEDUCTION;
}
/**
* 计算月度工资薪金预扣预缴税额(累计预扣法)
* @param {Array} monthlySalaries - 每月工资数组,如 [10000, 10000, ...]
* @param {number} months - 计算到第几个月
* @returns {Array} 每月预扣预缴明细
*/
calculateMonthlyWithholding(monthlySalaries, months = null) {
const totalMonths = months || monthlySalaries.length;
const results = [];
let cumulativeIncome = 0;
let cumulativeDeduction = 0;
let cumulativeTax = 0;
let cumulativeSpecialDeduction = 0;
// 计算每月专项附加扣除
const monthlySpecialDeduction = calculateSpecialAdditionalDeduction(this.specialAdditionalDeduction);
for (let i = 0; i < totalMonths; i++) {
const salary = monthlySalaries[i] || monthlySalaries[monthlySalaries.length - 1] || 0;
// 社保公积金
const insurance = calculateSocialInsurance(
salary,
this.socialInsuranceRates,
this.socialInsuranceBase
);
// 累计收入
cumulativeIncome += salary;
// 累计减除费用
cumulativeDeduction += this.basicDeduction;
// 累计专项扣除(社保公积金)
cumulativeSpecialDeduction += insurance.total;
// 累计专项附加扣除
const cumulativeAdditional = monthlySpecialDeduction * (i + 1);
// 累计应纳税所得额
const cumulativeTaxableIncome = cumulativeIncome
- cumulativeDeduction
- cumulativeSpecialDeduction
- cumulativeAdditional;
// 累计应预扣预缴税额
const cumulativeTaxResult = calculateTaxByBrackets(
Math.max(0, cumulativeTaxableIncome),
MONTHLY_TAX_BRACKETS
);
// 本月应预扣预缴税额 = 累计应预扣 - 已预扣
const currentMonthTax = Math.max(0, cumulativeTaxResult.tax - cumulativeTax);
cumulativeTax = cumulativeTaxResult.tax;
results.push({
month: i + 1,
salary: Math.round(salary * 100) / 100,
insurance: insurance,
basicDeduction: this.basicDeduction,
specialAdditionalDeduction: monthlySpecialDeduction,
cumulativeIncome: Math.round(cumulativeIncome * 100) / 100,
cumulativeTaxableIncome: Math.round(Math.max(0, cumulativeTaxableIncome) * 100) / 100,
cumulativeTax: Math.round(cumulativeTaxResult.tax * 100) / 100,
currentMonthTax: Math.round(currentMonthTax * 100) / 100,
afterTaxSalary: Math.round((salary - insurance.total - currentMonthTax) * 100) / 100,
taxRate: cumulativeTaxResult.rate,
taxLevel: cumulativeTaxResult.level
});
}
return results;
}
/**
* 计算年度综合所得汇算清缴
* @param {Object} params - 年度收入与扣除参数
* @returns {Object} 汇算清缴结果
*/
calculateAnnualSettlement(params = {}) {
const {
totalSalary = 0, // 全年工资薪金收入
totalBonus = 0, // 全年年终奖(如选择合并计税)
totalLabor = 0, // 全年劳务报酬收入
totalRoyalty = 0, // 全年稿酬收入
totalAuthorRemuneration = 0, // 全年特许权使用费收入
totalSocialInsurance = 0, // 全年社保公积金个人缴纳
specialAdditionalDeduction = null, // 专项附加扣除(如不传则使用类配置)
otherDeductions = 0, // 其他扣除(如年金、商业健康险等)
donations = 0 // 公益捐赠
} = params;
// 综合所得收入额
// 劳务报酬:收入减除20%费用
const laborIncome = totalLabor * 0.8;
// 稿酬:收入减除20%费用后再减按70%计算
const royaltyIncome = totalRoyalty * 0.8 * 0.7;
// 特许权使用费:收入减除20%费用
const authorIncome = totalAuthorRemuneration * 0.8;
const totalIncome = totalSalary + totalBonus + laborIncome + royaltyIncome + authorIncome;
// 年度专项附加扣除
let annualSpecialAdditional = 0;
if (specialAdditionalDeduction !== null) {
annualSpecialAdditional = specialAdditionalDeduction;
} else {
annualSpecialAdditional = calculateSpecialAdditionalDeduction(this.specialAdditionalDeduction) * 12;
}
// 年度基本减除费用
const annualBasicDeduction = this.basicDeduction * 12;
// 应纳税所得额
const taxableIncome = Math.max(0,
totalIncome
- annualBasicDeduction
- totalSocialInsurance
- annualSpecialAdditional
- otherDeductions
- donations
);
// 计算税额
const taxResult = calculateTaxByBrackets(taxableIncome, ANNUAL_TAX_BRACKETS);
// 已预缴税额(假设由月度预扣累加,此处简化处理)
const prepaidTax = params.prepaidTax || 0;
// 应补/退税额
const refundOrPay = Math.round((prepaidTax - taxResult.tax) * 100) / 100;
return {
totalIncome: Math.round(totalIncome * 100) / 100,
totalSalary: Math.round(totalSalary * 100) / 100,
totalBonus: Math.round(totalBonus * 100) / 100,
laborIncome: Math.round(laborIncome * 100) / 100,
royaltyIncome: Math.round(royaltyIncome * 100) / 100,
authorIncome: Math.round(authorIncome * 100) / 100,
annualBasicDeduction: Math.round(annualBasicDeduction * 100) / 100,
totalSocialInsurance: Math.round(totalSocialInsurance * 100) / 100,
annualSpecialAdditional: Math.round(annualSpecialAdditional * 100) / 100,
otherDeductions: Math.round(otherDeductions * 100) / 100,
donations: Math.round(donations * 100) / 100,
taxableIncome: Math.round(taxableIncome * 100) / 100,
taxRate: taxResult.rate,
taxDeduction: taxResult.deduction,
taxLevel: taxResult.level,
annualTax: taxResult.tax,
prepaidTax: Math.round(prepaidTax * 100) / 100,
refundOrPay: refundOrPay,
refund: refundOrPay > 0,
refundAmount: refundOrPay > 0 ? refundOrPay : 0,
payAmount: refundOrPay < 0 ? Math.abs(refundOrPay) : 0
};
}
/**
* 计算年终奖最优计税方式
* @param {number} annualBonus - 年终奖金额
* @param {number} annualSalary - 全年工资(用于比较合并计税)
* @param {Object} params - 其他参数
* @returns {Object} 两种计税方式对比结果
*/
calculateAnnualBonus(annualBonus, annualSalary = 0, params = {}) {
// 方式一:单独计税
const monthlyBonus = annualBonus / 12;
let separateTax = 0;
let separateRate = 0;
let separateDeduction = 0;
let separateLevel = 0;
for (const bracket of ANNUAL_BONUS_BRACKETS) {
if (monthlyBonus > bracket.min && monthlyBonus <= bracket.max) {
separateTax = annualBonus * bracket.rate - bracket.deduction;
separateRate = bracket.rate;
separateDeduction = bracket.deduction;
separateLevel = bracket.level;
break;
}
}
// 方式二:并入综合所得
const combinedSettlement = this.calculateAnnualSettlement({
totalSalary: annualSalary,
totalBonus: annualBonus,
...params
});
// 单独计税时的年度汇算(工资部分)
const separateSettlement = this.calculateAnnualSettlement({
totalSalary: annualSalary,
totalBonus: 0,
...params
});
const totalSeparate = separateTax + separateSettlement.annualTax;
const totalCombined = combinedSettlement.annualTax;
return {
annualBonus: Math.round(annualBonus * 100) / 100,
monthlyBonus: Math.round(monthlyBonus * 100) / 100,
separate: {
tax: Math.round(separateTax * 100) / 100,
rate: separateRate,
deduction: separateDeduction,
level: separateLevel,
salaryTax: separateSettlement.annualTax,
totalTax: Math.round(totalSeparate * 100) / 100
},
combined: {
tax: combinedSettlement.annualTax,
rate: combinedSettlement.taxRate,
taxableIncome: combinedSettlement.taxableIncome,
totalTax: Math.round(totalCombined * 100) / 100
},
optimal: totalSeparate <= totalCombined ? 'separate' : 'combined',
saving: Math.round(Math.abs(totalSeparate - totalCombined) * 100) / 100
};
}
/**
* 计算劳务报酬预扣预缴税额
* @param {number} income - 每次收入
* @returns {Object} 预扣预缴税额
*/
calculateLaborRemuneration(income) {
// 预扣预缴应纳税所得额
let taxableIncome;
if (income <= 4000) {
taxableIncome = income - 800;
} else {
taxableIncome = income * 0.8;
}
// 劳务报酬预扣率表
const laborBrackets = [
{ min: 0, max: 20000, rate: 0.20, deduction: 0 },
{ min: 20000, max: 50000, rate: 0.30, deduction: 2000 },
{ min: 50000, max: Infinity, rate: 0.40, deduction: 7000 }
];
const result = calculateTaxByBrackets(Math.max(0, taxableIncome), laborBrackets);
return {
income: Math.round(income * 100) / 100,
taxableIncome: Math.round(Math.max(0, taxableIncome) * 100) / 100,
tax: result.tax,
rate: result.rate,
deduction: result.deduction,
afterTax: Math.round((income - result.tax) * 100) / 100
};
}
/**
* 计算稿酬预扣预缴税额
* @param {number} income - 每次收入
* @returns {Object} 预扣预缴税额
*/
calculateRoyalty(income) {
let taxableIncome;
if (income <= 4000) {
taxableIncome = (income - 800) * 0.7;
} else {
taxableIncome = income * 0.8 * 0.7;
}
const tax = Math.max(0, taxableIncome * 0.20);
return {
income: Math.round(income * 100) / 100,
taxableIncome: Math.round(Math.max(0, taxableIncome) * 100) / 100,
tax: Math.round(tax * 100) / 100,
rate: 0.20,
afterTax: Math.round((income - tax) * 100) / 100
};
}
}
// ==================== 使用示例 ====================
// 示例1:月度工资预扣预缴
function example1() {
console.log('========== 示例1:月度工资预扣预缴 ==========');
const simulator = new TaxSimulator({
socialInsuranceRates: DEFAULT_SOCIAL_INSURANCE_RATES,
specialAdditionalDeduction: {
childEducation: { count: 1 }, // 1个子女教育
housingLoan: true, // 住房贷款利息
elderlySupport: { isOnlyChild: true } // 独生子女赡养老人
}
});
const monthlySalaries = [15000, 15000, 15000, 15000, 15000, 15000, 15000, 15000, 15000, 15000, 15000, 15000];
const results = simulator.calculateMonthlyWithholding(monthlySalaries);
console.table(results.map(r => ({
月份: r.month,
工资: r.salary,
社保公积金: r.insurance.total,
专项附加扣除: r.specialAdditionalDeduction,
累计应纳税所得额: r.cumulativeTaxableIncome,
本月个税: r.currentMonthTax,
税后工资: r.afterTaxSalary,
税率: (r.taxRate * 100).toFixed(0) + '%'
})));
const totalTax = results.reduce((sum, r) => sum + r.currentMonthTax, 0);
console.log(`全年个税合计:${totalTax.toFixed(2)} 元`);
}
// 示例2:年度汇算清缴
function example2() {
console.log('\n========== 示例2:年度汇算清缴 ==========');
const simulator = new TaxSimulator({
specialAdditionalDeduction: {
childEducation: { count: 1 },
housingLoan: true,
elderlySupport: { isOnlyChild: true }
}
});
const result = simulator.calculateAnnualSettlement({
totalSalary: 180000,
totalBonus: 0,
totalLabor: 20000,
totalRoyalty: 10000,
totalSocialInsurance: 36000,
prepaidTax: 8000
});
console.log('年度汇算清缴结果:');
console.log(`综合所得收入额:${result.totalIncome} 元`);
console.log(`基本减除费用:${result.annualBasicDeduction} 元`);
console.log(`专项扣除(社保公积金):${result.totalSocialInsurance} 元`);
console.log(`专项附加扣除:${result.annualSpecialAdditional} 元`);
console.log(`应纳税所得额:${result.taxableIncome} 元`);
console.log(`适用税率:${(result.taxRate * 100).toFixed(0)}%`);
console.log(`速算扣除数:${result.taxDeduction} 元`);
console.log(`年度应纳税额:${result.annualTax} 元`);
console.log(`已预缴税额:${result.prepaidTax} 元`);
console.log(`应退/补税额:${result.refundOrPay > 0 ? '退税' : '补税'} ${Math.abs(result.refundOrPay)} 元`);
}
// 示例3:年终奖最优计税
function example3() {
console.log('\n========== 示例3:年终奖最优计税 ==========');
const simulator = new TaxSimulator({
specialAdditionalDeduction: {
childEducation: { count: 1 },
housingLoan: true
}
});
const result = simulator.calculateAnnualBonus(60000, 150000, {
totalSocialInsurance: 30000,
prepaidTax: 5000
});
console.log(`年终奖金额:${result.annualBonus} 元`);
console.log(`月均年终奖:${result.monthlyBonus} 元`);
console.log('\n【单独计税】');
console.log(`年终奖个税:${result.separate.tax} 元(税率${(result.separate.rate * 100).toFixed(0)}%)`);
console.log(`工资个税:${result.separate.salaryTax} 元`);
console.log(`合计个税:${result.separate.totalTax} 元`);
console.log('\n【合并计税】');
console.log(`合计个税:${result.combined.totalTax} 元`);
console.log(`\n最优方案:${result.optimal === 'separate' ? '单独计税' : '合并计税'}`);
console.log(`可节省:${result.saving} 元`);
}
// 示例4:劳务报酬与稿酬
function example4() {
console.log('\n========== 示例4:劳务报酬与稿酬 ==========');
const simulator = new TaxSimulator();
const labor = simulator.calculateLaborRemuneration(10000);
console.log('劳务报酬 10000 元:');
console.log(`应纳税所得额:${labor.taxableIncome} 元`);
console.log(`预扣个税:${labor.tax} 元`);
console.log(`税后收入:${labor.afterTax} 元`);
const royalty = simulator.calculateRoyalty(10000);
console.log('\n稿酬 10000 元:');
console.log(`应纳税所得额:${royalty.taxableIncome} 元`);
console.log(`预扣个税:${royalty.tax} 元`);
console.log(`税后收入:${royalty.afterTax} 元`);
}
// ==================== 运行示例 ====================
// 如果在 Node.js 环境运行
if (typeof module !== 'undefined' && module.exports) {
module.exports = {
TaxSimulator,
ANNUAL_TAX_BRACKETS,
MONTHLY_TAX_BRACKETS,
ANNUAL_BONUS_BRACKETS,
calculateTaxByBrackets,
calculateSocialInsurance,
calculateSpecialAdditionalDeduction,
DEFAULT_SOCIAL_INSURANCE_RATES,
SPECIAL_ADDITIONAL_DEDUCTIONS,
BASIC_DEDUCTION
};
// 运行示例
example1();
example2();
example3();
example4();
}
// 如果在浏览器环境运行
if (typeof window !== 'undefined') {
window.TaxSimulator = TaxSimulator;
window.TaxSimulatorExamples = { example1, example2, example3, example4 };
}
```