Rem Inicijalizacija postavki
strPostavke = "SELECT * FROM tblPostavke"
Set rsp = CurrentDb.OpenRecordset(strPostavke)
Dim VelicinaPapira
Dim PosPrinter
Dim FolderSlika
Dim PrintEXE
Dim Stopa
VelicinaPapira = rsp!Papir
PosPrinter = rsp!Printer
FolderSlika = rsp!FolderSlika
PrintEXE = rsp!PrintEXE
Stopa = rsp!Stopa
Dim strSQLF As String
Dim http As Object
Dim url As String
Dim body As String
Dim response As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim artikli As String
Dim NacinPlacanja As String
Dim amount As Double
Dim items As String
Dim i As Integer
' Definisite URL
url = rsp!IPAdresa & ":3566/api/invoices"
' Kreirajte XMLHTTP objekat
Set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
' Prikupi podatke iz tabele
strSQLF = "SELECT * FROM QIzlaz WHERE QIzlaz.BrojRacuna = " & BrojRacuna
Set rs = CurrentDb.OpenRecordset(strSQLF)
' Inicijalizuj items
items = ""
While Not rs.EOF
' Dodaj podatke za svaki artikl
items = items & "{""name"": """ & rs!OpisArt & """, ""labels"": [""" & Stopa & """], ""totalAmount"": " & (rs!Iznos) & ", ""unitPrice"": " & rs!MPC & ", ""quantity"": " & rs!SumOfKolicina & "},"
amount = amount + rs!Iznos ' Ukupni iznos
rs.MoveNext
Wend
' Ukloni posljednji zarez
If Right(items, 1) = "," Then
items = Left(items, Len(items) - 1)
End If
rs.Close
Set rs = Nothing
Set db = Nothing
If rsp!Papir = 80 Then
' Formatiraj telo zahteva
body = "{""print"": false, ""renderReceiptImage"": true, ""receiptLayout"": ""Slip"", ""receiptImageFormat"": ""Png"", ""receiptSlipWidth"": 400, ""receiptSlipFontSizeNormal"": 23, ""receiptSlipFontSizeLarge"": 27, ""invoiceRequest"": {""invoiceType"": """ & Me.VrstaRN & """, ""transactionType"": ""Sale"", ""payment"": [{""amount"": """ & Me.Uplata & """, ""paymentType"": """ & Me.NP & """}], ""items"": [" & items & "], ""cashier"": """ & Me.Prodavac & """}}"
Else
body = "{""print"": false, ""renderReceiptImage"": true, ""receiptLayout"": ""Slip"", ""receiptImageFormat"": ""Png"", ""receiptSlipWidth"": 300, ""receiptSlipFontSizeNormal"": 20, ""receiptSlipFontSizeLarge"": 23, ""invoiceRequest"": {""invoiceType"": """ & Me.VrstaRN & """, ""transactionType"": ""Sale"", ""payment"": [{""amount"": """ & Me.Uplata & """, ""paymentType"": """ & Me.NP & """}], ""items"": [" & items & "], ""cashier"": """ & Me.Prodavac & """}}"
End If
Rem Debug.Print body
' Otvorite HTTP konekciju
http.Open "POST", url, False
' Dodajte zaglavlja
http.setRequestHeader "Authorization", "Bearer " & rsp!ApiKljuc
http.setRequestHeader "RequestId", "12385"
http.setRequestHeader "Content-Type", "application/json"
rsp.Close
Set rsp = Nothing
' Posaljite zahtjev
http.send body
' Dobijte odgovor
response = http.responseText
Dim strData As String
Dim str As String
Dim strTempPath As String
str = Mid(ExtractBase64String(response), 23)
strTempPath = FolderSlika
Open strTempPath For Binary As #1
Put #1, 1, DecodeBase64(str)
Close #1
' Oslobodite resurse
Set http = Nothing
Dim exePath As String
Dim parameters As String
exePath = PrintEXE
parameters = PosPrinter & "," & FolderSlika
shell exePath & " " & parameters, vbNormalFocus
DoCmd.OpenForm "IspisRacuna"