Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

E-fakture download izlaznih faktura u PDF-u sa SEF-a

[es] :: Access :: E-fakture download izlaznih faktura u PDF-u sa SEF-a

[ Pregleda: 274 | Odgovora: 4 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

mustur
Mustur Gojko
Beograd

Član broj: 32122
Poruke: 47
*.dynamic.sbb.rs.



+1 Profil

icon E-fakture download izlaznih faktura u PDF-u sa SEF-a09.03.2023. u 09:34 - pre 16 dana i 4h
Da li je neko imao iskustvo sa automatizacijom download-a izlaznih faktura u PDF-u sa SEF-a.
 
Odgovor na temu

bokinet

Član broj: 29844
Poruke: 557



+50 Profil

icon Re: E-fakture download izlaznih faktura u PDF-u sa SEF-a12.03.2023. u 21:17 - pre 12 dana i 16h
svih.
 
Odgovor na temu

mustur
Mustur Gojko
Beograd

Član broj: 32122
Poruke: 47
*.dynamic.sbb.rs.



+1 Profil

icon Re: E-fakture download izlaznih faktura u PDF-u sa SEF-a14.03.2023. u 11:58 - pre 11 dana i 1h
Moze svih, moze pojedinacno.
 
Odgovor na temu

mmarkoni
Milan Marković

Član broj: 95013
Poruke: 43
*.dynamic.isp.telekom.rs.



Profil

icon Re: E-fakture download izlaznih faktura u PDF-u sa SEF-a15.03.2023. u 09:25 - pre 10 dana i 4h
Onako na brzinu

Potrebne reference
WinHttpRequest.5.1,
Microsoft Scripting Runtime

Potrebno je preuzeti vba modul JsonConverter.bas sa sajta: [url=]https://github.com/VBA-tools/VBA-JSON[/url]


Code:

Public Function PurchaseInvoiceIds()
    Dim http As Object
    Dim strUrl As String
    strUrl = "https://efaktura.mfin.gov.rs/api/publicApi/purchase-invoice/ids"
    Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
    With http
        .Open "Post", strUrl, False
        .setRequestHeader "ApiKey", "tvoj api key"
        .setRequestHeader "Content-Type", "*/*"
        .Send
        If .Status = 200 Then
            Dim strOdgovor As String
            strOdgovor = http.ResponseText
            Debug.Print strOdgovor
            Debug.Print JsonConverter.ConvertToJson(strOdgovor, Whitespace:=2)
            PurchaseInvoiceIds = JsonConverter.ConvertToJson(strOdgovor, Whitespace:=2)
        Else
            Debug.Print .Status
            PurchaseInvoiceIds = ""
        End If
    End With
    Set http = Nothing
    On Error GoTo 0
    Exit Function
End Function

Code:

Public Function PurchaseInvoiceById(ByVal IdEfak As LongPtr)
    Dim http As Object
    Dim strUrl As String
    strUrl = "https://efaktura.mfin.gov.rs/a...pi/purchase-invoice?invoiceid=" & IdEfak
    Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
    With http
        .Open "Get", strUrl, False
        .setRequestHeader "ApiKey", "tvoj api key"
        .setRequestHeader "Content-Type", "*/*"
        .Send
        If .Status = 200 Then
            Dim strOdgovor As String
            strOdgovor = http.ResponseText
            Debug.Print strOdgovor
            Debug.Print JsonConverter.ConvertToJson(strOdgovor, Whitespace:=2)
            PurchaseInvoiceById = JsonConverter.ConvertToJson(strOdgovor, Whitespace:=2)
        Else
            Debug.Print .Status
            PurchaseInvoiceById = ""
        End If
    End With
    Set http = Nothing
    On Error GoTo 0
    Exit Function
End Function

Pozdrav

 
Odgovor na temu

mmarkoni
Milan Marković

Član broj: 95013
Poruke: 43
*.dynamic.isp.telekom.rs.



Profil

icon Re: E-fakture download izlaznih faktura u PDF-u sa SEF-a15.03.2023. u 21:19 - pre 9 dana i 16h
Malo smernice u radu sa json odgovorima Sef api-ja na prethoodom primeru

PurchaseInvoiceIds drugi pristup što bi rekli "u sitna crevca"
Code:

Public Function PurchaseInvoiceIds(strApiKey As String) ' Ovde smo stavili Api key kao parametar funkcije
    Dim http As Object
    Dim strUrl As String
    Dim aNiz() As Long
    strUrl = "https://efaktura.mfin.gov.rs/api/publicApi/purchase-invoice/ids"
    Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
    With http
        .Open "Post", strUrl, False
        .setRequestHeader "ApiKey", strApiKey
        .setRequestHeader "Content-Type", "*/*"
        .Send
        If .Status = 200 Then
            Dim strOdgovor As String
            strOdgovor = http.responseText
            Dim jsonObject As Object
            Dim strString As Variant
            
            Dim output As String
            Dim i As LongPtr
            Dim Parsed As Scripting.Dictionary
            Dim Parsed2 As VBA.Collection
            Dim InvoiceIds As Scripting.Dictionary
            Dim lngBroj As LongPtr
            Dim Item As Object

            Set jsonObject = JsonConverter.ParseJson(.responseText)
            If TypeOf jsonObject Is Scripting.Dictionary Then                     ' Proveravamo dalije jsonObjrkt json
                Debug.Print "Korak 1"                                                      ' Ovaj korak se dešava ako postoji .responseText
                Set Parsed = jsonObject
                If jsonObject.Exists("PurchaseInvoiceIds") Then
                    Debug.Print "Korak 2"                                                    ' Ovaj korak se dešava ako ima ID ulaznih računa
                Set Parsed = jsonObject
                    If TypeOf jsonObject.Item("PurchaseInvoiceIds") Is Scripting.Dictionary Then
                            Debug.Print "Korak 3"      ' Ovaj korak se neće dogoditi u našeoj funkciji jer vrednost ključa PurchaseInvoiceIds nije json, ali sam ipak naveo kako se radi ako jeste
                            Set Parsed = jsonObject.Item("PurchaseInvoiceIds")
                            lngBroj = Parsed.Count
                            ReDim aNiz(lngBroj)
                            i = 0
                            
                            For Each Item In Parsed
                                Debug.Print Item
                                aNiz(i) = Item
                                i = i + 1
                            Next Item
                            '  
                        Else
                            Debug.Print "jsonObject vraca JSON Objekat sa PurchaseInvoiceIds key čija vrednost nije JSON Objekat, već je VBA kolekcija"
                            Set Parsed2 = jsonObject.Item("PurchaseInvoiceIds")
                            lngBroj = Parsed2.Count
                            Debug.Print lngBroj
                            ReDim aNiz(lngBroj)
                            For i = 1 To Parsed2.Count
                                aNiz(i) = Parsed2(i)
                                Debug.Print aNiz(i)
                            Next i
                    End If
 
                Else
                        Debug.Print "jsonObject je vratio JSON Object bez PurchaseInvoiceIds ključa, znači nema ulaznih faktura"
                        PurchaseInvoiceIds = .""
                        Exit Function
                End If

            Else
                    Debug.Print "jsonObject nije vratio JSON Objekat"
                    PurchaseInvoiceIds = .""
                    Exit Function
            End If
            PurchaseInvoiceIds = .responseText

        Else
            Debug.Print .Status

        End If
    End With
    Set http = Nothing
    On Error GoTo 0
    Exit Function
End Function



Nadam se da če primer malo pojasniti kako se radi sa json objektima.
 
Odgovor na temu

[es] :: Access :: E-fakture download izlaznih faktura u PDF-u sa SEF-a

[ Pregleda: 274 | Odgovora: 4 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.