Clean imported documents, first pass of Import form
This commit is contained in:
@@ -29,6 +29,14 @@ Namespace Winline
|
||||
MappingConfig = pMappingConfig
|
||||
End Sub
|
||||
|
||||
Public Enum DocumentType
|
||||
Offer = 1
|
||||
Order = 2
|
||||
DeliverySlip = 3
|
||||
Invoice = 4
|
||||
End Enum
|
||||
|
||||
|
||||
Public Async Function LoadArticles(pMandator As Mandator) As Task
|
||||
Logger.Info("Loading Articles for Mandator [{0}]", pMandator)
|
||||
Dim oYear = Config.GetWinLineYear()
|
||||
@@ -447,6 +455,95 @@ Namespace Winline
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
Public Function GetDocuments(pMandator As Mandator, pDocumentType As DocumentType) As List(Of Document)
|
||||
Try
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
Dim oDocumentType As Integer = pDocumentType
|
||||
Dim oSql = $"
|
||||
SELECT
|
||||
c139 DOCUMENT_TYPE,
|
||||
|
||||
c021 ACCOUNT_NUMBER,
|
||||
c022 RUNNING_NUMBER,
|
||||
|
||||
c043 OFFER_NUMBER,
|
||||
c027 OFFER_DATE,
|
||||
|
||||
c044 ORDER_NUMBER,
|
||||
c028 ORDER_DATE,
|
||||
|
||||
c045 DELIVERY_NUMBER,
|
||||
c029 DELIVERY_DATE,
|
||||
|
||||
c055 INVOICE_NUMBER,
|
||||
c032 INVOICE_DATE,
|
||||
|
||||
mesoyear
|
||||
FROM [{pMandator.Database}].[dbo].[T025]
|
||||
WHERE
|
||||
c139 = {oDocumentType} AND
|
||||
[mesocomp] = '{pMandator.Id}' AND [mesoyear] = {oYear}"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSql)
|
||||
Dim oDocuments As New List(Of Document)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Try
|
||||
Dim oDocument = GetDocumentFromDataRow(oRow)
|
||||
oDocuments.Add(oDocument)
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
|
||||
Next
|
||||
|
||||
Return oDocuments
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Error while loading documents for mandator [{0}] and document type [{1}]", pMandator, pDocumentType)
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetDocumentFromDataRow(pDataRow As DataRow) As Document
|
||||
Dim oAccountNumber = pDataRow.Item("ACCOUNT_NUMBER")
|
||||
Dim oRunningNumber As String = pDataRow.Item("RUNNING_NUMBER")
|
||||
Dim oDocumentType As Integer = pDataRow.Item("DOCUMENT_TYPE")
|
||||
Dim oDocumentNumber As String = Nothing
|
||||
Dim oDocumentDate As Date = Nothing
|
||||
|
||||
Dim oAccount = Accounts.
|
||||
Where(Function(acc) acc.Id = oAccountNumber).
|
||||
FirstOrDefault()
|
||||
|
||||
Select Case oDocumentType
|
||||
Case 1
|
||||
oDocumentNumber = pDataRow.Item("OFFER_NUMBER")
|
||||
oDocumentDate = pDataRow.Item("OFFER_DATE")
|
||||
Case 2
|
||||
oDocumentNumber = pDataRow.Item("ORDER_NUMBER")
|
||||
oDocumentDate = pDataRow.Item("ORDER_DATE")
|
||||
Case 3
|
||||
oDocumentNumber = pDataRow.Item("DELIVERY_NUMBER")
|
||||
oDocumentDate = pDataRow.Item("DELIVERY_DATE")
|
||||
Case 4
|
||||
oDocumentNumber = pDataRow.Item("INVOICE_NUMBER")
|
||||
oDocumentDate = pDataRow.Item("INVOICE_DATE")
|
||||
|
||||
End Select
|
||||
|
||||
Dim oDocument As New Document With {
|
||||
.Account = oAccount,
|
||||
.RunningNumber = oRunningNumber,
|
||||
.Number = oDocumentNumber,
|
||||
.[Date] = oDocumentDate
|
||||
}
|
||||
|
||||
Return oDocument
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Turns a database info like "SQLCWLDATEN on SERVER\INSTANCE" into a Tuple of two strings
|
||||
''' </summary>
|
||||
|
||||
Reference in New Issue
Block a user