From aff92e2b347241ca031a21d3a009b3da76f52293 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Fri, 8 Apr 2022 10:28:46 +0200 Subject: [PATCH] Add packing units, calculate price according to packing units --- MultiTool.Common/Documents/Document.vb | 1 - MultiTool.Common/Documents/DocumentType.vb | 8 -- MultiTool.Common/MultiTool.Common.vbproj | 2 +- MultiTool.Common/Templates/Template.vb | 37 ++++++ .../Winline/Entities/PackingUnit.vb | 25 ++++ MultiTool.Common/Winline/WinlineData.vb | 110 ++++++++++++++++-- MultiTool.Form/frmExportMain.vb | 9 +- 7 files changed, 165 insertions(+), 27 deletions(-) delete mode 100644 MultiTool.Common/Documents/DocumentType.vb create mode 100644 MultiTool.Common/Winline/Entities/PackingUnit.vb diff --git a/MultiTool.Common/Documents/Document.vb b/MultiTool.Common/Documents/Document.vb index 1d8999e..be40524 100644 --- a/MultiTool.Common/Documents/Document.vb +++ b/MultiTool.Common/Documents/Document.vb @@ -5,7 +5,6 @@ Imports MultiTool.Common.Winline.Entities Namespace Documents Public Class Document Public File As FileInfo - Public Property Type As DocumentType Public Schema As Template Public Mandator As Mandator diff --git a/MultiTool.Common/Documents/DocumentType.vb b/MultiTool.Common/Documents/DocumentType.vb deleted file mode 100644 index 680b1bd..0000000 --- a/MultiTool.Common/Documents/DocumentType.vb +++ /dev/null @@ -1,8 +0,0 @@ -Namespace Documents - Public Enum DocumentType - Order ' Auftrag - OrderResponse ' Bestellbestätigung - DispatchNotification ' Lieferavis/ Eingangs Lieferschein - Invoice ' Rechnung - End Enum -End Namespace diff --git a/MultiTool.Common/MultiTool.Common.vbproj b/MultiTool.Common/MultiTool.Common.vbproj index 740841d..ca9f5a5 100644 --- a/MultiTool.Common/MultiTool.Common.vbproj +++ b/MultiTool.Common/MultiTool.Common.vbproj @@ -107,7 +107,6 @@ - @@ -140,6 +139,7 @@ + diff --git a/MultiTool.Common/Templates/Template.vb b/MultiTool.Common/Templates/Template.vb index d2d6b13..7165216 100644 --- a/MultiTool.Common/Templates/Template.vb +++ b/MultiTool.Common/Templates/Template.vb @@ -1,4 +1,5 @@ Imports DigitalData.Modules.Language +Imports MultiTool.Common.Winline.WinlineData Namespace Templates @@ -21,6 +22,41 @@ Namespace Templates Public Property OutputDirectory As String Public Property ArchiveDirectory As String + Public ReadOnly Property DocType As DocumentType + Get + Dim oDocType As String = GetParameter("DOCTYPE") + Dim oPreselectedDocType As Integer = 0 + + If oDocType IsNot Nothing Then + Integer.TryParse(oDocType, oPreselectedDocType) + End If + + Return [Enum].Parse(GetType(DocumentType), oPreselectedDocType) + End Get + End Property + + Public ReadOnly Property DocTypeCategory As DocumentTypeCategory + Get + Select Case DocType + Case DocumentType.IncomingOffer, + DocumentType.IncomingOrder, + DocumentType.IncomingDeliveryNote, + DocumentType.IncomingInvoice + Return DocumentTypeCategory.Outgoing + + Case DocumentType.OutgoingOffer, + DocumentType.OutgoingOrder, + DocumentType.OutgoingDeliveryNote, + DocumentType.OutgoingInvoice + Return DocumentTypeCategory.Incoming + + Case Else + Return DocumentTypeCategory.Undefined + + End Select + End Get + End Property + Public ReadOnly Property OutputReportDirectory Get Return IO.Path.Combine(OutputDirectory, "Reports") @@ -39,6 +75,7 @@ Namespace Templates 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) diff --git a/MultiTool.Common/Winline/Entities/PackingUnit.vb b/MultiTool.Common/Winline/Entities/PackingUnit.vb new file mode 100644 index 0000000..7533467 --- /dev/null +++ b/MultiTool.Common/Winline/Entities/PackingUnit.vb @@ -0,0 +1,25 @@ +Namespace Winline.Entities + Public Class PackingUnit + Public Property Name As String + Public Property Description As String + Public Property Description2 As String + Public Property Unit As Integer + Public Property Factor As Decimal + Public Property Flag As Integer + + Public Property Mandator As Mandator + + Public Overrides Function GetHashCode() As Integer + Return Name.GetHashCode() + End Function + + Public Overrides Function Equals(obj As Object) As Boolean + Return DirectCast(obj, PackingUnit).Name = Name + End Function + + Public Overrides Function ToString() As String + Return Name + End Function + End Class + +End Namespace diff --git a/MultiTool.Common/Winline/WinlineData.vb b/MultiTool.Common/Winline/WinlineData.vb index 7ff8692..c1c4569 100644 --- a/MultiTool.Common/Winline/WinlineData.vb +++ b/MultiTool.Common/Winline/WinlineData.vb @@ -17,6 +17,7 @@ Namespace Winline Public Property Articles As New List(Of Article) Public Property Accounts As New List(Of Account) + Public Property PackingUnits As New List(Of PackingUnit) Public Property Mandators As New List(Of Mandator) Public Property DocumentKinds As New List(Of DocumentKind) @@ -30,16 +31,27 @@ Namespace Winline MappingConfig = pMappingConfig End Sub + ''' + ''' Winline Doctype. + ''' + ''' Used for filtering Documents when exporting and determining the type of document (sales/purchasing) + ''' Public Enum DocumentType - Undefined - OutgoingOffer - OutgoingOrder - OutgoingDeliveryNote - OutgoingInvoice - IncomingOffer - IncomingOrder - IncomingDeliveryNote - IncomingInvoice + Undefined = 0 + OutgoingOffer = 1 + OutgoingOrder = 2 + OutgoingDeliveryNote = 3 + OutgoingInvoice = 4 + IncomingOffer = 5 + IncomingOrder = 6 + IncomingDeliveryNote = 7 + IncomingInvoice = 8 + End Enum + + Public Enum DocumentTypeCategory + Undefined = 0 + Outgoing = 1 + Incoming = 2 End Enum Public Class GetDocumentArgs @@ -93,6 +105,57 @@ Namespace Winline End Try End Function + Public Async Function LoadPackingUnits(pMandator As Mandator) As Task + Logger.Info("Loading Packing Units for Mandator [{0}]", pMandator) + Dim oYear = Config.GetWinLineYear() + + Try + Dim oSQL = $" + SELECT DISTINCT + [c002], -- Name + [c003], -- Description + [c004], -- Description 2 + [c005], -- Unit + [c006], -- Value/Factor + [c007] -- Flag (?) + FROM [{pMandator.Server}].[{pMandator.Database}].[dbo].[t346] + WHERE + mesocomp = '{pMandator.Id}' + AND mesoyear = {oYear}" + Dim oTable = Await Database.GetDatatableAsync(oSQL) + Dim oPackingUnits As New List(Of PackingUnit) + + For Each oRow As DataRow In oTable.Rows + Dim oName As String = ItemEx(oRow, "c002", String.Empty) + Dim oDescription As String = ItemEx(oRow, "c003", String.Empty) + Dim oDescription2 As String = ItemEx(oRow, "c004", String.Empty) + Dim oUnit As Decimal = ItemEx(oRow, "c005", 0.0) + Dim oFactor As Decimal = ItemEx(oRow, "c006", 0.0) + Dim oFlag As Integer = ItemEx(oRow, "c007", 0) + + oPackingUnits.Add(New PackingUnit With { + .Name = oName, + .Description = oDescription, + .Description2 = oDescription2, + .Unit = oUnit, + .Factor = oFactor, + .Flag = oFlag, + .Mandator = pMandator + }) + Next + PackingUnits.AddRange(oPackingUnits) + + If oPackingUnits.Count = 0 Then + Logger.Warn("No Packing Units loaded for Mandator [{0}]", pMandator) + End If + + Logger.Info("[{0}] Packing Units loaded for Mandator [{1}]", oPackingUnits.Count, pMandator) + Catch ex As Exception + Logger.Warn("Could not load Packing Units for Mandator [{0}]", pMandator) + Logger.Error(ex) + End Try + End Function + Public Async Function LoadAccounts(pMandator As Mandator) As Task Logger.Info("Loading Accounts for Mandator [{0}]", pMandator) Dim oYear = Config.GetWinLineYear() @@ -370,6 +433,11 @@ Namespace Winline Dim oRow As DataRow = oTable.Rows.Item(0) Dim oPrice As Double = oRow.Item("PRICE") + Dim oPackingUnit As PackingUnit = MaybeGetPackingUnit(pTemplate, oRow, pMandator) + + If oPackingUnit IsNot Nothing AndAlso oPackingUnit.Factor > 0 Then + oPrice *= oPackingUnit.Factor + End If Return oPrice @@ -381,6 +449,30 @@ Namespace Winline End Try End Function + Private Function MaybeGetPackingUnit(pTemplate As Template, oRow As DataRow, pMandator As Mandator) As PackingUnit + Dim oPackingUnit As PackingUnit = Nothing + + Select Case pTemplate.DocTypeCategory + Case DocumentTypeCategory.Incoming + Dim oPackingUnitPurchasingName = oRow.ItemEx("PACKINGUNIT_PURCHASING", "") + Dim oPackingUnitPurchasing = PackingUnits. + Where(Function(unit) unit.Name.Equals(oPackingUnitPurchasingName) And unit.Mandator.Equals(pMandator)). + FirstOrDefault() + + oPackingUnit = oPackingUnitPurchasing + + Case DocumentTypeCategory.Outgoing + Dim oPackingUnitSalesName = oRow.ItemEx("PACKINGUNIT_SALES", "") + Dim oPackingUnitSales = PackingUnits. + Where(Function(unit) unit.Name.Equals(oPackingUnitSalesName) And unit.Mandator.Equals(pMandator)). + FirstOrDefault() + + oPackingUnit = oPackingUnitSales + End Select + + Return oPackingUnit + End Function + ''' ''' This function is completely SCHAUM related. ''' diff --git a/MultiTool.Form/frmExportMain.vb b/MultiTool.Form/frmExportMain.vb index 9fd5267..a80fb2f 100644 --- a/MultiTool.Form/frmExportMain.vb +++ b/MultiTool.Form/frmExportMain.vb @@ -89,14 +89,7 @@ Public Class frmExportMain Cast(Of WinlineData.DocumentType)(). 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 + comboDocumentType.EditValue = DirectCast(CurrentTemplate.DocType, Integer) If ConfigManager.Config.LastUsedMandator <> "" Then lookupMandator.EditValue = Winline.Mandators.