WIP Price Calculation
This commit is contained in:
@@ -206,7 +206,7 @@ Namespace Documents
|
||||
' Create a DocumentRow object for each Top Level Element
|
||||
Dim oRow = New DocumentRow With {
|
||||
.SortKey = oRowSortKey,
|
||||
.Name = oTopLevelElement.Name.ToString,
|
||||
.TableName = oTopLevelElement.Name.ToString,
|
||||
.Fields = oFields
|
||||
}
|
||||
|
||||
@@ -243,19 +243,56 @@ Namespace Documents
|
||||
Else
|
||||
pDocument = ApplyDefinedItemFunctionsForImport(pDocument, oMandator, pTemplate)
|
||||
pDocument = ApplyDynamicItemFunctionsForImport(pDocument, oMandator)
|
||||
pDocument = ApplyPriceFunctions(pDocument, oMandator, pTemplate)
|
||||
End If
|
||||
|
||||
pDocument.Mandator = oMandator
|
||||
Return pDocument
|
||||
End Function
|
||||
|
||||
Private Function ApplyDefinedItemFunctionsForImport(pDocument As Document, pMandator As Mandator, pTemplate As Template) As Document
|
||||
If pMandator Is Nothing Then
|
||||
Return pDocument
|
||||
End If
|
||||
|
||||
''' <summary>
|
||||
''' Apply price calculation to the documents products
|
||||
'''
|
||||
''' This needs to be strictly seperated from `ApplyDefinedItemFunctionsForImport`
|
||||
''' because prices can only be calculated if GLN and EAN functions were already (successfully) processed
|
||||
''' </summary>
|
||||
Private Function ApplyPriceFunctions(pDocument As Document, pMandator As Mandator, pTemplate As Template) As Document
|
||||
For Each oRow As DocumentRow In pDocument.Rows
|
||||
Dim oTable = pTemplate.Tables.Where(Function(table) table.Name = oRow.Name).SingleOrDefault()
|
||||
Dim oTable = pTemplate.Tables.Where(Function(table) table.Name = oRow.TableName).SingleOrDefault()
|
||||
|
||||
For Each oField In oRow.Fields
|
||||
If oTable Is Nothing Then
|
||||
Exit For
|
||||
End If
|
||||
|
||||
Dim oColumn = oTable.Columns.Where(Function(c) c.Name = oField.Key).SingleOrDefault()
|
||||
If oColumn Is Nothing Then
|
||||
Continue For
|
||||
End If
|
||||
|
||||
Dim oFunctionName = oColumn.Config?.Function?.Name
|
||||
|
||||
' TODO: Make more nice
|
||||
Dim oParams = oColumn.Config?.Function.Params
|
||||
Dim oParamList = oParams.Split("|").ToList()
|
||||
Dim oParamsDict As New Dictionary(Of String, String)
|
||||
For Each oParam In oParamList
|
||||
Dim oParamSplit = oParam.Split("=")
|
||||
oParamsDict.Add(oParamSplit(0), oParamSplit(1))
|
||||
Next
|
||||
|
||||
If oFunctionName = "PRICE" Then
|
||||
SetPrice(oRow, oField.Key, oParamsDict, pMandator, pTemplate)
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
|
||||
Return pDocument
|
||||
End Function
|
||||
|
||||
Private Function ApplyDefinedItemFunctionsForImport(pDocument As Document, pMandator As Mandator, pTemplate As Template) As Document
|
||||
For Each oRow As DocumentRow In pDocument.Rows
|
||||
Dim oTable = pTemplate.Tables.Where(Function(table) table.Name = oRow.TableName).SingleOrDefault()
|
||||
|
||||
For Each oField In oRow.Fields
|
||||
If oTable Is Nothing Then
|
||||
@@ -284,11 +321,11 @@ Namespace Documents
|
||||
Return pDocument
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Execute Mappings defined in TBEDI_XML_MAPPING_CONFIG,
|
||||
''' for example mapping Article Numbers to Winline Mandators
|
||||
''' </summary>
|
||||
Private Function ApplyDynamicItemFunctionsForImport(pDocument As Document, pMandator As Mandator) As Document
|
||||
If pMandator Is Nothing Then
|
||||
Return pDocument
|
||||
End If
|
||||
|
||||
' We only want the mapping config for things in the xml file.
|
||||
' that excludes things like setting the mandator.
|
||||
Dim oFilteredMappingConfig = MappingConfig.Items.
|
||||
@@ -326,6 +363,23 @@ Namespace Documents
|
||||
Return pDocument
|
||||
End Function
|
||||
|
||||
Private Sub SetPrice(pRow As DocumentRow, pPriceField As String, oFieldMap As Dictionary(Of String, String), pMandator As Mandator, pTemplate As Template)
|
||||
Dim oPriceItem As DocumentRow.FieldValue = pRow.Fields.GetOrDefault(pPriceField)
|
||||
Dim oArticleNumberField As String = oFieldMap.GetOrDefault("Article", Nothing)
|
||||
Dim oAccountNumberField As String = oFieldMap.GetOrDefault("Account", Nothing)
|
||||
Dim oDocumentDateField As String = oFieldMap.GetOrDefault("DocumentDate", Nothing)
|
||||
|
||||
' TODO: Check for missing values
|
||||
|
||||
Dim oArticleNumber As String = pRow.Fields.Item(oArticleNumberField).Final
|
||||
Dim oAccountNumber As String = pRow.Fields.Item(oAccountNumberField).Final
|
||||
Dim oDocumentDate As Date = pRow.Fields.Item(oDocumentDateField).Final
|
||||
Dim oQuantity As Integer = 1
|
||||
|
||||
Dim oArticlePrice As Double = Winline.TryGetArticlePrice(oArticleNumber, oAccountNumber, oQuantity, oDocumentDate, pMandator, pTemplate)
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub SetArticleByEAN(pRow As DocumentRow, pMandator As Mandator, pArticleField As String)
|
||||
Dim oNumberItem As DocumentRow.FieldValue = pRow.Fields.GetOrDefault(pArticleField)
|
||||
Dim oArticleNumber = Winline.TryGetArticleNumber(oNumberItem.Original, pMandator)
|
||||
|
||||
@@ -10,11 +10,16 @@
|
||||
''' Counter to ensure consistency and order when writing XML
|
||||
''' </summary>
|
||||
Public Property SortKey As Integer
|
||||
|
||||
''' <summary>
|
||||
''' Tabellen/Elementname aus XML
|
||||
''' </summary>
|
||||
Public Property Name As String
|
||||
Public Property TableName As String
|
||||
|
||||
''' <summary>
|
||||
''' List of Row Values
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property Fields As Dictionary(Of String, FieldValue)
|
||||
|
||||
Public ReadOnly Property HasErrors As Boolean
|
||||
|
||||
@@ -63,11 +63,11 @@ Public Class ReportGenerator(Of TReport As IReport)
|
||||
FillFieldValuesFromSQL(pDocument, oSQLConfig)
|
||||
|
||||
Dim oHeadRow = pDocument.Rows.
|
||||
Where(Function(r) r.Name.EndsWith("T025")).
|
||||
Where(Function(r) r.TableName.EndsWith("T025")).
|
||||
Select(Function(r) r.Fields).
|
||||
FirstOrDefault()
|
||||
Dim oPositionRows = pDocument.Rows.
|
||||
Where(Function(r) r.Name.EndsWith("T026")).
|
||||
Where(Function(r) r.TableName.EndsWith("T026")).
|
||||
ToList()
|
||||
|
||||
Dim oReportHead = oHeadMapper.Map(Of Dictionary(Of String, FieldValue), ReportHead)(oHeadRow)
|
||||
|
||||
@@ -188,7 +188,7 @@ Namespace Winline
|
||||
pDocument.Rows.Sort()
|
||||
|
||||
For Each oRow In pDocument.Rows
|
||||
w.WriteStartElement(oRow.Name)
|
||||
w.WriteStartElement(oRow.TableName)
|
||||
|
||||
For Each oField As KeyValuePair(Of String, DocumentRow.FieldValue) In oRow.Fields
|
||||
If oField.Value.Final = String.Empty Then
|
||||
|
||||
@@ -304,6 +304,45 @@ Namespace Winline
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function TryGetArticlePrice(pArticle As String, pAccountNumber As String, pQuantity As String, pDocumentDate As Date, pMandator As Mandator, pTemplate As Template) As Double
|
||||
Try
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
Dim oSQL As String = $"
|
||||
EXECUTE [PRCUST_GET_ACCOUNT_PRICE_CONDITION_VALUES]
|
||||
'{pAccountNumber}',
|
||||
'*',
|
||||
'{pArticle}',
|
||||
'{pQuantity}',
|
||||
{pDocumentDate:yyyy-MM-dd},
|
||||
{pDocumentDate:yyyy-MM-dd},
|
||||
'{pMandator.Id}',
|
||||
{oYear},
|
||||
1008,
|
||||
NULL,
|
||||
'Multitool/{pTemplate.Name}',
|
||||
'CalcPricing'
|
||||
"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
||||
|
||||
If oTable.Rows.Count = 0 Then
|
||||
Logger.Debug("Price for article [{0}] and Account [{1}] was not found in Mandator: [{2}]", pArticle, pAccountNumber, pMandator.Id)
|
||||
Return Nothing
|
||||
|
||||
End If
|
||||
|
||||
Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
Dim oPrice As Double = oRow.Item("PRICE")
|
||||
|
||||
Return oPrice
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Error while trying to get Price for Article [{0}] and Account [{1}]", pArticle, pAccountNumber)
|
||||
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()
|
||||
@@ -450,7 +489,7 @@ Namespace Winline
|
||||
|
||||
Public Function FindMatchingMandatorFromOrder(pData As Documents.Document) As Mandator
|
||||
Dim oPositions = pData.Rows.
|
||||
Where(Function(r) r.Name.ToUpper.EndsWith("T026")).
|
||||
Where(Function(r) r.TableName.ToUpper.EndsWith("T026")).
|
||||
ToList()
|
||||
Dim oEANNumbers = oPositions.
|
||||
Select(Function(p)
|
||||
|
||||
Reference in New Issue
Block a user