*
*   smaze v datastore objednana+nesnedena jidla PO datu expirace
*

LPARAMETERS client, expirace, stat

IF m.stat # "A"
    expirace = LEFT(TTOC(DATE(), 3), 10)
ENDIF 

IF BETWEEN(expirace, TTOC(DATE(), 3), TTOC(DATE()+33, 3))

    json_orders = http_get("canteen/crud/orders?page_size=333&filter{client}=" + ALLTRIM(STR(client)) + "&filter{meal.date.gt}=" + ALLTRIM(expirace))
    pocet_rdku = json_rowcount(m.json_orders)
    FOR iiii = 1 TO m.pocet_rdku
       id_order  = get_integer_item (m.json_orders, "id"      , iiii)
       ordered   = get_integer_item (m.json_orders, "ordered" , iiii)
       eaten     = get_integer_item (m.json_orders, "eaten"   , iiii)
       IF m.eaten = 0 .and. m.ordered > 0
           http_request('canteen/crud/orders/' + ALLTRIM(STR(m.id_order)), "PATCH", '{"ordered":0,"eaten":0}')  
       ENDIF 
    ENDFOR 

*{"id":114537,"client":30,"meal":16363,"ordered":1,"eaten":1,"created_at":"2019-08-14T09:46:57.630140Z","updated_at":"2019-08-23T09:06:27.166370Z"},

ENDIF 
