WIP
This commit is contained in:
@@ -14,9 +14,13 @@ Namespace Winline
|
||||
|
||||
Public Accounts As New List(Of Account)
|
||||
Public Mandators As New List(Of Mandator)
|
||||
Public DocumentKinds As New List(Of DocumentKind)
|
||||
Public Years As List(Of Integer)
|
||||
|
||||
Public Const ALL_MESOCOMP = "mesocomp"
|
||||
|
||||
Public Const V21_ARTICLENUMBER = "c011"
|
||||
Public Const V21_REPLACEMENTARTICLENUMBER = "c123"
|
||||
|
||||
Public Const V50_ACCOUNTNUMBER = "c002"
|
||||
Public Const V50_ACCOUNTNAME = "c003"
|
||||
@@ -37,10 +41,12 @@ Namespace Winline
|
||||
Config = pConfig
|
||||
End Sub
|
||||
|
||||
<DebuggerStepThrough>
|
||||
Public Function GetWinLineYear(pYear As Integer)
|
||||
Return (pYear - 1900) * 12
|
||||
End Function
|
||||
|
||||
<DebuggerStepThrough>
|
||||
Public Function GetWinLineYear()
|
||||
Return GetWinLineYear(Config.GetYear)
|
||||
End Function
|
||||
@@ -111,42 +117,51 @@ Namespace Winline
|
||||
Years = oRange
|
||||
End Sub
|
||||
|
||||
Public Function GetDocumentKinds(pMandator As Mandator, pYear As Integer) As List(Of DocumentKind)
|
||||
Public Sub LoadDocumentKinds(pMandators As List(Of Mandator))
|
||||
Dim oDocumentKinds As New List(Of DocumentKind)
|
||||
Dim oMandatorString = String.Join(",", pMandators.Select(Function(m) $"'{m.Id}'").ToArray)
|
||||
Dim oYear As Integer = GetWinLineYear()
|
||||
|
||||
Try
|
||||
Dim oSQL = $"
|
||||
SELECT
|
||||
[c030],
|
||||
[c001]
|
||||
FROM [t357] (NOLOCK)
|
||||
WHERE (
|
||||
[c001] LIKE 'Werk%(VK)' OR
|
||||
[c001] LIKE 'Werk%(WK)'
|
||||
)
|
||||
AND [mesocomp] = '{pMandator.Id}' AND [mesoyear] = {pYear}"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
||||
|
||||
If oTable.Rows.Count = 0 Then
|
||||
Logger.Warn("No DocumentKinds found")
|
||||
Return oDocumentKinds
|
||||
DocumentKinds.Clear()
|
||||
|
||||
End If
|
||||
For Each oMandator As Mandator In pMandators
|
||||
Try
|
||||
Dim oSQL = $"
|
||||
SELECT
|
||||
[c030],
|
||||
[c001],
|
||||
[mesocomp]
|
||||
FROM [{oMandator.Database}].[dbo].[t357] (NOLOCK)
|
||||
WHERE (
|
||||
[c001] LIKE 'Werk%(VK)' OR
|
||||
[c001] LIKE 'Werk%(WK)'
|
||||
)
|
||||
AND [mesocomp] = '{oMandator.Id}' AND [mesoyear] = {oYear}"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
oDocumentKinds.Add(New DocumentKind With {
|
||||
.Id = oRow.Item(T357_KINDID),
|
||||
.Name = oRow.Item(T357_KINDNAME)
|
||||
})
|
||||
Next
|
||||
If oTable.Rows.Count = 0 Then
|
||||
Logger.Warn("No DocumentKinds found for Mandator [{0}]", oMandator.Id)
|
||||
Continue For
|
||||
End If
|
||||
|
||||
Return oDocumentKinds
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Could not load DocumentKinds")
|
||||
Logger.Error(ex)
|
||||
Return oDocumentKinds
|
||||
End Try
|
||||
End Function
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
oDocumentKinds.Add(New DocumentKind With {
|
||||
.Id = oRow.Item(T357_KINDID),
|
||||
.Name = oRow.Item(T357_KINDNAME),
|
||||
.Mandator = oRow.Item(ALL_MESOCOMP)
|
||||
})
|
||||
Next
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Could not load DocumentKinds")
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
Next
|
||||
|
||||
DocumentKinds = oDocumentKinds.ToList()
|
||||
|
||||
End Sub
|
||||
|
||||
Public Function TryGetAccount(pGLN As String, pMandator As Mandator) As Account
|
||||
Try
|
||||
@@ -200,13 +215,13 @@ Namespace Winline
|
||||
Dim oYear As Integer = GetWinLineYear()
|
||||
Dim oSQL As String = $"
|
||||
SELECT
|
||||
[c011], -- Artikelnummer
|
||||
[c003], -- Artikelbezeichnung
|
||||
[c075], -- EAN-Nummer
|
||||
[c123] -- Ersatzartikelnummer
|
||||
FROM [{pMandator.Database}].[dbo].[v021]
|
||||
WHERE [c075] = '{pEAN}'
|
||||
AND [mesocomp] = '{pMandator.Id}' AND [mesoyear] = {oYear}"
|
||||
[c011], -- Artikelnummer
|
||||
[c003], -- Artikelbezeichnung
|
||||
[c075], -- EAN-Nummer
|
||||
[c123] -- Ersatzartikelnummer
|
||||
FROM [{pMandator.Database}].[dbo].[v021]
|
||||
WHERE [c075] = '{pEAN}'
|
||||
AND [mesocomp] = '{pMandator.Id}' AND [mesoyear] = {oYear}"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
||||
|
||||
' EAN not found in this Mandator, continue to next one
|
||||
@@ -234,6 +249,47 @@ Namespace Winline
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetReplacementArticleNumber(pArticleNumber As String, pMandator As Mandator)
|
||||
Try
|
||||
Dim oYear As Integer = GetWinLineYear()
|
||||
Dim oSQL As String = $"
|
||||
SELECT
|
||||
[c011], -- Artikelnummer
|
||||
[c003], -- Artikelbezeichnung
|
||||
[c075], -- EAN-Nummer
|
||||
[c123] -- Ersatzartikelnummer
|
||||
FROM [{pMandator.Database}].[dbo].[v021]
|
||||
WHERE [c011] = '{pArticleNumber}'
|
||||
AND [mesocomp] = '{pMandator.Id}' AND [mesoyear] = {oYear}"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
||||
|
||||
' ArticleNumber not found in this Mandator, continue to next one
|
||||
If oTable.Rows.Count = 0 Then
|
||||
Logger.Debug("ArticleNumber [{0}] was not found in Mandator: [{1}]", pArticleNumber, pMandator.Id)
|
||||
Return Nothing
|
||||
|
||||
End If
|
||||
|
||||
' Duplicate EAN, exit and do nothing about this number
|
||||
If oTable.Rows.Count > 1 Then
|
||||
Logger.Warn("ArticleNumber [{0}] was found more than once", pArticleNumber)
|
||||
Return Nothing
|
||||
|
||||
End If
|
||||
|
||||
Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
Dim oReplacementArticleNumber = Utils.NotNull(oRow.Item(V21_REPLACEMENTARTICLENUMBER), Nothing)
|
||||
|
||||
If oReplacementArticleNumber Is Nothing Then
|
||||
Return pArticleNumber
|
||||
End If
|
||||
|
||||
Return GetReplacementArticleNumber(oReplacementArticleNumber, pMandator)
|
||||
Catch ex As Exception
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function FindMatchingMandatorFromOrder(pData As Schemas.Orders.Input.MESOWebService) As Mandator
|
||||
Dim oPositions As List(Of Schemas.Orders.Input.MESOWebServiceEXIMVRG_ordersT026) = pData.Items.
|
||||
Where(Function(i) TypeOf i Is Schemas.Orders.Input.MESOWebServiceEXIMVRG_ordersT026).
|
||||
|
||||
Reference in New Issue
Block a user