Creditsafe, Barverkauf Fiskaltrust, etc.

This commit is contained in:
2026-05-27 18:09:34 +02:00
parent ef3ede6132
commit d1a1f42295
12 changed files with 681 additions and 73 deletions

View File

@@ -1,8 +1,7 @@
Imports System.Net.Http
Imports System.Data.SqlClient
Imports System.Net.Http
Imports System.Reflection
Imports System.Text
Imports System.Threading
Imports DocumentFormat.OpenXml.Drawing
Imports DocumentFormat.OpenXml.Wordprocessing
Imports Newtonsoft.Json
Public Class cFiskaltrustClient
@@ -26,7 +25,7 @@ Public Class cFiskaltrustClient
' ================================
Public Async Function SignReceiptAsync(amount As Double, vat As Double, POS As List(Of EABelegPositionen)) As Task(Of String)
Dim payload = BuildPayload(amount, vat, POS)
Dim payload = BuildPayloadReceipt(amount, vat, POS)
Dim endpoint = GetEndpoint("payment")
Dim requestContent As StringContent
@@ -46,6 +45,60 @@ Public Class cFiskaltrustClient
Return Await SendAsync(endpoint, payload, requestContent)
End Function
Public Async Function SignNullReceiptAsync() As Task(Of String)
Dim payload = BuildPayloadNullReceipt()
Dim endpoint = GetEndpoint("payment")
Dim requestContent As StringContent
If _country = "AT" Then
' Plaintext
Dim text As String = If(payload?.ToString(), "")
Dim json As String = JsonConvert.SerializeObject(text)
requestContent = New StringContent(json, Encoding.UTF8, "text/plain")
Else
' JSON Objekt
Dim json As String = JsonConvert.SerializeObject(payload)
requestContent = New StringContent(json, Encoding.UTF8, "application/json")
End If
Return Await SendAsync(endpoint, payload, requestContent)
End Function
Public Async Function Journal(type As String) As Task(Of String)
Dim payload = ""
Dim endpoint = GetEndpoint("journal")
If type > 0 Then
endpoint &= "?type=" & type
End If
Dim requestContent As StringContent
If _country = "AT" Then
' Plaintext
Dim text As String = If(payload?.ToString(), "")
Dim json As String = JsonConvert.SerializeObject(text)
requestContent = New StringContent(json, Encoding.UTF8, "text/plain")
Else
' JSON Objekt
Dim json As String = JsonConvert.SerializeObject(payload)
requestContent = New StringContent(json, Encoding.UTF8, "application/json")
End If
Return Await SendAsync(endpoint, payload, requestContent)
End Function
Public Async Function SignReceiptAsync_test() As Task(Of String)
Dim LIST = New List(Of EABelegPositionen)
@@ -63,7 +116,7 @@ Public Class cFiskaltrustClient
p.Anzahl = 1
LIST.Add(p)
Dim payload = BuildPayload(100, 0, LIST)
Dim payload = BuildPayloadReceipt(100, 0, LIST)
Dim endpoint = GetEndpoint("payment")
Dim requestContent As StringContent
@@ -116,7 +169,22 @@ Public Class cFiskaltrustClient
End Function
' Optional: Storno Beispiel
Public Async Function CancelReceiptAsync(reference As String) As Task(Of String)
'reference unique id!
Public Async Function CancelReceiptAsync(reference As String, POS As List(Of EABelegPositionen), amount As Double) As Task(Of String)
' ChargeItems Liste vorbereiten
Dim chargeItems = New List(Of Object)
For Each p In POS
chargeItems.Add(New With {
.Quantity = p.Anzahl,
.Amount = p.Preis,
.VATRate = 0,
.Description = p.LeistungsBez,
.ftChargeItemCase = 4919338167972134929
})
Next
Dim payload = New With {
.ftCashBoxID = _cashboxId,
@@ -124,8 +192,18 @@ Public Class cFiskaltrustClient
.cbTerminalID = "T1",
.cbReceiptReference = reference,
.cbReceiptMoment = DateTime.UtcNow.ToString("o"),
.ftReceiptCase = 4919338172267102210 ' Storno
}
.ftReceiptCase = 4919338172267102210,
.cbChargeItems = chargeItems,
.cbPayItems = New Object() {
New With {
.Quantity = 1.0,
.Amount = amount,
.Description = "Cash",
.ftPayItemCase = 4919338167972134913
}
}
}
Dim requestContent As StringContent
@@ -164,7 +242,10 @@ Public Class cFiskaltrustClient
request.Headers.Add("cashboxid", _cashboxId)
request.Headers.Add("accesstoken", _accessToken)
request.Content = requestContent
If payload <> "" Then
request.Content = requestContent
End If
Dim response = Await _httpClient.SendAsync(request)
Dim result = Await response.Content.ReadAsStringAsync()
@@ -210,7 +291,7 @@ Public Class cFiskaltrustClient
End Function
Private Function BuildPayload(amount As Double, vat As Double, POS As List(Of EABelegPositionen)) As Object
Private Function BuildPayloadReceipt(amount As Double, vat As Double, POS As List(Of EABelegPositionen)) As Object
' ChargeItems Liste vorbereiten
Dim chargeItems = New List(Of Object)
@@ -248,6 +329,24 @@ Public Class cFiskaltrustClient
End Function
Private Function BuildPayloadNullReceipt() As Object
Dim payload = New With {
.ftCashBoxID = _cashboxId,
.ftPosSystemId = "POS-1",
.cbTerminalID = "T1",
.cbReceiptReference = "ZeroReceiptAfterFailure",
.cbReceiptMoment = DateTime.UtcNow.ToString("o"),
.cbChargeItems = New Object() {},
.cbPayItems = New Object() {},
.ftReceiptCase = 4919338172267102210
}
Return payload
End Function
Private Function GetEndpoint(type As String) As String
@@ -274,6 +373,17 @@ Public Class cFiskaltrustClient
Throw New Exception("Unsupported country")
End Select
ElseIf type = "journal" Then
Select Case _country
Case "DE"
Return "/json/v0/Journal"
Case "AT"
Return "/json/Journal"
Case Else
Throw New Exception("Unsupported country")
End Select
End If
@@ -282,8 +392,408 @@ Public Class cFiskaltrustClient
End Function
Public Function saveRKSV_FT(ByRef result_zahlung As String, ByRef QR_CodeString As String) As Boolean
If result_zahlung <> "" Then
Dim json As New Chilkat.JsonObject
Dim success As Boolean = json.Load(result_zahlung)
If (success <> True) Then
Debug.WriteLine(json.LastErrorText)
Return False
End If
Dim ftSig As New cFiskaltrustSignatures()
Dim ftReceiptMoment As New Chilkat.CkDateTime
Dim dt As New Chilkat.DtObj
Dim getAsLocal As Boolean = False
Dim ftID As Integer = -1
success = json.DateOf("ftReceiptMoment", ftReceiptMoment)
Debug.WriteLine(ftReceiptMoment.GetAsTimestamp(getAsLocal))
With ftSig
.ftCashBoxID = json.StringOf("ftCashBoxID")
.ftQueueID = json.StringOf("ftQueueID")
.ftQueueItemID = json.StringOf("ftQueueItemID")
.ftQueueRow = json.IntOf("ftQueueRow")
.cbTerminalID = json.StringOf("cbTerminalID")
.cbReceiptReference = json.StringOf("cbReceiptReference")
.ftCashBoxIdentification = json.StringOf("ftCashBoxIdentification")
.ftReceiptIdentification = json.StringOf("ftReceiptIdentification")
.ftReceiptMoment = ftReceiptMoment.GetAsTimestamp(getAsLocal)
.ftState = json.StringOf("ftState")
ftID = .SAVE()
End With
Dim num As Integer = json.SizeOfArray("ftSignatures")
If num = 0 Then
Return False
End If
Dim Signatures As Chilkat.JsonArray = json.ArrayOf("ftSignatures")
If (json.LastMethodSuccess = False) Then
Return False
End If
Dim numSignatures As Integer = Signatures.Size
For i = 0 To numSignatures
While i < numSignatures
Dim SignObj As Chilkat.JsonObject = Signatures.ObjectAt(i)
Dim ftSigPos As New cFiskaltrustSignaturPositions()
With ftSigPos
.ftSignatures = ftSig.ft_id
.ftData = SignObj.StringOf("Data")
.ftSignatureFormat = SignObj.StringOf("ftSignatureFormat")
.ftSignatureType = SignObj.StringOf("ftSignatureType")
.SAVE()
If IsNumeric(.ftSignatureType) AndAlso CInt(.ftSignatureType) = 3 Then
QR_CodeString = .ftData
End If
End With
i = i + 1
End While
Next
End If
End Function
Public Function exportJournal(ByRef result_Journal As String) As Boolean
If result_Journal <> "" Then
Dim jsonArr As New Chilkat.JsonArray
Dim success As Boolean = jsonArr.Load(result_Journal)
If (success <> True) Then
Debug.WriteLine(jsonArr.LastErrorText)
Return False
End If
Dim dt As New DataTable
dt.Columns.Add("ftReceiptJournalId", GetType(String))
dt.Columns.Add("ftReceiptMoment", GetType(String))
dt.Columns.Add("ftReceiptNumber", GetType(String))
dt.Columns.Add("ftReceiptTotal", GetType(String))
dt.Columns.Add("ftQueueId", GetType(String))
dt.Columns.Add("ftReceiptHash", GetType(String))
dt.Columns.Add("ftQueueItemId", GetType(String))
dt.Columns.Add("TimeStamp", GetType(String))
Dim i = 0
Dim num As Integer = jsonArr.Size
If num = 0 Then
Return False
End If
Dim tmstmp As New Chilkat.CkDateTime
Dim getAsLocal As Boolean = False
While i < num
Dim SignObj As Chilkat.JsonObject = jsonArr.ObjectAt(i)
Dim R As DataRow = dt.NewRow
With SignObj
R("ftReceiptJournalId") = .StringOf("ftReceiptJournalId")
R("ftReceiptMoment") = .StringOf("ftReceiptMoment")
R("ftReceiptNumber") = .IntOf("ftReceiptNumber")
R("ftReceiptTotal") = .StringOf("ftReceiptTotal")
R("ftQueueId") = .StringOf("ftQueueId")
R("ftQueueItemId") = .StringOf("ftQueueItemId")
R("ftReceiptHash") = .StringOf("ftReceiptHash")
R("TimeStamp") = tmstmp.GetAsTimestamp(getAsLocal)
End With
dt.Rows.Add(R)
i = i + 1
End While
If dt.Rows.Count > 0 Then
Dim Path = VERAG_PROG_ALLGEMEIN.cProgramFunctions.genExcelFromDT_NEW(dt)
End If
End If
End Function
Private Sub Log(message As String)
Console.WriteLine(message)
End Sub
End Class
Public Class cFiskaltrustSignatures
Property ft_id As Integer
Property ftQueueID As Object = Nothing
Property ftQueueItemID As Object = Nothing
Property ftQueueRow As Object = Nothing
Property ftCashBoxIdentification As Object = Nothing
Property ftReceiptIdentification As Object = Nothing
Property ftReceiptMoment As Object = Nothing
Property ftState As Object = Nothing
Property ftCashBoxID As Object = Nothing
Property cbTerminalID As Object = Nothing
Property cbReceiptReference As Object = Nothing
Public hasEntry = False
Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
Sub New()
End Sub
Sub New(ft_id)
Me.ft_id = ft_id
LOAD()
End Sub
Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ft_id", ft_id,, True))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftQueueID", ftQueueID))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftQueueItemID", ftQueueItemID))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftQueueRow", ftQueueRow))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftCashBoxIdentification", ftCashBoxIdentification))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftReceiptIdentification", ftReceiptIdentification))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftReceiptMoment", ftReceiptMoment))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftState", ftState))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftCashBoxID", ftCashBoxID))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("cbTerminalID", cbTerminalID))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("cbReceiptReference", cbReceiptReference))
Return list
End Function
Public Function SAVE() As Boolean
Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
Dim sqlstr = " BEGIN " & getInsertCmd() & " END " '&
'" commit tran "
Dim id = SQL.doSQLVarListID(ft_id, sqlstr, "FMZOLL", , list)
Me.ft_id = id
Return id > 0
End Function
Public Sub LOAD()
Try
hasEntry = False
Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
Using cmd As New SqlCommand("SELECT * FROM tblRKSV_FT WHERE ft_id=@ft_id ", conn)
cmd.Parameters.AddWithValue("@ft_id", ft_id)
Dim dr = cmd.ExecuteReader()
If dr.Read Then
For Each li In getParameterList()
Dim propInfo As PropertyInfo = Me.GetType.GetProperty(li.Scalarvariable)
If dr.Item(li.Text) Is DBNull.Value Then
propInfo.SetValue(Me, Nothing)
Else
propInfo.SetValue(Me, dr.Item(li.Text))
End If
Next
hasEntry = True
End If
dr.Close()
End Using
End Using
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Sub
'Public Function getUpdateCmd() As String
' Try
' Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
' Dim str As String = ""
' For Each i In list
' If Not i.isPrimaryParam Then
' str &= "[" & i.Text & "] = @" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
' End If
' Next
' str = str.Substring(0, str.Length - 1) 'wg. ','
' Return (" UPDATE [tblTABLE] SET " & str & " WHERE _BASE_id=@_BASE_id ")
' Catch ex As Exception
' VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
' End Try
' Return ""
'End Function
Public Function getInsertCmd() As String
Try
Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
Dim str As String = ""
Dim values As String = ""
For Each i In list
If Not i.isPrimaryParam Then
str &= "[" & i.Text & "],"
values &= "@" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
End If
Next
str = str.Substring(0, str.Length - 1) 'wg. ','
values = values.Substring(0, values.Length - 1) 'wg. ','
Return (" INSERT INTO tblRKSV_FT (" & str & ") VALUES(" & values & ") ")
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
Return ""
End Function
End Class
Public Class cFiskaltrustSignaturPositions
Property ftSignatures As Integer
Property ftSignatureFormat As Object = Nothing
Property ftSignatureType As Object = Nothing
Property ftData As Object = Nothing
Public hasEntry = False
Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
Sub New()
End Sub
Sub New(ftSignatures, ftSignatureType)
Me.ftSignatures = ftSignatures
Me.ftSignatureType = ftSignatureType
LOAD()
End Sub
Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftSignatures", ftSignatures))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftSignatureFormat", ftSignatureFormat))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftSignatureType", ftSignatureType))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("ftData", ftData))
Return list
End Function
Public Function SAVE() As Boolean
Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
Dim sqlstr = " BEGIN " & getInsertCmd() & " END " '&
'" commit tran "
Return SQL.doSQLVarList(sqlstr, "FMZOLL", , list)
End Function
Public Sub LOAD()
Try
hasEntry = False
Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
Using cmd As New SqlCommand("SELECT * FROM tblRKSV_FTSignatures WHERE ftSignatures=@ftSignatures AND ftSignatureType = @ftSignatureType ", conn)
cmd.Parameters.AddWithValue("@ftSignatures", ftSignatures)
cmd.Parameters.AddWithValue("@ftSignatureType", ftSignatureType)
Dim dr = cmd.ExecuteReader()
If dr.Read Then
For Each li In getParameterList()
Dim propInfo As PropertyInfo = Me.GetType.GetProperty(li.Scalarvariable)
If dr.Item(li.Text) Is DBNull.Value Then
propInfo.SetValue(Me, Nothing)
Else
propInfo.SetValue(Me, dr.Item(li.Text))
End If
Next
hasEntry = True
End If
dr.Close()
End Using
End Using
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Sub
'Public Function getUpdateCmd() As String
' Try
' Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
' Dim str As String = ""
' For Each i In list
' If Not i.isPrimaryParam Then
' str &= "[" & i.Text & "] = @" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
' End If
' Next
' str = str.Substring(0, str.Length - 1) 'wg. ','
' Return (" UPDATE [tblTABLE] SET " & str & " WHERE _BASE_id=@_BASE_id ")
' Catch ex As Exception
' VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
' End Try
' Return ""
'End Function
Public Function getInsertCmd() As String
Try
Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
Dim str As String = ""
Dim values As String = ""
For Each i In list
If Not i.isPrimaryParam Then
str &= "[" & i.Text & "],"
values &= "@" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
End If
Next
str = str.Substring(0, str.Length - 1) 'wg. ','
values = values.Substring(0, values.Length - 1) 'wg. ','
Return (" INSERT INTO tblRKSV_FTSignatures (" & str & ") VALUES(" & values & ") ")
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
Return ""
End Function
End Class

