Author:水如烟
测试:
类:
测试:
Dim r As New LzmTW.Common.RatePayingClass
'测试,不分层级
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
r.TaxArray = New Object() {100, 0.03}
For i As Integer = 50 To 300 Step 50
Console.WriteLine(r.Calculating(i).ToString)
Next
End Sub
'结果
'收入额: 50 起征点: 100 应纳税所得额: 0 速算扣除额: 0 税率: 0 扣缴所得税: 0 税后所得额: 50
'收入额: 100 起征点: 100 应纳税所得额: 0 速算扣除额: 0 税率: 0 扣缴所得税: 0 税后所得额: 100
'收入额: 150 起征点: 100 应纳税所得额: 50 速算扣除额: 0 税率: 0.03 扣缴所得税: 1.5 税后所得额: 148.5
'收入额: 200 起征点: 100 应纳税所得额: 100 速算扣除额: 0 税率: 0.03 扣缴所得税: 3 税后所得额: 197
'收入额: 250 起征点: 100 应纳税所得额: 150 速算扣除额: 0 税率: 0.03 扣缴所得税: 4.5 税后所得额: 245.5
'收入额: 300 起征点: 100 应纳税所得额: 200 速算扣除额: 0 税率: 0.03 扣缴所得税: 6 税后所得额: 294
'测试,分层级
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
r.TaxArray = New Object() {1000, 500, 0.05, 2000, 0.1, 5000, 0.15, 20000, 0.2, 40000, 0.25, 60000, 0.3, 80000, 0.35, 100000, 0.4, 0.45}
For Each i As Decimal In New Decimal() {500, 1000, 2000, 4000, 50000, 100000, 1000000}
Console.WriteLine(r.Calculating(i).ToString)
Next
r.TaxArray = New Object() {1600, 500, 0.05, 2000, 0.1, 5000, 0.15, 20000, 0.2, 40000, 0.25, 60000, 0.3, 80000, 0.35, 100000, 0.4, 0.45}
For Each i As Decimal In New Decimal() {500, 1000, 2000, 4000, 50000, 100000, 1000000}
Console.WriteLine(r.Calculating(i).ToString)
Next
End Sub
'结果
'收入额: 500 起征点: 1000 应纳税所得额: 0 速算扣除额: 0 税率: 0 扣缴所得税: 0 税后所得额: 500
'收入额: 1000 起征点: 1000 应纳税所得额: 0 速算扣除额: 0 税率: 0 扣缴所得税: 0 税后所得额: 1000
'收入额: 2000 起征点: 1000 应纳税所得额: 1000 速算扣除额: 25 税率: 0.1 扣缴所得税: 75 税后所得额: 1925
'收入额: 4000 起征点: 1000 应纳税所得额: 3000 速算扣除额: 125 税率: 0.15 扣缴所得税: 325 税后所得额: 3675
'收入额: 50000 起征点: 1000 应纳税所得额: 49000 速算扣除额: 3375 税率: 0.3 扣缴所得税: 11325 税后所得额: 38675
'收入额: 100000 起征点: 1000 应纳税所得额: 99000 速算扣除额: 10375 税率: 0.4 扣缴所得税: 29225 税后所得额: 70775
'收入额: 1000000 起征点: 1000 应纳税所得额: 999000 速算扣除额: 15375 税率: 0.45 扣缴所得税: 434175 税后所得额: 565825
'收入额: 500 起征点: 1600 应纳税所得额: 0 速算扣除额: 0 税率: 0 扣缴所得税: 0 税后所得额: 500
'收入额: 1000 起征点: 1600 应纳税所得额: 0 速算扣除额: 0 税率: 0 扣缴所得税: 0 税后所得额: 1000
'收入额: 2000 起征点: 1600 应纳税所得额: 400 速算扣除额: 0 税率: 0.05 扣缴所得税: 20 税后所得额: 1980
'收入额: 4000 起征点: 1600 应纳税所得额: 2400 速算扣除额: 125 税率: 0.15 扣缴所得税: 235 税后所得额: 3765
'收入额: 50000 起征点: 1600 应纳税所得额: 48400 速算扣除额: 3375 税率: 0.3 扣缴所得税: 11145 税后所得额: 38855
'收入额: 100000 起征点: 1600 应纳税所得额: 98400 速算扣除额: 10375 税率: 0.4 扣缴所得税: 28985 税后所得额: 71015
'收入额: 1000000 起征点: 1600 应纳税所得额: 998400 速算扣除额: 15375 税率: 0.45 扣缴所得税: 433905 税后所得额: 566095
'测试,不分层级
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
r.TaxArray = New Object() {100, 0.03}
For i As Integer = 50 To 300 Step 50
Console.WriteLine(r.Calculating(i).ToString)
Next
End Sub
'结果
'收入额: 50 起征点: 100 应纳税所得额: 0 速算扣除额: 0 税率: 0 扣缴所得税: 0 税后所得额: 50
'收入额: 100 起征点: 100 应纳税所得额: 0 速算扣除额: 0 税率: 0 扣缴所得税: 0 税后所得额: 100
'收入额: 150 起征点: 100 应纳税所得额: 50 速算扣除额: 0 税率: 0.03 扣缴所得税: 1.5 税后所得额: 148.5
'收入额: 200 起征点: 100 应纳税所得额: 100 速算扣除额: 0 税率: 0.03 扣缴所得税: 3 税后所得额: 197
'收入额: 250 起征点: 100 应纳税所得额: 150 速算扣除额: 0 税率: 0.03 扣缴所得税: 4.5 税后所得额: 245.5
'收入额: 300 起征点: 100 应纳税所得额: 200 速算扣除额: 0 税率: 0.03 扣缴所得税: 6 税后所得额: 294
'测试,分层级
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
r.TaxArray = New Object() {1000, 500, 0.05, 2000, 0.1, 5000, 0.15, 20000, 0.2, 40000, 0.25, 60000, 0.3, 80000, 0.35, 100000, 0.4, 0.45}
For Each i As Decimal In New Decimal() {500, 1000, 2000, 4000, 50000, 100000, 1000000}
Console.WriteLine(r.Calculating(i).ToString)
Next
r.TaxArray = New Object() {1600, 500, 0.05, 2000, 0.1, 5000, 0.15, 20000, 0.2, 40000, 0.25, 60000, 0.3, 80000, 0.35, 100000, 0.4, 0.45}
For Each i As Decimal In New Decimal() {500, 1000, 2000, 4000, 50000, 100000, 1000000}
Console.WriteLine(r.Calculating(i).ToString)
Next
End Sub
'结果
'收入额: 500 起征点: 1000 应纳税所得额: 0 速算扣除额: 0 税率: 0 扣缴所得税: 0 税后所得额: 500
'收入额: 1000 起征点: 1000 应纳税所得额: 0 速算扣除额: 0 税率: 0 扣缴所得税: 0 税后所得额: 1000
'收入额: 2000 起征点: 1000 应纳税所得额: 1000 速算扣除额: 25 税率: 0.1 扣缴所得税: 75 税后所得额: 1925
'收入额: 4000 起征点: 1000 应纳税所得额: 3000 速算扣除额: 125 税率: 0.15 扣缴所得税: 325 税后所得额: 3675
'收入额: 50000 起征点: 1000 应纳税所得额: 49000 速算扣除额: 3375 税率: 0.3 扣缴所得税: 11325 税后所得额: 38675
'收入额: 100000 起征点: 1000 应纳税所得额: 99000 速算扣除额: 10375 税率: 0.4 扣缴所得税: 29225 税后所得额: 70775
'收入额: 1000000 起征点: 1000 应纳税所得额: 999000 速算扣除额: 15375 税率: 0.45 扣缴所得税: 434175 税后所得额: 565825
'收入额: 500 起征点: 1600 应纳税所得额: 0 速算扣除额: 0 税率: 0 扣缴所得税: 0 税后所得额: 500
'收入额: 1000 起征点: 1600 应纳税所得额: 0 速算扣除额: 0 税率: 0 扣缴所得税: 0 税后所得额: 1000
'收入额: 2000 起征点: 1600 应纳税所得额: 400 速算扣除额: 0 税率: 0.05 扣缴所得税: 20 税后所得额: 1980
'收入额: 4000 起征点: 1600 应纳税所得额: 2400 速算扣除额: 125 税率: 0.15 扣缴所得税: 235 税后所得额: 3765
'收入额: 50000 起征点: 1600 应纳税所得额: 48400 速算扣除额: 3375 税率: 0.3 扣缴所得税: 11145 税后所得额: 38855
'收入额: 100000 起征点: 1600 应纳税所得额: 98400 速算扣除额: 10375 税率: 0.4 扣缴所得税: 28985 税后所得额: 71015
'收入额: 1000000 起征点: 1600 应纳税所得额: 998400 速算扣除额: 15375 税率: 0.45 扣缴所得税: 433905 税后所得额: 566095
类:
''' -----------------------------------------------------------------------------
''' Project : LzmTW.Common
''' Class : Common.RatePayingClass
'''
''' -----------------------------------------------------------------------------
''' <summary>
''' 计税类
''' </summary>
''' <remarks>
''' 计税信息,如不分层级,按 RatePayingClass.TaxArray = New Object() {100, 0.03}
''' 分层级,则按 RatePayingClass.TaxArray = New Object() {1600, 500, 0.05, 2000, 0.1, 5000, 0.15, 20000, 0.2, 40000, 0.25, 60000, 0.3, 80000, 0.35, 100000, 0.4, 0.45}赋值
''' </remarks>
''' <history>
''' [lzmtw] 2005-10-29 Created
''' </history>
''' -----------------------------------------------------------------------------
Public Class RatePayingClass
'_TaxArray 有两种情形:
'一是不分层级,即_TaxArray={0,30%},表不设起征点全按30%纳税,或_TaxArray={1000,30%}表示超过起征点1000的按30%纳税;
'二是分层级,属下列情形,表示超过起征点1000的,
'不足500纳5%,
'不足2000纳10%,
'不足5000纳15%,
'不足20000纳20%,
'不足40000纳25%,
'不足60000纳30%,
'不足80000纳35%,
'不足100000纳40%,
'超(含)100000纳45%。
Private _TaxArray() As Object = {1000, 500, 0.05, 2000, 0.1, 5000, 0.15, 20000, 0.2, 40000, 0.25, 60000, 0.3, 80000, 0.35, 100000, 0.4, 0.45}
Private _Point As Single '起征点
Private _Rates() As Single '税率组
Private _InPoints() As Single '对应税率的应纳税所得额组
Private _SpeedyCalculation() As Single '对应税率的速算扣除额
Private _PlyRating As Boolean '是否分层级纳税
''' -----------------------------------------------------------------------------
''' <summary>
''' 计税信息,第一位为起征点,后面为税率或区段税率
''' </summary>
''' <value></value>
''' <remarks>
''' 例如 {1000, 500, 0.05, 2000, 0.1, 5000, 0.15, 20000, 0.2, 40000, 0.25, 60000, 0.3, 80000, 0.35, 100000, 0.4, 0.45}或{1000,30%}
''' </remarks>
''' <history>
''' [lzmtw] 2005-10-29 Created
''' </history>
''' -----------------------------------------------------------------------------
Public WriteOnly Property TaxArray() As Object()
Set(ByVal Value As Object())
_TaxArray = Value
Me.Initiallize()
End Set
End Property
Sub New()
Me.Initiallize()
End Sub
'初始有关参数
Private Sub Initiallize()
Dim PointLength As Integer = _TaxArray.Length / 2
ReDim _Rates(PointLength)
ReDim _InPoints(PointLength)
ReDim _SpeedyCalculation(PointLength)
_Point = _TaxArray(0) '起征点
If PointLength = 1 Then '不分层级情形
_PlyRating = False
_Rates(1) = _TaxArray(1)
Else '分层级情形()
_PlyRating = True
'赋税率和区段值
For i As Integer = 1 To PointLength - 1
_InPoints(i) = _TaxArray(2 * i - 1)
_Rates(i) = _TaxArray(2 * i)
Next
'最后一级
_InPoints(PointLength) = Decimal.MaxValue
_Rates(PointLength) = _TaxArray(_TaxArray.Length - 1)
'以下计算速算值
'先计区段税
Dim tmp(PointLength) As Decimal
For i As Integer = 1 To PointLength - 1
tmp(i) = tmp(i - 1) + (_InPoints(i) - _InPoints(i - 1)) * _Rates(i)
Next
'计速算值
For i As Integer = 1 To PointLength
_SpeedyCalculation(i) = _InPoints(i - 1) * _Rates(i) - tmp(i - 1)
Next
End If
End Sub
'分层级纳税情形,定位适应税率索引
Private Function PointsIndex(ByVal IncomePaying As Decimal) As Integer
Dim Index As Integer = 1
Dim HaveFinish As Boolean = False
While Not HaveFinish
If _InPoints(Index) >= IncomePaying Then
HaveFinish = True
Else
Index += 1
End If
If Index = _InPoints.Length - 1 Then HaveFinish = True
End While
Return Index
End Function
''' -----------------------------------------------------------------------------
''' <summary>
''' 计算
''' </summary>
''' <param name="Income">收入额</param>
''' <returns></returns>
''' <remarks>
''' </remarks>
''' <history>
''' [lzmtw] 2005-10-29 Created
''' </history>
''' -----------------------------------------------------------------------------
Public Function Calculating(ByVal Income As Decimal) As Result
Dim tmpResult As Result
Dim IncomePaying As Decimal = Income - _Point '应纳税所得额
If IncomePaying <= 0 Then '应纳税所得额不足起征点
tmpResult = New Result(Income, _Point, 0, 0, 0)
Else '应纳税所得额大于起征点
If Not _PlyRating Then '不分层级的缴税
tmpResult = New Result(Income, _Point, _Rates(1), 0, IncomePaying * _Rates(1))
Else '分层级的缴税
Dim Index As Integer = PointsIndex(IncomePaying)
tmpResult = New Result(Income, _Point, _Rates(Index), _SpeedyCalculation(Index), IncomePaying * _Rates(Index) - _SpeedyCalculation(Index))
End If
End If
Return tmpResult
End Function
'输出信息
Public Class Result
Private _收入额 As Decimal
Private _起征点 As Single
Private _税率 As Single
Private _速算扣除额 As Single
Private _扣缴所得税 As Decimal
Sub New(ByVal Income As Decimal, ByVal PayPoint As Single, ByVal Rate As Single, ByVal SpeedCalPoint As Single, ByVal Tax As Decimal)
Me._收入额 = Income
Me._起征点 = PayPoint
Me._税率 = Rate
Me._速算扣除额 = SpeedCalPoint
Me._扣缴所得税 = Tax
End Sub
Public ReadOnly Property 税后所得额() As Decimal
Get
Return Me._收入额 - Me._扣缴所得税
End Get
End Property
Public ReadOnly Property 扣缴所得税() As Decimal
Get
Return Me._扣缴所得税
End Get
End Property
Public ReadOnly Property 速算扣除额() As Single
Get
Return Me._速算扣除额
End Get
End Property
Public ReadOnly Property 税率() As Single
Get
Return Me._税率
End Get
End Property
Public ReadOnly Property 应纳税所得额() As Decimal
Get
Return IIf((Me._收入额 - Me.起征点) > 0, Me._收入额 - Me.起征点, 0)
End Get
End Property
Public ReadOnly Property 起征点() As Single
Get
Return Me._起征点
End Get
End Property
Public ReadOnly Property 收入额() As Decimal
Get
Return Me._收入额
End Get
End Property
Public Overrides Function ToString() As String
Return String.Format("收入额: {0} 起征点: {1} 应纳税所得额: {2} 速算扣除额: {3} 税率: {4} 扣缴所得税: {5} 税后所得额: {6}", Me.收入额, Me.起征点, Me.应纳税所得额, Me.速算扣除额, Me.税率, Me.扣缴所得税, Me.税后所得额)
End Function
End Class
End Class
''' Project : LzmTW.Common
''' Class : Common.RatePayingClass
'''
''' -----------------------------------------------------------------------------
''' <summary>
''' 计税类
''' </summary>
''' <remarks>
''' 计税信息,如不分层级,按 RatePayingClass.TaxArray = New Object() {100, 0.03}
''' 分层级,则按 RatePayingClass.TaxArray = New Object() {1600, 500, 0.05, 2000, 0.1, 5000, 0.15, 20000, 0.2, 40000, 0.25, 60000, 0.3, 80000, 0.35, 100000, 0.4, 0.45}赋值
''' </remarks>
''' <history>
''' [lzmtw] 2005-10-29 Created
''' </history>
''' -----------------------------------------------------------------------------
Public Class RatePayingClass
'_TaxArray 有两种情形:
'一是不分层级,即_TaxArray={0,30%},表不设起征点全按30%纳税,或_TaxArray={1000,30%}表示超过起征点1000的按30%纳税;
'二是分层级,属下列情形,表示超过起征点1000的,
'不足500纳5%,
'不足2000纳10%,
'不足5000纳15%,
'不足20000纳20%,
'不足40000纳25%,
'不足60000纳30%,
'不足80000纳35%,
'不足100000纳40%,
'超(含)100000纳45%。
Private _TaxArray() As Object = {1000, 500, 0.05, 2000, 0.1, 5000, 0.15, 20000, 0.2, 40000, 0.25, 60000, 0.3, 80000, 0.35, 100000, 0.4, 0.45}
Private _Point As Single '起征点
Private _Rates() As Single '税率组
Private _InPoints() As Single '对应税率的应纳税所得额组
Private _SpeedyCalculation() As Single '对应税率的速算扣除额
Private _PlyRating As Boolean '是否分层级纳税
''' -----------------------------------------------------------------------------
''' <summary>
''' 计税信息,第一位为起征点,后面为税率或区段税率
''' </summary>
''' <value></value>
''' <remarks>
''' 例如 {1000, 500, 0.05, 2000, 0.1, 5000, 0.15, 20000, 0.2, 40000, 0.25, 60000, 0.3, 80000, 0.35, 100000, 0.4, 0.45}或{1000,30%}
''' </remarks>
''' <history>
''' [lzmtw] 2005-10-29 Created
''' </history>
''' -----------------------------------------------------------------------------
Public WriteOnly Property TaxArray() As Object()
Set(ByVal Value As Object())
_TaxArray = Value
Me.Initiallize()
End Set
End Property
Sub New()
Me.Initiallize()
End Sub
'初始有关参数
Private Sub Initiallize()
Dim PointLength As Integer = _TaxArray.Length / 2
ReDim _Rates(PointLength)
ReDim _InPoints(PointLength)
ReDim _SpeedyCalculation(PointLength)
_Point = _TaxArray(0) '起征点
If PointLength = 1 Then '不分层级情形
_PlyRating = False
_Rates(1) = _TaxArray(1)
Else '分层级情形()
_PlyRating = True
'赋税率和区段值
For i As Integer = 1 To PointLength - 1
_InPoints(i) = _TaxArray(2 * i - 1)
_Rates(i) = _TaxArray(2 * i)
Next
'最后一级
_InPoints(PointLength) = Decimal.MaxValue
_Rates(PointLength) = _TaxArray(_TaxArray.Length - 1)
'以下计算速算值
'先计区段税
Dim tmp(PointLength) As Decimal
For i As Integer = 1 To PointLength - 1
tmp(i) = tmp(i - 1) + (_InPoints(i) - _InPoints(i - 1)) * _Rates(i)
Next
'计速算值
For i As Integer = 1 To PointLength
_SpeedyCalculation(i) = _InPoints(i - 1) * _Rates(i) - tmp(i - 1)
Next
End If
End Sub
'分层级纳税情形,定位适应税率索引
Private Function PointsIndex(ByVal IncomePaying As Decimal) As Integer
Dim Index As Integer = 1
Dim HaveFinish As Boolean = False
While Not HaveFinish
If _InPoints(Index) >= IncomePaying Then
HaveFinish = True
Else
Index += 1
End If
If Index = _InPoints.Length - 1 Then HaveFinish = True
End While
Return Index
End Function
''' -----------------------------------------------------------------------------
''' <summary>
''' 计算
''' </summary>
''' <param name="Income">收入额</param>
''' <returns></returns>
''' <remarks>
''' </remarks>
''' <history>
''' [lzmtw] 2005-10-29 Created
''' </history>
''' -----------------------------------------------------------------------------
Public Function Calculating(ByVal Income As Decimal) As Result
Dim tmpResult As Result
Dim IncomePaying As Decimal = Income - _Point '应纳税所得额
If IncomePaying <= 0 Then '应纳税所得额不足起征点
tmpResult = New Result(Income, _Point, 0, 0, 0)
Else '应纳税所得额大于起征点
If Not _PlyRating Then '不分层级的缴税
tmpResult = New Result(Income, _Point, _Rates(1), 0, IncomePaying * _Rates(1))
Else '分层级的缴税
Dim Index As Integer = PointsIndex(IncomePaying)
tmpResult = New Result(Income, _Point, _Rates(Index), _SpeedyCalculation(Index), IncomePaying * _Rates(Index) - _SpeedyCalculation(Index))
End If
End If
Return tmpResult
End Function
'输出信息
Public Class Result
Private _收入额 As Decimal
Private _起征点 As Single
Private _税率 As Single
Private _速算扣除额 As Single
Private _扣缴所得税 As Decimal
Sub New(ByVal Income As Decimal, ByVal PayPoint As Single, ByVal Rate As Single, ByVal SpeedCalPoint As Single, ByVal Tax As Decimal)
Me._收入额 = Income
Me._起征点 = PayPoint
Me._税率 = Rate
Me._速算扣除额 = SpeedCalPoint
Me._扣缴所得税 = Tax
End Sub
Public ReadOnly Property 税后所得额() As Decimal
Get
Return Me._收入额 - Me._扣缴所得税
End Get
End Property
Public ReadOnly Property 扣缴所得税() As Decimal
Get
Return Me._扣缴所得税
End Get
End Property
Public ReadOnly Property 速算扣除额() As Single
Get
Return Me._速算扣除额
End Get
End Property
Public ReadOnly Property 税率() As Single
Get
Return Me._税率
End Get
End Property
Public ReadOnly Property 应纳税所得额() As Decimal
Get
Return IIf((Me._收入额 - Me.起征点) > 0, Me._收入额 - Me.起征点, 0)
End Get
End Property
Public ReadOnly Property 起征点() As Single
Get
Return Me._起征点
End Get
End Property
Public ReadOnly Property 收入额() As Decimal
Get
Return Me._收入额
End Get
End Property
Public Overrides Function ToString() As String
Return String.Format("收入额: {0} 起征点: {1} 应纳税所得额: {2} 速算扣除额: {3} 税率: {4} 扣缴所得税: {5} 税后所得额: {6}", Me.收入额, Me.起征点, Me.应纳税所得额, Me.速算扣除额, Me.税率, Me.扣缴所得税, Me.税后所得额)
End Function
End Class
End Class