Merge branch 'newMaster2024' of https://dev.azure.com/VeragAG/_git/SDL into newMaster2024

This commit is contained in:
2025-04-15 09:47:50 +02:00
20 changed files with 2524 additions and 613 deletions

View File

@@ -4,6 +4,9 @@ Imports System.Reflection
Imports System.Threading
Imports System.Windows.Forms
Imports Chilkat
Imports DocumentFormat.OpenXml.Wordprocessing
Imports javax
Imports javax.xml.ws.soap.AddressingFeature
Imports VERAG_PROG_ALLGEMEIN.VERAG_OUT_NCTS
Public Class cATEZ_NCTS_Sessions
@@ -44,11 +47,13 @@ Public Class cATEZ_NCTS_Sessions
Me.token = token
Me.refresh_token = refreshtoken
token_validuntil = timestamp
program = program
Me.program = program
SAVE()
End Sub
Public Function SAVE(Optional errHinweis = "") As Boolean
Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
@@ -643,16 +648,19 @@ Public Class cATEZ_NCTS_IN
End Sub
Shared Function SendRequestAuthentificationToken(ByVal myuri As String, ByVal contentType As String, ByVal method As String, ByRef Itoken As String, ByVal program As String, Optional client_id As String = "", Optional grant_type As String = "") As String
Shared Function SendRequestAuthentificationToken(ByVal myuri As String, ByVal contentType As String, ByVal method As String, ByRef Itoken As String, ByVal program As String, Optional client_id As String = "", Optional grant_type As String = "", Optional useBody As Boolean = True) As String
Try
Dim session = New cATEZ_NCTS_Sessions()
If Not IsDBNull(session.token) AndAlso session.token IsNot Nothing Then
Itoken = session.token
token = Itoken
sessionID = session.session_Id
Return "200"
If CDate(session.token_validuntil) < DateTime.Now Then
Itoken = session.token
token = Itoken
sessionID = session.session_Id
Return "200"
End If
End If
If apiSettingsloaded = False Then Return "400"
@@ -676,28 +684,41 @@ Public Class cATEZ_NCTS_IN
End If
Dim json As New Chilkat.JsonObject
json.UpdateString("username", API.Rows(0).Item("api_user"))
json.UpdateString("password", API.Rows(0).Item("api_password"))
If client_id <> "" Then json.UpdateString("client_id", client_id)
If grant_type <> "" Then json.UpdateString("grant_type", grant_type)
rest.AddHeader("Content-Type", contentType)
Dim sbRequestBody As New Chilkat.StringBuilder
json.EmitSb(sbRequestBody)
'DEBUG-Mode -> no request will be sent!
'rest.DebugMode = True
Dim sbResponseBody As New Chilkat.StringBuilder
Dim ResponseStr As String
If useBody Then
Dim json As New Chilkat.JsonObject
json.UpdateString("username", API.Rows(0).Item("api_user"))
json.UpdateString("password", API.Rows(0).Item("api_password"))
If client_id <> "" Then json.UpdateString("client_id", client_id)
If grant_type <> "" Then json.UpdateString("grant_type", grant_type)
Dim sbRequestBody As New Chilkat.StringBuilder
json.EmitSb(sbRequestBody)
ResponseStr = rest.FullRequestSb(method, myuri, sbRequestBody, sbResponseBody)
Else
rest.ClearAllQueryParams()
rest.AddQueryParam("grant_type", grant_type)
rest.AddQueryParam("username", API.Rows(0).Item("api_user"))
rest.AddQueryParam("password", API.Rows(0).Item("api_password"))
rest.AddQueryParam("client_id", client_id)
ResponseStr = rest.FullRequestFormUrlEncoded(method, myuri)
End If
'myuri = myuri.Replace("https:/", "")
'myuri = myuri.Replace("http:/", "")
Dim ResponseStr = rest.FullRequestSb(method, myuri, sbRequestBody, sbResponseBody)
If (rest.ResponseStatusCode <> 200) Then
@@ -705,7 +726,13 @@ Public Class cATEZ_NCTS_IN
End If
Dim jsonResp = New Chilkat.JsonObject()
jsonResp.LoadSb(sbResponseBody)
If useBody Then
jsonResp.LoadSb(sbResponseBody)
Else
jsonResp.Load(ResponseStr)
End If
Itoken = jsonResp.StringOf("access_token")
token = Itoken
refresh_token = If(jsonResp.StringOf("refresh_token"), "")
@@ -725,23 +752,24 @@ Public Class cATEZ_NCTS_IN
Dim myUri As String = API_STRING
Dim contentType = "application/json"
Dim useBody As Boolean = True
Select Case program
Case "NCTS" : myUri &= "/api/tds/auth/"
Case "VAT" : myUri &= "/token" : contentType = "application/x-www-form-urlencoded"
Case "VAT" : myUri &= "/token" : contentType = "application/x-www-form-urlencoded" : useBody = False
End Select
Dim response = SendRequestAuthentificationToken(myUri, contentType, "POST", token, program, client_id, grant_type)
Dim response = SendRequestAuthentificationToken(myUri, contentType, "POST", token, program, client_id, grant_type, useBody)
Return response
End Function
Shared Function SendRequestWithAuthHeader(acceptContentType As String, ByRef failureDesc As String, myUrl As String, Method As String) As String
Shared Function SendRequestWithAuthHeader(acceptContentType As String, ByRef failureDesc As String, myUrl As String, Method As String, Optional dt As DataTable = Nothing) As String
Try
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
@@ -825,6 +853,51 @@ Public Class cATEZ_NCTS_IN
Dim jsonResult As New Chilkat.JsonObject
success = jsonResult.LoadSb(sbResponseBody)
jsonResult.Emit()
If dt IsNot Nothing Then
Dim data As New Chilkat.JsonObject
data = jsonResult
If (data.LastMethodSuccess = False) Then
Debug.WriteLine("data member not found.")
End If
Dim num As Integer = 1
If num = -1 Then
Return "FEHLER Array Data ist leer"
End If
Dim j As Integer = 0
While j < num
Dim invoice As Chilkat.JsonObject = data.ObjectAt(0)
Dim R As DataRow = dt.NewRow
R("currency") = checkNullStr(invoice.StringOf("currency"))
Dim totalAmonut As String = invoice.StringOf("total_VAT_amount").Replace(".", ",")
R("total_VAT_amount") = CDbl(checkNulDbl(totalAmonut))
R("invoice_id") = checkNullStr(invoice.StringOf("invoice_id"))
R("invoice_date") = checkNullStr(invoice.StringOf("invoice_date"))
R("seller_VAT_id") = checkNullStr(invoice.StringOf("seller_VAT_id"))
R("seller_address_city") = checkNullStr(invoice.StringOf("seller_address_city"))
R("seller_address_country") = checkNullStr(invoice.StringOf("seller_address_country"))
R("seller_address_postcode") = checkNullStr(invoice.StringOf("seller_address_postcode"))
R("seller_address_street") = checkNullStr(invoice.StringOf("seller_address_street"))
R("status") = checkNullStr(jsonResult.StringOf("status"))
dt.Rows.Add(R)
j = j + 1
End While
Return jsonResult.StringOf("status")
End If
Return jsonResult.StringOf("atezId")
End If
@@ -837,6 +910,23 @@ Public Class cATEZ_NCTS_IN
End Try
End Function
Public Shared Function checkNullStr(ByVal o As Object) As String
If o IsNot Nothing AndAlso o IsNot DBNull.Value AndAlso Not o = "null" Then Return CStr(o)
Return ""
End Function
Public Shared Function checkNulDbl(ByVal o As Object) As Double
If o IsNot Nothing And o IsNot DBNull.Value Then
If IsNumeric(o) Then
Return Math.Round(CDbl(o), 2)
Else
Return 0
End If
Else
Return 0
End If
End Function
Shared Function setJsonNCTS(ncts As cATEZ_NCTS_DATA)
jsonData.Clear()
@@ -896,7 +986,7 @@ Public Class cATEZ_NCTS_IN
Dim success As Boolean
success = jsonData.UpdateString("document_type", documentType)
Dim base64 As Chilkat.BinData
Dim base64 As New Chilkat.BinData
success = base64.LoadFile(VERAG_PROG_ALLGEMEIN.cDATENSERVER.GET_PDFPath_BY_DocID(docID))
success = jsonData.UpdateString("document_base64", base64.GetEncoded("base64"))