Finish FinalSQL, GLN/EAN for export, double click to open template, exporting multiple documents

This commit is contained in:
Jonathan Jenne
2022-01-20 16:34:52 +01:00
parent ff7c8c63ea
commit c315640d7d
25 changed files with 531 additions and 362 deletions

View File

@@ -13,6 +13,7 @@ Namespace Winline
Private ReadOnly Property Config As GeneralConfig
Private ReadOnly Property MandatorConfig As MandatorConfig
Private ReadOnly Property MappingConfig As MappingConfig
Private ReadOnly Property Patterns As Patterns
Public Property Articles As New List(Of Article)
Public Property Accounts As New List(Of Account)
@@ -23,6 +24,7 @@ Namespace Winline
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As GeneralConfig, pMappingConfig As MappingConfig, pMandatorConfig As MandatorConfig)
MyBase.New(pLogConfig)
Patterns = New Patterns(pLogConfig, pConfig)
Database = pDatabase
Config = pConfig
MandatorConfig = pMandatorConfig
@@ -223,7 +225,7 @@ Namespace Winline
[c052], -- Ort
[c051] -- PLZ
FROM [{pMandator.Database}].[dbo].[v050]
WHERE [c004] = 2 -- KontoTyp
WHERE [c004] IN (2, 3) -- KontoTyp Debitor/Kreditor
AND [c260] = '{pGLN}'
AND [mesocomp] = '{pMandator.Id}' and [mesoyear] = {oYear}"
Dim oTable As DataTable = Database.GetDatatable(oSQL)
@@ -264,6 +266,37 @@ Namespace Winline
End Try
End Function
Public Function TryGetGLN(pAccountId As String, pMandator As Mandator) As String
Try
If pAccountId Is Nothing OrElse pAccountId = String.Empty Then
Return Nothing
End If
Dim oYear As Integer = Config.GetWinLineYear()
Dim oSQL = $"
SELECT
[c260] -- GLN
FROM [{pMandator.Database}].[dbo].[v050]
WHERE [c004] IN (2, 3) -- KontoTyp Debitor/Kreditor
AND [c002] = '{pAccountId}'
AND [mesocomp] = '{pMandator.Id}' and [mesoyear] = {oYear}"
Dim oGLN As String = Database.GetScalarValue(oSQL)
' GLN not found in this Mandator, continue to next one
If oGLN Is Nothing Then
Logger.Debug("Account [{0}] was not found in Mandator: [{1}]", pAccountId, pMandator.Id)
Return Nothing
End If
Return oGLN
Catch ex As Exception
Logger.Warn("Error while trying to get GLN for Account [{0}]", pAccountId)
Logger.Error(ex)
Return Nothing
End Try
End Function
Public Function TryGetArticleNumber(pEAN As String, pMandator As Mandator) As String
Try
Dim oYear As Integer = Config.GetWinLineYear()
@@ -303,6 +336,33 @@ Namespace Winline
End Try
End Function
Public Function TryGetEAN(pArticleNumber As String, pMandator As Mandator) As String
Try
Dim oYear As Integer = Config.GetWinLineYear()
Dim oSQL As String = $"
SELECT
[c075] -- EAN-Nummer
FROM [{pMandator.Database}].[dbo].[v021]
WHERE [c011] = '{pArticleNumber}'
AND [mesocomp] = '{pMandator.Id}' AND [mesoyear] = {oYear}"
Dim oEAN As String = Database.GetScalarValue(oSQL)
' EAN not found in this Mandator, continue to next one
If oEAN Is Nothing Then
Logger.Debug("ArticleNumber [{0}] was not found in Mandator: [{1}]", pArticleNumber, pMandator.Id)
Return Nothing
End If
Return oEAN
Catch ex As Exception
Logger.Error(ex)
Return Nothing
End Try
End Function
Public Function GetContacts(pAccountNumber As String, pMandator As Mandator) As List(Of Contact)
Try
Dim oContacts As New List(Of Contact)
@@ -480,7 +540,7 @@ Namespace Winline
oDateConstraint = $""
End If
Dim oExportedConstraint = "c111 = 0 AND"
Dim oExportedConstraint = "U010 = 0 AND"
If pOptions.ShowExported Then
oExportedConstraint = ""
End If
@@ -509,7 +569,7 @@ Namespace Winline
c100 GROSS_AMOUNT,
c114 NET_AMOUNT,
c111 ALREADY_EXPORTED
U010 ALREADY_EXPORTED
FROM [{pMandator.Database}].[dbo].[T025]
WHERE
@@ -543,13 +603,14 @@ Namespace Winline
End Try
End Function
Public Async Function ExecuteFinalSQL(pDocument As Document, pTemplate As Template) As Task(Of Boolean)
Public Async Function ExecuteFinalSQL(pDocument As Document, pTemplate As Template, pMandator As Mandator) As Task(Of Boolean)
Try
Dim oSql As String = pTemplate.FinalSQL
Dim oSql As String = Patterns.ReplaceForExport(pTemplate, pDocument, pMandator, pTemplate.FinalSQL)
Return Await Database.ExecuteNonQueryAsync(oSql)
Catch ex As Exception
Logger.Error(ex)
Return False
End Try
End Function