去年10月份开始个人所得税支持专项扣除和上调了个税起征点,针对该项改变写了一个小demo,在新政策下计算个人所得税扣除,工资所得,然后将每个月的扣除额度和实际所得额度展示。
截图如下:
直接上源码:
package com.chuck.taxcalculator
import android.app.Activity
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import java.text.DecimalFormat
class MainActivity : Activity() {
private lateinit var salary: EditText
private lateinit var specialDesc: EditText
private lateinit var gongJiJin: EditText
private lateinit var gongjiJinBase: EditText
private lateinit var shebao: EditText
private lateinit var startCalc: Button
private lateinit var result: TextView
/*级数 累计预扣预缴应纳税所得额 预扣税率(%) 速算扣除数
1 不超过36000元的部分 3 0
2 超过36000元至144000元的部分 10 2520
3 超过144000元至300000元的部分 20 16920
4 超过300000元至420000元的部分 25 31920
5 超过420000元至660000元的部分 30 52920
6 超过660000元至960000元的部分 35 85920
7 超过960000元的部分 45 181920
*/
val TOTAL_MONTH = 12
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val df = DecimalFormat("0.00")
salary = findViewById(R.id.salary)
specialDesc = findViewById(R.id.special_desc)
gongJiJin = findViewById(R.id.gongjijin)
shebao = findViewById(R.id.shebao)
startCalc = findViewById(R.id.start_calc)
result = findViewById(R.id.result)
gongjiJinBase = findViewById(R.id.gongjijin_base)
result.visibility = View.INVISIBLE
startCalc.setOnClickListener {
val salaryStr: String = salary.text.toString()
val specialDescStr: String = specialDesc.text.toString()
val gongJiJinStr: String = gongJiJin.text.toString()
val shebaoStr: String = shebao.text.toString()
val gongjijinBase: String = gongjiJinBase.text.toString()
if (salaryStr.isEmpty()
|| specialDescStr.isEmpty()
|| gongJiJinStr.isEmpty()
|| shebaoStr.isEmpty()
) {
Toast.makeText(this, "请完善相关信息", Toast.LENGTH_LONG).show()
return@setOnClickListener
}
result.visibility = View.VISIBLE
val salaryNum = salaryStr.toFloat()
val specialDescNum = specialDescStr.toFloat()
val gongJiJingNum = gongjijinBase.toInt() * (gongJiJinStr.toFloat() / 100)
val shebaoNum = salaryNum * (shebaoStr.toFloat() / 100)
if (salaryNum <= 5000
|| specialDescNum <= 0
|| gongJiJingNum <= 0
|| shebaoNum <= 0
) {
Toast.makeText(this, "相关信息不合法", Toast.LENGTH_LONG).show()
return@setOnClickListener
}
var totalSalaryNum = 0F
var totalTaxNum = 0F
var instantDesc = 0F
val totalBuilder = StringBuilder()
for (index in 1..TOTAL_MONTH) {
val total =
salaryNum * index -
5000 * index -
specialDescNum * index -
gongJiJingNum * index -
shebaoNum * index
var taxNum = 0F
var taxRate = 0F
when (total) {
in 0..36000 -> {
taxNum = total * 0.03F
instantDesc = 0F
taxRate = 0.03F
}
in 36000..144000 -> {
taxNum = total * 0.1F
instantDesc = 2520F
taxRate = 0.1F
}
in 144000..300000 -> {
taxNum = total * 0.2F
instantDesc = 16920F
taxRate = 0.2F
}
in 300000..420000 -> {
taxNum = total * 0.25F
instantDesc = 31920F
taxRate = 0.25F
}
in 420000..660000 -> {
taxNum = total * 0.3F
instantDesc = 52920F
taxRate = 0.3F
}
in 660000..960000 -> {
taxNum = total * 0.35F
instantDesc = 85920F
taxRate = 0.35F
}
else -> {
taxNum = total * 0.45F
instantDesc = 181920F
taxRate = 0.45F
}
}
val actualNum = taxNum - totalTaxNum - instantDesc
totalTaxNum += actualNum
val actualSalary = salaryNum - actualNum - shebaoNum - gongJiJingNum
totalSalaryNum += actualSalary
totalBuilder.append(index)
.append("月份,税额:")
.append(df.format(actualNum))
.append(",当月工资:")
.append(df.format(actualSalary))
.append(",需要纳税的额度:").append(df.format(total))
.append(",适用的税率:").append(taxRate)
.append("\n\n")
}
totalBuilder.append("你的总工资:").append(df.format(totalSalaryNum)).append("\n缴纳的总税额:")
.append(df.format(totalTaxNum)).append("\n公积金年总额(个人&公司):").append(df.format(gongJiJingNum * 2 * 12))
.append("\n\n")
result.text = totalBuilder.toString()
}
}
}
xml视图部分:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
tools:context=".MainActivity">
<LinearLayout
android:background="@null"
android:layout_marginTop="24dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal">
<TextView
android:text="月工资额:"
android:gravity="center|start"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
<EditText
android:id="@+id/salary"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="18sp"
android:gravity="center|start"
android:textCursorDrawable="@drawable/edit_cursor_color"
android:layout_marginStart="8dp"
android:inputType="number"
android:background="@drawable/input_background"
android:hint="月工资额"/>
LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:orientation="horizontal">
<TextView
android:text="专项扣除额度:"
android:gravity="center|start"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
<EditText
android:id="@+id/special_desc"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="18sp"
android:gravity="center|start"
android:layout_marginStart="8dp"
android:inputType="number"
android:textCursorDrawable="@drawable/edit_cursor_color"
android:background="@drawable/input_background"
android:hint="专项扣除额度"/>
LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:orientation="horizontal">
<TextView
android:text="公积金缴费基数:"
android:gravity="center|start"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
<EditText
android:id="@+id/gongjijin_base"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="18sp"
android:gravity="center|start"
android:layout_marginStart="8dp"
android:inputType="number"
android:textCursorDrawable="@drawable/edit_cursor_color"
android:background="@drawable/input_background"
android:hint="基数在支付宝城市服务中可查"/>
LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:orientation="horizontal">
<TextView
android:text="公积金缴费比例:"
android:gravity="center|start"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
<EditText
android:id="@+id/gongjijin"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="18sp"
android:gravity="center|start"
android:layout_marginStart="8dp"
android:inputType="number"
android:textCursorDrawable="@drawable/edit_cursor_color"
android:background="@drawable/input_background"
android:hint="比例12%,则填12"/>
LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:orientation="horizontal">
<TextView
android:text="社保缴费比例:"
android:gravity="center|start"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
<EditText
android:id="@+id/shebao"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="18sp"
android:background="@drawable/input_background"
android:gravity="center|start"
android:textCursorDrawable="@drawable/edit_cursor_color"
android:layout_marginStart="8dp"
android:inputType="number"
android:hint="比例12%,则填12"/>
LinearLayout>
<Button
android:id="@+id/start_calc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:background="@drawable/input_background"
android:layout_margin="16dp"
android:text="开始计算"/>
<TextView
android:id="@+id/result"
android:layout_margin="8dp"
android:textSize="18sp"
android:background="@android:color/darker_gray"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
LinearLayout>
ScrollView>
微信公众号:Android部落格