* Nastavi hodnotu sezrano u id objednavky
* p_lordered = prepise i ordered
PARAMETERS p_idorder, p_nvalue, p_lordered
PRIVATE vysledek, dotazString, qq, json 
		IF USED("myOrder")
			USE IN myOrder
		ENDIF 
		SELECT 0
		CREATE CURSOR myOrder;
	     (id I, meal I, client I, objednano N(2,0), sezrano N(2,0))


		  IF VARTYPE(m.http_logovat) # "U" AND VARTYPE(m.http_auth_token) # "U"
		  lcJSON = '{' ;
			       + '"eaten":"' + ALLTRIM(STR(m.p_nvalue,10))+'"';
			       + IIF(m.p_lordered, ', "ordered":"' + ALLTRIM(STR(m.p_nvalue,10))+'"', "");
			       + '}'
		  ELSE 
			  lcJSON = '{' ;
			       	   + '"NIC":"';
				       + '}'
		  ENDIF   

		  IF VARTYPE(m.http_logovat) # "U" AND VARTYPE(m.http_auth_token) # "U"
			m.dotazstring = "canteen/crud/orders/" + ALLTRIM(STR(m.p_idorder,12))
			json = http_request(m.dotazstring, "PATCH", m.lcJSON)		
		  ELSE 
		  ENDIF 

		  IF myjsonok(m.json)	&& lzHTTP.nError = 0 AND EMPTY(lzHTTP.cErrorMSg)	&&json_ok (m.json)
			IF VARTYPE(m.http_logovat) # "U" AND VARTYPE(m.http_auth_token) # "U"
		    	DO parsuj_json_qdf WITH m.json
		    ELSE
		    	DO parsuj_json WITH m.json
		    ENDIF 
		  ELSE 
		    * Web nedostupny nebo jina chyba
		    IF EMPTY(m.json)
		      m.vysledek = "9999 NO WEB CONNECTION"
		    ELSE
	      		IF VARTYPE(lzHTTP) == "O"
		      		m.vysledek = "ResultCode: " + lzHTTP.cResultCode + lzHTTP.cResultCodeMessage + " ERROR Code: " + ALLTRIM(STR(lzHTTP.nError)) + lzHTTP.cErrorMSg + "."
		      	ELSE
		      		m.vysledek = "ResultCode: " + STR(get_integer_item (m.json, '"http_status":'),6) + " " + m.json + "."
	      		ENDIF 
		    ENDIF 
		  ENDIF 
		  IF VARTYPE(m.vysledek) # 'C'
			  SELECT myOrder
			  m.pzaznamu = RECCOUNT()
			  DO CASE	  
			  CASE m.pzaznamu = 0
			    * Nenalezena objednavka
			    m.vysledek = "101 ORDER NOT FOUND"
			  CASE m.pzaznamu > 1
			    * Duplicitni klient
			    m.vysledek = "102 ORDER NOT UNIQUE"
			  OTHERWISE
			    * OK
			    m.vysledek = myOrder.id
			  ENDCASE 
		  ENDIF    
RETURN m.vysledek


**  **  **  **  **  **  **  **  **  **  **  **  **  **  **  **  **  **  
PROCEDURE parsuj_json (json)

RETURN 

PROCEDURE parsuj_json_qdf (json)
PRIVATE zavrit, nazev, canteen, course, pocet, c_karty, kk
m.zavrit = .F.
IF VARTYPE(loJSON) # 'O'
	m.lcProcLibWas = SET("procedure")
	IF !("QDFOXJSON" $ UPPER(m.lcProcLibWas))
	  SET PROCEDURE TO "QDFOXJSON" ADDITIVE 
	ENDIF 
    m.loJSON = CREATEOBJECT("jsonHelper")
	loVysledek=lojson.parse(m.json)
	m.zavrit = .T.
ELSE
	loVysledek=lojson.parse(m.json)
ENDIF 

	m.id       	= loVysledek.Order.id
	m.client    = loVysledek.Order.Client
	m.meal  	= loVysledek.Order.Meal
	m.objednano	= loVysledek.Order.ordered
	m.sezrano  	= loVysledek.Order.eaten
	IF !EMPTY(m.id)
	  INSERT INTO myOrder FROM MEMVAR
	ENDIF 
IF TYPE("loJSON") == 'O' AND m.zavrit
  RELEASE loJSON
ENDIF     
RETURN
