command

package
v0.0.0-...-c3006eb Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var (
	// InterestCommand ...
	InterestCommand = &cobra.Command{
		Use:     "interest",
		Aliases: []string{"i"},
		Short:   "计算利息",
		Run: func(cmd *cobra.Command, args []string) {
			a := &config.Answer{}
			err := survey.Ask(config.Question, a)
			if err != nil {
				xcolor.Fail(config.Error, fmt.Sprintf("输入错误: %s", err.Error()))
				return
			}
			items := [][]interface{}{
				{
					"金额", a.Capital,
				},
				{
					"利率", fmt.Sprintf("%s %.2f%%", a.RateType, a.RateValue*100),
				},
				{
					"周期", fmt.Sprintf("%d %s", a.PeriodValue, a.PeriodType),
				},
				{
					"方式", a.PayType,
				},
			}
			xcolor.Success(config.Separator)
			xtable.New(items).Style(xtable.Dashed).Border(true).Render()
			xcolor.Success(config.Separator)

			switch a.PayType {
			case config.PayTypeOnce:
				rate := a.GetRateByPeroid()
				fee := a.Capital * rate * float64(a.PeriodValue)
				xcolor.Success(config.Success, fmt.Sprintf("利息: %s", internal.FormatPrice(fee)))
			case config.PayTypeMonthEqualInterest:
				rate, peroid := a.GetMonthValue()
				monthList := CalMonthEqualInterest(a.Capital, rate, peroid)
				xcolor.Success(config.Success, "等额本息")
				xtable.New(monthList).Style(xtable.Dashed).Border(true).Render()
			case config.PayTypeMonthEqualCapital:
				rate, peroid := a.GetMonthValue()
				monthList := CalMonthEqualCapital(a.Capital, rate, peroid)
				xcolor.Success(config.Success, "等额本金")
				xtable.New(monthList).Style(xtable.Dashed).Border(true).Render()
			}
		},
	}
)
View Source
var (
	// TaxCommand ...
	TaxCommand = &cobra.Command{
		Use:     "tax",
		Aliases: []string{"i"},
		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 := &config.TaxAnswer{}
			err := survey.Ask(config.TaxQuestion, 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([]*config.TaxIncome, 0)
			insurance := ans.Salary * ans.Insurance
			fund := ans.Salary * ans.Fund
			for month := 1; month <= 12; month++ {
				totalBase += TaxBase
				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, &config.TaxIncome{
					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)
		},
	}
)

Functions

func CalMonthEqualCapital

func CalMonthEqualCapital(
	capital float64,
	rate float64,
	peroid int,
) []*config.MonthPayment

capital 计算等额本金(总额, 月利率, 周期(月))

func CalMonthEqualInterest

func CalMonthEqualInterest(
	amount float64,
	rate float64,
	peroid int,
) []*config.MonthPayment

CalMonthTotal 计算等额本息(总额, 月利率, 周期(月))

Types

This section is empty.

Jump to

Keyboard shortcuts

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