directories per template, export tweaks
This commit is contained in:
@@ -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