From 213bcef7328fe248ab23fc5850f703d4966c168a Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Mon, 28 Feb 2022 11:58:01 +0100 Subject: [PATCH] Fix DocumentTypes for Exports, Prepare Price calculation, load template parameters --- MultiTool.Form/frmExportMain.Designer.vb | 80 ++++++++++---------- MultiTool.Form/frmExportMain.vb | 21 +++-- MultiTool.Shared/Documents/Document.vb | 15 ++++ MultiTool.Shared/Documents/DocumentLoader.vb | 47 ++++++++---- MultiTool.Shared/Templates/Template.vb | 37 ++++++++- MultiTool.Shared/Winline/WinlineData.vb | 63 ++++++++++----- 6 files changed, 185 insertions(+), 78 deletions(-) diff --git a/MultiTool.Form/frmExportMain.Designer.vb b/MultiTool.Form/frmExportMain.Designer.vb index 69adc41..f27c2e1 100644 --- a/MultiTool.Form/frmExportMain.Designer.vb +++ b/MultiTool.Form/frmExportMain.Designer.vb @@ -80,8 +80,8 @@ Partial Class frmExportMain Me.LayoutControlItem6 = New DevExpress.XtraLayout.LayoutControlItem() Me.LayoutControlItem7 = New DevExpress.XtraLayout.LayoutControlItem() Me.LayoutControlItem8 = New DevExpress.XtraLayout.LayoutControlItem() - Me.LayoutControlItem9 = New DevExpress.XtraLayout.LayoutControlItem() Me.LayoutControlItem10 = New DevExpress.XtraLayout.LayoutControlItem() + Me.LayoutControlItem9 = New DevExpress.XtraLayout.LayoutControlItem() Me.LabelControl2 = New DevExpress.XtraEditors.LabelControl() Me.colName2 = New DevExpress.XtraGrid.Columns.GridColumn() Me.colId2 = New DevExpress.XtraGrid.Columns.GridColumn() @@ -124,8 +124,8 @@ Partial Class frmExportMain CType(Me.LayoutControlItem6, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.LayoutControlItem7, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.LayoutControlItem8, System.ComponentModel.ISupportInitialize).BeginInit() - CType(Me.LayoutControlItem9, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.LayoutControlItem10, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.LayoutControlItem9, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'RibbonControl1 @@ -422,14 +422,14 @@ Partial Class frmExportMain ' 'lookupMandator ' - Me.lookupMandator.Location = New System.Drawing.Point(104, 15) + Me.lookupMandator.Location = New System.Drawing.Point(112, 15) Me.lookupMandator.MenuManager = Me.RibbonControl1 Me.lookupMandator.Name = "lookupMandator" Me.lookupMandator.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)}) Me.lookupMandator.Properties.NullText = "" Me.lookupMandator.Properties.PopupSizeable = False Me.lookupMandator.Properties.PopupView = Me.GridLookUpEdit1View - Me.lookupMandator.Size = New System.Drawing.Size(179, 20) + Me.lookupMandator.Size = New System.Drawing.Size(171, 20) Me.lookupMandator.StyleController = Me.LayoutControl1 Me.lookupMandator.TabIndex = 4 ' @@ -460,27 +460,27 @@ Partial Class frmExportMain 'dateDocDateFrom ' Me.dateDocDateFrom.EditValue = Nothing - Me.dateDocDateFrom.Location = New System.Drawing.Point(104, 195) + Me.dateDocDateFrom.Location = New System.Drawing.Point(112, 195) Me.dateDocDateFrom.MenuManager = Me.RibbonControl1 Me.dateDocDateFrom.Name = "dateDocDateFrom" Me.dateDocDateFrom.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)}) Me.dateDocDateFrom.Properties.CalendarTimeProperties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)}) Me.dateDocDateFrom.Properties.CharacterCasing = System.Windows.Forms.CharacterCasing.Lower Me.dateDocDateFrom.Properties.SelectionMode = DevExpress.XtraEditors.Repository.CalendarSelectionMode.Multiple - Me.dateDocDateFrom.Size = New System.Drawing.Size(179, 20) + Me.dateDocDateFrom.Size = New System.Drawing.Size(171, 20) Me.dateDocDateFrom.StyleController = Me.LayoutControl1 Me.dateDocDateFrom.TabIndex = 5 ' 'lookupAccount ' - Me.lookupAccount.Location = New System.Drawing.Point(104, 105) + Me.lookupAccount.Location = New System.Drawing.Point(112, 105) Me.lookupAccount.MenuManager = Me.RibbonControl1 Me.lookupAccount.Name = "lookupAccount" Me.lookupAccount.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo), New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Clear)}) Me.lookupAccount.Properties.NullText = "" Me.lookupAccount.Properties.PopupSizeable = False Me.lookupAccount.Properties.PopupView = Me.GridView1 - Me.lookupAccount.Size = New System.Drawing.Size(179, 20) + Me.lookupAccount.Size = New System.Drawing.Size(171, 20) Me.lookupAccount.StyleController = Me.LayoutControl1 Me.lookupAccount.TabIndex = 7 ' @@ -520,44 +520,44 @@ Partial Class frmExportMain ' 'txtDocumentFrom ' - Me.txtDocumentFrom.Location = New System.Drawing.Point(104, 135) + Me.txtDocumentFrom.Location = New System.Drawing.Point(112, 135) Me.txtDocumentFrom.MenuManager = Me.RibbonControl1 Me.txtDocumentFrom.Name = "txtDocumentFrom" - Me.txtDocumentFrom.Size = New System.Drawing.Size(179, 20) + Me.txtDocumentFrom.Size = New System.Drawing.Size(171, 20) Me.txtDocumentFrom.StyleController = Me.LayoutControl1 Me.txtDocumentFrom.TabIndex = 10 ' 'txtDocumentTo ' - Me.txtDocumentTo.Location = New System.Drawing.Point(104, 165) + Me.txtDocumentTo.Location = New System.Drawing.Point(112, 165) Me.txtDocumentTo.MenuManager = Me.RibbonControl1 Me.txtDocumentTo.Name = "txtDocumentTo" - Me.txtDocumentTo.Size = New System.Drawing.Size(179, 20) + Me.txtDocumentTo.Size = New System.Drawing.Size(171, 20) Me.txtDocumentTo.StyleController = Me.LayoutControl1 Me.txtDocumentTo.TabIndex = 11 ' 'dateDocDateTo ' Me.dateDocDateTo.EditValue = Nothing - Me.dateDocDateTo.Location = New System.Drawing.Point(104, 225) + Me.dateDocDateTo.Location = New System.Drawing.Point(112, 225) Me.dateDocDateTo.MenuManager = Me.RibbonControl1 Me.dateDocDateTo.Name = "dateDocDateTo" Me.dateDocDateTo.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)}) Me.dateDocDateTo.Properties.CalendarTimeProperties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)}) - Me.dateDocDateTo.Size = New System.Drawing.Size(179, 20) + Me.dateDocDateTo.Size = New System.Drawing.Size(171, 20) Me.dateDocDateTo.StyleController = Me.LayoutControl1 Me.dateDocDateTo.TabIndex = 12 ' 'comboDocumentType ' - Me.comboDocumentType.Location = New System.Drawing.Point(104, 75) + Me.comboDocumentType.Location = New System.Drawing.Point(112, 45) Me.comboDocumentType.MenuManager = Me.RibbonControl1 Me.comboDocumentType.Name = "comboDocumentType" - Me.comboDocumentType.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo), New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Clear)}) + Me.comboDocumentType.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)}) Me.comboDocumentType.Properties.NullText = "" Me.comboDocumentType.Properties.PopupSizeable = False Me.comboDocumentType.Properties.PopupView = Me.GridView3 - Me.comboDocumentType.Size = New System.Drawing.Size(179, 20) + Me.comboDocumentType.Size = New System.Drawing.Size(171, 20) Me.comboDocumentType.StyleController = Me.LayoutControl1 Me.comboDocumentType.TabIndex = 13 ' @@ -570,12 +570,12 @@ Partial Class frmExportMain ' 'comboDocumentKind ' - Me.comboDocumentKind.Location = New System.Drawing.Point(104, 45) + Me.comboDocumentKind.Location = New System.Drawing.Point(112, 75) Me.comboDocumentKind.MenuManager = Me.RibbonControl1 Me.comboDocumentKind.Name = "comboDocumentKind" Me.comboDocumentKind.Properties.AllowMultiSelect = True Me.comboDocumentKind.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo), New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Clear)}) - Me.comboDocumentKind.Size = New System.Drawing.Size(179, 20) + Me.comboDocumentKind.Size = New System.Drawing.Size(171, 20) Me.comboDocumentKind.StyleController = Me.LayoutControl1 Me.comboDocumentKind.TabIndex = 14 ' @@ -583,7 +583,7 @@ Partial Class frmExportMain ' Me.Root.EnableIndentsWithoutBorders = DevExpress.Utils.DefaultBoolean.[True] Me.Root.GroupBordersVisible = False - Me.Root.Items.AddRange(New DevExpress.XtraLayout.BaseLayoutItem() {Me.LayoutControlItem1, Me.EmptySpaceItem1, Me.LayoutControlItem3, Me.LayoutControlItem2, Me.LayoutControlItem5, Me.LayoutControlItem6, Me.LayoutControlItem7, Me.LayoutControlItem8, Me.LayoutControlItem9, Me.LayoutControlItem10}) + Me.Root.Items.AddRange(New DevExpress.XtraLayout.BaseLayoutItem() {Me.LayoutControlItem1, Me.EmptySpaceItem1, Me.LayoutControlItem3, Me.LayoutControlItem2, Me.LayoutControlItem5, Me.LayoutControlItem6, Me.LayoutControlItem7, Me.LayoutControlItem8, Me.LayoutControlItem10, Me.LayoutControlItem9}) Me.Root.Name = "Root" Me.Root.Size = New System.Drawing.Size(298, 538) Me.Root.TextVisible = False @@ -596,7 +596,7 @@ Partial Class frmExportMain Me.LayoutControlItem1.Padding = New DevExpress.XtraLayout.Utils.Padding(5, 5, 5, 5) Me.LayoutControlItem1.Size = New System.Drawing.Size(278, 30) Me.LayoutControlItem1.Text = "Mandant" - Me.LayoutControlItem1.TextSize = New System.Drawing.Size(77, 13) + Me.LayoutControlItem1.TextSize = New System.Drawing.Size(85, 13) ' 'EmptySpaceItem1 ' @@ -614,7 +614,7 @@ Partial Class frmExportMain Me.LayoutControlItem3.Padding = New DevExpress.XtraLayout.Utils.Padding(5, 5, 5, 5) Me.LayoutControlItem3.Size = New System.Drawing.Size(278, 30) Me.LayoutControlItem3.Text = "Konto" - Me.LayoutControlItem3.TextSize = New System.Drawing.Size(77, 13) + Me.LayoutControlItem3.TextSize = New System.Drawing.Size(85, 13) ' 'LayoutControlItem2 ' @@ -624,7 +624,7 @@ Partial Class frmExportMain Me.LayoutControlItem2.Padding = New DevExpress.XtraLayout.Utils.Padding(5, 5, 5, 5) Me.LayoutControlItem2.Size = New System.Drawing.Size(278, 30) Me.LayoutControlItem2.Text = "Belegdatum Von" - Me.LayoutControlItem2.TextSize = New System.Drawing.Size(77, 13) + Me.LayoutControlItem2.TextSize = New System.Drawing.Size(85, 13) ' 'LayoutControlItem5 ' @@ -643,7 +643,7 @@ Partial Class frmExportMain Me.LayoutControlItem6.Padding = New DevExpress.XtraLayout.Utils.Padding(5, 5, 5, 5) Me.LayoutControlItem6.Size = New System.Drawing.Size(278, 30) Me.LayoutControlItem6.Text = "BelegNr Von" - Me.LayoutControlItem6.TextSize = New System.Drawing.Size(77, 13) + Me.LayoutControlItem6.TextSize = New System.Drawing.Size(85, 13) ' 'LayoutControlItem7 ' @@ -653,7 +653,7 @@ Partial Class frmExportMain Me.LayoutControlItem7.Padding = New DevExpress.XtraLayout.Utils.Padding(5, 5, 5, 5) Me.LayoutControlItem7.Size = New System.Drawing.Size(278, 30) Me.LayoutControlItem7.Text = "BelegNr Bis" - Me.LayoutControlItem7.TextSize = New System.Drawing.Size(77, 13) + Me.LayoutControlItem7.TextSize = New System.Drawing.Size(85, 13) ' 'LayoutControlItem8 ' @@ -663,31 +663,31 @@ Partial Class frmExportMain Me.LayoutControlItem8.Padding = New DevExpress.XtraLayout.Utils.Padding(5, 5, 5, 5) Me.LayoutControlItem8.Size = New System.Drawing.Size(278, 30) Me.LayoutControlItem8.Text = "Belegdatum Bis" - Me.LayoutControlItem8.TextSize = New System.Drawing.Size(77, 13) - ' - 'LayoutControlItem9 - ' - Me.LayoutControlItem9.Control = Me.comboDocumentType - Me.LayoutControlItem9.Location = New System.Drawing.Point(0, 60) - Me.LayoutControlItem9.Name = "LayoutControlItem9" - Me.LayoutControlItem9.Padding = New DevExpress.XtraLayout.Utils.Padding(5, 5, 5, 5) - Me.LayoutControlItem9.Size = New System.Drawing.Size(278, 30) - Me.LayoutControlItem9.Text = "Belegtyp" - Me.LayoutControlItem9.TextSize = New System.Drawing.Size(77, 13) + Me.LayoutControlItem8.TextSize = New System.Drawing.Size(85, 13) ' 'LayoutControlItem10 ' Me.LayoutControlItem10.Control = Me.comboDocumentKind - Me.LayoutControlItem10.Location = New System.Drawing.Point(0, 30) + Me.LayoutControlItem10.Location = New System.Drawing.Point(0, 60) Me.LayoutControlItem10.Name = "LayoutControlItem10" Me.LayoutControlItem10.Padding = New DevExpress.XtraLayout.Utils.Padding(5, 5, 5, 5) Me.LayoutControlItem10.Size = New System.Drawing.Size(278, 30) Me.LayoutControlItem10.Text = "Belegart" - Me.LayoutControlItem10.TextSize = New System.Drawing.Size(77, 13) + Me.LayoutControlItem10.TextSize = New System.Drawing.Size(85, 13) + ' + 'LayoutControlItem9 + ' + Me.LayoutControlItem9.Control = Me.comboDocumentType + Me.LayoutControlItem9.Location = New System.Drawing.Point(0, 30) + Me.LayoutControlItem9.Name = "LayoutControlItem9" + Me.LayoutControlItem9.Padding = New DevExpress.XtraLayout.Utils.Padding(5, 5, 5, 5) + Me.LayoutControlItem9.Size = New System.Drawing.Size(278, 30) + Me.LayoutControlItem9.Text = "Belegtyp" + Me.LayoutControlItem9.TextSize = New System.Drawing.Size(85, 13) ' 'LabelControl2 ' - Me.LabelControl2.Appearance.Font = New System.Drawing.Font("Tahoma", 48.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) + Me.LabelControl2.Appearance.Font = New System.Drawing.Font("Tahoma", 48.0!) Me.LabelControl2.Appearance.ForeColor = System.Drawing.Color.Silver Me.LabelControl2.Appearance.Options.UseFont = True Me.LabelControl2.Appearance.Options.UseForeColor = True @@ -770,8 +770,8 @@ Partial Class frmExportMain CType(Me.LayoutControlItem6, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.LayoutControlItem7, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.LayoutControlItem8, System.ComponentModel.ISupportInitialize).EndInit() - CType(Me.LayoutControlItem9, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.LayoutControlItem10, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.LayoutControlItem9, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) Me.PerformLayout() diff --git a/MultiTool.Form/frmExportMain.vb b/MultiTool.Form/frmExportMain.vb index ea74f41..8d41474 100644 --- a/MultiTool.Form/frmExportMain.vb +++ b/MultiTool.Form/frmExportMain.vb @@ -89,7 +89,13 @@ Public Class frmExportMain Select(AddressOf MapDocumentTypeFromEnum). ToList() + Dim oDocType = CurrentTemplate.GetParameter("DOCTYPE") + Dim oPreselectedDocType As Integer = 0 + If oDocType IsNot Nothing Then + Integer.TryParse(oDocType, oPreselectedDocType) + End If + comboDocumentType.EditValue = oPreselectedDocType If ConfigManager.Config.LastUsedMandator <> "" Then lookupMandator.EditValue = Winline.Mandators. @@ -101,8 +107,15 @@ Public Class frmExportMain End Try End Sub + Private Function MapDocumentTypeToEnum(Of T)(pValue As Integer) As T + Return [Enum].Parse(GetType(T), pValue) + End Function + Private Function MapDocumentTypeFromEnum(pValue As WinlineData.DocumentType) Select Case pValue + Case WinlineData.DocumentType.Undefined + Return New KeyValuePair(Of String, Integer)("Alle", pValue) + Case WinlineData.DocumentType.IncomingOffer Return New KeyValuePair(Of String, Integer)("Angebot EK", pValue) @@ -156,7 +169,7 @@ Public Class frmExportMain ConfigManager.Save() End Sub - Private Sub lookup_Properties_ButtonClick(sender As Object, e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles comboDocumentKind.Properties.ButtonClick, lookupAccount.Properties.ButtonClick, comboDocumentType.ButtonClick + Private Sub lookup_Properties_ButtonClick(sender As Object, e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles lookupAccount.Properties.ButtonClick Dim oLookup As GridLookUpEdit = sender If e.Button.Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Clear Then oLookup.EditValue = Nothing @@ -170,9 +183,6 @@ Public Class frmExportMain End If End Sub - - - Private Sub SearchDocuments() Try dateDocDateFrom.DoValidate() @@ -189,6 +199,7 @@ Public Class frmExportMain Dim oDocNumberFrom = Utils.NotNull(txtDocumentFrom.EditValue, String.Empty) Dim oDocNumberTo = Utils.NotNull(txtDocumentTo.EditValue, String.Empty) + Dim oDocType As WinlineData.DocumentType = MapDocumentTypeToEnum(Of WinlineData.DocumentType)(comboDocumentType.EditValue) If oMandator Is Nothing Then FormHelper.ShowWarning("Bitte einen Mandanten auswählen!") @@ -196,7 +207,7 @@ Public Class frmExportMain End If 'TODO: Make Document Type configurable - Dim oDocuments = Winline.GetDocuments(oMandator, CurrentTemplate, comboDocumentType.EditValue, New WinlineData.GetDocumentArgs With { + Dim oDocuments = Winline.GetDocuments(oMandator, CurrentTemplate, oDocType, New WinlineData.GetDocumentArgs With { .Account = oAccount, .Kinds = oKinds, .DateFrom = oDateFrom, diff --git a/MultiTool.Shared/Documents/Document.vb b/MultiTool.Shared/Documents/Document.vb index e7f0806..b8fcda2 100644 --- a/MultiTool.Shared/Documents/Document.vb +++ b/MultiTool.Shared/Documents/Document.vb @@ -52,6 +52,21 @@ Namespace Documents End Get End Property + ''' + ''' Finds the first occurrence of Field and returns its value + ''' + 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 diff --git a/MultiTool.Shared/Documents/DocumentLoader.vb b/MultiTool.Shared/Documents/DocumentLoader.vb index 5884dba..b3610ea 100644 --- a/MultiTool.Shared/Documents/DocumentLoader.vb +++ b/MultiTool.Shared/Documents/DocumentLoader.vb @@ -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 ''' - 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) + + ' 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) diff --git a/MultiTool.Shared/Templates/Template.vb b/MultiTool.Shared/Templates/Template.vb index 0051e32..65975e6 100644 --- a/MultiTool.Shared/Templates/Template.vb +++ b/MultiTool.Shared/Templates/Template.vb @@ -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) diff --git a/MultiTool.Shared/Winline/WinlineData.vb b/MultiTool.Shared/Winline/WinlineData.vb index 0b320e3..c2dbc56 100644 --- a/MultiTool.Shared/Winline/WinlineData.vb +++ b/MultiTool.Shared/Winline/WinlineData.vb @@ -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