Add packing units, calculate price according to packing units
This commit is contained in:
25
MultiTool.Common/Winline/Entities/PackingUnit.vb
Normal file
25
MultiTool.Common/Winline/Entities/PackingUnit.vb
Normal 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
|
||||
@@ -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
|
||||
|
||||
''' <summary>
|
||||
''' Winline Doctype.
|
||||
'''
|
||||
''' Used for filtering Documents when exporting and determining the type of document (sales/purchasing)
|
||||
''' </summary>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' This function is completely SCHAUM related.
|
||||
''' </summary>
|
||||
|
||||
Reference in New Issue
Block a user