tax

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Base 个税起征点
	Base = 5000
)

Variables

View Source
var (
	// Command ...
	Command = &cobra.Command{
		Use:     "tax",
		Aliases: []string{"t"},
		Short:   "计算五险一金和个税",
		Run: func(cmd *cobra.Command, args []string) {
			xcolor.Success(config.Separator)
			xcolor.Success(config.Success, "五险一金默认配置")
			xcolor.Success(config.Success, "社保: 养老 8% + 医疗 2% + 失业 0.5% = 10.5%")
			xcolor.Success(config.Success, "公积金: 7%")
			xcolor.Success(config.Separator)

			ans := &Answer{}
			err := survey.Ask(Question, ans)
			if err != nil {
				xcolor.Fail(config.Error, fmt.Sprintf("输入错误: %s", err.Error()))
				return
			}

			var (
				totalBase      float64 // 累计扣除基数
				totalSalary    float64 // 累计税前收入
				totalInsurance float64 // 累计社保
				totalFund      float64 // 累计公积金
				totalDeduction float64 // 累计附加扣除
				taxSalary      float64 // 累计计税收入
				lastTotalTax   float64 // 上月累计应纳税额
				totalTax       float64 // 累计应纳数额
				totalIncome    float64 // 累计税后收入
			)

			list := make([]*MonthIncome, 0)
			insurance := ans.Salary * ans.Insurance
			fund := ans.Salary * ans.Fund
			for month := 1; month <= 12; month++ {
				totalBase += Base
				totalSalary += ans.Salary
				totalInsurance += insurance
				totalFund += fund
				totalDeduction += ans.Deduction

				taxSalary = totalSalary - totalInsurance - totalFund - totalDeduction - totalBase
				taxRate, taxDeduction := internal.GetTaxRate(taxSalary)
				totalTax = taxSalary*taxRate - taxDeduction

				tax := totalTax - lastTotalTax
				lastTotalTax = totalTax

				income := ans.Salary - insurance - fund - tax
				totalIncome += income
				list = append(list, &MonthIncome{
					Month:       month,
					Salary:      xconvert.ToUint(ans.Salary),
					TotalSalary: xconvert.ToUint(totalSalary),
					Insurance:   fmt.Sprintf("%.0f (%.0f)", insurance, totalInsurance),
					Fund:        fmt.Sprintf("%.0f (%.0f)", fund, totalFund),
					Tax:         fmt.Sprintf("%.0f (%.0f)", tax, totalTax),
					Income:      xconvert.ToUint(income),
					TotalIncome: xconvert.ToUint(totalIncome),
				})
			}
			xtable.New(list).Style(xtable.Dashed).Border(true).Render()

			xcolor.Success(config.Separator)
		},
	}
)
View Source
var (
	Question = []*survey.Question{
		{
			Name: "Insurance",
			Prompt: &survey.Input{
				Message: "五种险个人比例, 默认 10.5%",
				Default: "0.105",
			},
			Validate:  survey.Required,
			Transform: survey.Title,
		},
		{
			Name: "Fund",
			Prompt: &survey.Input{
				Message: "公积金个人比例, 默认 7%",
				Default: "0.07",
			},
			Validate:  survey.Required,
			Transform: survey.Title,
		},
		{
			Name: "Salary",
			Prompt: &survey.Input{
				Message: "月收入",
				Default: "50000",
			},
			Validate:  survey.Required,
			Transform: survey.Title,
		},
		{
			Name: "Deduction",
			Prompt: &survey.Input{
				Message: "专项附加扣除, 包括租房房贷或赡养老人等",
				Default: "0",
			},
			Validate:  survey.Required,
			Transform: survey.Title,
		},
	}
)

Functions

This section is empty.

Types

type Answer

type Answer struct {
	Insurance float64 `survey:"Insurance"`
	Fund      float64 `survey:"Fund"`
	Salary    float64 `survey:"Salary"`
	Deduction float64 `survey:"Deduction"`
}

Answer ...

type MonthIncome

type MonthIncome struct {
	Month       int    `table:"月份"`
	Salary      uint64 `table:"月收入(税前)"`
	TotalSalary uint64 `table:"年收入(税前)"`
	Insurance   string `table:"月缴社保"`
	Fund        string `table:"月缴公积金"`
	Tax         string `table:"月个税"`
	Income      uint64 `table:"月收入"`
	TotalIncome uint64 `table:"年收入"`
}

MonthIncome 月收入信息

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL