diff --git a/MultiTool.Shared/Constants.vb b/MultiTool.Shared/Constants.vb index 9f1c288..125b6b7 100644 --- a/MultiTool.Shared/Constants.vb +++ b/MultiTool.Shared/Constants.vb @@ -7,6 +7,7 @@ Public Const FUNCTION_EAN = "EAN" Public Const FUNCTION_PRICE = "PRICE" Public Const FUNCTION_SQL = "SQL" + Public Const FUNCTION_FIELD = "FIELD" Public Const TEMPLATE_TYPE_DATE = "xs:date" Public Const TEMPLATE_TYPE_INTEGER = "xs:integer" diff --git a/MultiTool.Shared/Documents/DocumentLoader.vb b/MultiTool.Shared/Documents/DocumentLoader.vb index c981faa..52c26c4 100644 --- a/MultiTool.Shared/Documents/DocumentLoader.vb +++ b/MultiTool.Shared/Documents/DocumentLoader.vb @@ -254,6 +254,10 @@ Namespace Documents ' These functions will only be applied if the document does not have errors pDocument = Await MaybeApplyPriceFunctions(pDocument, oMandator, pTemplate) + + ' This function needs to be the last one because + ' it can relate to any previously set value + ApplyFieldFunctionForImport(pDocument, oMandator, pTemplate) End If Return pDocument @@ -329,6 +333,42 @@ Namespace Documents Return pDocument End Function + Private Function ApplyFieldFunctionForImport(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 + 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.FunctionName + Dim oFunctionParams = oColumn.Config.FunctionParams + Dim oParamsDict = ParseFunctionParamsAsDict(oFunctionParams) + + If oFunctionName = Constants.FUNCTION_FIELD Then + + Dim oParam = oParamsDict.FirstOrDefault() + + If IsNothing(oParam) Then + Logger.Warn("FIELD function needs exactly one parameter!") + Return pDocument + End If + + + + End If + Next + Next + + Return pDocument + End Function + ''' ''' Execute Mappings defined in TBMT_MAPPING_CONFIG, ''' for example mapping Article Numbers to Winline Mandators