Created
October 28, 2018 19:19
-
-
Save rifki/4872972c1a187de7941b652f8603cac3 to your computer and use it in GitHub Desktop.
Calculate pph21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strconv" | |
"strings" | |
) | |
// condition|rate|percent | |
var taxRates = [4]string{"<=|50000000|5", "<=|250000000|15", "<=|500000000|25", ">=|500000001|30"} | |
var statusRates = [5]string{"TK0|36000000", "K0|39000000", "K1|42000000", "K2|45000000", "K3|48000000"} | |
// MAIN | |
func main() { | |
var gapok int | |
fmt.Print("Enter your monthly salary : IDR ") | |
_, err := fmt.Scanf("%d\n", &gapok) | |
if err != nil { | |
fmt.Println("Failed, Please input your salary(monthly).") | |
return | |
} | |
fmt.Println("______________________________________________") | |
fmt.Println("TK0 - Single") | |
fmt.Println("K0 - Married with no dependant") | |
fmt.Println("K1 - Married with 1 dependant") | |
fmt.Println("K2 - Married with 2 dependants") | |
fmt.Println("K3 - Married with 3 dependants") | |
var status string | |
fmt.Print("Enter your married status (e.g K1) : ") | |
_, err = fmt.Scanf("%s\n", &status) | |
if err != nil { | |
fmt.Println("Failed, Please input your married status, See example above. 👆") | |
return | |
} | |
// cacl | |
calcTaxableIncome := calcTaxableIncome(gapok, strings.ToUpper(status)) | |
calcTaxIncome := calcTaxIncome(calcTaxableIncome) | |
// result | |
fmt.Println("______________________________________________") | |
fmt.Println("") | |
fmt.Println("Annual taxable income = IDR ", calcTaxableIncome) | |
fmt.Println("Annual tax income = IDR ", calcTaxIncome) | |
} | |
func calcTaxableIncome(incomePermonth int, statusInput string) int { | |
result := 0 | |
for i := 0; i < len(statusRates); i++ { | |
arr := strings.Split(statusRates[i], "|") | |
status := arr[0] | |
rate := arr[1] | |
if statusInput == status { | |
parseRate, err := strconv.Atoi(rate) | |
if err != nil { | |
panic("Parse to integer error!") | |
} | |
result = (incomePermonth * 12) - parseRate | |
break | |
} | |
} | |
return result | |
} | |
func calcTaxIncome(annualIncome int) int { | |
result := 0 | |
for i := 0; i < len(taxRates); i++ { | |
value := strings.Split(taxRates[i], "|") | |
math := value[0] | |
max, err := strconv.Atoi(value[1]) | |
percent, err := strconv.Atoi(value[2]) | |
if err != nil { | |
panic("Parse to integer error!") | |
} | |
if math == "<=" { | |
if annualIncome <= max { | |
result = (percent * annualIncome) / 100 | |
break | |
} | |
} else if math == ">=" { | |
result = (percent * annualIncome) / 100 | |
break | |
} | |
} | |
return result | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OUTPUT:
$ go run calculatepph21.go
Enter your monthly salary : IDR 4500000
TK0 - Single
K0 - Married with no dependant
K1 - Married with 1 dependant
K2 - Married with 2 dependants
K3 - Married with 3 dependants
Enter your married status (e.g K1) : k1
Annual taxable income = IDR 12000000
Annual tax income = IDR 600000