fix: 补全人工费用公积金及月度个税公式 #616

Merged
chenxi merged 1 commits from fix/chenxi-labor-expense-housing-tax-formulas into main 2026-10-26 17:14:30 +08:00
3 changed files with 34 additions and 10 deletions

View File

@ -26,13 +26,13 @@ return [
['key' => 'M', 'label' => '原需交个税金额', 'group' => 'original', 'kind' => 'formula_number', 'formula' => '=J#*K#-L#'],
['key' => 'N', 'label' => '原需年交个税金额', 'group' => 'original', 'kind' => 'formula_number', 'formula' => '=M#*12'],
['key' => 'O', 'label' => '新公积金缴存基数', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=IF(F#<=0,"",IF(F#<=8500,4952,IF(F#<=15000,8000,IF(F#<=25000,10000,12000))))'],
['key' => 'P', 'label' => '新单位公积金月缴存12%', 'group' => 'fund', 'kind' => 'number'],
['key' => 'Q', 'label' => '新个人公积金月缴存12%', 'group' => 'fund', 'kind' => 'number'],
['key' => 'R', 'label' => '超额代扣缴', 'group' => 'fund', 'kind' => 'number'],
['key' => 'P', 'label' => '新单位公积金月缴存12%', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=O#*0.12'],
['key' => 'Q', 'label' => '新个人公积金月缴存12%', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=O#*0.12'],
['key' => 'R', 'label' => '超额代扣缴', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=Q#-H#'],
['key' => 'S', 'label' => '新月度应纳税所得额', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=F#-G#-I#-P#-R#'],
['key' => 'T', 'label' => '新月度个税比列', 'group' => 'fund', 'kind' => 'formula_percent', 'formula' => '=IF(S#<=0,"",IF(S#<=3000,0.03,IF(S#<=12000,0.1,IF(S#<=25000,0.2,IF(S#<=35000,0.25,IF(S#<=55000,0.3,IF(S#<=80000,0.35,0.45)))))))'],
['key' => 'U', 'label' => '新月度新速算扣除数', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=IF(S#<=0,"",IF(S#<=3000,0,IF(S#<=12000,210,IF(S#<=25000,1410,IF(S#<=35000,2660,IF(S#<=55000,4410,IF(S#<=80000,7160,15160)))))))'],
['key' => 'V', 'label' => '新月度个税金额', 'group' => 'fund', 'kind' => 'number'],
['key' => 'V', 'label' => '新月度个税金额', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=S#*T#-U#'],
['key' => 'W', 'label' => '全年应纳税所得额', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=S#*12'],
['key' => 'X', 'label' => '年度税率', 'group' => 'fund', 'kind' => 'formula_percent', 'formula' => '=IF(S#=0,"",IF(W#<=0,0,IF(W#<=36000,0.03,IF(W#<=144000,0.1,IF(W#<=300000,0.2,IF(W#<=420000,0.25,IF(W#<=660000,0.3,IF(W#<=960000,0.35,0.45))))))))'],
['key' => 'Y', 'label' => '年度速算扣除数', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=IF(W#=0,"",IF(W#<=0,0,IF(W#<=36000,0,IF(W#<=144000,2520,IF(W#<=300000,16920,IF(W#<=420000,31920,IF(W#<=660000,52920,IF(W#<=960000,85920,181920))))))))'],

View File

@ -549,7 +549,14 @@
const v = (key) => numeric(row[key]);
const monthlyBasicDeduction = 5000;
const originalTaxable = v('F') - v('G') - v('H') - monthlyBasicDeduction;
const newMonthlyTaxable = v('F') - v('G') - monthlyBasicDeduction - v('P') - v('R');
const newHousingFundBase = housingFundBase(v('F'));
const newEmployerHousingFund = newHousingFundBase === null ? null : newHousingFundBase * 0.12;
const newPersonalHousingFund = newHousingFundBase === null ? null : newHousingFundBase * 0.12;
const excessHousingFundWithholding = newPersonalHousingFund === null
? null
: newPersonalHousingFund - v('H');
const newMonthlyTaxable = v('F') - v('G') - monthlyBasicDeduction
- numeric(newEmployerHousingFund) - numeric(excessHousingFundWithholding);
const newAnnualTaxable = newMonthlyTaxable * 12;
const newAnnualBracket = annualBracket(newAnnualTaxable);
const originalRate = newMonthlyTaxable === 0 ? null : newAnnualBracket.rate;
@ -562,11 +569,14 @@
? null
: originalTaxable * originalMonthlyBracket.rate - originalMonthlyBracket.deduction;
const originalAnnualTax = originalMonthlyTax === null ? null : originalMonthlyTax * 12;
const newHousingFundBase = housingFundBase(v('F'));
const parttimeSalary = v('AB') + v('AC');
const newSalary = v('F') - parttimeSalary;
const salaryTaxable = newSalary - v('G') - monthlyBasicDeduction - v('P') - v('R');
const salaryTaxable = newSalary - v('G') - monthlyBasicDeduction
- numeric(newEmployerHousingFund) - numeric(excessHousingFundWithholding);
const newMonthlyBracket = monthlyWageBracket(newMonthlyTaxable);
const newMonthlyTax = newMonthlyBracket === null
? null
: newMonthlyTaxable * newMonthlyBracket.rate - newMonthlyBracket.deduction;
const salaryMonthlyBracket = monthlyWageBracket(salaryTaxable);
const salaryAnnualTaxable = salaryTaxable * 12;
const salaryBracket = annualBracket(salaryAnnualTaxable);
@ -594,7 +604,9 @@
const parttimeIncome = monthlyParttime * 12 * 0.8;
const totalIncome = salaryIncome + parttimeIncome;
const annualBasicDeduction = 60000;
const socialFundDeduction = (v('G') + v('P') + v('R')) * 12;
const socialFundDeduction = (
v('G') + numeric(newEmployerHousingFund) + numeric(excessHousingFundWithholding)
) * 12;
const settlementTaxable = totalIncome - annualBasicDeduction - socialFundDeduction;
const settlementBracket = annualBracket(settlementTaxable);
const settlementRate = settlementTaxable <= 0 ? null : settlementBracket.rate;
@ -618,7 +630,11 @@
M: originalMonthlyTax,
N: originalAnnualTax,
O: newHousingFundBase,
P: newEmployerHousingFund,
Q: newPersonalHousingFund,
R: excessHousingFundWithholding,
S: newMonthlyTaxable,
V: newMonthlyTax,
W: newAnnualTaxable,
X: originalRate,
Y: originalDeduction,

View File

@ -69,7 +69,7 @@ class LaborExpensePageAccessTest extends FeatureTestCase
);
$this->assertCount(61, $fields);
$this->assertCount(43, $formulaFields);
$this->assertCount(47, $formulaFields);
$response = $this->loginAs($chenxi)->get(route('business.pages.show', [
'section' => 'financial-operations',
@ -89,11 +89,14 @@ class LaborExpensePageAccessTest extends FeatureTestCase
->assertSee('=IF(J#&lt;=0,&quot;&quot;,IF(J#&lt;=3000,0,IF(J#&lt;=12000,210', false)
->assertSee('=J#*K#-L#', false)
->assertSee('=IF(F#&lt;=0,&quot;&quot;,IF(F#&lt;=8500,4952', false)
->assertSee('=O#*0.12', false)
->assertSee('=Q#-H#', false)
->assertSee('=S#*T#-U#', false)
->assertDontSee('data-labor-row="0"', false);
$html = $response->getContent();
$this->assertSame(61, substr_count($html, 'data-labor-header="'));
$this->assertSame(43, substr_count($html, 'class="labor-expense-formula"'));
$this->assertSame(47, substr_count($html, 'class="labor-expense-formula"'));
}
public function test_basic_deduction_tax_amount_and_housing_fund_base_are_formula_driven(): void
@ -113,6 +116,11 @@ class LaborExpensePageAccessTest extends FeatureTestCase
[4952, 8000, 10000, 12000],
$this->housingFundBases($fields['O']['formula'])
);
foreach (['P' => '=O#*0.12', 'Q' => '=O#*0.12', 'R' => '=Q#-H#', 'V' => '=S#*T#-U#'] as $key => $formula) {
$this->assertSame('formula_number', $fields[$key]['kind']);
$this->assertSame($formula, $fields[$key]['formula']);
}
}
public function test_monthly_and_annual_tax_quick_deductions_are_formula_driven(): void