用golang计算个人所得税
个人所得现在按纳税年度合并计算个人所得税 ,即现在开始逐月累加计算应纳税所得额,再计算出应交税额,年终补税或退税.
个人每个月的工资,税费构成将是个结构体
type Employee struct{
IncomeBeforeTax [12]float64 // 税前应发工资
Tax [12]float64 // 应缴税费
TaxSum [12]float64 // 税费总额
Allowance [2]float64 // 免纳税额
IncomeNet [12]float64 // 实发工资
}
然后逐月计算其应纳税所得额
var taxAble float64 = 0 // 应纳税所得额
for i,_ := range e.IncomeBeforeTax { // e 是一Employee类型
if i <6 { // 五险一金基数通常每年7月调整一次.
taxAble = taxAble + e.IncomeBeforeTax[i] - (5000+ e.Allowance[0])
} else {
taxAble = taxAble + e.IncomeBeforeTax[i] - (5000+ e.Allowance[1])
}
得到应纳税所得额后,对照个税税档计算个税,
每一档其实是个struct
type TaxLevel struct {
Bottom float64
Top float64
Rate float64 // 税率
Decount float64 // 速算扣除额
}
编写档次数据
var tax0 = TaxLevel {
-99999,
0,
0,
0,
}
var tax1 = TaxLevel {
0,
36000,
0.03,
0,
}
var tax2 = TaxLevel {
36000,
144000,
0.1,
2520,
}
var tax3 = TaxLevel {
144000,
300000,
0.2,
16920,
}
var tax4 = TaxLevel {
300000,
420000,
0.25,
31920,
}
var tax5 = TaxLevel {
420000,
660000,
0.3,
52920,
}
var tax6 = TaxLevel {
660000,
960000,
0.35,
85920,
}
var tax7 = TaxLevel {
960000,
99999999,
0.45,
181920,
}
设计函数判断所属计税档次,并进行计算
func TaxCal(taxAble float64) float64{
var taxSum float64
taxLevel := []TaxLevel{
tax0,tax1,tax2,tax3,tax4,tax5,tax6,tax7,
}
for _,v := range taxLevel {
if v.Bottom <= taxAble && taxAble < v.Top {
taxSum = taxAble * v.Rate - v.Decount
}
}
return taxSum
}
}
计算得出累计税费后,计算当月应缴税费
if i ==0 {
e.Tax[i] = e.TaxSum[i]
} else {
e.Tax[i] = e.TaxSum[i] - e.TaxSum[i-1]
}
计算实发工资
if i< 6 {
e.IncomeNet[i] = e.IncomeBeforeTax[i] - e.Tax[i] - e.Allowance[0]
} else {
e.IncomeNet[i] = e.IncomeBeforeTax[i] - e.Tax[i] - e.Allowance[1]
}
设计接口输入工资和可扣除额
var (
income1,income2,income3,income4,income5,income6,income7,income8,income9,income10,income11,income12 float64
decount1,decount2 float64
)
fmt.Println("请输入1到12月份应发工资,若偿未到发工资月份,以0补:")
fmt.Scan(&income1,&income2,&income3,&income4,&income5,&income6,&income7,&income8,&income9,&income10,&income11,&income12)
fmt.Println("请输入上,下半年五险一金缴扣金额和专项附加扣除额的总和:")
fmt.Scan(&decount1,&decount2)
var e = Employee {
IncomeBeforeTax: [12]float64{income1,income2,income3,income4,income5,income6,income7,income8,income9,income10,income11,income12},
Allowance: [2]float64{decount1 ,decount2},
}
最后上全部代码
package main
import (
"fmt"
)
type TaxLevel struct {
Bottom float64
Top float64
Rate float64 // 税率
Decount float64 // 速算扣除额
}
var tax0 = TaxLevel {
-99999,
0,
0,
0,
}
var tax1 = TaxLevel {
0,
36000,
0.03,
0,
}
var tax2 = TaxLevel {
36000,
144000,
0.1,
2520,
}
var tax3 = TaxLevel {
144000,
300000,
0.2,
16920,
}
var tax4 = TaxLevel {
300000,
420000,
0.25,
31920,
}
var tax5 = TaxLevel {
420000,
660000,
0.3,
52920,
}
var tax6 = TaxLevel {
660000,
960000,
0.35,
85920,
}
var tax7 = TaxLevel {
960000,
99999999,
0.45,
181920,
}
func TaxCal(taxAble float64) float64{
var taxSum float64
taxLevel := []TaxLevel{
tax0,tax1,tax2,tax3,tax4,tax5,tax6,tax7,
}
for _,v := range taxLevel {
if v.Bottom <= taxAble && taxAble < v.Top {
taxSum = taxAble * v.Rate - v.Decount
}
}
return taxSum
}
type Employee struct{
IncomeBeforeTax [12]float64 // 税前应发工资
Tax [12]float64 // 应缴税费
TaxSum [12]float64 // 税费总额
Allowance [2]float64 // 免纳税额
IncomeNet [12]float64 // 实发工资
}
func (e Employee) SalaryCal() Employee {
var taxAble float64 = 0 // 应纳税所得额
for i,_ := range e.IncomeBeforeTax {
if i <6 {
taxAble = taxAble + e.IncomeBeforeTax[i] - (5000+ e.Allowance[0])
} else {
taxAble = taxAble + e.IncomeBeforeTax[i] - (5000+ e.Allowance[1])
}
e.TaxSum[i] = TaxCal( taxAble )
if i ==0 {
e.Tax[i] = e.TaxSum[i]
} else {
e.Tax[i] = e.TaxSum[i] - e.TaxSum[i-1]
}
if i< 6 {
e.IncomeNet[i] = e.IncomeBeforeTax[i] - e.Tax[i] - e.Allowance[0]
} else {
e.IncomeNet[i] = e.IncomeBeforeTax[i] - e.Tax[i] - e.Allowance[1]
}
fmt.Printf("第%d月应缴纳个人所得税额为:%.2f\n",i+1,e.Tax[i])
//fmt.Printf("第%d月的实收工资为:%.2f\n",i+1,p.IncomeNet[i])
}
return e
}
func main() {
var (
income1,income2,income3,income4,income5,income6,income7,income8,income9,income10,income11,income12 float64
decount1,decount2 float64
)
fmt.Println("请输入1到12月份应发工资,若偿未到发工资月份,以0补:")
fmt.Scan(&income1,&income2,&income3,&income4,&income5,&income6,&income7,&income8,&income9,&income10,&income11,&income12)
fmt.Println("请输入上,下半年五险一金缴扣金额和专项附加扣除额的总和:")
fmt.Scan(&decount1,&decount2)
var e = Employee {
IncomeBeforeTax: [12]float64{income1,income2,income3,income4,income5,income6,income7,income8,income9,income10,income11,income12},
Allowance: [2]float64{decount1 ,decount2},
}
e.SalaryCal()
}