Add packing units, calculate price according to packing units

This commit is contained in:
Jonathan Jenne 2022-04-08 10:28:46 +02:00
parent 648666ef8c
commit aff92e2b34
7 changed files with 165 additions and 27 deletions

View File

@ -5,7 +5,6 @@ Imports MultiTool.Common.Winline.Entities
Namespace Documents Namespace Documents
Public Class Document Public Class Document
Public File As FileInfo Public File As FileInfo
Public Property Type As DocumentType
Public Schema As Template Public Schema As Template
Public Mandator As Mandator Public Mandator As Mandator

View File

@ -1,8 +0,0 @@
Namespace Documents
Public Enum DocumentType
Order ' Auftrag
OrderResponse ' Bestellbestätigung
DispatchNotification ' Lieferavis/ Eingangs Lieferschein
Invoice ' Rechnung
End Enum
End Namespace

View File

@ -107,7 +107,6 @@
<Compile Include="Documents\Document.vb" /> <Compile Include="Documents\Document.vb" />
<Compile Include="Documents\DocumentCleaner.vb" /> <Compile Include="Documents\DocumentCleaner.vb" />
<Compile Include="Documents\DocumentRow.vb" /> <Compile Include="Documents\DocumentRow.vb" />
<Compile Include="Documents\DocumentType.vb" />
<Compile Include="Documents\DocumentLoader.vb" /> <Compile Include="Documents\DocumentLoader.vb" />
<Compile Include="Exceptions.vb" /> <Compile Include="Exceptions.vb" />
<Compile Include="IDictionaryEx.vb" /> <Compile Include="IDictionaryEx.vb" />
@ -140,6 +139,7 @@
<Compile Include="Report\ReportPosition.vb" /> <Compile Include="Report\ReportPosition.vb" />
<Compile Include="Report\ReportSource.vb" /> <Compile Include="Report\ReportSource.vb" />
<Compile Include="Winline\Entities\ExportDocument.vb" /> <Compile Include="Winline\Entities\ExportDocument.vb" />
<Compile Include="Winline\Entities\PackingUnit.vb" />
<Compile Include="Winline\Entities\Response.vb" /> <Compile Include="Winline\Entities\Response.vb" />
<Compile Include="Templates\Template.vb" /> <Compile Include="Templates\Template.vb" />
<Compile Include="Templates\TemplateLoader.vb" /> <Compile Include="Templates\TemplateLoader.vb" />

View File

@ -1,4 +1,5 @@
Imports DigitalData.Modules.Language Imports DigitalData.Modules.Language
Imports MultiTool.Common.Winline.WinlineData
Namespace Templates Namespace Templates
@ -21,6 +22,41 @@ Namespace Templates
Public Property OutputDirectory As String Public Property OutputDirectory As String
Public Property ArchiveDirectory 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 Public ReadOnly Property OutputReportDirectory
Get Get
Return IO.Path.Combine(OutputDirectory, "Reports") Return IO.Path.Combine(OutputDirectory, "Reports")
@ -39,6 +75,7 @@ Namespace Templates
End Get End Get
End Property End Property
Public Function GetParameter(pName As String) As String Public Function GetParameter(pName As String) As String
Dim oParam1 As String = Utils.NotNull(Parameter1, String.Empty) Dim oParam1 As String = Utils.NotNull(Parameter1, String.Empty)
Dim oParam2 As String = Utils.NotNull(Parameter2, String.Empty) Dim oParam2 As String = Utils.NotNull(Parameter2, String.Empty)

View File

@ -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

View File

@ -17,6 +17,7 @@ Namespace Winline
Public Property Articles As New List(Of Article) Public Property Articles As New List(Of Article)
Public Property Accounts As New List(Of Account) 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 Mandators As New List(Of Mandator)
Public Property DocumentKinds As New List(Of DocumentKind) Public Property DocumentKinds As New List(Of DocumentKind)
@ -30,16 +31,27 @@ Namespace Winline
MappingConfig = pMappingConfig MappingConfig = pMappingConfig
End Sub End Sub
''' <summary>
''' Winline Doctype.
'''
''' Used for filtering Documents when exporting and determining the type of document (sales/purchasing)
''' </summary>
Public Enum DocumentType Public Enum DocumentType
Undefined Undefined = 0
OutgoingOffer OutgoingOffer = 1
OutgoingOrder OutgoingOrder = 2
OutgoingDeliveryNote OutgoingDeliveryNote = 3
OutgoingInvoice OutgoingInvoice = 4
IncomingOffer IncomingOffer = 5
IncomingOrder IncomingOrder = 6
IncomingDeliveryNote IncomingDeliveryNote = 7
IncomingInvoice IncomingInvoice = 8
End Enum
Public Enum DocumentTypeCategory
Undefined = 0
Outgoing = 1
Incoming = 2
End Enum End Enum
Public Class GetDocumentArgs Public Class GetDocumentArgs
@ -93,6 +105,57 @@ Namespace Winline
End Try End Try
End Function 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 Public Async Function LoadAccounts(pMandator As Mandator) As Task
Logger.Info("Loading Accounts for Mandator [{0}]", pMandator) Logger.Info("Loading Accounts for Mandator [{0}]", pMandator)
Dim oYear = Config.GetWinLineYear() Dim oYear = Config.GetWinLineYear()
@ -370,6 +433,11 @@ Namespace Winline
Dim oRow As DataRow = oTable.Rows.Item(0) Dim oRow As DataRow = oTable.Rows.Item(0)
Dim oPrice As Double = oRow.Item("PRICE") 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 Return oPrice
@ -381,6 +449,30 @@ Namespace Winline
End Try End Try
End Function 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
''' <summary> ''' <summary>
''' This function is completely SCHAUM related. ''' This function is completely SCHAUM related.
''' </summary> ''' </summary>

View File

@ -89,14 +89,7 @@ Public Class frmExportMain
Cast(Of WinlineData.DocumentType)(). Cast(Of WinlineData.DocumentType)().
Select(AddressOf MapDocumentTypeFromEnum). Select(AddressOf MapDocumentTypeFromEnum).
ToList() ToList()
comboDocumentType.EditValue = DirectCast(CurrentTemplate.DocType, Integer)
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 If ConfigManager.Config.LastUsedMandator <> "" Then
lookupMandator.EditValue = Winline.Mandators. lookupMandator.EditValue = Winline.Mandators.