View File

@@ -92,7 +92,7 @@ Public Class cRKSV
End Function
Shared Function insertRKSVFiskaltrust(ByVal kasse As cRKSV_Kasse, CompanyGUID As String, ByVal umsatzZaehler As Double, ByVal belegDat As DateTime, ByVal steuerSchluessel As Integer, ByVal RKSV_Beleg_Id As Integer, ByVal summeBRUTTO As Double, TEST As Boolean, POS As List(Of EABelegPositionen)) As Boolean
Shared Async Function insertRKSVFiskaltrustAsync(ByVal kasse As cRKSV_Kasse, CompanyGUID As String, ByVal umsatzZaehler As Double, ByVal belegDat As DateTime, ByVal steuerSchluessel As Integer, ByVal RKSV_Beleg_Id As Integer, ByVal summeBRUTTO As Double, TEST As Boolean, POS As List(Of EABelegPositionen), QR_CodeString As String, LastJWS As String) As Task(Of Boolean)
Try
@@ -126,10 +126,9 @@ Public Class cRKSV
Dim StandUmsatzzaehler = umsatzZaehler 'KASSE.rksv_Umsatzzaehler
Dim countryID As String
Dim client As New cFiskaltrustClient(kasse.rksv_FT_RestServiceURL, kasse.rksv_FT_CashboxID, kasse.rksv_FT_AccessToken, kasse.rksv_FT_Country)
Dim result = client.SignReceiptAsync(summeBRUTTO, steuersatz, POS)
Dim result = Await client.SignReceiptAsync(summeBRUTTO, steuersatz, POS)
client.saveRKSV_FT(result, QR_CodeString)
Catch ex As Exception