问题描述
我在与某件事斗争了几天,我真的需要你的帮助,因为这对我来说太难了。
我工作的公司有很多债务客户。有时他们无法还清所有债务,所以他们想通过分期/贷款系统还清欠款。我正在使用 VB.NET 处理它。我必须准备将分期付款的单张发票。我可以轻松地将发票拆分为分期付款,每个发票都有付款截止日期,但在此之后,在第二步中,我必须在发票上拆分每期付款。下面是在 Excel 中为 2 个示例发票手动制作的会计示例。我知道代码中使用的循环应该有 2 个“if”条件:Condition1: Installment amonunt = Invoice amount,但是应用程序用户(讨债部门的员工)可以生成混合流(各种每期的金额),其中两个条件都可以满足。
另外的简化是该计划根本不收取利息(更高级别[!决定)。
对于解决此问题的任何帮助或任何线索,我将不胜感激。
也许你们中的一些人以前有过这样的问题?
提前致谢!
解决方法
对于会计应用,我们有一个匹配表来连接发票和收据(分期付款)。安排分期付款时,您会根据 FIFO 相应地匹配发票。因此,您需要将数据更新到匹配表中,同时您需要在发票上有 Amount Match 和 Amountunmatched 字段以跟踪部分付款。
所以当第一个计划完成时
分期付款:第1期
发票:Inv A
未匹配:50
比赛日期:2021-05-15
债务人:ABC
同时需要将 Invoice A amountmatched 更新为 50,amountunmatched 更新为 106.53(未清)
第二期
分期付款:第2期
发票:Inv A
未匹配:50
比赛日期:2021-06-15
债务人:ABC
第三期
分期付款:第3期
发票:Inv A
未匹配:50
比赛日期:2021-07-15
债务人:ABC
第四期,需要更新2条记录
分期付款:第4期
发票:Inv A
不匹配:6.53
比赛日期:2021-08-15
债务人:ABC
分期付款:第4期
发票 : Inv B
未匹配:43.47
比赛日期:2021-08-15
债务人:ABC
你可以看到这个模式与你的桌子非常相似。
在编程部分,您需要输入开始日期和分期付款的日期,以计算每期和最后一期的金额。您可以使用未偿付除以未偿付并四舍五入得到分配给上个月的四舍五入数字。
先将分期付款计划保存到表格中。之后循环分期付款计划并生成匹配表并更新每个循环的未付发票。如果您认为此方法可以解决问题,并且您需要进一步的帮助。你只是让我嗡嗡作响。
,我会输入我想安排的分期付款次数和分期付款前缀,以生成分期付款的交易编号。
代码在这里
Imports System.Data.SqlClient
Public Class frmInstalment
Private Sub btnGenerateInstalment_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnGenerateInstalment.Click
Dim TotalOustanding = Modws.GetDecimalFromQuery("Select Sum(amtunmatched) from Invoice")
Dim InstNo As Integer = Val(txtInstalmentNo.Text)
Dim Balance = TotalOustanding
Dim i As Integer = 1
Do Until i = InstNo + 1
Dim InstalAmount = Math.Ceiling(TotalOustanding / InstNo)
Balance = Balance - InstalAmount
Dim Amount As Decimal
If Balance > 0 Then
Amount = InstalAmount
Else
Amount = InstalAmount + Balance
End If
Dim InstalNo As String = txtInsalPre.Text & i.ToString("00")
Modws.UpdateItem("Insert into Instalment(TransNo,Instalment,Amount) Values('" & InstalNo & "'," & i & "," & Amount & ")")
i = i + 1
Loop
Modws.DisplayDataGrid(dgvInstalment,"Select TransNo,Amount from Instalment Order by TransNo")
For x = 0 To dgvInstalment.Rows.Count - 1
AddMatching(dgvInstalment("TransNo",x).Value,Val(dgvInstalment("Amount",x).Value))
Next
Modws.DisplayDataGrid(dgvResult,"Select * from Matching Order by Instalment")
End Sub
Private Sub AddMatching(InstalmentNo As String,InstAmt As Decimal)
Dim StrConn As String = My.Settings.ImportLinkCS
Dim CN = New SqlConnection(StrConn)
CN.Open()
Dim StrSql As String = "Select * from Invoice Where AMTUNMATCHED <> 0 order by transdate,TransNo"
Dim cmdReader As SqlCommand = New SqlCommand(StrSql,CN)
cmdReader.CommandType = CommandType.Text
Dim SdrReader As SqlDataReader = cmdReader.ExecuteReader(CommandBehavior.CloseConnection)
'SdrReader = cmdReader.ExecuteReader
Try
With SdrReader
If .HasRows Then
While .Read
If .Item("Amtunmatched") > InstAmt Then
Modws.UpdateItem("Update Invoice set amtmatched = amtmatched + " & InstAmt & ",amtunmatched = amtunmatched - " & InstAmt & " Where TransNo = '" & .Item("TransNo") & "'")
Modws.UpdateItem("Insert into Matching(Invoice,Amtmached,InvOutstanding) " + _
"Values('" & .Item("TransNo") & "','" & InstalmentNo & "'," & InstAmt & "," & (.Item("Amtunmatched") - InstAmt) & " )")
Exit Sub
Else
Modws.UpdateItem("Update Invoice set amtmatched = Total,amtunmatched = 0 Where TransNo = '" & .Item("TransNo") & "'")
Modws.UpdateItem("Insert into Matching(Invoice," & .Item("AMTUNMATCHED") & ",0 )")
InstAmt = InstAmt - .Item("Amtunmatched")
End If
End While
End If
End With
Catch ex As System.Exception
MsgBox(ex.Message,MsgBoxStyle.Critical,"Error")
End Try
End Sub
Private Sub btnReset_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnReset.Click
Modws.DeleteItem("Delete from Instalment")
Modws.DeleteItem("Delete from Matching")
Modws.UpdateItem("Update Invoice set amtmatched = 0,amtunmatched = Total")
End Sub
End Class
你还需要在你的程序中添加一个模块类
Imports System.Data
Imports System.Data.SqlClient
Imports ImportLink.GridPrintPreviewLib
Module Modws
Public Function GetDecimalFromQuery(ByVal SQLQuery As String) As Decimal
Dim StrConn As String = My.Settings.ImportLinkCS
Dim CN = New SqlConnection(StrConn)
GetDecimalFromQuery = 0
CN.Open()
Dim StrSql As String = SQLQuery
Dim cmdReader As SqlCommand = New SqlCommand(StrSql,CN)
cmdReader.CommandType = CommandType.Text
Dim SdrReader As SqlDataReader = cmdReader.ExecuteReader(CommandBehavior.CloseConnection)
'SdrReader = cmdReader.ExecuteReader
'GetDoubleFromQuery = 0
Try
With SdrReader
If .HasRows Then
While .Read
If .GetValue(0) Is DBNull.Value Then
'GetDoubleFromQuery = 20
'MsgBox("Null Value")
Else
If IsDBNull(.GetValue(0).ToString) Then
'GetDoubleFromQuery = 50
'MsgBox("Null Value")
Else
GetDecimalFromQuery = .GetValue(0).ToString
End If
End If
End While
Else
'MsgBox("No Row")
End If
End With
CN.Close()
Catch ex As Exception
MsgBox(ex.Message,MsgBoxStyle.Exclamation,"Error")
End Try
End Function
Public Sub UpdateItem(ByVal SqlQuery As String)
Dim StrConn As String = My.Settings.ImportLinkCS
Dim CN = New SqlConnection(StrConn)
Try
CN.Open()
Dim StrSql As String = SqlQuery
Dim cmdupdate As New SqlCommand(StrSql,CN)
cmdupdate.CommandText = StrSql
cmdupdate.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message & SqlQuery,"Error-UpdateItem")
End Try
CN.Close()
CN = Nothing
End Sub
Public Sub DisplayDataGrid(ByVal dgv As DataGridView,ByVal SQLSTR As String)
dgv.DataSource = Nothing
Try
Dim dbBindSource As New BindingSource
Dim strCon As String = My.Settings.ImportLinkCS
Dim strSQL As String = SQLSTR
Dim dataAdapter As SqlDataAdapter = New SqlDataAdapter(strSQL,strCon)
Dim commandBuilder As SqlCommandBuilder = New SqlCommandBuilder(dataAdapter)
'Populate a new data table and bind it to the BindingSource.
Dim table As DataTable = New DataTable()
table.Locale = System.Globalization.CultureInfo.InvariantCulture
dataAdapter.Fill(table)
dbBindSource.DataSource = table
'Resize the DataGridView columns to fit the newly loaded content.
dgv.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader)
dgv.DataSource = dbBindSource
dgv.Columns(2).Width = 200
Catch ex As Exception
MsgBox(ex.Message,"error")
End Try
End Sub
End Module
我试过了,效果很好。另外,您只需要添加customer参数,它就会根据客户进行处理。