*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *
*
* program cte dbf poslancu a posle je na datastore do tabulek clients, client_infos a users
*
*    *    *    *    *    *    *    *    *    *    *    *      #> ver. 2021-11-04 <#       *    *    *    *    *    *    *    *    *    *    *    *    *


HTTP_READ_ONLY_MODE = .F.

DO (LOWER(JUSTPATH(sys(16))) + "\http_ppgm") WITH "https://alto:1991.Altopraha@btr.psp.cz/"

ACTIVATE SCREEN 
_screen.Cls

USE i:\poslanci
SELECT *, 00000000 as id_clients FROM poslanci INTO TABLE stravnici

*json = http_request("kredit/crud/clients/766"  , "DELETE", "")

DO posli_cloveky



*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *
PROCEDURE posli_cloveky

SELECT stravnici
SCAN  FOR RECNO() > 1
    SCATTER MEMVAR 
    ? m.surname

    client_req = '{"status":"N","client_id":"[OSC]","card_id":"[OSC]","chip_id":"[CHIP]","email":"[EMAIL]","firstname":"[FIRSTNAME]","surname":"[SURNAME]"' + ',"news":false,"daily_menu":false,"expiration_date":"2055-05-15","personal":{},"company":{"dic":"","ico":"1","name":"Poslanci"},"address":{},"address2":{}, "comment":"Poslanci" }'
    info_req   = '{"client":[CLIENT_ID],"typ":"1","limit":-20000,"limit_var":500,"limit_den":0,"sl_limit":0,"sl_limit_mes":0,"c_hlad":1,"pl_c_hlad":1,"typ_slevy":2' + ',"pl_typ_slevy":1,"sl_koef":"0.00","pl_sl_koef":"0.00","omez_platba":false,"k_vyplate":false,"max_den_odber":1 }'
    user_req   = '{"client":[CLIENT_ID],"username":"[OSC]","first_name":"[FIRSTNAME]","last_name":"[SURNAME]","email":"[EMAIL]","is_active":true,"is_staff":false' + ',"is_superuser":false,"password":"9999","groups":["clients"],"pin":null}'

    client_req = STRTRAN(m.client_req, '[OSC]'      , ALLTRIM(STR(client_id)))
    client_req = STRTRAN(m.client_req, '[CHIP]'     , ALLTRIM(chip_id))
    client_req = STRTRAN(m.client_req, '[FIRSTNAME]', ALLTRIM(firstname))
    client_req = STRTRAN(m.client_req, '[SURNAME]'  , ALLTRIM(surname))
    client_req = STRTRAN(m.client_req, '[EMAIL]'    , ALLTRIM(email))

small_log(m.client_req, "poslanci")

    json = http_request("kredit/crud/clients", "POST", m.client_req)
    id_clients = get_integer_item(m.json, "id")
    GATHER FIELDS id_clients MEMVAR 

small_log(STR(m.id_clients) + "    " + m.json, "poslanci")

        user_req = STRTRAN(m.user_req, '[CLIENT_ID]', ALLTRIM(STR(id_clients)))
        user_req = STRTRAN(m.user_req, '[OSC]'      , ALLTRIM(STR(client_id)))
        user_req = STRTRAN(m.user_req, '[CHIP]'     , ALLTRIM(chip_id))
        user_req = STRTRAN(m.user_req, '[FIRSTNAME]', ALLTRIM(firstname))
        user_req = STRTRAN(m.user_req, '[SURNAME]'  , ALLTRIM(surname))
        user_req = STRTRAN(m.user_req, '[EMAIL]'    , ALLTRIM(email))

        info_req = STRTRAN(m.info_req, '[CLIENT_ID]', ALLTRIM(STR(id_clients)))


small_log(m.user_req, "poslanci")
small_log(m.info_req, "poslanci")

small_log("    ----", "poslanci")


    IF m.id_clients # 0
        http_request("kredit/crud/client_infos", "POST", m.info_req)
        http_request("auth/crud/users"         , "POST", m.user_req)
    ENDIF 
ENDSCAN 
