implement searching for alternative field for accounts
This commit is contained in:
@@ -430,7 +430,8 @@ Namespace Documents
|
||||
End If
|
||||
|
||||
' Try to find an account that matches the GLN
|
||||
Dim oAccount = Winline.TryGetAccount(oNumberItem.Original, pMandator)
|
||||
Dim oAlternateField = pParams.GetOrDefault("AltField", String.Empty)
|
||||
Dim oAccount = Winline.TryGetAccount(oNumberItem.Original, pMandator, "c260", oAlternateField)
|
||||
|
||||
' If an account was found, set it for External and Final value
|
||||
If oAccount IsNot Nothing Then
|
||||
|
||||
@@ -217,8 +217,16 @@ Namespace Winline
|
||||
End Function
|
||||
|
||||
Public Function TryGetAccount(pGLN As String, pMandator As Mandator) As Account
|
||||
Return TryGetAccount(pGLN, pMandator, "c260", String.Empty)
|
||||
End Function
|
||||
|
||||
Public Function TryGetAccount(pGLN As String, pMandator As Mandator, pSearchField As String) As Account
|
||||
Return TryGetAccount(pGLN, pMandator, pSearchField, String.Empty)
|
||||
End Function
|
||||
|
||||
Public Function TryGetAccount(pIdentifier As String, pMandator As Mandator, pSearchField As String, pAlternativeField As String) As Account
|
||||
Try
|
||||
If pGLN Is Nothing OrElse pGLN = String.Empty Then
|
||||
If pIdentifier Is Nothing OrElse pIdentifier = String.Empty Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
@@ -229,23 +237,24 @@ Namespace Winline
|
||||
[c003], -- Kundenname
|
||||
[c050], -- Straße
|
||||
[c052], -- Ort
|
||||
[c051] -- PLZ
|
||||
[c051], -- PLZ
|
||||
* -- Everything else
|
||||
FROM [{pMandator.Database}].[dbo].[v050]
|
||||
WHERE [c004] IN (2, 3) -- KontoTyp Debitor/Kreditor
|
||||
AND [c260] = '{pGLN}'
|
||||
AND [{pSearchField}] = '{pIdentifier}'
|
||||
AND [mesocomp] = '{pMandator.Id}' and [mesoyear] = {oYear}"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
||||
|
||||
' GLN not found in this Mandator, continue to next one
|
||||
If oTable.Rows.Count = 0 Then
|
||||
Logger.Debug("GLN [{0}] was not found in Mandator: [{1}]", pGLN, pMandator.Id)
|
||||
Logger.Debug("GLN [{0}] was not found in Mandator: [{1}]", pIdentifier, pMandator.Id)
|
||||
Return Nothing
|
||||
|
||||
End If
|
||||
|
||||
' Duplicate GLN, exit and do nothing about this number
|
||||
If oTable.Rows.Count > 1 Then
|
||||
Logger.Warn("GLN [{0}] was found more than once in Mandator: [{1}]", pGLN, pMandator.Id)
|
||||
Logger.Warn("GLN [{0}] was found more than once in Mandator: [{1}]", pIdentifier, pMandator.Id)
|
||||
Return Nothing
|
||||
|
||||
End If
|
||||
@@ -257,6 +266,15 @@ Namespace Winline
|
||||
Dim oZipCode As String = ItemEx(oRow, V50_ZIPCODE, String.Empty)
|
||||
Dim oCityName As String = ItemEx(oRow, V50_CITYNAME, String.Empty)
|
||||
|
||||
|
||||
If pAlternativeField <> String.Empty Then
|
||||
Dim oAlternativeValue = ItemEx(oRow, pAlternativeField, String.Empty)
|
||||
|
||||
If oAlternativeValue <> String.Empty Then
|
||||
Return TryGetAccount(oAlternativeValue, pMandator, "c002")
|
||||
End If
|
||||
End If
|
||||
|
||||
Return New Account With {
|
||||
.Id = oAccountNumber,
|
||||
.Name = oAccountName,
|
||||
@@ -266,7 +284,7 @@ Namespace Winline
|
||||
.Mandator = pMandator
|
||||
}
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Error while trying to get account for GLN [{0}]", pGLN)
|
||||
Logger.Warn("Error while trying to get account for GLN [{0}]", pIdentifier)
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
|
||||
Reference in New Issue
Block a user