*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
*
*     generator prazdnych clientu do datastore s vyplnenym carovym kodem a statusem "U"
*
*
* 2021-04-09 - news = true
* 2021-04-12 - zmenen typ karty a typ_slevy
*
*
*
*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    


DO ppgm_http 

*HTTP_READ_ONLY_MODE = .T.

#DEFINE COUNTRYCODE "777"
#DEFINE POCET_KARET 99

stahni_klienty()
rand(-99)
ACTIVATE SCREEN 
COUNT FOR status = "U" TO qwe
IF MESSAGEBOX("Jeste mate " + ALLTRIM(STR(qwe)) + " volnych karet," + CHR(13) + "chcete generovat dalsi?",3+32) = 6
    FOR iii = 1 TO POCET_KARET
        cislo_cloveka = TRANSFORM(rand() *999999999, "@L 999999999")
        LOCATE FOR client_id = m.cislo_cloveka
        IF .not. FOUND()
            DO vyrob_cloveka &&with cislo_cloveka
            ?? "."
        ELSE 
            ?? "-"
        ENDIF 
    ENDFOR 
ENDIF 


*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *
FUNCTION vyrob_cloveka ()

*{"id":188,"info":188,"status":"A","client_id":"42389","card_id":"42389","chip_id":"0113800B7D","email":"42389@fejk.cz","firstname":"Ondøej","surname":"Bittner","expiration_date":"2055-05-05","company":{"dic":"","ico":"2","name":"DTS"}},
*{"id":198,"client":198,"typ":"1","limit":-5000,"limit_var":0,"limit_den":0,"sl_limit":0,"sl_limit_mes":0,"c_hlad":2,"pl_c_hlad":2,"typ_slevy":2,"pl_typ_slevy":2,"sl_koef":"0.00","pl_sl_koef":"0.00","omez_platba":false,"k_vyplate":false,"rod_cis":null,"id_vlastnik":null,"pr_pozice":null,"st_autor":null,"rezerva":null,"profil":null,"max_den_odber":99,"akt_den_odber":null,"id_omezeni":null,"posl_poh_nul":null,"posl_poh_arc":null,"id_firmy":null,"id_zuct":null,"sl_min_cast":null,"d_zm_status":null,"d_konec_kred":null,"d_posl_odber":null,"created_at":"2019-10-23T11:31:48.199679Z","updated_at":"2020-10-13T12:36:37.299545Z"},

    firma         = 'pivovar'

    client_id     = m.cislo_cloveka
    card_id       = m.cislo_cloveka
    chip_id       = COUNTRYCODE + m.cislo_cloveka

    c_hlad        = "2"
    pl_c_hlad     = "1"
    typ_slevy     = "14"
    pl_typ_slevy  = "1"
    sl_koef       = '"0.0"'
    pl_sl_koef    = '"0.0"'
    limit         = "0"

    rq_cli =            '{ "card_id":"' + m.card_id + '", "client_id":"' + m.client_id + '", "chip_id":"' + m.chip_id + '"'
    rq_cli = m.rq_cli + ', "status":"U", "expiration_date":"2055-05-05", "news":true }'

    json = http_request("kredit/crud/clients", "POST", m.rq_cli)
    IF .not. json_ok(m.json)
        MESSAGEBOX(m.json, 1+16, "Nepodarilo se zapsat stravnika - client")
    ELSE 
        cl_id = get_integer_item(m.json, "id")
        rq_info =             '{ "client":' + nx(m.cl_id)
        rq_info = m.rq_info + ',    "c_hlad":' +    m.c_hlad + ',    "typ_slevy":' +    m.typ_slevy + ',    "sl_koef":'    + m.sl_koef
        rq_info = m.rq_info + ', "pl_c_hlad":' + m.pl_c_hlad + ', "pl_typ_slevy":' + m.pl_typ_slevy + ', "pl_sl_koef":' + m.pl_sl_koef
        rq_info = m.rq_info + ', "limit":' + m.limit + ', "typ":"C", "limit_var":0, "limit_den":0, "sl_limit":0, "sl_limit_mes":0 }'
        json = http_request("kredit/crud/client_infos", "POST" , m.rq_info)
        IF .not. json_ok(m.json)
                MESSAGEBOX(m.json, 1+16, "Nepodarilo se zapsat stravnika - client_infos")
        ENDIF 
    ENDIF 



***********************************
***********************************


*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *
PROCEDURE stahni_klienty

#DEFINE PAGESIZE  "250"

CREATE TABLE (m.gcpri_path + "stravnici_web") FREE ;
       (id I, surname C(22) NULL, client_id C(22), chip_id C(22), card_id C(22), status C(1), expiration C(10) )
INDEX ON client_id TAG client_id

zacatek_prace = SECONDS()
? "clients (" + PAGESIZE + ") "
FOR page_no = 1 TO 9999
    json = http_get( "kredit/crud/clients?page_size=" + PAGESIZE + "&page=" + ALLTRIM(STR(m.page_no)))
    next_page = get_string_item (m.json, "next")
    ?? nx(m.page_no) + " "
    FOR ii = 1 TO VAL(PAGESIZE)+3
       id          = get_integer_item (m.json, "id"              , ii)
       client_id   = get_string_item  (m.json, "client_id"       , ii)
       card_id     = get_string_item  (m.json, "card_id"         , ii)
       chip_id     = get_string_item  (m.json, "chip_id"         , ii)
       surname     = get_string_item  (m.json, "surname"         , ii)
       status      = get_string_item  (m.json, "status"          , ii)
       expiration  = get_string_item  (m.json, "expiration_date" , ii)

       chip_id     = IIF(ISNULL(m.chip_id)   , "", m.chip_id)
       expiration  = IIF(ISNULL(m.expiration), "", m.expiration)
       IF m.id # 0
          INSERT INTO stravnici_web FROM MEMVAR 
       ENDIF 
    ENDFOR 

    IF ISNULL(m.next_page)
        EXIT 
    ENDIF 
ENDFOR 
?? STR(SECONDS() - m.zacatek_prace) + "sec"



