*
* cisla stredisek v leu mame ulozena v partneri.ext_id
* cisla artiklu jsou v karty.kod  
*
PARAMETERS c_dokl

#DEFINE ODD ","
#DEFINE CRLF CHR(13)+CHR(10)

SELECT doklady
LOCATE FOR c_dokl = m.c_dokl
c_partnera = doklady.c_partner
rajd       = ""
IF "|" $ pz1
    rajd = LEFT(pz1, AT("|", pz1)-1)
ENDIF 
SELECT partneri
LOCATE FOR c_partner = m.c_partnera

DO CASE 
CASE .not. FOUND()
    RETURN 
CASE partneri.ico # "VAGO"
    RETURN 
CASE doklady.operace # "VE"
    RETURN 
CASE doklady.c_partner > 0
    RETURN 
OTHERWISE 

WAIT "vydejka do LEO" WINDOW NOWAIT 

    json_leo = '{ "title_id": "' + nx(ABS(doklady.c_partner)) + '", "ride_id_in": "' + m.rajd + '", "alto_document_id": "' + nx(m.c_dokl) + '", "products": ['
    SELECT * FROM obraty WHERE c_dokl = m.c_dokl INTO CURSOR doklad1
    SET RELATION TO c_karty INTO karty
    SCAN
        json_leo = m.json_leo + ' {"product_id":"' + ALLTRIM(karty.kod) + '", "count":"' + nx(- doklad1.mnozstvi) + '"},'
    ENDSCAN 
    IF RIGHT(m.json_leo, 1) = ","
        json_leo = LEFT(m.json_leo, LEN(m.json_leo)-1)
    ENDIF 
    json_leo = m.json_leo + ' ] }'
*json_leo = '{  "title_id": "6", "ride_id_in": "504350", "alto_document_id": "123444", "products": [ { "product_id": 123, "count": "11" }, { "product_id": 117, "count": "15"  }  ] }'

    DO ppgm_http_leo WITH "https://api.le.cz/api/v1/"  && parametr je ignorovan

    json = http_request("catering/stock/documents/", "POST", m.json_leo)
*    MESSAGEBOX(m.json, 1+64,"json_leo LEO",4444)
    small_log (m.json_leo, "leo")

ENDCASE 
WAIT CLEAR 


********** vraci string s uvozovkami nahrazenymi apostrofy + uvozovky  **********
FUNCTION tx2 (retez)
RETURN ALLTRIM(STRTRAN(IIF(ISNULL(m.retez), "", m.retez), '"', "'"))

********** vraci string s carkami nahrazenymi teckami  **********
FUNCTION tx (retez)
retval = STRTRAN(m.retez, ",", ".")
RETURN ALLTRIM(STRTRAN(retval, '"', "'"))

