FUNCTION zapisinventurustrediska
DO FORM snake NAME lsnakex LINKED WITH jaz('form_zapisujem_inventuru')
LOCAL m.ret
m.ret=.t.
lsnakex.DRAW()
DO CASE 
	CASE m.food_daemon_typ="TCPIP"
		LOCAL m.vysleok
		SET CLASSLIB TO "JSON.VCX" ADDITIVE 
		http = CREATEOBJECT("WinHttp.WinHttpRequest.5.1")
		*!*    http.OPEN("POST","https://"+m.food_daemon_ip+":"+ALLTRIM(STR(m.food_daemon_port,10,0))+"/food_inventura/updateProducts/" , .F.)
		*!*    Http.Option(4) = 13056
		*!*    http.settimeouts(0, 0, 0, 0)
		*!*    http.setrequestheader("content-type", "application/json;charset=utf-8;")
		*!*    Http.SetCredentials(m.food_daemon_meno,m.food_daemon_heslo, 0)
		m.loJSON = CREATEOBJECT("JSON")
		CREATE CURSOR jsontxt (jsontxt M)
		INSERT INTO jsontxt (jsontxt) VALUES ("") 
		lsnakex.DRAW()
		REPLACE jsontxt.jsontxt WITH jsontxt.jsontxt+lojson.stringify("invtablet")
		lsnakex.DRAW()
		REPLACE jsontxt.jsontxt WITH jsontxt.jsontxt+']'+CHR(13)+CHR(10)
		lsnakex.DRAW()
		REPLACE jsontxt.jsontxt WITH STRTRAN(jsontxt.jsontxt,'"VFPData": {"invtablet": ','')
		lsnakex.DRAW()
		REPLACE jsontxt.jsontxt WITH STRTRAN(jsontxt.jsontxt,'}]}]','}]')
		REPLACE jsontxt.jsontxt WITH STRTRAN(jsontxt.jsontxt,'\u009D','ť')


		=STRTOFILE(jsontxt.jsontxt,"m:\41_export.json")
		USE IN jsontxt
		*!*    lsnakex.DRAW()
		*!*    TRY 
		*!*        lsnakex.DRAW()
		*!*        http.SEND(jsontxt.jsontxt)
		*!*        lsnakex.DRAW()
		*!*        m.httpodpoved=http.statustext
		*!*        m.vysledok=http.status
		*!*    CATCH
		*!*        m.vysledok=-100
		*!*        m.httpodpoved=jaz("form_food_daemon_neodpoveda")
		*!*    ENDTRY 
		*!*    USE IN jsontxt
		*!*    IF m.vysledok=200
		*!*        IF !ISNULL(http.responsetext)
		*!*            lsnakex.DRAW()
		*!*            m.vysledok=lojson.parse(http.responsetext)
		*!*            lsnakex.DRAW()
		*!*            TRY 
		*!*                m.ret=vysledok.result
		*!*                m.odpoved="Inventúra odoslaná"
		*!*            CATCH
		*!*                m.ret=100
		*!*                m.odpoved=vysledok.message
		*!*            ENDTRY 
		*!*            RELEASE lojson
		*!*        ELSE
		*!*            m.ret=http.status
		*!*            m.odpoved=http.statustext
		*!*        ENDIF 
		*!*    ELSE
		*!*        m.ret=m.vysledok
		*!*        m.odpoved=http.statustext
		*!*    ENDIF 
		RELEASE m.http
		lsnakex.release()
		RELEASE CLASSLIB json.vcx
	CASE m.food_daemon_typ="CSV"
		LOCAL cesta, pokracuj, m.cesta_zal
		IF USED("invtablet")
			m.cesta = get_ini(m.machine, "InventuraExportPath")
			m.cesta_zal=m.cesta
			IF ! EMPTY(m.cesta)
			    backslash( @m.cesta )
			    DO mk_dir WITH m.cesta
			    IF STRTOFILE(m.cesta, m.cesta + "testrautexportpath.txt") = 0
			        m.cesta = ""
			    ELSE
			        DELETE FILE m.cesta + "testrautexportpath.txt"
			    ENDIF 
			ENDIF
			IF EMPTY(m.cesta)
				m.cesta = GETDIR("..\", jaz("form_adresar_pre_inventuru"), "")
			ELSE
				m.cesta = GETDIR(m.cesta, jaz("form_adresar_pre_inventuru"), "")
			ENDIF 
			IF ! EMPTY(m.cesta)
				IF FILE(m.cesta+"inv"+m.gcpgm_id+".csv")
					IF MESSAGEBOX(jaz("form_inv_export_pokracovat"),4+32+256,"FoodMan")=6
						TRY 
							ERASE (m.cesta+"inv"+m.gcpgm_id+".csv")
							m.pokracuj=.t.
						CATCH 
							m.pokracuj=.f.
						ENDTRY
					ELSE
						m.pokracuj=.f. 
					ENDIF 
				ELSE
					m.pokracuj=.t.
				ENDIF 
				SELECT invtablet
				COPY FIELDS stredisko, c_karty, nazev, druh, mnozstvi, na_sklade, cena TO (m.cesta+"inv"+m.gcpgm_id+".csv") DELIMITED WITH CHARACTER ";"
				=MESSAGEBOX(jaz("form_export_subory_pripravene")+ " ("+m.cesta+"inv"+m.gcpgm_id+".csv)",64,"FoodMan")
				IF LOWER(m.cesta)==LOWER(m.cesta_zal)
				ELSE 
					= put_ini(m.machine, "InventuraExportPath", m.cesta)
				ENDIF 
			ELSE
				=MESSAGEBOX(jaz("form_neybrana_cesta_exportu"),64,"FoodMan")
			ENDIF 
		ELSE 
			=MESSAGEBOX(jazparam("form_subor_neexistuje","invtablet.dbf"),64,"FoodMan")
		ENDIF 
ENDCASE 
RETURN m.ret 
