Improve config screen, add waiting days
This commit is contained in:
@@ -420,6 +420,12 @@ Namespace Documents
|
||||
Dim oArticleNumberField As String = oFieldMap.GetOrDefault("Article", Nothing)
|
||||
Dim oArticleNumber As String = pRow.Fields.Item(oArticleNumberField).Final
|
||||
|
||||
Dim oQuantityField As String = oFieldMap.GetOrDefault("Quantity", Nothing)
|
||||
Dim oQuantity As Integer = 1
|
||||
If Integer.TryParse(pRow.Fields.Item(oQuantityField).Final, oQuantity) = False Then
|
||||
Logger.Warn("Value for parameter Quantity could not be parsed. Setting to 1.")
|
||||
End If
|
||||
|
||||
' These fields a fetched from the head row, ie. the first row
|
||||
Dim oAccountNumberField As String = oFieldMap.GetOrDefault("Account", Nothing)
|
||||
Dim oAccountNumber = pDocument.GetFieldValue(oAccountNumberField)
|
||||
@@ -427,12 +433,21 @@ Namespace Documents
|
||||
Dim oDocumentDateField As String = oFieldMap.GetOrDefault("DocumentDate", Nothing)
|
||||
Dim oDocumentDate = pDocument.GetFieldValue(oDocumentDateField)
|
||||
|
||||
Dim oDocumentKindField As String = oFieldMap.GetOrDefault("DocumentKind", Nothing)
|
||||
Dim oDocumentKind As Integer = 0
|
||||
If Integer.TryParse(pDocument.GetFieldValue(oDocumentKindField), oDocumentKind) Then
|
||||
Logger.Warn("Value for parameter DocumentKind could not be parsed. Setting to 0.")
|
||||
End If
|
||||
|
||||
' TODO: Add Field Names as Constants
|
||||
' TODO: Check for missing values
|
||||
|
||||
Dim oQuantity As Integer = 1
|
||||
' TODO: This function should not be hardcoded, but be replaced with virtual field or something..
|
||||
' It is related to customer SCHAUM and nothing general
|
||||
Dim oWaitingDays As Integer = Await Winline.TryGetWaitingDays(oDocumentKind, pMandator)
|
||||
' END TODO
|
||||
|
||||
Dim oArticlePrice As Double = Await Winline.TryGetArticlePrice(oArticleNumber, oAccountNumber, oQuantity, oDocumentDate, pMandator, pTemplate)
|
||||
Dim oArticlePrice As Double = Await Winline.TryGetArticlePrice(oArticleNumber, oAccountNumber, oQuantity, oDocumentDate, pMandator, pTemplate, oWaitingDays)
|
||||
|
||||
If oArticlePrice > 0 Then
|
||||
oPriceItem.External = oArticlePrice
|
||||
|
||||
@@ -134,6 +134,10 @@ Namespace Winline
|
||||
Next
|
||||
Accounts.AddRange(oAccounts)
|
||||
|
||||
If oAccounts.Count = 0 Then
|
||||
Logger.Warn("No Acconts loaded for Mandator [{0}]", pMandator)
|
||||
End If
|
||||
|
||||
Logger.Info("[{0}] Accounts loaded for Mandator [{1}]", oAccounts.Count, pMandator)
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Could not load Accounts for Mandator [{0}]", pMandator)
|
||||
@@ -323,19 +327,29 @@ Namespace Winline
|
||||
End Function
|
||||
|
||||
Public Async Function TryGetArticlePrice(pArticle As String, pAccountNumber As String, pQuantity As String, pDocumentDate As Date, pMandator As Mandator, pTemplate As Template) As Task(Of Double)
|
||||
Return Await TryGetArticlePrice(pArticle, pAccountNumber, pQuantity, pDocumentDate, pMandator, pTemplate, 0)
|
||||
End Function
|
||||
|
||||
Public Async Function TryGetArticlePrice(pArticle As String, pAccountNumber As String, pQuantity As String, pDocumentDate As Date, pMandator As Mandator, pTemplate As Template, pWaitingDays As Integer) As Task(Of Double)
|
||||
Try
|
||||
Dim oUserName = Environment.UserName
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
Dim oDebug = Convert.ToInt32(LogConfig.Debug)
|
||||
|
||||
' TODO: pGroupPropertyID in config
|
||||
' TODO: pTempTableSuffix in config (nice to have)
|
||||
|
||||
Dim oDateFrom = pDocumentDate.AddDays(pWaitingDays * -1)
|
||||
Dim oDateTo = pDocumentDate
|
||||
|
||||
Dim oSQL As String = $"
|
||||
EXEC [{pMandator.Database}].[dbo].[PRCUST_GET_ACCOUNT_PRICE_CONDITION_VALUES]
|
||||
@pAccountNr = '{pAccountNumber}',
|
||||
@pGroupNr = '*',
|
||||
@pProductNr = '{pArticle}',
|
||||
@pProductQuantity = '*',
|
||||
@pProductPriceDateFrom = '{pDocumentDate:dd.MM.yyyy}',
|
||||
@pProductPriceDateTo = '{pDocumentDate:dd.MM.yyyy}',
|
||||
@pProductQuantity = '<={pQuantity}',
|
||||
@pProductPriceDateFrom = '{oDateFrom:dd.MM.yyyy}',
|
||||
@pProductPriceDateTo = '{oDateTo:dd.MM.yyyy}',
|
||||
@pmesocomp = '{pMandator.Id}',
|
||||
@pmesoyear = {oYear},
|
||||
@pGroupPropertyID = 1008,
|
||||
@@ -367,6 +381,34 @@ Namespace Winline
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' This function is completely SCHAUM related.
|
||||
''' </summary>
|
||||
Public Async Function TryGetWaitingDays(pDocumentKind As Integer, pMandator As Mandator) As Task(Of Integer)
|
||||
Try
|
||||
Dim oSql = $"
|
||||
SELECT [Karenztage].[u012] FROM [{pMandator.Database}].[dbo].[t670] As [Werksdefinition]
|
||||
INNER JOIN [{pMandator.Database}].[dbo].[t670] AS [Werkszuordnung] ON [Werksdefinition].[u007] = [Werkszuordnung].[u007]
|
||||
INNER JOIN [{pMandator.Database}].[dbo].[t670] AS [Karenztage] ON [Werksdefinition].[u000] = [Karenztage].[u032]
|
||||
WHERE [Werksdefinition].[u011] In ({pDocumentKind},{pDocumentKind}*10)
|
||||
AND [Werkszuordnung].[u006] = '%ConditionAccountNr%'
|
||||
AND [Karenztage].[u002] = 'Karenztage'
|
||||
"
|
||||
Dim oWaitingDays As Integer = Await Database.GetScalarValueAsync(oSql)
|
||||
|
||||
If IsNothing(oWaitingDays) Then
|
||||
oWaitingDays = 0
|
||||
End If
|
||||
|
||||
Return oWaitingDays
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return 0
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function TryGetArticleNumber(pEAN As String, pMandator As Mandator) As String
|
||||
Try
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
|
||||
Reference in New Issue
Block a user