Skip to content

Commit

Permalink
improve the tax calculation based on given income/expenses
Browse files Browse the repository at this point in the history
  • Loading branch information
krustowski committed Feb 2, 2024
1 parent bbb19a4 commit 620e892
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

APP_NAME=swis-api
APP_ROOT=/opt/${APP_NAME}
APP_VERSION=5.11.6
APP_VERSION=5.11.7


#
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @title swis-api (swapi) v5
// @version 5.11.6
// @version 5.11.7
// @description sakalWeb Information System v5 RESTful API documentation
// @termsOfService http://swagger.io/terms/

Expand Down
13 changes: 11 additions & 2 deletions pkg/finance/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,17 @@ func DoTaxesByOwner(ctx *gin.Context) {
}
}
}

tax.Base += tax.IncomeTotal - tax.ExpenseTotal

// define the tax constants
const incTaxRate = 0.15
const expRate60 = 0.60

// calculate the base for the income tax
tax.Base = tax.IncomeTotal - tax.ExpenseTotal

// calculate two estimations of the income tax
tax.IncomeTaxEstAbs = tax.Base * (1 - incTaxRate)
tax.IncomeTaxEst60 = (tax.IncomeTotal * (1 - expRate60) * (1 - incTaxRate))

ctx.IndentedJSON(http.StatusOK, gin.H{
"code": http.StatusOK,
Expand Down
6 changes: 6 additions & 0 deletions pkg/finance/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,10 @@ type Tax struct {

// Difference between incomes and expenses. Base for income tax.
Base float64 `json:"base_sum"`

// Absolute estimation of the income tax per year, from given totals.
IncomeTaxEstAbs float64 `json:"income_tax_estimation_abs"`

// Weighted estimation of the income tax, where 60% of income are meant as expenses.
IncomeTaxEst60 float64 `json:"income_tax_estimation_60"`
}

0 comments on commit 620e892

Please sign in to comment.