*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
*
* cisla artiklu jsou v karty.kod  
*
* 2022-01-14 - vysledkovy json se zobrazi jen pokud neni 200 OK
*
*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    

PARAMETERS c_dokl

#DEFINE CRLF CHR(13)+CHR(10)

SELECT doklady
LOCATE FOR c_dokl = m.c_dokl
IF FOUND() .and. c_dokl_x # 0
    WAIT "prijemka z LEO" WINDOW NOWAIT 

    json_leo = '{ "accepted_at": "' + TTOC(DATETIME(), 3)+ '", "alto_document_id":"' + ALLTRIM(STR(m.c_dokl,11)) + '" ,"products":['

    SELECT obraty.c_karty, obraty.mnozstvi, karty.kod FROM obraty LEFT JOIN karty ON obraty.c_karty = karty.c_karty WHERE c_dokl = m.c_dokl INTO CURSOR doklad1
    SCAN
        json_leo = m.json_leo + ' {"product_id":"' + ALLTRIM(doklad1.kod) + '", "count_accepted":"' + ALLTRIM(STR(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 + ' ] }'

    DO ppgm_http_leo
    json = http_request("catering/stock/documents/" + ALLTRIM(STR(doklady.c_dokl_x,11)), "PATCH", json_leo)

    IF ATC("200 OK", m.json) = 0
        MESSAGEBOX(m.json, 1+64,"json from LEO", 4444)
    ENDIF 
    small_log (m.json_leo, "leo")

ENDIF 
WAIT CLEAR 
