930 lines
32 KiB
VB.net
930 lines
32 KiB
VB.net
Imports Chilkat
|
||
Imports io.konik.zugferd.unqualified
|
||
Imports QRCoder
|
||
Imports VERAG_PROG_ALLGEMEIN
|
||
|
||
Public Class FtReceiptCases
|
||
|
||
' Normaler Verkauf
|
||
Public Const PosReceipt As Long = &H4445000000000001L
|
||
|
||
' Test-/Nullbeleg
|
||
Public Const ZeroReceipt As Long = &H4445000000000002L
|
||
|
||
' Kassenlebenszyklus
|
||
Public Const InitialOperation As Long = &H4445000000000003L
|
||
Public Const OutOfOperation As Long = &H4445000000000004L
|
||
|
||
' Tagesabschluss (Z-Bericht)
|
||
Public Const MonthlyClosing As Long = &H4445000000000005L
|
||
Public Const YearlyClosing As Long = &H4445000000000006L
|
||
Public Const DailyClosing As Long = &H4445000000000007L
|
||
|
||
' Kasseneinzahlung / Kassenauszahlung / Geldtransfer
|
||
Public Const CashDepositOrWithdrawal As Long = &H4445000000000011L
|
||
|
||
|
||
' Flags
|
||
Public Const ImplicitTransaction As Long = &H100000000L
|
||
Public Const ReversalReceipt As Long = &H40000L
|
||
Public Const TrainingReceipt As Long = &H20000L
|
||
' aktiviert den Late-Signing-Modus
|
||
Public Const FailedReceipt As Long = &H10000L
|
||
|
||
' Receipt-Request:
|
||
' bereits verarbeiteten Beleg anhand cbReceiptReference abrufen
|
||
Public Const ReceiptRequest As Long = &H800000000000L
|
||
|
||
End Class
|
||
|
||
Public Class FtChargeItemCase
|
||
|
||
' DE – Verkaufsbelege
|
||
Public Const RevenueNormal As Long = &H4445000000000001L ' 19 % Regelsteuersatz
|
||
|
||
Public Const RevenueReduced As Long = &H4445000000000002L ' 7 % ermäßigter Steuersatz
|
||
|
||
Public Const RevenueNotTaxable As Long = &H4445000000000005L ' Nicht steuerbar
|
||
|
||
Public Const RevenueTaxFree As Long = &H4445000000000006L ' Umsatzsteuerfrei, 0 %
|
||
|
||
' DE – Kassenbewegungen
|
||
Public Const Anfangsbestand As Long = &H4445000000000090L ' Anfangsbestand
|
||
|
||
Public Const Privatentnahme As Long = &H4445000000000091L ' Privatentnahme
|
||
|
||
Public Const Privateinlage As Long = &H4445000000000092L ' Privateinlage
|
||
|
||
Public Const Geldtransit As Long = &H4445000000000093L ' Geldtransit
|
||
|
||
Public Const Lohnzahlung As Long = &H4445000000000094L ' Lohnzahlung
|
||
|
||
Public Const Einzahlung As Long = &H4445000000000095L ' Einzahlung
|
||
|
||
Public Const Auszahlung As Long = &H4445000000000096L ' Auszahlung
|
||
|
||
End Class
|
||
|
||
Public Class FtJournalType
|
||
|
||
Public Const VersionInformation As Integer = 0
|
||
Public Const ActionJournal As Integer = 1
|
||
Public Const ReceiptJournal As Integer = 2
|
||
Public Const QueueItemJournal As Integer = 3
|
||
|
||
End Class
|
||
|
||
Public Class ReceiptCaseIntern
|
||
|
||
Public Const STORNO As String = "Storno"
|
||
Public Const VERKAUF As String = "Verkauf"
|
||
Public Const EINGANG As String = "Eingang"
|
||
Public Const AUSGANG As String = "Ausgang"
|
||
Public Const WIEDERHOLUNG As String = "Retry"
|
||
Public Const NULLBELEG As String = "NULL-BELEG"
|
||
Public Const STARTBELEG As String = "START-BELEG"
|
||
Public Const OUTOFOPERATIONBELEG As String = "END-BELEG"
|
||
Public Const TEMP_OUTOFOPERATIONBELEG As String = "TEMP-AUSFALL"
|
||
Public Const DAILYCLOSING As String = "TAGESABSCHLUSS"
|
||
|
||
End Class
|
||
|
||
|
||
Public Class PayItemCasesIntern
|
||
|
||
Public Const Cash As String = "Cash"
|
||
Public Const DebitCard As String = "DebitCard"
|
||
Public Const Kasseneinzahlungen_Auszahlungen As String = "Kasseneinzahlungen_Auszahlungen"
|
||
|
||
|
||
End Class
|
||
|
||
|
||
|
||
Public Class FtPayItemCases
|
||
|
||
'DE
|
||
|
||
' Barzahlung
|
||
Public Const Cash As Long = &H4445000000000001L
|
||
|
||
' EC-/Girokarte
|
||
Public Const DebitCard As Long = &H4445000000000004L
|
||
|
||
' Kreditkarte
|
||
Public Const CreditCard As Long = &H4445000000000005L
|
||
|
||
' Online-Zahlung (PayPal, Klarna, etc.)
|
||
Public Const OnlinePayment As Long = &H4445000000000006L
|
||
|
||
' Gutschein
|
||
Public Const Voucher As Long = &H4445000000000007L
|
||
|
||
'Cash transfer from/to cash book
|
||
Public Const Kasseineinzahlung_Auszahlung As Long = &H4445000000000016L
|
||
|
||
End Class
|
||
|
||
Public Class cFiskaltrustClient_chilkat
|
||
|
||
Private ReadOnly _baseUrl As String
|
||
Private ReadOnly _cashboxId As String
|
||
Private ReadOnly _accessToken As String
|
||
Private ReadOnly _country As String
|
||
Private ReadOnly _isFiskaltrust As Boolean = False
|
||
|
||
Public Sub New(baseUrl As String, cashboxId As String, accessToken As String, country As String)
|
||
_baseUrl = baseUrl.TrimEnd("/"c)
|
||
_cashboxId = cashboxId
|
||
_accessToken = accessToken
|
||
_country = country
|
||
|
||
If _cashboxId <> "" AndAlso baseUrl <> "" AndAlso _accessToken <> "" AndAlso _country <> "" Then
|
||
_isFiskaltrust = True
|
||
Else
|
||
_isFiskaltrust = False
|
||
End If
|
||
|
||
End Sub
|
||
|
||
Public Function isFiskaltrust() As Boolean
|
||
Return _isFiskaltrust
|
||
End Function
|
||
|
||
|
||
|
||
|
||
|
||
Public Function SignReceipt_test(posSystemId As String, TSEisOnline As Boolean) As String
|
||
|
||
Dim LIST = New List(Of EABelegPositionen)
|
||
Dim p = New EABelegPositionen
|
||
p.Mandant = "VERA"
|
||
p.Niederlassung = "SUB"
|
||
p.Benutzer = 74
|
||
p.BelegDat = Now
|
||
p.BelegNr = 1
|
||
p.PreislistenNr = 1
|
||
p.PreislistenPos = 1
|
||
p.LeistungsNr = 300
|
||
p.LeistungsBez = "TEST"
|
||
p.Preis = 10
|
||
p.Anzahl = 10
|
||
LIST.Add(p)
|
||
|
||
Dim amount = 100
|
||
Dim vat = 0
|
||
Dim POS = LIST
|
||
Dim kindOfPayment = "Cash"
|
||
Try
|
||
Dim payload As JsonObject = BuildPayloadReceipt(amount, vat, POS, kindOfPayment, posSystemId, "Verkauf", "", TSEisOnline)
|
||
|
||
Return SendChilkat(GetEndpoint("payment"), payload.Emit())
|
||
Catch ex As Exception
|
||
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
||
End Try
|
||
End Function
|
||
|
||
|
||
|
||
|
||
|
||
Public Function ChancelReceipt_test(reference As String, posSystemId As String, TSEisOnline As Boolean) As String
|
||
|
||
Try
|
||
Dim LIST = New List(Of EABelegPositionen)
|
||
Dim p = New EABelegPositionen
|
||
p.Mandant = "VERA"
|
||
p.Niederlassung = "SUB"
|
||
p.Benutzer = 74
|
||
p.BelegDat = Now
|
||
p.BelegNr = 1
|
||
p.PreislistenNr = 1
|
||
p.PreislistenPos = 1
|
||
p.LeistungsNr = 300
|
||
p.LeistungsBez = "TEST"
|
||
p.Preis = 10
|
||
p.Anzahl = 1
|
||
LIST.Add(p)
|
||
|
||
Dim amount = 100
|
||
Dim vat = 0
|
||
Dim POS = LIST
|
||
Dim kindOfPayment = "Cash"
|
||
|
||
Dim payload As JsonObject = BuildPayloadReceipt(amount, vat, POS, kindOfPayment, posSystemId, "Storno", reference, TSEisOnline)
|
||
|
||
Return SendChilkat(GetEndpoint("storno"), payload.Emit())
|
||
Catch ex As Exception
|
||
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
||
End Try
|
||
End Function
|
||
|
||
Public Function SignReceipt(amount As Decimal, vat As Decimal, POS As List(Of EABelegPositionen), kindOfPayment As String, posSystemId As String, typOfReceiptCase As String, reference As String, TESisOnline As Boolean) As String
|
||
Try
|
||
Dim payload As JsonObject = BuildPayloadReceipt(amount, vat, POS, kindOfPayment, posSystemId, typOfReceiptCase, reference, TESisOnline)
|
||
|
||
Return SendChilkat(GetEndpoint("payment"), payload.Emit())
|
||
Catch ex As Exception
|
||
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
||
End Try
|
||
|
||
End Function
|
||
|
||
Public Function SignNullReceipt(posSystemId As String) As String
|
||
Try
|
||
Return SendChilkat(GetEndpoint("payment"), BuildPayloadNullReceipt(posSystemId, _country).Emit())
|
||
Catch ex As Exception
|
||
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
||
End Try
|
||
End Function
|
||
|
||
Public Function ChancelReceipt(reference As String, amount As Decimal, vat As Decimal, POS As List(Of EABelegPositionen), kindOfPayment As String, posSystemId As String, TSEisOnline As Boolean) As String
|
||
Try
|
||
Dim payload As JsonObject = BuildPayloadReceipt(amount, vat, POS, kindOfPayment, posSystemId, "Storno", reference, TSEisOnline)
|
||
|
||
Return SendChilkat(GetEndpoint("storno"), payload.Emit())
|
||
Catch ex As Exception
|
||
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
||
End Try
|
||
End Function
|
||
|
||
Public Function SignOutOfOrderReceipt(posSystemId As String) As String
|
||
Try
|
||
Return SendChilkat(GetEndpoint("payment"), BuildPayloadOutOfOperationReceipt(posSystemId, _country).Emit())
|
||
Catch ex As Exception
|
||
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
||
End Try
|
||
End Function
|
||
|
||
Public Function SignTempOutOfOrderReceipt(posSystemId As String) As String
|
||
Try
|
||
Return SendChilkat(GetEndpoint("payment"), BuildPayloadOutOfOperationReceipt(posSystemId, _country).Emit())
|
||
Catch ex As Exception
|
||
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
||
End Try
|
||
End Function
|
||
|
||
Public Function SignInitialOperationReceipt(posSystemId As String) As String
|
||
Try
|
||
Return SendChilkat(GetEndpoint("payment"), BuildPayloadInitialOperationReceipt(posSystemId, _country).Emit())
|
||
Catch ex As Exception
|
||
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
||
End Try
|
||
End Function
|
||
|
||
Public Function SignClosingReceipt(receiptType As String, posSystemId As String, kind As String) As String
|
||
Try
|
||
Return SendChilkat(GetEndpoint("payment"), BuildPayloadClosingReceipt(receiptType, posSystemId, kind).Emit())
|
||
Catch ex As Exception
|
||
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
||
End Try
|
||
End Function
|
||
|
||
Public Function Echo(kassenName As String) As String
|
||
Try
|
||
Dim json As New JsonObject()
|
||
json.UpdateString("Message", kassenName & " - VERBINDUNG OK")
|
||
|
||
Return SendChilkat(GetEndpoint("test"), json.Emit())
|
||
Catch ex As Exception
|
||
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
||
End Try
|
||
End Function
|
||
|
||
Public Function Journal(ftJournalType As Integer) As String
|
||
Try
|
||
|
||
Dim endpoint = GetEndpoint("journal")
|
||
|
||
endpoint &= "?type=" & ftJournalType
|
||
|
||
Return SendChilkat(endpoint, "")
|
||
|
||
Catch ex As Exception
|
||
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
||
End Try
|
||
End Function
|
||
|
||
|
||
Private Function SendChilkat(endpoint As String, payload As String, Optional isGet As Boolean = False) As String
|
||
|
||
Dim retries As Integer = 3
|
||
Dim lastEx As Exception = Nothing
|
||
|
||
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
|
||
|
||
Dim rest As New Chilkat.Rest
|
||
rest.VerboseLogging = True
|
||
|
||
For i As Integer = 1 To retries
|
||
|
||
Try
|
||
Dim uri As New Uri(_baseUrl)
|
||
|
||
If Not rest.Connect(uri.Host, uri.Port, uri.Scheme = "https", True) Then
|
||
Throw New Exception(rest.LastErrorText)
|
||
End If
|
||
|
||
rest.AddHeader("cashboxid", _cashboxId)
|
||
rest.AddHeader("accesstoken", _accessToken)
|
||
|
||
Dim response As String
|
||
|
||
If isGet Then
|
||
|
||
response = rest.FullRequestNoBody(
|
||
"GET",
|
||
uri.AbsoluteUri & endpoint
|
||
)
|
||
|
||
Else
|
||
|
||
If _country = "AT" Then
|
||
rest.AddHeader("Content-Type", "text/plain")
|
||
Else
|
||
rest.AddHeader("Content-Type", "application/json")
|
||
End If
|
||
|
||
response = rest.FullRequestString("POST", uri.AbsoluteUri & endpoint, payload)
|
||
|
||
End If
|
||
|
||
Dim statusCode As Integer = rest.ResponseStatusCode
|
||
|
||
' SUCCESS
|
||
If statusCode >= 200 AndAlso statusCode < 300 Then
|
||
Return response
|
||
End If
|
||
|
||
' 4xx = client/request error -> DO NOT RETRY
|
||
If statusCode >= 400 AndAlso statusCode < 500 Then
|
||
Throw New Exception(
|
||
"HTTP " & statusCode & ": " & response
|
||
)
|
||
End If
|
||
|
||
' 5xx = server error -> retry
|
||
If statusCode >= 500 AndAlso statusCode < 600 Then
|
||
|
||
lastEx = New Exception(
|
||
"HTTP " & statusCode & ": " & response
|
||
)
|
||
|
||
If i < retries Then
|
||
Threading.Thread.Sleep(500)
|
||
Continue For
|
||
End If
|
||
|
||
Throw lastEx
|
||
End If
|
||
|
||
' Unexpected status code
|
||
Throw New Exception(
|
||
"HTTP " & statusCode & ": " & response
|
||
)
|
||
|
||
Catch ex As Exception
|
||
|
||
lastEx = ex
|
||
|
||
' If this was an HTTP 4xx, don't retry.
|
||
If rest.ResponseStatusCode >= 400 AndAlso
|
||
rest.ResponseStatusCode < 500 Then
|
||
|
||
Throw
|
||
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name, ERROR_OP.MAIL)
|
||
|
||
End If
|
||
|
||
' Connection/transport error -> retry
|
||
If i < retries Then
|
||
Threading.Thread.Sleep(500)
|
||
End If
|
||
|
||
End Try
|
||
|
||
Next
|
||
|
||
Throw lastEx
|
||
|
||
|
||
|
||
|
||
End Function
|
||
|
||
Private Function BuildPayloadReceipt(amount As Decimal, vat As Decimal, POS As List(Of EABelegPositionen), kindOfPayment As String, posSystemId As String, _receiptCase As String, _reference As String, TSEisOnline As Boolean) As JsonObject
|
||
|
||
Dim json As New JsonObject()
|
||
|
||
json.UpdateString("ftCashBoxID", _cashboxId)
|
||
json.UpdateString("ftPosSystemId", getVersion(posSystemId))
|
||
json.UpdateString("cbTerminalID", posSystemId)
|
||
|
||
If _reference <> "" Then
|
||
json.UpdateString("cbReceiptReference", _reference)
|
||
Else
|
||
json.UpdateString("cbReceiptReference", Guid.NewGuid().ToString())
|
||
End If
|
||
|
||
json.UpdateString("cbReceiptMoment", DateTime.UtcNow.ToString("o"))
|
||
|
||
Dim receiptCaseValue As Long
|
||
|
||
|
||
If _receiptCase = ReceiptCaseIntern.STORNO Then
|
||
|
||
' Neue Referenz für den Stornobeleg
|
||
json.UpdateString("cbReceiptReference", Guid.NewGuid().ToString())
|
||
' Referenz auf den ursprünglichen Beleg
|
||
json.UpdateString("cbPreviousReceiptReference", _reference)
|
||
|
||
If TSEisOnline Then
|
||
receiptCaseValue = FtReceiptCases.PosReceipt Or FtReceiptCases.ReversalReceipt Or FtReceiptCases.ImplicitTransaction
|
||
Else
|
||
receiptCaseValue = FtReceiptCases.PosReceipt Or FtReceiptCases.ReversalReceipt Or FtReceiptCases.FailedReceipt Or FtReceiptCases.ImplicitTransaction
|
||
End If
|
||
json.UpdateString("cbUser", VERAG_PROG_ALLGEMEIN.cAllgemein.USRKURZNAME)
|
||
|
||
ElseIf _receiptCase = ReceiptCaseIntern.WIEDERHOLUNG Then
|
||
|
||
'Receipt-Request nach Kommunikationsfehler
|
||
'dieselbe cbReceiptReference verwenden
|
||
'dieselben cbChargeItems und cbPayItems mitsenden
|
||
'optional dieselbe cbTerminalID
|
||
|
||
json.UpdateString("cbReceiptReference", _reference)
|
||
receiptCaseValue = FtReceiptCases.PosReceipt Or FtReceiptCases.ReceiptRequest
|
||
|
||
' Kasseneinzahlung (ohne Positionen) / Kassenauszahlung (ohne Positionen)
|
||
ElseIf (_receiptCase = ReceiptCaseIntern.EINGANG OrElse _receiptCase = ReceiptCaseIntern.AUSGANG) Then
|
||
kindOfPayment = PayItemCasesIntern.Kasseneinzahlungen_Auszahlungen
|
||
json.UpdateString("cbReceiptReference", Guid.NewGuid().ToString())
|
||
|
||
If TSEisOnline Then
|
||
receiptCaseValue = FtReceiptCases.CashDepositOrWithdrawal Or FtReceiptCases.ImplicitTransaction
|
||
Else
|
||
receiptCaseValue = FtReceiptCases.CashDepositOrWithdrawal Or FtReceiptCases.FailedReceipt Or FtReceiptCases.ImplicitTransaction
|
||
End If
|
||
|
||
|
||
Else
|
||
|
||
' New reference for a normal receipt
|
||
json.UpdateString("cbReceiptReference", Guid.NewGuid().ToString())
|
||
If TSEisOnline Then
|
||
receiptCaseValue = FtReceiptCases.PosReceipt Or FtReceiptCases.ImplicitTransaction
|
||
Else
|
||
receiptCaseValue = FtReceiptCases.PosReceipt Or FtReceiptCases.FailedReceipt Or FtReceiptCases.ImplicitTransaction
|
||
End If
|
||
|
||
|
||
End If
|
||
|
||
json.UpdateString("ftReceiptCase", receiptCaseValue.ToString())
|
||
|
||
|
||
Dim chargeItems = json.AppendArray("cbChargeItems")
|
||
|
||
If POS.Count > 0 Then
|
||
|
||
For Each p In POS
|
||
|
||
If chargeItems.AddObjectAt(-1) Then
|
||
|
||
|
||
Dim quantity As Double = p.Anzahl
|
||
Dim unitPrice As Double = p.Preis
|
||
Dim lineAmount As Double = p.Betrag
|
||
|
||
'bei Storno negieren (BEI DE nur einen Teil)! -> im V1 Beispiel sind beide negativ!!!
|
||
'To cancel a receipt, resend it with this flag added to the ftReceiptCase and inverse the cbPayItems OR cbChargeItems (This is not the same behavior as described in the general part — in Germany, this flag requires only one of cbPayItems or cbChargeItems to be negative, and both must not be negative at the same time)'
|
||
'https://docs.fiskaltrust.cloud/docs/poscreators/middleware-doc/germany/reference-tables/ftreceiptcase
|
||
|
||
If _receiptCase = ReceiptCaseIntern.STORNO Then
|
||
quantity = quantity * -1
|
||
lineAmount = lineAmount * -1
|
||
End If
|
||
|
||
Dim item As Chilkat.JsonObject = chargeItems.ObjectAt(chargeItems.Size - 1)
|
||
item.UpdateInt("Quantity", quantity)
|
||
item.UpdateNumber("Amount", lineAmount)
|
||
item.UpdateNumber("VATRate", vat)
|
||
item.UpdateString("Description", p.LeistungsBez)
|
||
|
||
Dim ChargeItemCase As Long
|
||
Select Case vat
|
||
|
||
Case 19D
|
||
ChargeItemCase = FtChargeItemCase.RevenueNormal
|
||
|
||
Case 7D
|
||
ChargeItemCase = FtChargeItemCase.RevenueReduced
|
||
|
||
Case 0D
|
||
ChargeItemCase = FtChargeItemCase.RevenueTaxFree
|
||
|
||
Case Else
|
||
Throw New Exception("Unbekannter Steuersatz")
|
||
End Select
|
||
|
||
|
||
item.UpdateString("ftChargeItemCase", ChargeItemCase)
|
||
End If
|
||
|
||
|
||
Next
|
||
|
||
End If
|
||
|
||
|
||
Dim paidAmount As Double = amount
|
||
Dim paidQuantity As Integer = 1
|
||
|
||
'bei Storno negieren (BEI DE nur einen Teil)! -> im V1 Beispiel sind beide negativ!!!
|
||
'To cancel a receipt, resend it with this flag added to the ftReceiptCase and inverse the cbPayItems OR cbChargeItems (This is not the same behavior as described in the general part — in Germany, this flag requires only one of cbPayItems or cbChargeItems to be negative, and both must not be negative at the same time)'
|
||
'https://docs.fiskaltrust.cloud/docs/poscreators/middleware-doc/germany/reference-tables/ftreceiptcase
|
||
|
||
If PayItemCasesIntern.Kasseneinzahlungen_Auszahlungen Then
|
||
|
||
End If
|
||
|
||
|
||
|
||
If _receiptCase = ReceiptCaseIntern.STORNO Then
|
||
paidAmount = paidAmount * -1
|
||
paidQuantity = paidQuantity * -1
|
||
End If
|
||
|
||
|
||
|
||
Dim payItems = json.AppendArray("cbPayItems")
|
||
payItems.AddObjectAt(-1)
|
||
Dim pay As Chilkat.JsonObject = payItems.ObjectAt(payItems.Size - 1)
|
||
pay.UpdateInt("Quantity", paidQuantity)
|
||
pay.UpdateNumber("Amount", paidAmount)
|
||
Dim Description As String = ""
|
||
|
||
Select Case kindOfPayment
|
||
Case PayItemCasesIntern.Cash
|
||
pay.UpdateString("ftPayItemCase", FtPayItemCases.Cash)
|
||
Description = "Bar"
|
||
Case PayItemCasesIntern.DebitCard
|
||
pay.UpdateString("ftPayItemCase", FtPayItemCases.DebitCard)
|
||
Description = "ECKarte"
|
||
Case PayItemCasesIntern.Kasseneinzahlungen_Auszahlungen
|
||
pay.UpdateString("ftPayItemCase", FtPayItemCases.Kasseineinzahlung_Auszahlung)
|
||
If amount > 0 Then
|
||
Description = "Kasseneingang"
|
||
ElseIf amount < 0 Then
|
||
Description = "Kassenausgang"
|
||
End If
|
||
End Select
|
||
|
||
|
||
pay.UpdateString("Description", Description)
|
||
|
||
|
||
Return json
|
||
|
||
End Function
|
||
|
||
Private Function BuildPayloadNullReceipt(posSystemId As String, country As String) As JsonObject
|
||
|
||
Dim json As New JsonObject()
|
||
|
||
json.UpdateString("ftCashBoxID", _cashboxId)
|
||
json.UpdateString("ftPosSystemId", getVersion(posSystemId))
|
||
json.UpdateString("cbTerminalID", posSystemId)
|
||
json.UpdateString("cbReceiptMoment", DateTime.UtcNow.ToString("o"))
|
||
json.UpdateString("ftReceiptCase", (FtReceiptCases.ZeroReceipt Or FtReceiptCases.ImplicitTransaction).ToString())
|
||
json.UpdateString("cbReceiptReference", "ZeroReceiptAfterFailure")
|
||
|
||
Dim chargeItems = json.AppendArray("cbChargeItems")
|
||
Dim payItems = json.AppendArray("cbPayItems")
|
||
|
||
Return json
|
||
End Function
|
||
|
||
Private Function BuildPayloadInitialOperationReceipt(posSystemId As String, country As String) As JsonObject
|
||
|
||
Dim json As New JsonObject()
|
||
|
||
json.UpdateString("ftCashBoxID", _cashboxId)
|
||
json.UpdateString("ftPosSystemId", getVersion(posSystemId))
|
||
json.UpdateString("cbTerminalID", posSystemId)
|
||
json.UpdateString("cbReceiptMoment", DateTime.UtcNow.ToString("o"))
|
||
json.UpdateString("ftReceiptCase", (FtReceiptCases.InitialOperation Or FtReceiptCases.ImplicitTransaction).ToString())
|
||
json.UpdateString("cbReceiptReference", "INIT")
|
||
|
||
json.UpdateString("cbUser", "Admin")
|
||
json.UpdateString("ftReceiptCaseData", "")
|
||
|
||
Dim chargeItems = json.AppendArray("cbChargeItems")
|
||
Dim payItems = json.AppendArray("cbPayItems")
|
||
|
||
Return json
|
||
End Function
|
||
|
||
Private Function BuildPayloadOutOfOperationReceipt(posSystemId As String, country As String) As JsonObject
|
||
|
||
Dim json As New JsonObject()
|
||
|
||
json.UpdateString("ftCashBoxID", _cashboxId)
|
||
json.UpdateString("ftPosSystemId", getVersion(posSystemId))
|
||
json.UpdateString("cbTerminalID", posSystemId)
|
||
json.UpdateString("cbReceiptMoment", DateTime.UtcNow.ToString("o"))
|
||
json.UpdateString("ftReceiptCase", (FtReceiptCases.OutOfOperation Or FtReceiptCases.ImplicitTransaction).ToString())
|
||
json.UpdateString("cbReceiptReference", "OutOfOperation")
|
||
json.UpdateString("cbUser", "Admin")
|
||
json.UpdateString("ftReceiptCaseData", "")
|
||
|
||
Dim chargeItems = json.AppendArray("cbChargeItems")
|
||
Dim payItems = json.AppendArray("cbPayItems")
|
||
|
||
Return json
|
||
End Function
|
||
|
||
Private Function BuildPayloadClosingReceipt(receiptType As String, posSystemId As String, kind As String) As JsonObject
|
||
|
||
Dim json As New JsonObject()
|
||
|
||
json.UpdateString("ftCashBoxID", _cashboxId)
|
||
json.UpdateString("ftPosSystemId", getVersion(posSystemId))
|
||
json.UpdateString("cbTerminalID", posSystemId)
|
||
json.UpdateString("cbReceiptMoment", DateTime.UtcNow.ToString("o"))
|
||
Dim chargeItems = json.AppendArray("cbChargeItems")
|
||
Dim payItems = json.AppendArray("cbPayItems")
|
||
|
||
|
||
|
||
Select Case kind
|
||
Case "yearly"
|
||
|
||
json.UpdateString("cbReceiptReference", "yearly-closing-" & DateTime.UtcNow.ToString("o"))
|
||
json.UpdateString("ftReceiptCase", (FtReceiptCases.YearlyClosing Or FtReceiptCases.ImplicitTransaction).ToString())
|
||
|
||
Case "monthly"
|
||
|
||
json.UpdateString("cbReceiptReference", "monthly-closing-" & DateTime.UtcNow.ToString("o"))
|
||
json.UpdateString("ftReceiptCase", (FtReceiptCases.MonthlyClosing Or FtReceiptCases.ImplicitTransaction).ToString())
|
||
|
||
Case Else 'daily
|
||
json.UpdateString("cbReceiptReference", "daily-closing-" & DateTime.UtcNow.ToString("o"))
|
||
json.UpdateString("ftReceiptCase", (FtReceiptCases.DailyClosing Or FtReceiptCases.ImplicitTransaction).ToString())
|
||
|
||
End Select
|
||
|
||
Return json
|
||
End Function
|
||
|
||
Private Function GetEndpoint(type As String) As String
|
||
|
||
Select Case type
|
||
|
||
Case "payment"
|
||
|
||
Select Case _country
|
||
Case "DE" : Return "/json/v1/Sign"
|
||
Case "AT" : Return "/json/Sign"
|
||
End Select
|
||
|
||
Case "test"
|
||
|
||
Select Case _country
|
||
Case "DE" : Return "/json/v1/Echo"
|
||
Case "AT" : Return "/json/Echo"
|
||
End Select
|
||
|
||
Case "journal"
|
||
|
||
Select Case _country
|
||
Case "DE" : Return "/json/v1/Journal"
|
||
Case "AT" : Return "/json/Journal"
|
||
End Select
|
||
|
||
Case "storno"
|
||
|
||
Select Case _country
|
||
Case "DE" : Return "/json/v1/Sign"
|
||
Case "AT" : Return "/json/Sign"
|
||
End Select
|
||
|
||
|
||
End Select
|
||
|
||
Throw New Exception("Unsupported country")
|
||
|
||
End Function
|
||
|
||
Private Function getVersion(Terminal_ID As String) As String
|
||
Return Terminal_ID '& "_" & Application.ProductVersion
|
||
End Function
|
||
|
||
Public Function saveRKSV_FT(ByRef result_zahlung As String, ByRef QR_CodeString As String, ByRef beleg_temp As EABeleg, ByRef isStorno As Boolean) As Boolean
|
||
|
||
If String.IsNullOrWhiteSpace(result_zahlung) Then
|
||
Return False
|
||
End If
|
||
|
||
|
||
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 saved As Boolean = False
|
||
|
||
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")
|
||
|
||
If beleg_temp Is Nothing Then
|
||
.ftBeleg_ID = -1
|
||
Else
|
||
.ftBeleg_ID = beleg_temp.BelegNr
|
||
End If
|
||
|
||
|
||
saved = .SAVE()
|
||
|
||
If saved AndAlso beleg_temp IsNot Nothing Then
|
||
|
||
If isStorno Then
|
||
beleg_temp.FT_ReceiptReference_Storno = .cbReceiptReference
|
||
beleg_temp.SAVE()
|
||
Else
|
||
beleg_temp.FT_ReceiptReference = .cbReceiptReference
|
||
beleg_temp.SAVE()
|
||
End If
|
||
|
||
|
||
End If
|
||
|
||
End With
|
||
|
||
|
||
Dim num As Integer = json.SizeOfArray("ftSignatures")
|
||
If num = 0 Then
|
||
MsgBox("Signatureinheit liefert keine (gültige) Signatur, Signatureinheit ausgefallen" & vbNewLine & "Beleg kann nachträglich signiert werden!")
|
||
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 - 1
|
||
|
||
|
||
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")
|
||
saved = .SAVE()
|
||
|
||
|
||
|
||
End With
|
||
|
||
Next
|
||
|
||
'https://receipts.fiskaltrust.eu/{ftQueueID}/{ftQueueItemID}
|
||
Dim URL_FT As String = ""
|
||
If Not String.IsNullOrWhiteSpace(ftSig.ftQueueID) AndAlso Not String.IsNullOrWhiteSpace(ftSig.ftQueueItemID) Then
|
||
URL_FT = $"https://receipts.fiskaltrust.eu/{ftSig.ftQueueID}/{ftSig.ftQueueItemID}"
|
||
|
||
Using qrGenerator As New QRCodeGenerator()
|
||
Using qrData As QRCodeData = qrGenerator.CreateQrCode(URL_FT, QRCodeGenerator.ECCLevel.Q)
|
||
|
||
Dim qrCode As New PngByteQRCode(qrData)
|
||
Dim qrBytes As Byte() = qrCode.GetGraphic(20)
|
||
Dim qrBase64 As String = Convert.ToBase64String(qrBytes)
|
||
|
||
QR_CodeString = qrBase64
|
||
|
||
End Using
|
||
End Using
|
||
|
||
End If
|
||
|
||
|
||
Return saved
|
||
|
||
|
||
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") = .StringOf("ftReceiptMoment")
|
||
|
||
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
|
||
|
||
Public Function PrettyPrintJson(jsonText As String) As String
|
||
|
||
Dim json As New Chilkat.JsonObject()
|
||
|
||
If Not json.Load(jsonText) Then
|
||
Return jsonText
|
||
End If
|
||
|
||
json.EmitCompact = False
|
||
|
||
Return json.Emit()
|
||
|
||
End Function
|
||
|
||
End Class
|
||
|