Constraints for search export documents
This commit is contained in:
@@ -12,7 +12,7 @@ Imports System.Runtime.InteropServices
|
||||
<Assembly: AssemblyDescription("")>
|
||||
<Assembly: AssemblyCompany("")>
|
||||
<Assembly: AssemblyProduct("MultiTool.Shared")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2021")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2022")>
|
||||
<Assembly: AssemblyTrademark("")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' indem Sie "*" wie unten gezeigt eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.0.0.0")>
|
||||
<Assembly: AssemblyVersion("1.2.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
||||
|
||||
@@ -7,7 +7,7 @@ Imports MultiTool.Shared.Winline.Entities
|
||||
Public Class Patterns
|
||||
Inherits BaseClass
|
||||
|
||||
Private GeneralConfig As GeneralConfig
|
||||
Private ReadOnly GeneralConfig As GeneralConfig
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pGeneralConfig As GeneralConfig)
|
||||
MyBase.New(pLogConfig)
|
||||
|
||||
@@ -33,10 +33,14 @@ Namespace Winline
|
||||
End Sub
|
||||
|
||||
Public Enum DocumentType
|
||||
Offer = 1
|
||||
Order = 2
|
||||
DeliverySlip = 3
|
||||
Invoice = 4
|
||||
OutgoingOffer = 1
|
||||
OutgoingOrder = 2
|
||||
OutgoingDeliveryNote = 3
|
||||
OutgoingInvoice = 4
|
||||
IncomingOffer = -1
|
||||
IncomingOrder = -2
|
||||
IncomingDeliveryNote = -3
|
||||
IncomingInvoice = -4
|
||||
End Enum
|
||||
|
||||
Public Class GetDocumentArgs
|
||||
@@ -44,6 +48,8 @@ Namespace Winline
|
||||
Public Property Kind As DocumentKind
|
||||
Public Property DateFrom As Date
|
||||
Public Property DateTo As Date
|
||||
Public Property DocNumberFrom As String
|
||||
Public Property DocNumberTo As String
|
||||
Public Property ShowExported As Boolean
|
||||
End Class
|
||||
|
||||
@@ -522,66 +528,92 @@ Namespace Winline
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
Public Function GetDocuments(pMandator As Mandator, pTemplate As Template, pDocumentType As DocumentType, pOptions As GetDocumentArgs) As List(Of Document)
|
||||
Public Function GetDocuments(pMandator As Mandator, pTemplate As Template, pDocumentType As Integer, pOptions As GetDocumentArgs) As List(Of Document)
|
||||
Try
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
|
||||
Dim oTypeConstraint = ""
|
||||
If pDocumentType <> 0 Then
|
||||
oTypeConstraint = $"T.c139 = {pDocumentType} AND "
|
||||
End If
|
||||
|
||||
Dim oAccountConstraint = ""
|
||||
If pOptions.Account IsNot Nothing Then
|
||||
oAccountConstraint = $"c021 = '{pOptions.Account.Id}' AND "
|
||||
oAccountConstraint = $"T.c021 = '{pOptions.Account.Id}' AND "
|
||||
End If
|
||||
|
||||
Dim oKindConstraint = ""
|
||||
If pOptions.Kind IsNot Nothing Then
|
||||
oKindConstraint = $"c035 = {pOptions.Kind.Id} AND "
|
||||
oKindConstraint = $"T.c035 = {pOptions.Kind.Id} AND "
|
||||
End If
|
||||
|
||||
Dim oDateConstraint = ""
|
||||
If pOptions.DateFrom <> Date.MinValue And pOptions.DateTo <> Date.MinValue Then
|
||||
oDateConstraint = $""
|
||||
Dim oDateFromConstraint = ""
|
||||
If pOptions.DateFrom <> Date.MinValue Then
|
||||
oDateFromConstraint = $"T2.DATE >= CAST('{pOptions.DateFrom.ToString("yyyy-MM-dd")}' as date) AND "
|
||||
End If
|
||||
|
||||
Dim oExportedConstraint = "U010 = 0 AND"
|
||||
Dim oDateToConstraint = ""
|
||||
If pOptions.DateTo <> Date.MinValue Then
|
||||
oDateToConstraint = $"T2.DATE <= CAST('{pOptions.DateTo.ToString("yyyy-MM-dd")}' as date) AND "
|
||||
End If
|
||||
|
||||
Dim oDocNumberConstraint = ""
|
||||
If pOptions.DocNumberFrom <> String.Empty Then
|
||||
oDocNumberConstraint &= $"T.c044 >= '{pOptions.DocNumberFrom}' AND "
|
||||
End If
|
||||
If pOptions.DocNumberTo <> String.Empty Then
|
||||
oDocNumberConstraint &= $"T.c044 <= '{pOptions.DocNumberTo}' AND "
|
||||
End If
|
||||
|
||||
Dim oExportedConstraint = "(T.U010 = 0 OR T.U010 IS NULL) AND"
|
||||
If pOptions.ShowExported Then
|
||||
oExportedConstraint = ""
|
||||
End If
|
||||
|
||||
Dim oDocumentType As Integer = pDocumentType
|
||||
Dim oSql = $"
|
||||
SELECT
|
||||
c139 DOCUMENT_TYPE,
|
||||
c035 DOCUMENT_KIND,
|
||||
|
||||
c021 ACCOUNT_NUMBER,
|
||||
c022 RUNNING_NUMBER,
|
||||
|
||||
c043 OFFER_NUMBER,
|
||||
c027 OFFER_DATE,
|
||||
|
||||
c044 ORDER_NUMBER,
|
||||
c028 ORDER_DATE,
|
||||
|
||||
c045 DELIVERY_NUMBER,
|
||||
c029 DELIVERY_DATE,
|
||||
|
||||
c055 INVOICE_NUMBER,
|
||||
c032 INVOICE_DATE,
|
||||
|
||||
c100 GROSS_AMOUNT,
|
||||
c114 NET_AMOUNT,
|
||||
|
||||
U010 ALREADY_EXPORTED,
|
||||
U011 EXPORTED_WHO,
|
||||
U012 EXPORTED_WHEN,
|
||||
U013 EXPORTED_FILE
|
||||
|
||||
FROM [{pMandator.Database}].[dbo].[T025]
|
||||
SELECT
|
||||
T2.DATE,
|
||||
T.c139 DOCUMENT_TYPE,
|
||||
T.c035 DOCUMENT_KIND,
|
||||
T.c021 ACCOUNT_NUMBER,
|
||||
T.c022 RUNNING_NUMBER,
|
||||
T.c043 OFFER_NUMBER,
|
||||
T.c027 OFFER_DATE,
|
||||
T.c044 ORDER_NUMBER,
|
||||
T.c028 ORDER_DATE,
|
||||
T.c045 DELIVERY_NUMBER,
|
||||
T.c029 DELIVERY_DATE,
|
||||
T.c055 INVOICE_NUMBER,
|
||||
T.c032 INVOICE_DATE,
|
||||
T.c100 GROSS_AMOUNT,
|
||||
T.c114 NET_AMOUNT,
|
||||
T.U010 ALREADY_EXPORTED,
|
||||
T.U011 EXPORTED_WHO,
|
||||
T.U012 EXPORTED_WHEN,
|
||||
T.U013 EXPORTED_FILE
|
||||
FROM [{pMandator.Database}].[dbo].[T025] T
|
||||
INNER JOIN (SELECT * FROM (
|
||||
SELECT c021, c022, mesoyear, mesocomp, c027 [DATE] FROM [{pMandator.Database}].[dbo].[T025]
|
||||
WHERE c139 = 1 OR c139 = -1
|
||||
UNION
|
||||
SELECT c021, c022, mesoyear, mesocomp, c028 [DATE] FROM [{pMandator.Database}].[dbo].[T025]
|
||||
WHERE c139 = 2 OR c139 = -2
|
||||
UNION
|
||||
SELECT c021, c022, mesoyear, mesocomp, c029 [DATE] FROM [{pMandator.Database}].[dbo].[T025]
|
||||
WHERE c139 = 3 OR c139 = -3
|
||||
UNION
|
||||
SELECT c021, c022, mesoyear, mesocomp, c032 [DATE] FROM [{pMandator.Database}].[dbo].[T025]
|
||||
WHERE c139 = 4 OR c139 = -4
|
||||
) QUERY) T2 ON T.c021 = T2.c021 AND T.c022 = T2.c022 AND T.mesoyear = T2.mesoyear AND T.mesocomp = T2.mesocomp
|
||||
WHERE
|
||||
c139 = {oDocumentType} AND
|
||||
{oTypeConstraint}
|
||||
{oAccountConstraint}
|
||||
{oKindConstraint}
|
||||
{oExportedConstraint}
|
||||
[mesocomp] = '{pMandator.Id}' AND [mesoyear] = {oYear}"
|
||||
{oDocNumberConstraint}
|
||||
{oDateFromConstraint}
|
||||
{oDateToConstraint}
|
||||
T.[mesocomp] = '{pMandator.Id}' AND T.[mesoyear] = {oYear}"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSql)
|
||||
Dim oDocuments As New List(Of Document)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user