directories per template, export tweaks
This commit is contained in:
@@ -3,4 +3,5 @@
|
||||
Public Class Config
|
||||
<ConnectionString>
|
||||
Public Property ConnectionString As String = ""
|
||||
Public Property Debug As Boolean = False
|
||||
End Class
|
||||
|
||||
@@ -10,7 +10,7 @@ Namespace Documents
|
||||
Public Mandator As Mandator
|
||||
|
||||
Public TemplateName As String
|
||||
Public TemplateType As Integer
|
||||
Public Property TemplateType As Integer
|
||||
Public [Option] As Integer
|
||||
Public PrintVoucher As Integer
|
||||
|
||||
|
||||
@@ -6,18 +6,18 @@ Namespace Documents
|
||||
Public Class DocumentCleaner
|
||||
Inherits BaseClass
|
||||
|
||||
Private ReadOnly GeneralConfig As GeneralConfig
|
||||
Private ReadOnly Template As Template
|
||||
Private ReadOnly FileEx As DigitalData.Modules.Filesystem.File
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pGeneralConfig As GeneralConfig)
|
||||
Public Sub New(pLogConfig As LogConfig, pTemplate As Template)
|
||||
MyBase.New(pLogConfig)
|
||||
GeneralConfig = pGeneralConfig
|
||||
Template = pTemplate
|
||||
FileEx = New DigitalData.Modules.Filesystem.File(LogConfig)
|
||||
End Sub
|
||||
|
||||
Public Function CleanImportedDocuments(pDocuments As List(Of Document)) As Boolean
|
||||
Dim oResult = True
|
||||
Dim oOutputDirectory = FileEx.GetDateDirectory(GeneralConfig.OutputXmlFileDirectory)
|
||||
Dim oOutputDirectory = FileEx.GetDateDirectory(Template.OutputXmlFileDirectory)
|
||||
Dim oImportedDocuments = pDocuments.
|
||||
Where(Function(doc) doc.Imported = True).
|
||||
ToList()
|
||||
|
||||
@@ -29,17 +29,12 @@ Namespace Documents
|
||||
TemplateConfig = pTemplateConfig
|
||||
End Sub
|
||||
|
||||
|
||||
Public Function LoadFiles(pInputDirectory As String, pTemplate As Template, pMandator As Mandator) As Boolean
|
||||
If pInputDirectory = String.Empty Then
|
||||
Throw New ArgumentNullException("InputDirectory")
|
||||
End If
|
||||
|
||||
Logger.Info("Loading files from directory [{0}]", pInputDirectory)
|
||||
Public Function LoadFiles(pTemplate As Template, pMandator As Mandator) As Boolean
|
||||
Logger.Info("Loading files from directory [{0}]", pTemplate.InputDirectory)
|
||||
Files.Clear()
|
||||
|
||||
Try
|
||||
Dim oDirectory As New DirectoryInfo(pInputDirectory)
|
||||
Dim oDirectory As New DirectoryInfo(pTemplate.InputDirectory)
|
||||
Dim oFiles = oDirectory.GetFiles()
|
||||
|
||||
Logger.Debug("Found [{0}] files in directory [{1}]", oFiles.Count, oDirectory)
|
||||
|
||||
@@ -23,8 +23,8 @@ Public Class ReportGenerator(Of TReport As IReport)
|
||||
FileEx = New DigitalData.Modules.Filesystem.File(LogConfig)
|
||||
End Sub
|
||||
|
||||
Public Function GetReportFilePath(pDocument As Document)
|
||||
Dim oFinalDirectory = FileEx.GetDateDirectory(GeneralConfig.OutputReportDirectory)
|
||||
Public Function GetReportFilePath(pDocument As Document, pTemplate As Template)
|
||||
Dim oFinalDirectory = FileEx.GetDateDirectory(pTemplate.OutputReportDirectory)
|
||||
Dim oFileName = FileEx.GetFilenameWithSuffix(IO.Path.GetFileNameWithoutExtension(pDocument.File.Name), FileEx.GetDateTimeString, "pdf")
|
||||
Dim oFilePath As String = IO.Path.Combine(oFinalDirectory, oFileName)
|
||||
Return oFilePath
|
||||
|
||||
@@ -1,26 +1,8 @@
|
||||
Namespace Templates
|
||||
Public Class GeneralConfig
|
||||
Public Property InputDirectory As String = ""
|
||||
Public Property OutputDirectory As String = ""
|
||||
Public Property TemplateDirectory As String = ""
|
||||
|
||||
Public ReadOnly Property OutputReportDirectory
|
||||
Get
|
||||
Return IO.Path.Combine(OutputDirectory, "Reports")
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property OutputWebserviceDirectory
|
||||
Get
|
||||
Return IO.Path.Combine(OutputDirectory, "WebService")
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property OutputXmlFileDirectory
|
||||
Get
|
||||
Return IO.Path.Combine(OutputDirectory, "XmlFiles")
|
||||
End Get
|
||||
End Property
|
||||
Public Property Templates As New List(Of TemplateConfig)
|
||||
|
||||
Public Property Webservice As New WebServiceConfig()
|
||||
Public Property DefaultYearOverride As Integer = 0
|
||||
|
||||
@@ -1,12 +1,38 @@
|
||||
Namespace Templates
|
||||
Public Class Template
|
||||
Public Property Guid As Integer
|
||||
Public Property Name As String
|
||||
Public Property FileName As String
|
||||
Public Property Description As String
|
||||
Public Property IsImport As Boolean
|
||||
Public Property Parameter1 As String
|
||||
Public Property Parameter2 As String
|
||||
Public Property FinalSQL As String
|
||||
|
||||
Public Property Tables As New List(Of Table)
|
||||
|
||||
Public Property InputDirectory As String
|
||||
Public Property OutputDirectory As String
|
||||
Public Property ArchiveDirectory As String
|
||||
|
||||
Public ReadOnly Property OutputReportDirectory
|
||||
Get
|
||||
Return IO.Path.Combine(OutputDirectory, "Reports")
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property OutputWebserviceDirectory
|
||||
Get
|
||||
Return IO.Path.Combine(OutputDirectory, "WebService")
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property OutputXmlFileDirectory
|
||||
Get
|
||||
Return IO.Path.Combine(OutputDirectory, "XmlFiles")
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Class Table
|
||||
Public Property Name As String
|
||||
Public Property Columns As New List(Of Column)
|
||||
|
||||
@@ -34,10 +34,14 @@ Namespace Templates
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oTemplate As New Template With {
|
||||
.Guid = oRow.Item("GUID"),
|
||||
.Name = oRow.ItemEx("NAME", String.Empty),
|
||||
.Description = oRow.ItemEx("DESCRIPTION", String.Empty),
|
||||
.FileName = oRow.ItemEx("FILE_NAME", String.Empty),
|
||||
.IsImport = oRow.ItemEx("IS_IMPORT", True)
|
||||
.IsImport = oRow.ItemEx("IS_IMPORT", True),
|
||||
.FinalSQL = oRow.ItemEx("FINAL_SQL", String.Empty),
|
||||
.Parameter1 = oRow.ItemEx("PARAMETER_1", String.Empty),
|
||||
.Parameter2 = oRow.ItemEx("PARAMETER_2", String.Empty)
|
||||
}
|
||||
|
||||
oTemplates.Add(oTemplate)
|
||||
@@ -80,12 +84,6 @@ Namespace Templates
|
||||
Case "WEBSERVICE_IMPORT_RELATIVE_PATH"
|
||||
oGeneralConfig.Webservice.ImportRelativePath = oValue
|
||||
|
||||
Case "INPUT_DIRECTORY"
|
||||
oGeneralConfig.InputDirectory = oValue
|
||||
|
||||
Case "OUTPUT_DIRECTORY"
|
||||
oGeneralConfig.OutputDirectory = oValue
|
||||
|
||||
Case "TEMPLATE_DIRECTORY"
|
||||
oGeneralConfig.TemplateDirectory = oValue
|
||||
|
||||
@@ -237,7 +235,7 @@ Namespace Templates
|
||||
Return pTemplate
|
||||
End Function
|
||||
|
||||
Public Function UpdateTemplateFromDatabase(pTemplate As Template, pTemplateConfig As TemplateConfig) As Template
|
||||
Public Function UpdateTemplateTablesFromDatabase(pTemplate As Template, pTemplateConfig As TemplateConfig) As Template
|
||||
If pTemplateConfig Is Nothing Then
|
||||
Return pTemplate
|
||||
End If
|
||||
@@ -260,6 +258,35 @@ Namespace Templates
|
||||
Return pTemplate
|
||||
End Function
|
||||
|
||||
Public Function UpdateTemplateFromDatabase(pTemplate As Template) As Template
|
||||
Try
|
||||
Dim oTable As DataTable = Database.GetDatatable($"{SQL_TBEDI_XML_CONFIG} WHERE TEMPLATE_ID = {pTemplate.Guid}")
|
||||
Dim oGeneralConfig As New GeneralConfig
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oValue As String = oRow.ItemEx("VALUE", String.Empty)
|
||||
|
||||
Select Case oRow.Item("KEY")
|
||||
Case "INPUT_DIRECTORY"
|
||||
pTemplate.InputDirectory = oValue
|
||||
|
||||
Case "OUTPUT_DIRECTORY"
|
||||
pTemplate.OutputDirectory = oValue
|
||||
|
||||
Case "ARCHIVE_DIRECTORY"
|
||||
pTemplate.ArchiveDirectory = oValue
|
||||
|
||||
End Select
|
||||
Next
|
||||
|
||||
Return pTemplate
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return pTemplate
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetElementType(pElement As XElement) As Constants.ColumnType
|
||||
Dim oTypeString = XmlData.GetElementAttribute(pElement, "type")
|
||||
|
||||
|
||||
@@ -1,9 +1,24 @@
|
||||
Namespace Winline.Entities
|
||||
Public Class Document
|
||||
Public Property Schema As Templates.Template
|
||||
|
||||
Public Property Account As Account
|
||||
Public ReadOnly Property AccountName As String
|
||||
Get
|
||||
Return Account?.ToString()
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Property Kind As DocumentKind
|
||||
Public Property RunningNumber As String
|
||||
Public Property Number As String
|
||||
Public Property [Date] As Date
|
||||
Public Property DateColumn As String
|
||||
Public Property NetAmount As Double
|
||||
Public Property GrossAmount As Double
|
||||
|
||||
Public Property IsSelected As Boolean = False
|
||||
Public Property IsExported As Boolean = False
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
@@ -4,6 +4,7 @@ Imports System.Xml
|
||||
Imports DigitalData.Modules.Filesystem
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports MultiTool.Shared.Documents
|
||||
Imports MultiTool.Shared.Templates
|
||||
Imports MultiTool.Shared.Templates.GeneralConfig
|
||||
Imports MultiTool.Shared.Winline.Entities
|
||||
|
||||
@@ -13,16 +14,16 @@ Namespace Winline
|
||||
|
||||
Private ReadOnly Config As WebServiceConfig
|
||||
Private ReadOnly Serializer As Serializer
|
||||
Private ReadOnly OutputDirectory As String
|
||||
Private ReadOnly GeneralConfig As GeneralConfig
|
||||
Private ReadOnly FileEx As File
|
||||
|
||||
Public Event WebServiceProgress As EventHandler(Of String)
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pWebserviceConfig As WebServiceConfig, pOutputDirectoryPath As String)
|
||||
Public Sub New(pLogConfig As LogConfig, pWebserviceConfig As WebServiceConfig, pGeneralConfig As GeneralConfig)
|
||||
MyBase.New(pLogConfig)
|
||||
Serializer = New Serializer(pLogConfig)
|
||||
Config = pWebserviceConfig
|
||||
OutputDirectory = pOutputDirectoryPath
|
||||
GeneralConfig = pGeneralConfig
|
||||
FileEx = New DigitalData.Modules.Filesystem.File(LogConfig)
|
||||
End Sub
|
||||
|
||||
@@ -30,13 +31,10 @@ Namespace Winline
|
||||
RaiseEvent WebServiceProgress(Me, pMessage)
|
||||
End Sub
|
||||
|
||||
Public Async Function TransferDocumentToWinline(pDocument As Documents.Document, pMandator As Mandator, Optional pIsTest As Boolean = False) As Task(Of Boolean)
|
||||
Public Async Function TransferDocumentToWinline(pDocument As Documents.Document, pTemplate As Template, pMandator As Mandator, Optional pIsTest As Boolean = False) As Task(Of Boolean)
|
||||
Dim oBytes As Byte() = GetBytesFromDocument(pDocument)
|
||||
Dim oWS = Config
|
||||
|
||||
' --- Get and create path for request/response files
|
||||
Dim oOutputDirectory = FileEx.GetDateDirectory(OutputDirectory)
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Einstellungen laden")
|
||||
|
||||
' --- Build all teh filenamez and pathz
|
||||
@@ -44,22 +42,24 @@ Namespace Winline
|
||||
Dim oBaseFileName As String = FileEx.GetDateTimeString()
|
||||
Dim oFileName = FileEx.GetFilenameWithSuffix(oBaseFileName, "Request", "xml")
|
||||
|
||||
' --- Get and create path for request/response files
|
||||
Dim oOutputDirectory = FileEx.GetDateDirectory(pTemplate.OutputWebserviceDirectory)
|
||||
|
||||
' Relative Path for Webservice Call
|
||||
Dim oImportRelativeFilePath = IO.Path.Combine(FileEx.GetDateDirectory(oWS.ImportRelativePath), oFileName)
|
||||
|
||||
' Absolute Path to copy Request file
|
||||
Dim oImportAbsolutePath = IO.Path.Combine(oWS.ImportBasePath, oWS.ImportRelativePath)
|
||||
Dim oImportAbsoluteFilePath = IO.Path.Combine(FileEx.GetDateDirectory(oImportAbsolutePath), oFileName)
|
||||
Dim oImportAbsoluteFilePath = IO.Path.Combine(oWS.ImportBasePath, FileEx.GetDateDirectory(oWS.ImportRelativePath), oFileName)
|
||||
|
||||
' --- Serialize Data into XML string
|
||||
' Output path
|
||||
Dim oOutputFilePath = IO.Path.Combine(oOutputDirectory, oFileName)
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Dateien schreiben")
|
||||
|
||||
Dim oOutputFilePath = IO.Path.Combine(oOutputDirectory, oFileName)
|
||||
' --- Serialize Data into XML string
|
||||
IO.File.WriteAllBytes(oOutputFilePath, oBytes)
|
||||
|
||||
' --- Copy file to Winline Import Directory
|
||||
|
||||
Try
|
||||
IO.File.Copy(oOutputFilePath, oImportAbsoluteFilePath, True)
|
||||
Catch ex As Exception
|
||||
@@ -94,7 +94,7 @@ Namespace Winline
|
||||
' --- Bring the action!
|
||||
Try
|
||||
Dim oResponse As HttpResponseMessage = Await oClient.GetAsync(oURL)
|
||||
Await HandleResponse(oResponse, oOutputDirectory, oBaseFileName)
|
||||
Await HandleImportResponse(oResponse, pTemplate, oBaseFileName)
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
@@ -105,11 +105,60 @@ Namespace Winline
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Async Function ExportDocumentFromWinline() As Task
|
||||
'TODO: Implement export call to winline
|
||||
Async Function ExportDocumentFromWinline(pDocument As Entities.Document, pTemplate As Template, pMandator As Mandator, Optional pIsTest As Boolean = False) As Task(Of Boolean)
|
||||
Dim oWS = Config
|
||||
|
||||
' --- Build all teh filenamez and pathz
|
||||
|
||||
Dim oBaseFileName As String = FileEx.GetDateTimeString()
|
||||
Dim oFileName = FileEx.GetFilenameWithSuffix(oBaseFileName, "Request", "xml")
|
||||
|
||||
' Absolute Path to copy Request file
|
||||
Dim oImportAbsolutePath = IO.Path.Combine(oWS.ImportBasePath, oWS.ImportRelativePath)
|
||||
Dim oImportAbsoluteFilePath = IO.Path.Combine(FileEx.GetDateDirectory(oImportAbsolutePath), oFileName)
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Dateien schreiben")
|
||||
|
||||
' --- Prepare URL and HTTP Client
|
||||
Dim oTemplateType = 30
|
||||
Dim oTemplateName = pDocument.Schema.Name
|
||||
Dim oKey = $"{pDocument.Account.Id}-{pDocument.RunningNumber}"
|
||||
|
||||
' ActionCode: Should this be a test or not?
|
||||
' 0 = Test call
|
||||
' 1 = Real call
|
||||
Dim oActionCode = 1
|
||||
If pIsTest = True Then
|
||||
oActionCode = 0
|
||||
End If
|
||||
|
||||
' Byref: Should data be supplied as file or as string?
|
||||
' 0 = As String
|
||||
' 1 = As File (relative to Winline Server directory)
|
||||
Dim oByref = 0
|
||||
|
||||
Dim oURL As String = $"{oWS.BaseUrl}/ewlservice/export?User={oWS.Username}&Password={oWS.Password}&Company={pMandator.Id}&Type={oTemplateType}&Vorlage={oTemplateName}&ActionCode={oActionCode}&Key={oKey}"
|
||||
Dim oClient As New HttpClient()
|
||||
|
||||
Logger.Info("Creating HTTP Request to [{0}]", oWS.BaseUrl)
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Anfrage absenden")
|
||||
|
||||
' --- Bring the action!
|
||||
Try
|
||||
Dim oResponse As HttpResponseMessage = Await oClient.GetAsync(oURL)
|
||||
Await HandleExportResponse(oResponse, pTemplate, oBaseFileName)
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Throw ex
|
||||
Finally
|
||||
oClient.Dispose()
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Async Function HandleResponse(pResponse As HttpResponseMessage, pOutputPath As String, pBaseFileNAme As String) As Task
|
||||
Private Async Function HandleExportResponse(pResponse As HttpResponseMessage, pTemplate As Template, pBaseFileNAme As String) As Task
|
||||
pResponse.EnsureSuccessStatusCode()
|
||||
Dim oResponseBody As String = Await pResponse.Content.ReadAsStringAsync()
|
||||
Dim oContentType = pResponse.Content.Headers.ContentType.MediaType
|
||||
@@ -119,7 +168,31 @@ Namespace Winline
|
||||
|
||||
Select Case oContentType
|
||||
Case "text/xml"
|
||||
WriteResponseFile(pOutputPath, pBaseFileNAme, oResponseBody, "xml")
|
||||
WriteResponseFile(pTemplate.OutputWebserviceDirectory, pBaseFileNAme, oResponseBody, "xml")
|
||||
WriteResponseFile(pTemplate.OutputXmlFileDirectory, pBaseFileNAme, oResponseBody, "xml")
|
||||
WriteResponseFile(FileEx.GetDateDirectory(pTemplate.ArchiveDirectory), pBaseFileNAme, oResponseBody, "xml")
|
||||
|
||||
Case "text/html"
|
||||
WriteResponseFile(pTemplate.OutputWebserviceDirectory, pBaseFileNAme, oResponseBody, "txt")
|
||||
|
||||
Throw New ApplicationException(oResponseBody)
|
||||
|
||||
Case Else
|
||||
Throw New ApplicationException(oResponseBody)
|
||||
End Select
|
||||
End Function
|
||||
|
||||
Private Async Function HandleImportResponse(pResponse As HttpResponseMessage, pTemplate As Template, pBaseFileNAme As String) As Task
|
||||
pResponse.EnsureSuccessStatusCode()
|
||||
Dim oResponseBody As String = Await pResponse.Content.ReadAsStringAsync()
|
||||
Dim oContentType = pResponse.Content.Headers.ContentType.MediaType
|
||||
Dim oSerializer = Serializer.GetSerializer(GetType(Templates.Entities.MESOWebServiceResult))
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Antwort verarbeiten")
|
||||
|
||||
Select Case oContentType
|
||||
Case "text/xml"
|
||||
WriteResponseFile(pTemplate.OutputWebserviceDirectory, pBaseFileNAme, oResponseBody, "xml")
|
||||
|
||||
Dim oBytes As Byte() = Encoding.UTF8.GetBytes(oResponseBody)
|
||||
Using oStream As New IO.MemoryStream(oBytes)
|
||||
@@ -148,7 +221,7 @@ Namespace Winline
|
||||
End Using
|
||||
|
||||
Case "text/html"
|
||||
WriteResponseFile(pOutputPath, pBaseFileNAme, oResponseBody, "txt")
|
||||
WriteResponseFile(pTemplate.OutputWebserviceDirectory, pBaseFileNAme, oResponseBody, "txt")
|
||||
|
||||
Throw New ApplicationException(oResponseBody)
|
||||
|
||||
|
||||
@@ -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