directories per template, export tweaks
This commit is contained in:
@@ -36,6 +36,14 @@ Namespace Winline
|
||||
Invoice = 4
|
||||
End Enum
|
||||
|
||||
Public Class GetDocumentArgs
|
||||
Public Property Account As Account
|
||||
Public Property Kind As DocumentKind
|
||||
Public Property DateFrom As Date
|
||||
Public Property DateTo As Date
|
||||
Public Property ShowExported As Boolean
|
||||
End Class
|
||||
|
||||
|
||||
Public Async Function LoadArticles(pMandator As Mandator) As Task
|
||||
Logger.Info("Loading Articles for Mandator [{0}]", pMandator)
|
||||
@@ -391,8 +399,6 @@ Namespace Winline
|
||||
|
||||
Dim oYear = Config.GetWinLineYear()
|
||||
Dim oMandatorId As String = String.Empty
|
||||
|
||||
' TODO: Instead load whitelisted mandators from database
|
||||
Dim oWhitelistedMandators = Mandators.
|
||||
Where(Function(m) m.IsWhitelisted = True).
|
||||
OrderBy(Function(m) m.Order).
|
||||
@@ -455,13 +461,35 @@ Namespace Winline
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
Public Function GetDocuments(pMandator As Mandator, pDocumentType As DocumentType) As List(Of Document)
|
||||
Public Function GetDocuments(pMandator As Mandator, pTemplate As Template, pDocumentType As DocumentType, pOptions As GetDocumentArgs) As List(Of Document)
|
||||
Try
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
|
||||
Dim oAccountConstraint = ""
|
||||
If pOptions.Account IsNot Nothing Then
|
||||
oAccountConstraint = $"c021 = '{pOptions.Account.Id}' AND "
|
||||
End If
|
||||
|
||||
Dim oKindConstraint = ""
|
||||
If pOptions.Kind IsNot Nothing Then
|
||||
oKindConstraint = $"c035 = {pOptions.Kind.Id} AND "
|
||||
End If
|
||||
|
||||
Dim oDateConstraint = ""
|
||||
If pOptions.DateFrom <> Date.MinValue And pOptions.DateTo <> Date.MinValue Then
|
||||
oDateConstraint = $""
|
||||
End If
|
||||
|
||||
Dim oExportedConstraint = "c111 = 0 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,
|
||||
@@ -478,10 +506,17 @@ Namespace Winline
|
||||
c055 INVOICE_NUMBER,
|
||||
c032 INVOICE_DATE,
|
||||
|
||||
mesoyear
|
||||
c100 GROSS_AMOUNT,
|
||||
c114 NET_AMOUNT,
|
||||
|
||||
c111 ALREADY_EXPORTED
|
||||
|
||||
FROM [{pMandator.Database}].[dbo].[T025]
|
||||
WHERE
|
||||
c139 = {oDocumentType} AND
|
||||
{oAccountConstraint}
|
||||
{oKindConstraint}
|
||||
{oExportedConstraint}
|
||||
[mesocomp] = '{pMandator.Id}' AND [mesoyear] = {oYear}"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSql)
|
||||
Dim oDocuments As New List(Of Document)
|
||||
@@ -489,6 +524,7 @@ Namespace Winline
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Try
|
||||
Dim oDocument = GetDocumentFromDataRow(oRow)
|
||||
oDocument.Schema = pTemplate
|
||||
oDocuments.Add(oDocument)
|
||||
|
||||
Catch ex As Exception
|
||||
@@ -511,26 +547,39 @@ Namespace Winline
|
||||
Dim oAccountNumber = pDataRow.Item("ACCOUNT_NUMBER")
|
||||
Dim oRunningNumber As String = pDataRow.Item("RUNNING_NUMBER")
|
||||
Dim oDocumentType As Integer = pDataRow.Item("DOCUMENT_TYPE")
|
||||
Dim oDocumentKind As Integer = pDataRow.Item("DOCUMENT_KIND")
|
||||
Dim oGrossAmount As Double = pDataRow.Item("GROSS_AMOUNT")
|
||||
Dim oNetAmount As Double = pDataRow.Item("NET_AMOUNT")
|
||||
Dim oExported As Boolean = pDataRow.Item("ALREADY_EXPORTED")
|
||||
Dim oDocumentNumber As String = Nothing
|
||||
Dim oDocumentDate As Date = Nothing
|
||||
Dim oDocumentDateColumn As String = Nothing
|
||||
|
||||
Dim oAccount = Accounts.
|
||||
Where(Function(acc) acc.Id = oAccountNumber).
|
||||
FirstOrDefault()
|
||||
|
||||
Dim oKind = DocumentKinds.
|
||||
Where(Function(kind) kind.Id = oDocumentKind).
|
||||
FirstOrDefault()
|
||||
|
||||
Select Case oDocumentType
|
||||
Case 1
|
||||
oDocumentNumber = pDataRow.Item("OFFER_NUMBER")
|
||||
oDocumentDate = pDataRow.Item("OFFER_DATE")
|
||||
oDocumentDateColumn = "c027"
|
||||
Case 2
|
||||
oDocumentNumber = pDataRow.Item("ORDER_NUMBER")
|
||||
oDocumentDate = pDataRow.Item("ORDER_DATE")
|
||||
oDocumentDateColumn = "c028"
|
||||
Case 3
|
||||
oDocumentNumber = pDataRow.Item("DELIVERY_NUMBER")
|
||||
oDocumentDate = pDataRow.Item("DELIVERY_DATE")
|
||||
oDocumentDateColumn = "c029"
|
||||
Case 4
|
||||
oDocumentNumber = pDataRow.Item("INVOICE_NUMBER")
|
||||
oDocumentDate = pDataRow.Item("INVOICE_DATE")
|
||||
oDocumentDateColumn = "c032"
|
||||
|
||||
End Select
|
||||
|
||||
@@ -538,7 +587,12 @@ Namespace Winline
|
||||
.Account = oAccount,
|
||||
.RunningNumber = oRunningNumber,
|
||||
.Number = oDocumentNumber,
|
||||
.[Date] = oDocumentDate
|
||||
.[Date] = oDocumentDate,
|
||||
.DateColumn = oDocumentDateColumn,
|
||||
.Kind = oKind,
|
||||
.GrossAmount = oGrossAmount,
|
||||
.NetAmount = oNetAmount,
|
||||
.IsExported = oExported
|
||||
}
|
||||
|
||||
Return oDocument
|
||||
|
||||
Reference in New Issue
Block a user