Fix DocumentTypes for Exports, Prepare Price calculation, load template parameters
This commit is contained in:
@@ -52,6 +52,21 @@ Namespace Documents
|
||||
End Get
|
||||
End Property
|
||||
|
||||
''' <summary>
|
||||
''' Finds the first occurrence of Field and returns its value
|
||||
''' </summary>
|
||||
Public Function GetFieldValue(pField As String) As String
|
||||
For Each oRow In Rows
|
||||
For Each oField In oRow.Fields
|
||||
If oField.Key = pField Then
|
||||
Return oField.Value.Final
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
Public Overrides Function Equals(obj As Object) As Boolean
|
||||
Return FullName = DirectCast(obj, Document).FullName
|
||||
End Function
|
||||
|
||||
@@ -86,6 +86,11 @@ Namespace Documents
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Sub ReplaceDocument(pDocument As Document)
|
||||
Dim oIndex = Files.IndexOf(pDocument)
|
||||
Files.Item(oIndex) = pDocument
|
||||
End Sub
|
||||
|
||||
|
||||
Private Function IncludeSchema(pDocument As Document, pTemplate As Template) As Document
|
||||
pDocument.Schema = pTemplate
|
||||
@@ -243,7 +248,9 @@ Namespace Documents
|
||||
Else
|
||||
pDocument = ApplyDefinedItemFunctionsForImport(pDocument, oMandator, pTemplate)
|
||||
pDocument = ApplyDynamicItemFunctionsForImport(pDocument, oMandator)
|
||||
pDocument = ApplyPriceFunctions(pDocument, oMandator, pTemplate)
|
||||
|
||||
' These functions will only be applied if the document does not have errors
|
||||
pDocument = MaybeApplyPriceFunctions(pDocument, oMandator, pTemplate)
|
||||
End If
|
||||
|
||||
pDocument.Mandator = oMandator
|
||||
@@ -256,7 +263,11 @@ Namespace Documents
|
||||
''' 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
|
||||
Public Function MaybeApplyPriceFunctions(pDocument As Document, pMandator As Mandator, pTemplate As Template) As Document
|
||||
If pDocument.HasErrors Then
|
||||
Return pDocument
|
||||
End If
|
||||
|
||||
For Each oRow As DocumentRow In pDocument.Rows
|
||||
Dim oTable = pTemplate.Tables.Where(Function(table) table.Name = oRow.TableName).SingleOrDefault()
|
||||
|
||||
@@ -273,16 +284,20 @@ Namespace Documents
|
||||
Dim oFunctionName = oColumn.Config?.Function?.Name
|
||||
|
||||
' TODO: Make more nice
|
||||
Dim oParams = oColumn.Config?.Function.Params
|
||||
Dim oParamList = oParams.Split("|").ToList()
|
||||
Dim oParams = oColumn.Config?.Function?.Params
|
||||
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 oParams IsNot Nothing AndAlso oParams <> String.Empty Then
|
||||
Dim oParamList = oParams.Split("|").ToList()
|
||||
For Each oParam In oParamList
|
||||
Dim oParamSplit = oParam.Split("=")
|
||||
oParamsDict.Add(oParamSplit(0), oParamSplit(1))
|
||||
Next
|
||||
End If
|
||||
|
||||
|
||||
If oFunctionName = "PRICE" Then
|
||||
SetPrice(oRow, oField.Key, oParamsDict, pMandator, pTemplate)
|
||||
SetPrice(oRow, oField.Key, oParamsDict, pDocument, pMandator, pTemplate)
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
@@ -363,17 +378,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)
|
||||
Private Sub SetPrice(pRow As DocumentRow, pPriceField As String, oFieldMap As Dictionary(Of String, String), pDocument As Document, 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)
|
||||
|
||||
' These fields are fetched from the current row
|
||||
Dim oArticleNumberField As String = oFieldMap.GetOrDefault("Article", Nothing)
|
||||
Dim oArticleNumber As String = pRow.Fields.Item(oArticleNumberField).Final
|
||||
|
||||
' 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)
|
||||
|
||||
Dim oDocumentDateField As String = oFieldMap.GetOrDefault("DocumentDate", Nothing)
|
||||
Dim oDocumentDate = pDocument.GetFieldValue(oDocumentDateField)
|
||||
|
||||
' TODO: Add Field Names as Constants
|
||||
' 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)
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
Namespace Templates
|
||||
Imports DigitalData.Modules.Language
|
||||
|
||||
Namespace Templates
|
||||
|
||||
Public Class Template
|
||||
Public Property Guid As Integer
|
||||
Public Property Name As String
|
||||
@@ -33,6 +36,38 @@
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Function GetParameter(pName As String) As String
|
||||
Dim oParam1 As String = Utils.NotNull(Parameter1, String.Empty)
|
||||
Dim oParam2 As String = Utils.NotNull(Parameter2, String.Empty)
|
||||
|
||||
Dim oParamValue1 = TryGetParameter(oParam1)
|
||||
Dim oParamValue2 = TryGetParameter(oParam2)
|
||||
|
||||
If oParamValue1 IsNot Nothing AndAlso oParamValue1.Item1 = pName Then
|
||||
Return oParamValue1.Item2
|
||||
End If
|
||||
|
||||
If oParamValue2 IsNot Nothing AndAlso oParamValue2.Item1 = pName Then
|
||||
Return oParamValue2.Item2
|
||||
End If
|
||||
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
Private Function TryGetParameter(pParameterString As String) As Tuple(Of String, String)
|
||||
If pParameterString <> String.Empty Then
|
||||
Dim oSplit = pParameterString.Split("=").ToList()
|
||||
|
||||
If oSplit.Count = 2 Then
|
||||
Return New Tuple(Of String, String)(oSplit.First, oSplit.Last)
|
||||
Else
|
||||
Return Nothing
|
||||
End If
|
||||
Else
|
||||
Return Nothing
|
||||
End If
|
||||
End Function
|
||||
|
||||
Class Table
|
||||
Public Property Name As String
|
||||
Public Property Columns As New List(Of Column)
|
||||
|
||||
@@ -10,7 +10,6 @@ Namespace Winline
|
||||
Public Class WinlineData
|
||||
Inherits BaseClass
|
||||
|
||||
Private ReadOnly Property Database As MSSQLServer
|
||||
Private ReadOnly Property Config As GeneralConfig
|
||||
Private ReadOnly Property MandatorConfig As MandatorConfig
|
||||
Private ReadOnly Property MappingConfig As MappingConfig
|
||||
@@ -24,23 +23,23 @@ Namespace Winline
|
||||
Public Years As List(Of Integer)
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As GeneralConfig, pMappingConfig As MappingConfig, pMandatorConfig As MandatorConfig)
|
||||
MyBase.New(pLogConfig)
|
||||
MyBase.New(pLogConfig, pDatabase)
|
||||
Patterns = New Patterns(pLogConfig, pConfig)
|
||||
Database = pDatabase
|
||||
Config = pConfig
|
||||
MandatorConfig = pMandatorConfig
|
||||
MappingConfig = pMappingConfig
|
||||
End Sub
|
||||
|
||||
Public Enum DocumentType
|
||||
OutgoingOffer = 1
|
||||
OutgoingOrder = 2
|
||||
OutgoingDeliveryNote = 3
|
||||
OutgoingInvoice = 4
|
||||
IncomingOffer = -1
|
||||
IncomingOrder = -2
|
||||
IncomingDeliveryNote = -3
|
||||
IncomingInvoice = -4
|
||||
Undefined
|
||||
OutgoingOffer
|
||||
OutgoingOrder
|
||||
OutgoingDeliveryNote
|
||||
OutgoingInvoice
|
||||
IncomingOffer
|
||||
IncomingOrder
|
||||
IncomingDeliveryNote
|
||||
IncomingInvoice
|
||||
End Enum
|
||||
|
||||
Public Class GetDocumentArgs
|
||||
@@ -308,17 +307,18 @@ Namespace Winline
|
||||
Try
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
Dim oSQL As String = $"
|
||||
EXECUTE [PRCUST_GET_ACCOUNT_PRICE_CONDITION_VALUES]
|
||||
EXECUTE [{pMandator.Database}].[dbo].[PRCUST_GET_ACCOUNT_PRICE_CONDITION_VALUES]
|
||||
'{pAccountNumber}',
|
||||
'*',
|
||||
'{pArticle}',
|
||||
'{pQuantity}',
|
||||
{pDocumentDate:yyyy-MM-dd},
|
||||
{pDocumentDate:yyyy-MM-dd},
|
||||
'{pDocumentDate:dd.MM.yyyy}',
|
||||
'{pDocumentDate:dd.MM.yyyy}',
|
||||
'{pMandator.Id}',
|
||||
{oYear},
|
||||
1008,
|
||||
NULL,
|
||||
1,
|
||||
'Multitool/{pTemplate.Name}',
|
||||
'CalcPricing'
|
||||
"
|
||||
@@ -567,14 +567,39 @@ Namespace Winline
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
Public Function GetDocuments(pMandator As Mandator, pTemplate As Template, pDocumentType As Integer, pOptions As GetDocumentArgs) As List(Of ExportDocument)
|
||||
Public Function GetDocuments(pMandator As Mandator, pTemplate As Template, pDocumentType As DocumentType, pOptions As GetDocumentArgs) As List(Of ExportDocument)
|
||||
Try
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
|
||||
Dim oTypeConstraint = ""
|
||||
If pDocumentType <> 0 Then
|
||||
oTypeConstraint = $"T.c139 = {pDocumentType} AND "
|
||||
End If
|
||||
Dim oTypeConstraint
|
||||
Select Case pDocumentType
|
||||
Case DocumentType.OutgoingOffer
|
||||
oTypeConstraint = $"T.c137 = 1 AND c139 = 1 AND "
|
||||
|
||||
Case DocumentType.OutgoingOffer
|
||||
oTypeConstraint = $"T.c137 = 1 AND c139 = 2 AND "
|
||||
|
||||
Case DocumentType.OutgoingDeliveryNote
|
||||
oTypeConstraint = $"T.c137 = 1 AND (c139 = 3 OR c139 = -3) AND "
|
||||
|
||||
Case DocumentType.OutgoingInvoice
|
||||
oTypeConstraint = $"T.c137 = 1 AND c139 = 4 AND "
|
||||
|
||||
Case DocumentType.IncomingOffer
|
||||
oTypeConstraint = $"T.c137 = 2 AND c139 = 1 AND "
|
||||
|
||||
Case DocumentType.IncomingOrder
|
||||
oTypeConstraint = $"T.c137 = 2 AND c139 = 2 AND "
|
||||
|
||||
Case DocumentType.IncomingDeliveryNote
|
||||
oTypeConstraint = $"T.c137 = 2 AND c139 = 3 AND "
|
||||
|
||||
Case DocumentType.IncomingInvoice
|
||||
oTypeConstraint = $"T.c137 = 2 AND c139 = 4 AND "
|
||||
|
||||
Case Else
|
||||
oTypeConstraint = ""
|
||||
End Select
|
||||
|
||||
Dim oAccountConstraint = ""
|
||||
If pOptions.Account IsNot Nothing Then
|
||||
|
||||
Reference in New Issue
Block a user