PROCEDURE prispusteni
PRIVATE vtigerodpoved, naslosa, lic_najom, lic_cyklus, lic_pozast, tw, hd, ico_len, smer, dw, m.dokedy, m.riadok, m.xxx, m.nlic_konec, m.nlic_kod
PRIVATE zoznamstrediskfood, zoznamstredisktiger, typ_licencie, updateztigra, foodiesetup, foodiesetupkratky, licencnykodvtigri, m.pocetmobilovvtigri, foodiesetupfood, foodiesetupfoodkratky
PRIVATE m.typrozdielu, m.odpovedaktualizacie
PRIVATE menocloveka, heslocloveka, usedfoodset
m.typrozdielu=""
m.nlic_konec=""
*** "1"$m.typrozdielu  - rozdiel v pocte mobilov tiger zapisuje do foodu
*** "2"$m.typrozdielu  - rozdiel v pocte mobilov food zapisuje do tigra
*** "3"$m.typrozdielu  - nesuhlasi foodie setup (pocet povolenych spusteni jednotlivych foodie) tiger zapisuje do foodu
*** "4"$m.typrozdielu  - nesuhlasi foodie setup (pocet povolenych spusteni jednotlivych foodie) food zapisuje do tigra
*** "5"$m.typrozdielu  - nesuhlasi food_dat tiger zapisuje do foodu
*** "6"$m.typrozdielu  - nesuhlasi food_dat food zapisuje do tigra
*** "7"$m.typrozdielu  - odpojena stanica
m.pocetmobilovvtigri=0
PRIVATE posielaj
SET DATE TO GERMAN
IF !EMPTY(m.hotel_id)
	DIMENSION poslitigrovi(1,2)
	m.vtigerodpoved=citajvtiger()
	m.posielaj=0
	IF !EMPTY(m.vtigerodpoved)
		IF !EMPTY(m.hotel_ico)
			m.odpovedaktualizacie=citajaktualizacie()
			IF !EMPTY(m.odpovedaktualizacie)
				m.dostupnaverzia=get_vtiger_pole(m.odpovedaktualizacie,'dv')
				lic_adresar=get_vtiger_pole(m.odpovedaktualizacie,'cf_1161')
			ENDIF 
			IF VARTYPE(m.hotline_id)<>"C" OR EMPTY(m.hotline_id)
				IF VARTYPE(m.hotline_id)<>"C"
					PUBLIC hotline_id
					m.hotline_id=""
				ENDIF
				DO get_hotlineid WITH m.vtigerodpoved
			ENDIF
			LOCAL m.lic_najom, m.lic_cyklus, m.lic_pozast, m.lic_platnado, m.lic_veta, m.dokedy, m.nis_licenc, m.nvalid_thru, m.nlic_veta2, m.lic_generovana
			m.nis_licenc=m.is_licenc
			m.nvalid_thru=m.valid_thru
			m.lic_najom=get_vtiger_pole(m.vtigerodpoved,'cf_806')
			IF EMPTY(m.lic_najom)
				m.lic_najom="0"
			ENDIF
			m.lic_cyklus=get_vtiger_pole(m.vtigerodpoved,'cf_798')
			m.lic_pozast=get_vtiger_pole(m.vtigerodpoved,'cf_802')
			m.lic_pokec=STRCONV(get_vtiger_pole(m.vtigerodpoved,'cf_938'),11)
			m.lic_sprava=STRCONV(get_vtiger_pole(m.vtigerodpoved,'cf_1539'),11)
			m.lic_foodie_verzia=STRCONV(get_vtiger_pole(m.vtigerodpoved,'cf_1423'),11)
			m.lic_platnado=get_vtiger_pole(m.vtigerodpoved,'cf_939')
			m.typ_licencie=get_vtiger_pole(m.vtigerodpoved,'cf_1187')
			m.licencnykodvtigri=get_vtiger_pole(m.vtigerodpoved,'cf_1028')
			m.nlic_konec=LEFT(get_vtiger_pole(m.vtigerodpoved,'cf_1029'),7)
			m.nlic_kod=get_vtiger_pole(m.vtigerodpoved,'cf_1026')
			m.pocetmobilovvtigri=VAL(get_vtiger_pole(m.vtigerodpoved,'cf_1307'))
			IF !EMPTY(m.lic_platnado)
				m.dokedy=CTOD(RIGHT(m.lic_platnado,2)+"."+SUBSTR(m.lic_platnado,6,2)+"."+LEFT(m.lic_platnado,4))
			ELSE
				m.dokedy=GOMONTH(DATE(),100)
			ENDIF
			m.lic_veta=get_vtiger_pole(m.vtigerodpoved,'cf_942')
			m.lic_veta2=get_vtiger_pole(m.vtigerodpoved,'cf_943')
			m.nlic_veta2=m.lic_veta2
	**** Zistenie aktualneho datumu licencie ***
			IF m.is_licenc
				m.tw=""
				m.hd=""
				m.ico_len=LEN(m.hotel_ico)
				m.smer=1
				FOR i=1 TO LEN(m.hotel_ico)+8
					IF m.smer=1
						m.tw=m.tw+SUBSTR(m.valid_thru,i,1)
						IF m.ico_len>0
							m.smer=2
						ENDIF
					ELSE
						m.hd=m.hd+SUBSTR(m.valid_thru,i,1)
						m.ico_len=m.ico_len-1
						IF LEN(m.tw)<8
							m.smer=1
						ENDIF
					ENDIF
				ENDFOR
				m.dw=CTOD(RIGHT(m.tw,2)+"."+SUBSTR(m.tw,5,2)+"."+LEFT(m.tw,4))
				IF EMPTY(m.dw)
					m.dw=DATE()-7
				ENDIF
			ELSE
				m.dw=CTOD("")
			ENDIF


			IF m.lic_najom="1"
				IF !m.is_licenc
					m.dw=DATE()-7
				ENDIF
				m.nis_licenc=.t.
				IF m.lic_pozast="1"
					IF m.dw>(DATE()+4)
						m.dw=DATE()+4
					ENDIF
				ELSE
					IF m.dw<=(DATE()+7)
						DO CASE
							CASE ("mes"$m.lic_cyklus) OR EMPTY(m.lic_cyklus)
								m.dw=GOMONTH(m.dw,1)
							CASE ("tvr"$m.lic_cyklus)
								m.dw=GOMONTH(m.dw,3)
							CASE ("polro"$m.lic_cyklus)
								m.dw=GOMONTH(m.dw,6)
							CASE ("ro"$m.lic_cyklus)
								m.dw=GOMONTH(m.dw,12)
							CASE LEFT(m.lic_cyklus,1)="t"
								m.dw=m.dw+7
							CASE ("14"$m.lic_cyklus)
								m.dw=m.dw+14
							CASE ("3"$m.lic_cyklus)
								IF m.dw<=(DATE()+3)
									m.dw=m.dw+3
								ENDIF
							OTHERWISE
						ENDCASE
						IF !EMPTY(m.lic_platnado)
							IF m.dw>m.dokedy
								m.dw=m.dokedy
							ENDIF
						ENDIF 
					ENDIF
				ENDIF
			ELSE
				IF !EMPTY(m.lic_platnado)
					IF m.dw<>m.dokedy
						m.dw=m.dokedy
					ENDIF
					m.nis_licenc=.T.
				ELSE
					m.nis_licenc=.F.
				ENDIF
			ENDIF
			IF m.nis_licenc<>m.is_licenc
				PRIVATE m.hladajmodul, m.hladajvarname, m.hladajsetupskup
				m.hladajmodul=UPPER("food_set")
				m.hladajvarname="is_licenc"
				m.hladajsetupskup=""
				DO open_database
				IF m.issql
					IF USED("food_set")
						=REQUERY("food_set")
						m.usedfoodset=.t.
					ELSE 
						rv('defsuborvarname',"food_set")
						=CURSORSETPROP("Buffering",5,"food_set")
						m.usedfoodset=.f.
					ENDIF 
					SELECT food_set
					IF RECCOUNT("food_set")=0
						INSERT INTO food_set (var_name, var_value) VALUES (m.hladajvarname,IIF(m.nis_licenc,".T.",".F."))
					ELSE
						GO TOP
						REPLACE var_value WITH IIF(m.nis_licenc,".T.",".F.") FOR LOWER(ALLTRIM(var_name))=m.hladajvarname
					ENDIF
					=tux(.t.,.t.,"food_set")
				ELSE
					IF USED("food_set")
						m.usedfoodset=.t.
					ELSE 
						USE (m.gchom_path + "food_set") IN 0 ALIAS food_set
						m.usedfoodset=.f.
					ENDIF 
					SELECT food_set
					LOCATE FOR ALLTRIM(LOWER(var_name))=m.hladajvarname
					IF !FOUND()
						INSERT INTO food_set (var_name, var_value) VALUES (m.hladajvarname,IIF(m.nis_licenc,".T.",".F."))
					ELSE
						REPLACE var_value WITH IIF(m.nis_licenc,".T.",".F.") FOR LOWER(ALLTRIM(var_name))=m.hladajvarname
					ENDIF
				ENDIF
				IF !m.usedfoodset
					DO pozavirej WITH "food_set"
				ENDIF 
				m.is_licenc=m.nis_licenc
			ENDIF
			IF m.is_licenc
				m.nlic_veta2="Licencia:"+PADL(ALLTRIM(STR(DAY(m.dw),2,0)),2,"0")+"."+PADL(ALLTRIM(STR(MONTH(m.dw),2,0)),2,"0")+"."+RIGHT(PADL(ALLTRIM(STR(YEAR(m.dw),4,0)),4,"0"),2)
				m.tw=DTOS(m.dw)
				m.nvalid_thru=""
				FOR i=1 TO MAX(LEN(m.tw),LEN(m.hotel_ico))
					m.nvalid_thru=m.nvalid_thru+IIF(m.i<=LEN(m.tw),SUBSTR(m.tw,i,1),"")+IIF(m.i<=LEN(m.hotel_ico),SUBSTR(m.hotel_ico,i,1),"")
				ENDFOR
				m.nvalid_thru=m.nvalid_thru+SYS(2007,m.nvalid_thru)
				IF m.valid_thru<>m.nvalid_thru
					PRIVATE m.hladajmodul, m.hladajvarname, m.hladajsetupskup
					m.hladajmodul="FOOD_SET"
					m.hladajvarname="valid_thru"
					m.hladajsetupskup=""
					DO open_database
					IF m.issql
						IF USED("food_set")
							=REQUERY("food_set")
							m.usedfoodset=.t.
						ELSE 
							rv('defsuborvarname',"food_set")
							=CURSORSETPROP("Buffering",5,"food_set")
							m.usedfoodset=.f.
						ENDIF 
						SELECT food_set
						IF RECCOUNT("food_set")=0
							INSERT INTO food_set (var_name, var_value) VALUES (m.hladajvarname,'"'+ALLTRIM(m.valid_thru)+'"')
						ELSE
							GO TOP
							REPLACE var_value WITH '"'+ALLTRIM(m.nvalid_thru)+'"' FOR LOWER(ALLTRIM(var_name))=m.hladajvarname
						ENDIF
						=tux(.t.,.t.,"food_set")
					ELSE
						IF USED("food_set")
							m.usedfoodset=.t.
						ELSE 
							USE (m.gchom_path + "food_set") IN 0 ALIAS food_set
							m.usedfoodset=.f.
						ENDIF
						SELECT food_set
						LOCATE FOR ALLTRIM(LOWER(var_name))=m.hladajvarname
						IF !FOUND()
							INSERT INTO food_set (var_name, var_value) VALUES (m.hladajvarname,'"'+ALLTRIM(m.valid_thru)+'"')
						ELSE
							REPLACE var_value WITH '"'+ALLTRIM(m.nvalid_thru)+'"' FOR LOWER(ALLTRIM(var_name))=m.hladajvarname
						ENDIF
					ENDIF
					IF !m.usedfoodset
						DO pozavirej WITH "food_set"
					ENDIF 
					m.valid_thru=m.nvalid_thru
				ENDIF
			ELSE
				m.nlic_veta2="Licencia sa nekontroluje"
			ENDIF
			IF VARTYPE(m.lic_konec)=="C" AND m.nlic_konec<>m.lic_konec
				PRIVATE m.hladajmodul, m.hladajvarname, m.hladajsetupskup
				m.hladajmodul=UPPER("food_set")
				m.hladajvarname="lic_konec"
				m.hladajsetupskup=""
				DO open_database
				IF m.issql
					IF USED("food_set")
						=REQUERY("food_set")
						m.usedfoodset=.t.
					ELSE 
						rv('defsuborvarname',"food_set")
						=CURSORSETPROP("Buffering",5,"food_set")
						m.usedfoodset=.f.
					ENDIF 
					SELECT food_set
					IF RECCOUNT("food_set")=0
						INSERT INTO food_set (var_name, var_value) VALUES (m.hladajvarname,'"'+m.nlic_konec+'"')
					ELSE
						GO TOP
						REPLACE var_value WITH '"'+m.nlic_konec+'"' FOR LOWER(ALLTRIM(var_name))=m.hladajvarname
					ENDIF
					=tux(.t.,.t.,"food_set")
				ELSE
					IF USED("food_set")
						m.usedfoodset=.t.
					ELSE 
						USE (m.gchom_path + "food_set") IN 0 ALIAS food_set
						m.usedfoodset=.f.
					ENDIF 
					SELECT food_set
					LOCATE FOR ALLTRIM(LOWER(var_name))=m.hladajvarname
					IF !FOUND()
						INSERT INTO food_set (var_name, var_value) VALUES (m.hladajvarname,'"'+m.nlic_konec+'"')
					ELSE
						REPLACE var_value WITH '"'+m.nlic_konec+'"' FOR LOWER(ALLTRIM(var_name))=m.hladajvarname
					ENDIF
				ENDIF
				IF !m.usedfoodset
					DO pozavirej WITH "food_set"
				ENDIF 
				m.lic_konec=m.nlic_konec
			ENDIF 
			IF VARTYPE(m.lic_kod)=="C" AND !EMPTY(m.nlic_kod) AND m.nlic_kod<>m.lic_kod
				PRIVATE m.hladajmodul, m.hladajvarname, m.hladajsetupskup
				m.hladajmodul=UPPER("food_set")
				m.hladajvarname="lic_kod"
				m.hladajsetupskup=""
				DO open_database
				IF m.issql
					IF USED("food_set")
						=REQUERY("food_set")
						m.usedfoodset=.t.
					ELSE 
						rv('defsuborvarname',"food_set")
						=CURSORSETPROP("Buffering",5,"food_set")
						m.usedfoodset=.f.
					ENDIF 
					SELECT food_set
					IF RECCOUNT("food_set")=0
						INSERT INTO food_set (var_name, var_value) VALUES (m.hladajvarname,'"'+m.nlic_kod+'"')
					ELSE
						GO TOP
						REPLACE var_value WITH '"'+m.nlic_kod+'"' FOR LOWER(ALLTRIM(var_name))=m.hladajvarname
					ENDIF
					=tux(.t.,.t.,"food_set")
				ELSE
					IF USED("food_set")
						m.usedfoodset=.t.
					ELSE 
						USE (m.gchom_path + "food_set") IN 0 ALIAS food_set
						m.usedfoodset=.f.
					ENDIF 
					SELECT food_set
					LOCATE FOR ALLTRIM(LOWER(var_name))=m.hladajvarname
					IF !FOUND()
						INSERT INTO food_set (var_name, var_value) VALUES (m.hladajvarname,'"'+m.nlic_kod+'"')
					ELSE
						REPLACE var_value WITH '"'+m.nlic_kod+'"' FOR LOWER(ALLTRIM(var_name))=m.hladajvarname
					ENDIF
				ENDIF
				IF !m.usedfoodset
					DO pozavirej WITH "food_set"
				ENDIF 
				m.lic_kod=m.nlic_kod
			ENDIF 
			IF EMPTY(m.typ_licencie)
				m.posielaj=m.posielaj+1
				DIMENSION poslitigrovi(m.posielaj,2)
				poslitigrovi(m.posielaj,1)="cf_1187"
				IF m.gityp_inst<>1
					poslitigrovi(m.posielaj,2)="PRO"
				ELSE
					poslitigrovi(m.posielaj,2)="ONE"
				ENDIF
			ENDIF
			IF m.lic_veta2<>m.nlic_veta2
				m.posielaj=m.posielaj+1
				DIMENSION poslitigrovi(m.posielaj,2)
				poslitigrovi(m.posielaj,1)="cf_943"
				poslitigrovi(m.posielaj,2)=m.nlic_veta2
			ENDIF
			m.updateztigra=get_vtiger_pole(m.vtigerodpoved,'cf_1189')
			IF EMPTY(m.updateztigra) OR m.updateztigra="0"
				m.updateztigra=.f.
			ELSE
				m.updateztigra=.t.
			ENDIF
			IF !USED("setfooddat")
				DO open_database
				IF m.issql
					TRY
						rv("setfooddat2","setfooddat")
					CATCH
						rv("setfooddat","setfooddat")
					ENDTRY
				ELSE
					IF !USED("food_dat")
						USE (m.fn_food_dat) IN o ALIAS food_dat
					ENDIF
					TRY
						USE vsetfooddat2 IN 0 ALIAS setfooddat
					CATCH
						USE vsetfooddat IN 0 ALIAS setfooddat
					ENDTRY
				ENDIF
				SELECT setfooddat
				INDEX on id TAG id
				=CURSORSETPROP("Buffering", 5, "setfooddat")
			ENDIF
			m.zoznamstrediskfood=vytvorfooddatstr("setfooddat")
			DO WHILE INLIST(RIGHT(zoznamstrediskfood,1),CHR(13),CHR(10))
				zoznamstrediskfood=LEFT(zoznamstrediskfood,LENC(zoznamstrediskfood)-1)
			ENDDO 
			m.foodiesetupfood=vytvorfoodiesetup("setfooddat")
			foodiesetupfoodkratky=vytvorkratkysetupfoodie(m.foodiesetupfood)
			m.zoznamstredisktiger=STRCONV(get_vtiger_pole(m.vtigerodpoved,'cf_1031'),11)
			DO WHILE INLIST(RIGHT(m.zoznamstredisktiger,1),CHR(13),CHR(10))
				m.zoznamstredisktiger=LEFT(m.zoznamstredisktiger,LENC(m.zoznamstredisktiger)-1)
			ENDDO 
	*		m.zoznamstredisktiger=STRTRAN(STRTRAN(STRCONV(get_vtiger_pole(m.vtigerodpoved,'cf_1031'),11),CHR(10),CHR(13)+CHR(10)),CHR(13)+CHR(10)+CHR(13)+CHR(10),CHR(13)+CHR(10))
			m.foodiesetup=get_vtiger_pole(m.vtigerodpoved,'cf_1305')
			m.foodiesetupkratky=vytvorkratkysetupfoodie(m.foodiesetup)
			=skontrolujaposlicotreba(.f.)
		ELSE 
			m.vtiger_ico=get_vtiger_pole(m.vtigerodpoved,'cf_616')
			m.vtiger_dico=get_vtiger_pole(m.vtigerodpoved,'cf_617')
			IF m.vtiger_ico==m.hotel_ico AND m.vtiger_dico==m.hotel_dico
				*** licencovana skusobna verzia foodmanu. Netreba nic nikam posielat
			ELSE
				=MESSAGEBOX(jaz("form_nelicencovana_instalacia"),16,"FoodMan",10000)
				DO shut_dn
			ENDIF 
		ENDIF 
	ELSE
*!* Nechapem, naco som to tu mal. Ked je raz odpoved od vtigra prazdna, tak co chcem testovat		
*!*			m.lic_generovana=get_vtiger_pole(m.vtigerodpoved,'cf_1026')
*!*			IF !EMPTY(m.lic_generovana) AND m.lic_generovana<>m.lic_kod
*!*				=otestujlicenciu(m.lic_generovana)
*!*			ENDIF
	ENDIF
ENDIF
RELEASE m.vtigerodpoved
		


FUNCTION skontrolujaposlicotreba
PARAMETERS niecelkomprve,odpojenastanica
PRIVATE m.ret, m.usedfoodset
IF !EMPTY(odpojenastanica)
	m.typrozdielu=m.typrozdielu+"7"
ENDIF 
m.ret=.t.
IF USED("food_set")
	m.usedfoodset=.t.
ELSE
	m.usedfoodset=.f.
ENDIF 
IF m.pocetmobilovvtigri<>m.pocet_foodie_mobile
	IF m.updateztigra
		m.typrozdielu="1"
	ELSE
		m.typrozdielu="2"
		m.posielaj=m.posielaj+1
		DIMENSION poslitigrovi(m.posielaj,2)
		poslitigrovi(m.posielaj,1)="cf_1307"
		poslitigrovi(m.posielaj,2)=ALLTRIM(STR(m.pocet_foodie_mobile,10,0))
	ENDIF
ENDIF
IF !USED("setfooddat")
	DO open_database
	IF m.issql
		TRY
			rv("setfooddat2","setfooddat")
		CATCH
			rv("setfooddat","setfooddat")
		ENDTRY
	ELSE
		IF !USED("food_dat")
			USE (m.fn_food_dat) IN o ALIAS food_dat
		ENDIF
		TRY
			USE vsetfooddat2 IN 0 ALIAS setfooddat
		CATCH
			USE vsetfooddat IN 0 ALIAS setfooddat
		ENDTRY
	ENDIF
	SELECT setfooddat
	INDEX on id TAG id
	=CURSORSETPROP("Buffering", 5, "setfooddat")
ENDIF

IF EMPTY(m.zoznamstredisktiger)
	m.posielaj=m.posielaj+1
	DIMENSION poslitigrovi(m.posielaj,2)
	poslitigrovi(m.posielaj,1)="cf_1031"
	poslitigrovi(m.posielaj,2)=m.zoznamstrediskfood
ELSE
	IF m.zoznamstrediskfood<>m.zoznamstredisktiger OR m.zoznamstredisktiger<>m.zoznamstrediskfood
		IF !m.updateztigra
			m.typrozdielu=m.typrozdielu+"6"
			m.posielaj=m.posielaj+1
			DIMENSION poslitigrovi(m.posielaj,2)
			poslitigrovi(m.posielaj,1)="cf_1031"
			poslitigrovi(m.posielaj,2)=m.zoznamstrediskfood
		ELSE
			m.typrozdielu=m.typrozdielu+"5"
		ENDIF
	ENDIF
ENDIF
IF m.issql
	IF EMPTY(m.foodiesetup)
		IF !EMPTY(m.foodiesetupfood)
			m.posielaj=m.posielaj+1
			DIMENSION poslitigrovi(m.posielaj,2)
			poslitigrovi(m.posielaj,1)="cf_1305"
			poslitigrovi(m.posielaj,2)=m.foodiesetupfood
		ENDIF
	ELSE
		IF m.foodiesetupfoodkratky<>m.foodiesetupkratky OR m.foodiesetupkratky<>m.foodiesetupfoodkratky
			IF !m.updateztigra
				m.typrozdielu=m.typrozdielu+"4"
				m.posielaj=m.posielaj+1
				DIMENSION poslitigrovi(m.posielaj,2)
				poslitigrovi(m.posielaj,1)="cf_1305"
				poslitigrovi(m.posielaj,2)=m.foodiesetupfood
			ELSE
				m.typrozdielu=m.typrozdielu+"3"
			ENDIF
		ENDIF
	ENDIF
ENDIF
IF "1"$m.typrozdielu OR "3"$m.typrozdielu OR "5"$m.typrozdielu
*** Ide o vynutene zmeny z tigra. Spracujem ich a skontrolujem licencie, pripadne poslem mail o ziadostou o licenciu a urobim licenciu na mesiac
	IF "3"$m.typrozdielu OR "5"$m.typrozdielu
		=spracujfooddatztigra(m.zoznamstredisktiger, m.typrozdielu, m.vtigerodpoved, m.foodiesetup)
		SELECT ztigra
		m.maxstav=0
		m.nastavlicenciu=.f.
		SCAN FOR stav<>0
			m.maxstav=MAX(m.maxstav,ztigra.stav)
			DO CASE
				CASE stav=1 OR stav=3
				CASE stav=2
					m.nastavlicenciu=.t.
				CASE stav=4
					m.nastavlicenciu=.t.
			ENDCASE
		ENDSCAN
		=zapiszmenydofooddat()
		IF m.nastavlicenciu
			m.trebalicenciu=stiahnilicenciuztigra(m.vtigerodpoved, .t.)
			IF m.trebalicenciu
				=nastavlicenciunamesiac()
				=poslimaildoalta("Licencia pre hotel: "+ALLTRIM(m.hotel_name)+" ID: "+ALLTRIM(STR(m.hotel_id)),"")
			ENDIF
		ENDIF
		=zapislicenciudotigra(m.typrozdielu)
	ENDIF
	IF "1"$m.typrozdielu
		PRIVATE m.hladajmodul, m.hladajvarname, m.hladajsetupskup
		m.hladajmodul=UPPER("food_set")
		m.hladajvarname="pocet_foodie_mobile"
		m.hladajsetupskup=""
		DO open_database
		IF m.issql
			IF USED("food_set")
				=REQUERY("food_set")
				m.usedfoodset=.t.
			ELSE 
				rv('defsuborvarname',"food_set")
				=CURSORSETPROP("Buffering",5,"food_set")
				m.usedfoodset=.f.
			ENDIF  
			SELECT food_set
			IF RECCOUNT("food_set")=0
				INSERT INTO food_set (var_name, var_value) VALUES (m.hladajvarname,ALLTRIM(STR(m.pocetmobilovvtigri,10,0)))
			ELSE
				GO TOP
				REPLACE var_value WITH ALLTRIM(STR(m.pocetmobilovvtigri,10,0)) FOR LOWER(ALLTRIM(var_name))=m.hladajvarname
			ENDIF
			=tux(.t.,.t.,"food_set")
			
		ELSE
			IF USED("food_set")
				m.usedfoodset=.t.
			ELSE 
				USE (m.gchom_path + "food_set") IN 0 ALIAS food_set
				m.usedfoodset=.f.
			ENDIF 
			SELECT food_set
			LOCATE FOR ALLTRIM(LOWER(var_name))=m.hladajvarname
			IF !FOUND()
				INSERT INTO food_set (var_name, var_value) VALUES (m.hladajvarname,ALLTRIM(STR(m.pocetmobilovvtigri,10,0)))
			ELSE
				REPLACE var_value WITH ALLTRIM(STR(m.pocetmobilovvtigri,10,0)) FOR LOWER(ALLTRIM(var_name))=m.hladajvarname
			ENDIF
		ENDIF
		IF EMPTY(m.niecelkomprve)
			IF !m.usedfoodset
				DO pozavirej WITH "food_set"
			ENDIF 
		ENDIF 
		m.pocet_foodie_mobile=m.pocetmobilovvtigri
	ENDIF
	m.posielaj=m.posielaj+1
	DIMENSION poslitigrovi(m.posielaj,2)
	poslitigrovi(m.posielaj,1)="cf_1189"
	poslitigrovi(m.posielaj,2)="0"
ENDIF
m.ret=.t.
IF m.posielaj>0
	IF !EMPTY(m.typrozdielu)
		
		IF "6"$m.typrozdielu
			=spracujfooddatztigra(m.zoznamstredisktiger, m.typrozdielu, m.vtigerodpoved, m.foodiesetup)
			SELECT ztigra
			m.maxstav=0
			m.nastavlicenciu=.f.
			SCAN FOR stav<>0
				m.maxstav=MAX(m.maxstav,ztigra.stav)
				DO CASE
					CASE stav=1 OR stav=3
					CASE stav=2
						m.nastavlicenciu=.t.
					CASE stav=4
						m.nastavlicenciu=.t.
				ENDCASE
			ENDSCAN
			IF m.maxstav<3
				*** Islo iba o nepodstatne zmeny, mozem ich iba kludne prepisat do tigra
				m.typrozdielu=STRTRAN(m.typrozdielu,"6","")
			ENDIF 
		ENDIF 
		IF "2"$m.typrozdielu OR "4"$m.typrozdielu OR "6"$m.typrozdielu
			m.menocloveka=""
			m.heslocloveka=""
			DO FORM vtiger_user
		ELSE
			m.menocloveka="alto.alto"
			m.heslocloveka="alto"
		ENDIF
	ELSE
		m.menocloveka="alto.alto"
		m.heslocloveka="alto"
	ENDIF
	IF !EMPTY(m.heslocloveka) AND !EMPTY(m.menocloveka)
		=zapislicenciudotigra(m.typrozdielu)
		DO WHILE .t.
			m.vysledokzapisu=update_vtiger(ALLTRIM(STR(m.hotel_id,10,0)), m.menocloveka, m.heslocloveka, @poslitigrovi)
			DO CASE
				CASE  m.vysledokzapisu=0
					EXIT
				CASE m.vysledokzapisu=30
*** neoverene meno, heslo technika
					IF MESSAGEBOX("Chcete ďalší pokus na zadanie mena a hesla?",4+32+256,"FoodMan")=6
						DO FORM vtiger_user
						IF !EMPTY(m.heslocloveka) AND !EMPTY(m.menocloveka)
						ELSE
							EXIT
						ENDIF
					ELSE
						EXIT
					ENDIF
				OTHERWISE
*Nejaka chyba pri komunikacii s CRM
					IF "2"$m.typrozdielu OR "4"$m.typrozdielu OR "6"$m.typrozdielu
						IF MESSAGEBOX("Chcete ďalší pokus o odoslanie dát do CRM?",4+32+256,"FoodMan")<>6
							EXIT
						ENDIF
					ELSE
						EXIT
					ENDIF
			ENDCASE
		ENDDO
		DO CASE
			CASE m.vysledokzapisu=0
**** Zmeny do tigra presli
				IF m.updateztigra
*** Zrusim priznak na update z tigra (ked sa to uz spracovalo)
					DIMENSION poslitigrovi(1,2)
					poslitigrovi(1,1)="cf_1189"
					poslitigrovi(1,2)="0"
					=update_vtiger(ALLTRIM(STR(m.hotel_id,10,0)), m.menocloveka, m.heslocloveka, @poslitigrovi)
				ELSE
					m.lic_generovana=get_vtiger_pole(m.vtigerodpoved,'cf_1026')
					IF !EMPTY(m.lic_generovana) AND m.lic_generovana<>m.lic_kod
						=otestujlicenciu(m.lic_generovana)
					ENDIF
				ENDIF
			OTHERWISE
*** Zmeny do tigra nepresli
				m.ret=.f.
				=vratstavpodlatigra()
		ENDCASE
	ELSE 	
**** Zmeny boli urobene lokalne a do tigra nepresli. musim vratit povodny stav
		m.ret=.f.
		=vratstavpodlatigra()
	ENDIF
ELSE
*!*	**** Zmeny boli urobene lokalne a do tigra nepresli. musim vratit povodny stav
*!*		=vratstavpodlatigra()
ENDIF
m.zoznamstredisktiger=m.zoznamstrediskfood
IF ("1"$m.typrozdielu OR "4"$m.typrozdielu OR "7"$m.typrozdielu) AND m.issql AND m.ret 
	=nastavfoodiechecksumy()
ENDIF 
IF EMPTY(m.niecelkomprve)
	DO pozavirej WITH "setfooddat, food_dat"
	IF !m.usedfoodset
		DO pozavirej WITH "food_set"
	ENDIF 
ENDIF 
DO pozavirej WITH "ztigra" 
RETURN m.ret 


FUNCTION nastavfoodiechecksumy
LOCAL otvorenedevice, otvorenecassec, otvorenyfooddat, m.aa, m.id_zkratka, m.active_devices, m.esteniejefoodie
m.esteniejefoodie=.f.
IF m.issql AND m.pocetfoodiekas>0
	DO open_database
	IF USED("devices")
		m.otvorenedevice=.t.
	ELSE
		m.otvorenedevice=.f.
		TRY 
			USE (m.sqlprefix+"rdevices_all") IN 0 ALIAS devices
			=CURSORSETPROP("Buffering", 5, "devices")
		CATCH
			m.esteniejefoodie=.t.
		ENDTRY 
	ENDIF 

	IF USED("setfooddat")
		m.otvorenyfooddat=.t.
	ELSE 
		m.otvorenyfooddat=.f.
		IF m.issql
			TRY
				rv("setfooddat2","setfooddat")
			CATCH
				rv("setfooddat","setfooddat")
			ENDTRY
		ELSE
			IF !USED("food_dat")
				USE (m.fn_food_dat) IN o ALIAS food_dat
			ENDIF
			TRY
				USE vsetfooddat2 IN 0 ALIAS setfooddat
			CATCH
				USE vsetfooddat IN 0 ALIAS setfooddat
			ENDTRY
		ENDIF
	ENDIF
	IF USED("cassec")
		m.otvorenecassec=.t.
	ELSE 
		m.otvorenecassec=.f.
		IF !m.esteniejefoodie
			USE (m.sqlprefix+"rcashier_secrets") ALIAS cassec IN 0
			=CURSORSETPROP("Buffering",5,"cassec")
		ENDIF 
	ENDIF 
	IF !m.esteniejefoodie
		SELECT cassec
		SCAN ALL 
			aa=cassec.kas_id
			SELECT setfooddat
			LOCATE FOR id=m.aa
			IF FOUND()
				m.id_zkratka=setfooddat.id_zkratka
				SELECT devices
				COUNT TO m.active_devices FOR kas_id=m.aa AND !DELETED()
				SELECT cassec
				REPLACE checksum WITH "sha1$$"+LOWER(hashfoodie(ALLTRIM(cassec.secret)+" + "+ALLTRIM(STR(cassec.id,10,0))+" + "+ALLTRIM(cassec.kas_id)+" + "+ALLTRIM(STR(cassec.terminals,10,0))+" + "+'sWMSDixxtE@!'+" + "+ALLTRIM(STR(m.active_devices,10,0))+" + "+m.id_zkratka+" + "+ALLTRIM(STR(m.pocet_foodie_mobile,10,0))))
				SELECT devices
				SCAN FOR kas_id=m.aa
					REPLACE checksum WITH "sha1$$"+LOWER(hashfoodie(IIF(devices.is_mobile='1','True','False')+" + "+ALLTRIM(STR(devices.id,10,0))+" + "+ALLTRIM(devices.kas_id)+" + "+ALLTRIM(devices.session)+" + "+'bGbW3I@dRM6!'+" + "+TTOC(devices.created_at-3600*devices.hod,3)+" + "+TTOC(devices.last_seen-3600*devices.hod2,3)+" + "+m.id_zkratka))
				ENDSCAN 
			ENDIF 
		ENDSCAN 
		SELECT 0
		USE (m.sqlprefix+'rdanube_conf_mobilne_terminaly') ALIAS defmob
		=CURSORSETPROP("Buffering",5,"defmob")
		DO CASE 
			CASE RECCOUNT()=0
				INSERT INTO defmob (key, value, agent) VALUES ("K32.mobilne_terminaly", ALLTRIM(STR(m.pocet_foodie_mobile,10,0)),0)
			CASE RECCOUNT()>1
				DELETE ALL 
				INSERT INTO defmob (key, value, agent) VALUES ("K32.mobilne_terminaly", ALLTRIM(STR(m.pocet_foodie_mobile,10,0)),0)
			OTHERWISE 
				IF ALLTRIM(value)==ALLTRIM(STR(m.pocet_foodie_mobile,10,0))
				ELSE
					REPLACE value WITH ALLTRIM(STR(m.pocet_foodie_mobile,10,0))
				ENDIF 
		ENDCASE 
		=tux(.t.,.t.,"defmob")
		USE IN defmob
		=tux(.t.,.t.,"devices")
		=tux(.t.,.t.,"cassec")
	ENDIF 
	IF m.otvorenecassec
		=REQUERY("cassec")
		IF USED("foodiekasy")
			UPDATE foodiekasy SET heslo=cassec.secret from cassec WHERE foodiekasy.id=cassec.kas_id
		ENDIF 
	ELSE
		DO pozavirej WITH "cassec"
	ENDIF 
	IF m.otvorenedevice
		=REQUERY("devices")
	ELSE
		DO pozavirej WITH "devices"
	ENDIF 
	IF !m.otvorenyfooddat
		DO pozavirej WITH "food_dat, setfooddat"
	ENDIF 
ENDIF 


FUNCTION spracujfooddatztigra
PARAMETERS prislo, povinne, celaodpoved, fs

PRIVATE m.hladajmodul, m.hladajvarname, m.hladajsetupskup, m.chyba_pri_otevirani, m.otevira_se
LOCAL id, id_zkratka, pgm, pgm_param, dat_path, cen_path, pgm_path, bour_skup, setup_skup, prava_skup, master_kas, id_zkratka
LOCAL typ_inst, plateny, servis, datinst, c_data, m.oprava, m.riadok
LOCAL maxstav, nastavlicenciu, zoznamstrediskfood, sumarstredisk, priority
LOCAL oldexact
m.oldexact=SET("Exact")
SET EXACT ON 
m.pocetriadkov=hladajriadky(m.prislo)

m.hladajmodul="FOOD_SET"
m.hladajvarname="hotel_name"
m.hladajsetupskup=""
chyba_pri_otevirani = .f.
DO open_database
TRY
	IF m.issql
		IF !USED("setfooddat")
			m.otevira_se="rsetfooddat"
			TRY
				rv('setfooddat2',"setfooddat")
			CATCH
				rv('setfooddat',"setfooddat")
			ENDTRY
			SELECT setfooddat
			INDEX on id TAG id
			=CURSORSETPROP("Buffering", 5, "setfooddat")
		ENDIF
		m.otevira_se="rdefsuborvarname"
		IF !USED("food_set")
			rv('defsuborvarname',"food_set")
			=CURSORSETPROP("Buffering",5,"food_set")
		ENDIF
	ELSE
		IF !USED("setfooddat")
			IF !USED("food_dat")
				m.otevira_se=m.fn_food_dat
				USE (m.gchom_path + "food_dat") order id IN 0
			ENDIF
			m.otevira_se="vsetfooddat"
			TRY
				USE vsetfooddat2 ALIAS setfooddat IN 0
			CATCH
				USE vsetfooddat ALIAS setfooddat IN 0
			ENDTRY
			SELECT setfooddat
			INDEX on id TAG id
			=CURSORSETPROP("Buffering", 5, "setfooddat")
		ENDIF
		IF !USED("defsubor")
			m.otevira_se=(m.gchom_path+"food_set")
			USE (m.gchom_path + "food_set") IN 0 ALIAS defsubor SHARED 
		ENDIF
	ENDIF
CATCH
	chyba_pri_otevirani = .T.
ENDTRY
IF chyba_pri_otevirani
	=MESSAGEBOX(jaz("prg_dbf_neprist_skuste_pozdeji")+CHR(13)+m.otevira_se,64,"FoodMan",2000)
	DO zurnal_log WITH "OPERA", jaz( "form nastavenie foodman" ), jaz("nejde_otevrit") + m.otevira_se
	RETURN .F.
ENDIF
SELECT *, 0 as stav, .t. as vymaz, .f. as oprava FROM setfooddat INTO CURSOR ztigra  READWRITE

**** STAV=0 v poriadku
**** STAV=1 nepodstatna zmena - meno strediska, platena, servis, datum, ......
**** STAV=2 z tigra prisiel novy riadok
**** STAV=3 podstatna zmena - typ modulu, plateny, servis, datum, priorita (pocet moznych foodie spusteni)
**** STAV=4 v tigri chyba riadok
IF "5"$m.povinne OR "6"$m.povinne OR "3"$m.povinne OR "4"$m.povinne
	IF m.pocetriadkov>0
		FOR m.i=1 TO m.pocetriadkov
			m.riadok=vratriadok(m.i,m.prislo, m.pocetriadkov)
			IF !EMPTY(m.riadok)
				IF hladajsekciu("meno", m.riadok)>0
					m.id_zkratka=vratsekciu("meno",m.riadok,"C")
				ELSE
					m.id_zkratka=null
				ENDIF
				IF hladajsekciu("id", m.riadok)>0
					m.id=vratsekciu("id",m.riadok,"C")
				ELSE
					m.id=null
				ENDIF
				IF hladajsekciu("c_stredisk", m.riadok)>0
					m.c_stredisk=vratsekciu("c_stredisk",m.riadok,"N")
				ELSE
					m.c_stredisk=null
				ENDIF
				IF hladajsekciu("pgm", m.riadok)>0
					m.pgm=vratsekciu("pgm",m.riadok,"C")
				ELSE
					m.pgm=null
				ENDIF
				IF hladajsekciu("param", m.riadok)>0
					m.pgm_param=vratsekciu("param",m.riadok,"C")
				ELSE
					m.pgm_param=null
				ENDIF
				IF hladajsekciu("p_p", m.riadok)>0
					m.pgm_path=vratsekciu("p_p",m.riadok,"C")
				ELSE
					m.pgm_path=null
				ENDIF
				IF hladajsekciu("d_p", m.riadok)>0
					m.dat_path=vratsekciu("d_p",m.riadok,"C")
				ELSE
					m.dat_path=null
				ENDIF
				IF hladajsekciu("c_p", m.riadok)>0
					m.cen_path=vratsekciu("c_p",m.riadok,"C")
				ELSE
					m.cen_path=null
				ENDIF
				IF hladajsekciu("b_s", m.riadok)>0
					m.bour_skup=vratsekciu("b_s",m.riadok,"C")
				ELSE
					m.bour_skup=null
				ENDIF
				IF hladajsekciu("s_s", m.riadok)>0
					m.setup_skup=vratsekciu("s_s",m.riadok,"C")
				ELSE
					m.setup_skup=m.id
				ENDIF
				IF hladajsekciu("p_s", m.riadok)>0
					m.prava_skup=vratsekciu("p_s",m.riadok,"C")
				ELSE
					m.prava_skup=m.id
				ENDIF
				IF hladajsekciu("id_klapky", m.riadok)>0
					m.id_klapky=vratsekciu("id_klapky",m.riadok,"C")
				ELSE
					m.id_klapky=m.id
				ENDIF
				IF hladajsekciu("master_kas", m.riadok)>0
					m.master_kas=vratsekciu("master_kas",m.riadok,"C")
				ELSE
					m.master_kas=m.id
				ENDIF
				IF hladajsekciu("typ_inst", m.riadok)>0
					m.typ_inst=vratsekciu("typ_inst",m.riadok,"N")
				ELSE
					m.typ_inst=0
				ENDIF
				IF hladajsekciu("plateny", m.riadok)>0
					m.plateny=vratsekciu("plateny",m.riadok,"N")
				ELSE
					m.plateny=null
				ENDIF
				IF hladajsekciu("servis", m.riadok)>0
					m.servis=vratsekciu("servis",m.riadok,"N")
				ELSE
					m.servis=null
				ENDIF
				IF hladajsekciu("datum", m.riadok)>0
					m.datinst=vratsekciu("datum",m.riadok,"C")
					TRY
						m.datinst=CTOD(RIGHT(m.datinst,2)+"."+SUBSTR(m.datinst,5,2)+"."+LEFT(m.datinst,4))
					CATCH
						m.datinst=null
					ENDTRY
				ELSE
					m.datinst=null
				ENDIF
				IF hladajsekciu("c_d", m.riadok)>0
					m.c_data=vratsekciu("c_d",m.riadok,"N")
				ELSE
					m.c_data=null
				ENDIF
				IF !EMPTY(m.id) AND !ISNULL(m.id)
					SELECT ztigra
					LOCATE FOR id=m.id
					IF FOUND()
						REPLACE oprava WITH .t., vymaz WITH .f.
					ELSE
						INSERT INTO ztigra (id) VALUES (m.id)
					ENDIF
					SELECT ztigra
					LOCATE FOR id=m.id
					IF !EMPTY(m.id_zkratka) AND !ISNULL(m.id_zkratka)
						IF ALLTRIM(ztigra.id_zkratka)<>m.id_zkratka
							REPLACE id_zkratka WITH m.id_zkratka, stav WITH 1
						ENDIF
					ENDIF
					IF !EMPTY(m.pgm_param) AND !ISNULL(m.pgm_param)
						IF ALLTRIM(ztigra.pgm_param)<>m.pgm_param
							REPLACE pgm_param WITH m.pgm_param, stav WITH 1
						ENDIF
					ENDIF
					IF !EMPTY(m.dat_path) AND !ISNULL(m.dat_path)
						IF ALLTRIM(ztigra.dat_path)<>m.dat_path
							REPLACE dat_path WITH m.dat_path, stav WITH 1
						ENDIF
					ENDIF
					IF !EMPTY(m.cen_path) AND !ISNULL(m.cen_path)
						IF ALLTRIM(ztigra.cen_path)<>m.cen_path
							REPLACE cen_path WITH m.cen_path, stav WITH 1
						ENDIF
					ENDIF
					IF !EMPTY(m.pgm_path) AND !ISNULL(m.pgm_path)
						IF ALLTRIM(ztigra.pgm_path)<>m.pgm_path
							REPLACE pgm_path WITH m.pgm_path, stav WITH 1
						ENDIF
					ENDIF
					IF !EMPTY(m.bour_skup) AND !ISNULL(m.bour_skup)
						IF ALLTRIM(ztigra.bour_skup)<>m.bour_skup
							REPLACE bour_skup WITH m.bour_skup, stav WITH 1
						ENDIF
					ENDIF
					IF !EMPTY(m.setup_skup) AND !ISNULL(m.setup_skup)
						IF ALLTRIM(ztigra.setup_skup)<>m.setup_skup
							REPLACE setup_skup WITH m.setup_skup, stav WITH 1
						ENDIF
					ENDIF
					IF !EMPTY(m.prava_skup) AND !ISNULL(m.prava_skup)
						IF ALLTRIM(ztigra.prava_skup)<>m.prava_skup
							REPLACE prava_skup WITH m.prava_skup, stav WITH 1
						ENDIF
					ENDIF
					IF !EMPTY(m.id_klapky) AND !ISNULL(m.id_klapky)
						IF ALLTRIM(ztigra.id_klapky)<>m.id_klapky
							REPLACE id_klapky WITH m.id_klapky, stav WITH 1
						ENDIF
					ENDIF
					IF !EMPTY(m.master_kas) AND !ISNULL(m.master_kas)
						IF ALLTRIM(ztigra.master_kas)<>m.master_kas
							REPLACE master_kas WITH m.master_kas, stav WITH 1
						ENDIF
					ENDIF
					IF m.issql
						IF !EMPTY(m.c_data) AND !ISNULL(m.c_data)
							IF ztigra.c_data<>m.c_data
								REPLACE c_data WITH m.c_data, stav WITH 1
							ENDIF
						ENDIF
					ENDIF
					IF !EMPTY(m.pgm) AND !ISNULL(m.pgm)
						IF ALLTRIM(ztigra.pgm)<>m.pgm
							REPLACE pgm WITH m.pgm, stav WITH 3
						ENDIF
					ENDIF
					IF !EMPTY(m.c_stredisk) AND !ISNULL(m.c_stredisk)
						IF ztigra.c_stredisk<>m.c_stredisk
							REPLACE c_stredisk WITH m.c_stredisk, stav WITH 1
						ENDIF
					ENDIF
					IF !ISNULL(m.typ_inst)
						IF ztigra.typ_inst<>m.typ_inst
							REPLACE typ_inst WITH m.typ_inst, stav WITH 3
						ENDIF
					ENDIF
					IF !ISNULL(m.plateny)
						IF FSIZE("plateny","ztigra")>0
							IF ztigra.plateny<>m.plateny
								REPLACE plateny WITH m.plateny, stav WITH 3
							ENDIF
						ENDIF
					ENDIF
					IF !ISNULL(m.servis)
						IF FSIZE("servis","ztigra")>0
							IF ztigra.servis<>m.servis
								REPLACE servis WITH m.servis, stav WITH 3
							ENDIF
						ENDIF
					ENDIF
					IF !EMPTY(m.datinst) AND !ISNULL(m.datinst)
						IF FSIZE("datum","ztigra")>0
							IF ztigra.datum<>m.datinst
								REPLACE datum WITH m.datinst, stav WITH 3
							ENDIF
						ENDIF
					ENDIF
					IF !ztigra.oprava
						REPLACE stav WITH 2
					ENDIF
					IF FSIZE("datum")>0 AND stav>1
						REPLACE datum WITH DATE()
					ENDIF
				ENDIF
			ENDIF
		ENDFOR
	ENDIF
ENDIF
IF "3"$m.povinne OR "4"$m.povinne
	SELECT ztigra
	SCAN FOR pgm="KAS"
		m.priority=vratprioritu(ztigra.id,m.fs)
		IF ztigra.priority<>m.priority
			REPLACE priority WITH m.priority, stav WITH 3
		ENDIF
	ENDSCAN
ENDIF
SELECT ztigra
REPLACE stav WITH 4 FOR vymaz
SET EXACT &oldexact


*!*	IF m.maxstav>0
*!*		IF m.povinne
*!*			SELECT * FROM ztigra WHERE stav<>4 INTO CURSOR ztigra1 READWRITE
*!*			m.zoznamstrediskfood=vytvorfooddatstr("ztigra1")
*!*			DO pozavirej WITH "ztigra1"
*!*			SELECT ztigra
*!*		ELSE
*!*			m.zoznamstrediskfood=vytvorfooddatstr("setfooddat")
*!*		ENDIF
*!*		DIMENSION poslitigrovi(10,2)
*!*		m.posielaj=1
*!*		poslitigrovi(m.posielaj,1)="cf_1031"
*!*		poslitigrovi(m.posielaj,2)=m.zoznamstrediskfood
*!*		IF m.foodiesetupfoodkratky<>m.foodiesetupkratky
*!*			m.posielaj=2
*!*			poslitigrovi(m.posielaj,1)="cf_1305"
*!*			poslitigrovi(m.posielaj,2)=m.m.foodiesetupkratky
*!*		ENDIF
*!*		PRIVATE menocloveka, heslocloveka
*!*		DO CASE
*!*			CASE m.povinne OR m.maxstav=1
*!*				m.menocloveka="alto.alto"
*!*				m.heslocloveka="alto"
*!*				m.posielaj=m.posielaj+1
*!*				poslitigrovi(m.posielaj,1)="cf_1189"
*!*				poslitigrovi(m.posielaj,2)="0"
*!*			CASE m.maxstav>1
*!*				m.menocloveka=""
*!*				m.heslocloveka=""
*!*				DO FORM vtiger_user
*!*		ENDCASE
*!*		m.sumarstredisk=""
*!*		IF !EMPTY(m.heslocloveka) AND !EMPTY(m.menocloveka)
*!*			LOCAL m.trebalicenciu
*!*			m.trebalicenciu=m.nastavlicenciu
*!*			DO WHILE .t.
*!*				m.vysledokzapisu=update_vtiger(ALLTRIM(STR(m.hotel_id,10,0)), m.menocloveka, m.heslocloveka, @poslitigrovi)
*!*				DO CASE
*!*					CASE  m.vysledokzapisu=0
*!*						EXIT
*!*					CASE m.vysledokzapisu=30
*!*						*** neoverene meno, heslo technika
*!*						IF MESSAGEBOX("Chcete ďalší pokus na zadanie mena a hesla?",4+32+256,"FoodMan")=6
*!*							DO FORM vtiger_user
*!*							IF !EMPTY(m.heslocloveka) AND !EMPTY(m.menocloveka)
*!*							ELSE
*!*								EXIT
*!*							ENDIF
*!*						ELSE
*!*							EXIT
*!*						ENDIF
*!*					OTHERWISE
*!*						*Nejaka chyba pri komunikacii s CRM
*!*						IF MESSAGEBOX("Chcete ďalší pokus o odoslanie dát do CRM?",4+32+256,"FoodMan")<>6
*!*							EXIT
*!*						ENDIF
*!*				ENDCASE
*!*			ENDDO
*!*			DO CASE
*!*				CASE m.vysledokzapisu=0
*!*					**** Zmeny do tigra presli
*!*					IF m.povinne
*!*						*** Ide o vynutenu zmenu od tigra. Musim urobit zmenu vo food_date
*!*						=zapiszmenydofooddat()
*!*					ENDIF
*!*					IF m.nastavlicenciu
*!*						DIMENSION poslitigrovi(9,2)
*!*						m.posielaj=0
*!*						=zapislicenciudotigra(m.povinne)
*!*						=update_vtiger(ALLTRIM(STR(m.hotel_id,10,0)), m.menocloveka, m.heslocloveka, @poslitigrovi)
*!*						IF m.povinne
*!*							**** tu otestovat licenciu z tigra - moze uz byt opravena
*!*							m.trebalicenciu=stiahnilicenciuztigra(m.celaodpoved,.t.)
*!*						ENDIF
*!*						IF m.trebalicenciu
*!*							=nastavlicenciunamesiac()
*!*							LOCAL textmailu
*!*							m.textmailu=STRTRAN(m.sumarstredisk,CHR(13)+CHR(10),"<br>")+"<b>Technik:</b>"+m.menocloveka
*!*							=poslimaildoalta("Licencia pre hotel: "+ALLTRIM(m.hotel_name)+" ID: "+ALLTRIM(STR(m.hotel_id)),m.textmailu)
*!*						ENDIF
*!*					ENDIF
*!*				OTHERWISE
*!*					*** Zmeny do tigra nepresli
*!*					IF !povinne
*!*						**** Zmeny boli urobene lokalne a do tigra nepresli. musim vratit povodny stav
*!*						=MESSAGEBOX("Zmeny v zozname stredísk neboli autorizované."+CHR(10)+"Vraciam pôvodný zoznam stredísk.",64,"FoodMan")
*!*						=zapiszmenydofooddat()
*!*						**** Skontrolujem licenciu podla tigra
*!*						m.trebalicenciu=stiahnilicenciuztigra(m.celaodpoved)
*!*						IF m.trebalicenciu
*!*							=nastavlicenciunamesiac()
*!*							LOCAL textmailu
*!*							m.textmailu=STRTRAN(m.sumarstredisk,CHR(13)+CHR(10),"<br>")+"<b>Technik:</b>"+m.menocloveka
*!*							=poslimaildoalta("Licencia pre hotel: "+ALLTRIM(m.hotel_name)+" ID: "+ALLTRIM(STR(m.hotel_id)),m.textmailu)
*!*						ENDIF
*!*					ENDIF
*!*			ENDCASE
*!*		ELSE
*!*			=MESSAGEBOX("Zmeny v zozname stredísk neboli autorizované."+CHR(10)+"Vraciam pôvodný zoznam stredísk.",64,"FoodMan")
*!*			*** Ak nezadali meno a heslo technika, musim vratit obsah food_dat a licenciu podla tigra
*!*			=zapiszmenydofooddat()
*!*			**** Skontrolujem licenciu podla tigra
*!*			m.trebalicenciu=stiahnilicenciuztigra(m.celaodpoved)
*!*			IF m.trebalicenciu
*!*				=nastavlicenciunamesiac()
*!*				LOCAL textmailu
*!*				m.textmailu=STRTRAN(m.sumarstredisk,CHR(13)+CHR(10),"<br>")+"<b>Technik:</b>"+m.menocloveka
*!*				=poslimaildoalta("Licencia pre hotel: "+ALLTRIM(m.hotel_name)+" ID: "+ALLTRIM(STR(m.hotel_id)),m.textmailu)
*!*			ENDIF
*!*		ENDIF
*!*		RELEASE m.menocloveka, m.heslocloveka
*!*	ENDIF
*!*	DO pozavirej WITH "ztigra, setfooddat, food_set, food_dat, defsubor"

FUNCTION hladajriadky
PARAMETERS xmltext
LOCAL m.pocetzaciatkov
m.pocetzaciatkov=OCCURS("meno=",m.xmltext)
IF m.pocetzaciatkov>0
	RETURN m.pocetzaciatkov
ELSE
	RETURN 0
ENDIF


FUNCTION vratprioritu
PARAMETERS cislokasy, xmltext
LOCAL m.p1, m.p2
m.p1=AT("ID:"+m.cislokasy,m.xmltext)
IF m.p1>0
	m.xmltext=SUBSTR(m.xmltext,m.p1+LEN("ID:"+m.cislokasy)+7)
	IF AT(",", m.xmltext)>0
		m.p2=VAL(LEFT(m.xmltext,AT(",", m.xmltext)))
	ELSE
		m.p2=0
	ENDIF
ELSE
	m.p2=0
ENDIF
RETURN m.p2

FUNCTION vratriadok
PARAMETERS cisloriadku, xmltext, celkom
LOCAL m.p1, m.p2
m.p1=AT("meno=",m.xmltext,m.cisloriadku)
m.p2=AT(CHR(13)+CHR(10),m.xmltext, m.cisloriadku)
IF m.p2=0
	m.p2=AT(CHR(10),m.xmltext, m.cisloriadku)
ENDIF
IF m.cisloriadku=m.celkom
	RETURN SUBSTR(m.xmltext,m.p1)
ELSE
	RETURN SUBSTR(m.xmltext,m.p1,m.p2-m.p1)
ENDIF

FUNCTION hladajsekciu
PARAMETERS menosekcie, xmltext
LOCAL m.koniecsekcie, m.zaciatok, m.koniec, retazec
IF RIGHT(m.menosekcie,1)<>"="
	m.menosekcie=m.menosekcie+"="
ENDIF
RETURN ATC(m.menosekcie,m.xmltext)


FUNCTION vratsekciu
PARAMETERS menosekcie, xmltext, typvystupu
LOCAL m.zaciatok, m.koniec, retazec, m.zvysok
IF EMPTY(m.typvystupu)
	m.typ_vystupu="C"
ENDIF
IF RIGHT(m.menosekcie,1)<>"="
	IF m.typvystupu="C"
		m.menosekcie=m.menosekcie+"='"
	ELSE
		m.menosekcie=m.menosekcie+"="
	ENDIF
ENDIF
*** Pozicia uvodneho znaku zaciatku sekcie ***
m.zaciatok=ATC(m.menosekcie,m.xmltext)
m.zvysok=SUBSTR(m.xmltext,m.zaciatok+LEN(m.menosekcie))
*** Pozicia prveho znaku konca sekcie ***
DO CASE
	CASE ATC(";",m.zvysok,1)>0
		IF m.typvystupu="C"
			m.koniec=ATC(";",m.zvysok,1)-2
		ELSE
			m.koniec=ATC(";",m.zvysok,1)-1
		ENDIF
	CASE ATC(CHR(13)+CHR(10),m.zvysok)>0
		IF m.typvystupu="C"
			m.koniec=ATC(CHR(13)+CHR(10),m.zvysok)-2
		ELSE
			m.koniec=ATC(CHR(13)+CHR(10),m.zvysok)-1
		ENDIF
	OTHERWISE
		m.koniec=0
ENDCASE
m.retazec=LEFT(m.zvysok,m.koniec)
DO CASE
	CASE m.typvystupu="C"
*** Vraciam premennu character - nic nemenim - len od
	CASE m.typvystupu="N"
*** Vraciam cislo. Najprv prehodim bodku na znak ako je lokalne nastaveny, potom pustim VAL
		m.retazec=VAL(STRTRAN(m.retazec,".",SET("point")))
	CASE m.typvystupu="D"
*** Konverzia na datum
		DO CASE
			CASE AT("-",m.retazec,1)=5 AND AT("-",m.retazec,2)=8
				m.retazec=RIGHT(m.retazec,2)+"."+SUBSTR(m.retazec,6,2)+"."+LEFT(m.retazec,4)
		ENDCASE
		TRY
			m.retazec=CTOD(m.retazec)
		CATCH
			m.retazec=DATE()
		ENDTRY
	OTHERWISE
ENDCASE
RETURN m.retazec



FUNCTION zapislicenciudotigra
PARAMETERS nasilu
LOCAL m.sumarstredisk, o_pocet
IF "5"$m.nasilu OR "6"$m.nasilu
	IF "5"$m.nasilu
		SELECT LEFT(pgm,1) AS pgm, CNT(pgm) AS pocet GROUP BY 1 ORDER BY 2 FROM ztigra INTO CURSOR qwe WHERE stav<>4
	ELSE
		SELECT LEFT(pgm,1) AS pgm, CNT(pgm) AS pocet GROUP BY 1 ORDER BY 2 FROM setfooddat INTO CURSOR qwe
	ENDIF
	o_pocet = 1
	m.strediska_sum=""
	SCAN
		IF qwe.pocet # o_pocet
			strediska_sum = strediska_sum + TRANS(qwe.pocet)
			o_pocet = qwe.pocet
		ENDIF
		strediska_sum = strediska_sum + qwe.pgm
	ENDSCAN
	USE IN qwe

	m.sumarstredisk="Meno:"+ALLTRIM(m.hotel_name)+CHR(13)+CHR(10)
	m.sumarstredisk=m.sumarstredisk+"ICO:"+ALLTRIM(m.hotel_ico)+CHR(13)+CHR(10)
	m.sumarstredisk=m.sumarstredisk+"DIC:"+ALLTRIM(m.hotel_dico)+CHR(13)+CHR(10)
	m.sumarstredisk=m.sumarstredisk+"Strediska:"+ALLTRIM(m.strediska_sum)+CHR(13)+CHR(10)
	m.sumarstredisk=m.sumarstredisk+"ONE:"+IIF(m.gityp_inst=1,"TRUE","FALSE")+CHR(13)+CHR(10)
	IF m.sumarstredisk<>get_vtiger_pole(m.vtigerodpoved,'cf_1028')
		m.posielaj=m.posielaj+1
		DIMENSION poslitigrovi(m.posielaj,2)
		poslitigrovi(m.posielaj,1)="cf_1028"
		poslitigrovi(m.posielaj,2)=m.sumarstredisk
	ENDIF
	IF "6"$m.nasilu
		SELECT setfooddat
	ELSE
		SELECT ztigra
	ENDIF
	COUNT TO m.o_pocet FOR pgm="MAN" AND pgm_param="SKL"
	IF ALLTRIM(STR(m.o_pocet,10,0))<>get_vtiger_pole(m.vtigerodpoved,'cf_628')
		m.posielaj=m.posielaj+1
		DIMENSION poslitigrovi(m.posielaj,2)
		poslitigrovi(m.posielaj,1)="cf_628"
		poslitigrovi(m.posielaj,2)=ALLTRIM(STR(m.o_pocet,10,0))
	ENDIF
	COUNT TO m.o_pocet FOR pgm="MAN" AND pgm_param<>"SKL"
	IF ALLTRIM(STR(m.o_pocet,10,0))<>get_vtiger_pole(m.vtigerodpoved,'cf_629')
		m.posielaj=m.posielaj+1
		DIMENSION poslitigrovi(m.posielaj,2)
		poslitigrovi(m.posielaj,1)="cf_629"
		poslitigrovi(m.posielaj,2)=ALLTRIM(STR(m.o_pocet,10,0))
	ENDIF
	COUNT TO m.o_pocet FOR INLIST(pgm, "K32", "KAS") AND pgm_param<>"ORDDON" AND IIF(!EMPTY(m.lim_idkas),id<>m.lim_idkas,.t.)
	IF ALLTRIM(STR(m.o_pocet,10,0))<>get_vtiger_pole(m.vtigerodpoved,'cf_630')
		m.posielaj=m.posielaj+1
		DIMENSION poslitigrovi(m.posielaj,2)
		poslitigrovi(m.posielaj,1)="cf_630"
		poslitigrovi(m.posielaj,2)=ALLTRIM(STR(m.o_pocet,10,0))
	ENDIF
	COUNT TO m.o_pocet FOR pgm="K32" AND pgm_param="ORDDON" AND IIF(!EMPTY(m.lim_idkas),id<>m.lim_idkas,.t.)
	IF ALLTRIM(STR(m.o_pocet,10,0))<>get_vtiger_pole(m.vtigerodpoved,'cf_637')
		m.posielaj=m.posielaj+1
		DIMENSION poslitigrovi(m.posielaj,2)
		poslitigrovi(m.posielaj,1)="cf_637"
		poslitigrovi(m.posielaj,2)=ALLTRIM(STR(m.o_pocet,10,0))
	ENDIF
	COUNT TO m.o_pocet FOR INLIST(pgm, "KRE", "LOY")
	IF ALLTRIM(STR(m.o_pocet,10,0))<>get_vtiger_pole(m.vtigerodpoved,'cf_631')
		m.posielaj=m.posielaj+1
		DIMENSION poslitigrovi(m.posielaj,2)
		poslitigrovi(m.posielaj,1)="cf_631"
		poslitigrovi(m.posielaj,2)=ALLTRIM(STR(m.o_pocet,10,0))
	ENDIF
	COUNT TO m.o_pocet FOR pgm="UCTO"
	IF ALLTRIM(STR(m.o_pocet,10,0))<>get_vtiger_pole(m.vtigerodpoved,'cf_638')
		m.posielaj=m.posielaj+1
		DIMENSION poslitigrovi(m.posielaj,2)
		poslitigrovi(m.posielaj,1)="cf_638"
		poslitigrovi(m.posielaj,2)=ALLTRIM(STR(m.o_pocet,10,0))
	ENDIF
	COUNT TO m.o_pocet FOR pgm="EURO"
	IF ALLTRIM(STR(m.o_pocet,10,0))<>get_vtiger_pole(m.vtigerodpoved,'cf_641')
		m.posielaj=m.posielaj+1
		DIMENSION poslitigrovi(m.posielaj,2)
		poslitigrovi(m.posielaj,1)="cf_641"
		poslitigrovi(m.posielaj,2)=ALLTRIM(STR(m.o_pocet,10,0))
	ENDIF
	IF "Export do účtovníctva "+IIF(EMPTY(m.gcuct_typ),"nenastaveny",m.gcuct_typ)<>get_vtiger_pole(m.vtigerodpoved,'cf_633')
		m.posielaj=m.posielaj+1
		DIMENSION poslitigrovi(m.posielaj,2)
		poslitigrovi(m.posielaj,1)="cf_633"
		poslitigrovi(m.posielaj,2)="Export do účtovníctva "+IIF(EMPTY(m.gcuct_typ),"nenastaveny",m.gcuct_typ)
	ENDIF
ENDIF
IF "3"$m.nasilu OR "4"$m.nasilu
	IF "3"$m.nasilu
		IF m.foodiesetup<>get_vtiger_pole(m.vtigerodpoved,'cf_1305')
			m.posielaj=m.posielaj+1
			DIMENSION poslitigrovi(m.posielaj,2)
			poslitigrovi(m.posielaj,1)="cf_1305"
			poslitigrovi(m.posielaj,2)=m.foodiesetup
		ENDIF
	ELSE
		IF m.foodiesetupfood<>get_vtiger_pole(m.vtigerodpoved,'cf_1305')
			m.posielaj=m.posielaj+1
			DIMENSION poslitigrovi(m.posielaj,2)
			poslitigrovi(m.posielaj,1)="cf_1305"
			poslitigrovi(m.posielaj,2)=m.foodiesetupfood
		ENDIF
	ENDIF
ENDIF


FUNCTION zapiszmenydofooddat
PRIVATE m.id
LOCAL oldexact
m.oldexact=SET("Exact")
SET EXACT ON 
IF !USED("ztigra")
	=spracujfooddatztigra(m.zoznamstredisktiger, m.typrozdielu, m.vtigerodpoved, m.foodiesetup)
ENDIF 
SELECT ztigra
SCAN FOR stav<>0
	m.id=ztigra.id
	DO CASE
		CASE stav=1 OR stav=3
			SELECT setfooddat
			LOCATE FOR id=m.id
			IF ALLTRIM(ztigra.id_zkratka)<>ALLTRIM(setfooddat.id_zkratka)
				REPLACE id_zkratka WITH ztigra.id_zkratka
			ENDIF
			IF ALLTRIM(ztigra.pgm_param)<>ALLTRIM(setfooddat.pgm_param)
				REPLACE pgm_param WITH ztigra.pgm_param
			ENDIF
			IF ALLTRIM(ztigra.dat_path)<>ALLTRIM(setfooddat.dat_path)
				REPLACE dat_path WITH ztigra.dat_path
			ENDIF
			IF ALLTRIM(ztigra.cen_path)<>ALLTRIM(setfooddat.cen_path)
				REPLACE cen_path WITH ztigra.cen_path
			ENDIF
			IF ALLTRIM(ztigra.pgm_path)<>ALLTRIM(setfooddat.pgm_path)
				REPLACE pgm_path WITH ztigra.pgm_path
			ENDIF
			IF ALLTRIM(ztigra.bour_skup)<>ALLTRIM(setfooddat.bour_skup)
				REPLACE bour_skup WITH ztigra.bour_skup
			ENDIF
			IF ALLTRIM(ztigra.setup_skup)<>ALLTRIM(setfooddat.setup_skup)
				REPLACE setup_skup WITH ztigra.setup_skup
			ENDIF
			IF ALLTRIM(ztigra.prava_skup)<>ALLTRIM(setfooddat.prava_skup)
				REPLACE prava_skup WITH ztigra.prava_skup
			ENDIF
			IF ALLTRIM(ztigra.id_klapky)<>ALLTRIM(setfooddat.id_klapky)
				REPLACE id_klapky WITH ztigra.id_klapky
			ENDIF
			IF ALLTRIM(ztigra.master_kas)<>ALLTRIM(setfooddat.master_kas)
				REPLACE master_kas WITH ztigra.master_kas
			ENDIF
			IF ztigra.priority<>setfooddat.priority
				REPLACE priority WITH ztigra.priority
			ENDIF

			IF m.issql
				IF ztigra.c_data<>setfooddat.c_data
					REPLACE c_data WITH ztigra.c_data
				ENDIF
			ENDIF
			IF ALLTRIM(ztigra.pgm)<>ALLTRIM(setfooddat.pgm)
				REPLACE pgm WITH ztigra.pgm
			ENDIF
			IF ztigra.typ_inst<>setfooddat.typ_inst
				REPLACE typ_inst WITH ztigra.typ_inst
			ENDIF
			IF ztigra.c_stredisk<>setfooddat.c_stredisk
				REPLACE c_stredisk WITH ztigra.c_stredisk
			ENDIF
			IF FSIZE("plateny")>0
				IF ztigra.plateny<>setfooddat.plateny
					REPLACE plateny WITH ztigra.plateny
				ENDIF
			ENDIF
			IF FSIZE("servis")>0
				IF ztigra.servis<>setfooddat.servis
					REPLACE servis WITH ztigra.servis
				ENDIF
			ENDIF
			IF FSIZE("datum")>0
				IF ztigra.datum<>setfooddat.datum
					REPLACE datum WITH ztigra.datum
				ENDIF
			ENDIF
		CASE stav=2
			INSERT INTO setfooddat (id, pgm, pgm_param, c_stredisk, dat_path, cen_path, pgm_path, bour_skup, setup_skup, prava_skup, id_klapky, master_kas, typ_inst, id_zkratka) SELECT id, pgm, pgm_param, c_stredisk, dat_path, cen_path, pgm_path, bour_skup, setup_skup, prava_skup, id_klapky, master_kas, typ_inst, id_zkratka FROM ztigra WHERE id=m.id
			IF m.issql
				UPDATE setfooddat SET c_data=ztigra.c_data from ztigra WHERE setfooddat.id=ztigra.id
				UPDATE setfooddat SET priority=ztigra.priority from ztigra WHERE setfooddat.id=ztigra.id
			ENDIF
			IF FSIZE("datum","ztigra")>0
				UPDATE setfooddat SET datum=ztigra.datum from ztigra WHERE setfooddat.id=ztigra.id
			ENDIF
			IF FSIZE("servis","ztigra")>0
				UPDATE setfooddat SET servis=ztigra.servis from ztigra WHERE setfooddat.id=ztigra.id
			ENDIF
			IF FSIZE("plateny","ztigra")>0
				UPDATE setfooddat SET plateny=ztigra.plateny from ztigra WHERE setfooddat.id=ztigra.id
			ENDIF
		CASE stav=4
			DELETE FROM setfooddat WHERE id=m.id
	ENDCASE
ENDSCAN
=tux(.t.,.t.,"setfooddat")
=REQUERY("setfooddat")
SELECT LEFT(pgm,1) AS pgm, CNT(pgm) AS pocet GROUP BY 1 ORDER BY 2 FROM setfooddat INTO CURSOR qwe
LOCAL o_pocet
o_pocet = 1
m.strediska_sum=""
SCAN
	IF qwe.pocet # o_pocet
		strediska_sum = strediska_sum + TRANS(qwe.pocet)
		o_pocet = qwe.pocet
	ENDIF
	strediska_sum = strediska_sum + qwe.pgm
ENDSCAN
USE IN qwe
SET EXACT &oldexact


FUNCTION stiahnilicenciuztigra
PARAMETERS m.aktstav, lokalnestrediska
LOCAL m.ret, m.xx, m.aa, m.meno, m.riadok
PRIVATE m.hladajvarname, m.hladajsetupskup, m.hladajmodul
m.ret=.t.
m.xx=get_vtiger_pole(m.aktstav,'cf_1026')
m.aa=get_vtiger_pole(m.aktstav,'cf_1028')
IF !EMPTY(m.aa) AND !EMPTY(m.xx)
	CREATE cursor importovane (riadok c(200))
	DO WHILE LEN(m.aa)>0
		m.xxx=AT(CHR(10),m.aa)
		IF m.xxx>0
			m.riadok=LEFT(m.aa,m.xxx)
			m.aa=SUBSTR(m.aa,m.xxx+1)
			INSERT INTO importovane(riadok) VALUES (m.riadok)
		ELSE
			INSERT INTO importovane(riadok) VALUES (m.aa)
			m.aa=""
		ENDIF
	ENDDO
	REPLACE ALL riadok WITH STRTRAN(riadok,CHR(13),"")
	REPLACE ALL riadok WITH STRTRAN(riadok,CHR(10),"")
	LOCATE FOR LEFT(importovane.riadok,5)="Meno:"
	IF FOUND()
		m.meno=STRCONV(ALLTRIM(SUBSTR(importovane.riadok,6)),11)
		IF ALLTRIM(m.hotel_name)=m.meno
			LOCATE FOR LEFT(importovane.riadok,4)="ICO:"
			IF FOUND()
				m.meno=ALLTRIM(SUBSTR(importovane.riadok,5))
				IF ALLTRIM(m.hotel_ico)=m.meno
					LOCATE FOR LEFT(importovane.riadok,4)="DIC:"
					IF FOUND()
						m.meno=ALLTRIM(SUBSTR(importovane.riadok,5))
						IF ALLTRIM(m.hotel_dico)=m.meno
							LOCATE FOR LEFT(importovane.riadok,10)="Strediska:"
							IF FOUND()
								IF m.lokalnestrediska
									m.meno=m.strediska_sum
								ELSE
									m.meno=ALLTRIM(SUBSTR(importovane.riadok,11))
								ENDIF
								SET PROCEDURE TO s_o_lic ADDITIVE
								IF s_skusvthr(ALLTRIM(m.hotel_ico), ALLTRIM(m.hotel_dico), ALLTRIM(m.hotel_name), ALLTRIM(m.meno), m.xx)
									m.ret=.f.
									IF m.meno<>m.lic_id OR m.xx<>m.lic_kod
										m.lic_id=m.meno
										m.lic_kod=m.xx
										IF m.issql
											PRIVATE m.hladajmodul, m.hladajvarname, m.hladajsetupskup
											m.hladajmodul="FOOD_SET"
											m.hladajsetupskup=""
											m.hladajvarname="lic_id"
											=REQUERY("food_set")
											IF ALLTRIM(m.meno)==EVALUATE(food_set.var_value)
											ELSE
												SELECT food_set
												REPLACE var_value WITH "'"+ALLTRIM(m.meno)+"'"
												=tux(.t.,.t.,"food_set")
											ENDIF
											m.hladajvarname="lic_kod"
											=REQUERY("food_set")
											IF ALLTRIM(m.xx)==EVALUATE(food_set.var_value)
											ELSE
												SELECT food_set
												REPLACE var_value WITH "'"+ALLTRIM(m.xx)+"'"
												=tux(.t.,.t.,"food_set")
											ENDIF
											m.hladajvarname="typ_instalacie"
											=REQUERY("food_set")
											IF ALLTRIM(m.typ_instalacie)==EVALUATE(food_set.var_value)
											ELSE
												SELECT food_set
												REPLACE var_value WITH "'"+ALLTRIM(m.typ_instalacie)+"'"
												=tux(.t.,.t.,"food_set")
											ENDIF
										ELSE
											SELECT defsubor
											REPLACE var_value WITH "'"+ALLTRIM(m.meno)+"'" FOR ALLTRIM(var_name)=="lic_id"
											REPLACE var_value WITH "'"+ALLTRIM(m.xx)+"'" FOR ALLTRIM(var_name)=="lic_kod"
											REPLACE var_value WITH "'"+ALLTRIM(m.typ_instalacie)+"'" FOR ALLTRIM(var_name)=="typ_instalacie"
										ENDIF
									ENDIF
								ENDIF
								RELEASE PROCEDURE s_o_lic
							ENDIF
						ENDIF
					ENDIF
				ENDIF
			ENDIF
		ENDIF
	ENDIF
	USE IN importovane
ELSE
*	=nastavlicenciunamesiac()
*	=MESSAGEBOX("V CRM nie je pripravená licencia",64,"Licencia")
ENDIF
RETURN m.ret

FUNCTION nastavlicenciunamesiac
LOCAL vvv, vvv_new, m.typ_inst, m.hrn, m.vt, m.le_new, m.l3_new
PRIVATE m.hladajvarname, m.hladajsetupskup, m.hladajmodul, m.retez
retez      = "ABCD" + "EFGH" + "IJKL" + "MNOP"
SELECT LEFT(pgm,1) AS pgm, CNT(pgm) AS pocet GROUP BY 1 ORDER BY 2 FROM setfooddat INTO CURSOR qwe
o_pocet = 1
m.strediska_sum=""
SCAN
	IF qwe.pocet # o_pocet
		strediska_sum = strediska_sum + TRANS(qwe.pocet)
		o_pocet = qwe.pocet
	ENDIF
	strediska_sum = strediska_sum + qwe.pgm
ENDSCAN
USE IN qwe
IF m.gityp_inst=1
	typ_inst="*"+"o"+"n"+"e"+"*"
ELSE
	typ_inst=""
ENDIF
SET PROCEDURE TO s_o_lic ADDITIVE
vvv = "hotel_"
vvv_new = LOWER(EVALUATE(vvv + "name") + m.typ_inst + EVALUATE(vvv + "ico") + EVALUATE(vvv + "dico") + m.strediska_sum)
hrn = DATE() + 35
vt = vvv_new + TRANS(YEAR(m.hrn), "9999") + "-" + TRANSFORM(MONTH(m.hrn), "@L 99")
l2_new = LEFT( chrtohex(s_h_a_1(m.vt)),15)
l2_new = LEFT(m.l2_new, 5) + "-" + SUBSTR(m.l2_new, 6, 5) + "-" + SUBSTR(m.l2_new, 11, 5)
IF m.issql
	vvv_new = LOWER(EVALUATE(vvv + "name") + m.typ_inst + EVALUATE(vvv + "ico") + EVALUATE(vvv + "dico") + m.strediska_sum)
ELSE
	vvv_new = LOWER(EVALUATE(vvv + "name") + m.typ_inst + EVALUATE(vvv + "ico") + EVALUATE(vvv + "dico") + STRTRAN(JUSTPATH(gchom_path), JUSTDRIVE(gchom_path), "") + m.strediska_sum)
ENDIF
vt = vvv_new + TRANS(YEAR(m.hrn), "9999") + "-" + TRANSFORM(MONTH(m.hrn), "@L 99")
l3_new = LEFT( chrtohex(s_h_a_1(m.vt)),15)
RELEASE PROCEDURE s_o_lic
IF m.issql
	m.hladajmodul=UPPER("f"+"oo"+"d_")
	m.hladajmodul=m.hladajmodul+"SET"
	m.hladajsetupskup=""
	m.hladajvarname="lic" + "_kod"
	=REQUERY("food_set")
	SELECT food_set
	LOCATE FOR ALLTRIM(LOWER(var_name))=m.hladajvarname
	IF FOUND()
		REPLACE var_value WITH "'"+ALLTRIM(m.l2_new)+"'"
	ELSE
		INSERT INTO food_set (var_name, var_value) VALUES (m.hladajvarname,m.l2_new)
	ENDIF
	=tux(.t.,.t.,"food_set")
	m.hladajvarname="lic" + "_id"
	=REQUERY("food_set")
	SELECT food_set
	LOCATE FOR ALLTRIM(LOWER(var_name))=m.hladajvarname
	IF FOUND()
		REPLACE var_value WITH "'"+m.strediska_sum+"'"
	ELSE
		INSERT INTO food_set (var_name, var_value) VALUES (m.hladajvarname,m.strediska_sum)
	ENDIF
	=tux(.t.,.t.,"food_set")
	m.hladajvarname="lic" + "ence"
	=REQUERY("food_set")
	SELECT food_set
	LOCATE FOR ALLTRIM(LOWER(var_name))=m.hladajvarname
	IF FOUND()
		REPLACE var_value WITH "'"+l3_new+"'"
	ELSE
		INSERT INTO food_set (var_name, var_value) VALUES (m.hladajvarname,m.l3_new)
	ENDIF
	=tux(.t.,.t.,"food_set")

ELSE
	SELECT defsubor
	LOCATE FOR ALLTRIM(LOWER(var_name))="lic_kod"
	IF FOUND()
		REPLACE var_value WITH "'"+ALLTRIM(m.l2_new)+"'"
	ELSE
		INSERT INTO defsubor (var_name, var_value) VALUES ("lic_kod",m.l2_new)
	ENDIF
	LOCATE FOR ALLTRIM(LOWER(var_name))="lic_id"
	IF FOUND()
		REPLACE var_value WITH "'"+ALLTRIM(m.strediska_sum)+"'"
	ELSE
		INSERT INTO defsubor (var_name, var_value) VALUES ("lic_id",m.strediska_sum)
	ENDIF
	LOCATE FOR ALLTRIM(LOWER(var_name))="licence"
	IF FOUND()
		REPLACE var_value WITH "'"+ALLTRIM(m.l3_new)+"'"
	ELSE
		INSERT INTO defsubor (var_name, var_value) VALUES ("licence",m.l3_new)
	ENDIF
ENDIF
m.lic_kod=m.l2_new
m.licence=m.l3_new
m.lic_id=m.strediska_sum
DIMENSION poslitigrovi(2,2)
poslitigrovi(1,1)="cf_1026"
poslitigrovi(1,2)=m.l2_new
poslitigrovi(2,1)="cf_1029"
poslitigrovi(2,2)=TRANS(YEAR(m.hrn), "9999") + "-" + TRANSFORM(MONTH(m.hrn), "@L 99")+"-01"
=update_vtiger(ALLTRIM(STR(m.hotel_id,10,0)), "alto.alto", "alto", @poslitigrovi)

RETURN .t.


FUNCTION otestujlicenciu
PARAMETERS prislo
PRIVATE m.hladajvarname, m.hladajsetupskup, m.hladajmodul, m.retez, m.typ_inst
retez      = "ABCD" + "EFGH" + "IJKL" + "MNOP"
IF m.gityp_inst=1
	typ_inst="*"+"o"+"n"+"e"+"*"
ELSE
	typ_inst=""
ENDIF
SET PROCEDURE TO s_o_lic ADDITIVE
IF s_skusvthr(ALLTRIM(m.hotel_ico), ALLTRIM(m.hotel_dico), ALLTRIM(m.hotel_name), ALLTRIM(m.strediska_sum), m.prislo)
	m.lic_kod=m.prislo
	m.lic_id=m.strediska_sum
	IF m.issql
		m.hladajmodul=UPPER("f"+"oo"+"d_")
		m.hladajmodul=m.hladajmodul+"SET"
		m.hladajsetupskup=""
		m.hladajvarname="lic" + "_kod"
		IF !USED("food_set")
			rv('defsuborvarname',"food_set")
			=CURSORSETPROP("Buffering",5,"food_set")
		ELSE
			=REQUERY("food_set")
		ENDIF
		SELECT food_set
		LOCATE FOR ALLTRIM(LOWER(var_name))=m.hladajvarname
		IF FOUND()
			REPLACE var_value WITH "'"+ALLTRIM(m.lic_kod)+"'"
		ELSE
			INSERT INTO food_set (var_name, var_value) VALUES (m.hladajvarname,m.lic_kod)
		ENDIF
		=tux(.t.,.t.,"food_set")
		m.hladajvarname="lic" + "_id"
		=REQUERY("food_set")
		SELECT food_set
		LOCATE FOR ALLTRIM(LOWER(var_name))=m.hladajvarname
		IF FOUND()
			REPLACE var_value WITH "'"+m.strediska_sum+"'"
		ELSE
			INSERT INTO food_set (var_name, var_value) VALUES (m.hladajvarname,m.strediska_sum)
		ENDIF
		=tux(.t.,.t.,"food_set")
	ELSE
		IF !USED("defsubor")
			m.otevira_se=(m.gchom_path+"food_set")
			USE (m.gchom_path + "food_set") IN 0 ALIAS defsubor
		ENDIF
		SELECT defsubor
		LOCATE FOR ALLTRIM(LOWER(var_name))="lic_kod"
		IF FOUND()
			REPLACE var_value WITH "'"+ALLTRIM(m.lic_kod)+"'"
		ELSE
			INSERT INTO defsubor (var_name, var_value) VALUES ("lic_kod",m.lic_kod)
		ENDIF
		LOCATE FOR ALLTRIM(LOWER(var_name))="lic_id"
		IF FOUND()
			REPLACE var_value WITH "'"+ALLTRIM(m.strediska_sum)+"'"
		ELSE
			INSERT INTO defsubor (var_name, var_value) VALUES ("lic_id",m.strediska_sum)
		ENDIF
	ENDIF
ENDIF
RELEASE PROCEDURE s_o_lic
RETURN .t.




FUNCTION vratstavpodlatigra
PRIVATE usedfoodset
IF "2"$m.typrozdielu OR "4"$m.typrozdielu  OR "6"$m.typrozdielu
**** Zmeny boli urobene lokalne a do tigra nepresli. musim vratit povodny stav
	=MESSAGEBOX("Zmeny v zozname stredísk neboli autorizované."+CHR(10)+"Vraciam pôvodný zoznam stredísk.",64,"FoodMan")
	IF "4"$m.typrozdielu OR "6"$m.typrozdielu
		=zapiszmenydofooddat()
	ENDIF
	IF "2"$m.typrozdielu
		PRIVATE m.hladajmodul, m.hladajvarname, m.hladajsetupskup
		m.hladajmodul=UPPER("food_set")
		m.hladajvarname="pocet_foodie_mobile"
		m.hladajsetupskup=""
		DO open_database
		IF m.issql
			IF USED("food_set")
				=REQUERY("food_set")
				m.usedfoodset=.t.
			ELSE 
				rv('defsuborvarname',"food_set")
				=CURSORSETPROP("Buffering",5,"food_set")
				m.usedfoodset=.f.
			ENDIF 
			SELECT food_set
			IF RECCOUNT("food_set")=0
				INSERT INTO food_set (var_name, var_value) VALUES (m.hladajvarname,ALLTRIM(STR(m.pocetmobilovvtigri,10,0)))
			ELSE
				GO TOP
				REPLACE var_value WITH ALLTRIM(STR(m.pocetmobilovvtigri,10,0)) FOR LOWER(ALLTRIM(var_name))=m.hladajvarname
			ENDIF
			=tux(.t.,.t.,"food_set")
		ELSE
			IF USED("food_set")
				m.usedfoodset=.t.
			ELSE 
				USE (m.gchom_path + "food_set") IN 0 ALIAS food_set SHARED AGAIN 
				m.usedfoodset=.f.
			ENDIF 
			SELECT food_set
			LOCATE FOR ALLTRIM(LOWER(var_name))=m.hladajvarname
			IF !FOUND()
				INSERT INTO food_set (var_name, var_value) VALUES (m.hladajvarname,ALLTRIM(STR(m.pocetmobilovvtigri,10,0)))
			ELSE
				REPLACE var_value WITH ALLTRIM(STR(m.pocetmobilovvtigri,10,0)) FOR LOWER(ALLTRIM(var_name))=m.hladajvarname
			ENDIF
		ENDIF
		IF !usedfoodset
			DO pozavirej WITH "food_set"
		ENDIF 
		m.pocet_foodie_mobile=m.pocetmobilovvtigri
	ENDIF
ENDIF



PROCEDURE nastavnuloveid
PRIVATE vtigerodpoved, m.pozicia
PRIVATE m.hladajvarname, m.hladajmodul, zoznamstredisktiger, zoznamstrediskfood
PRIVATE m.menocloveka, m.heslocloveka, m.vysledokzapisu, isfoodone
PRIVATE menocloveka, heslocloveka, usedfoodset, mojhotel, dlzkaretazca, m.hladamidhotela, m.sumarstredisk, o_pocet, strediska_sum, m.hladajsetupskup
m.mojhotel="hotel:"+ALLTRIM(m.hotel_name)+",ico:"+ALLTRIM(m.hotel_ico)+",dic:"+ALLTRIM(m.hotel_dico)+",hotel_id:"
m.dlzkaretazca=LEN(m.mojhotel)
PRIVATE posielaj
SET DATE TO GERMAN
DIMENSION poslitigrovi(1,2)
m.vtigerodpoved=citajvtiger()
m.posielaj=0
IF !EMPTY(m.vtigerodpoved)
	m.zoznamstredisktiger=STRCONV(get_vtiger_pole(m.vtigerodpoved,'cf_1031'),11)
	pozicia=AT(m.mojhotel,m.zoznamstredisktiger)
	IF pozicia>0
		m.hladamidhotela=SUBSTR(m.zoznamstredisktiger,m.pozicia)
		DO CASE 
			CASE AT(CHR(10),m.hladamidhotela)>0
				m.hladamidhotela=LEFT(m.hladamidhotela,AT(CHR(10),m.hladamidhotela)-1)
			CASE AT("hotel:",m.hladamidhotela,2)>0
				m.hladamidhotela=LEFT(m.hladamidhotela,AT("hotel:",m.hladamidhotela,2)-1)
			OTHERWISE 
				m.hladamidhotela=SUBSTR(m.hladamidhotela,m.dlzkaretazca+1)
		ENDCASE  				
		m.hladamidhotela=STRTRAN(m.hladamidhotela, m.mojhotel,"")
		m.hladamidhotela=STRTRAN(m.hladamidhotela, CHR(13),"")
		m.hladamidhotela=STRTRAN(m.hladamidhotela, CHR(10),"")
		IF m.hladamidhotela="0"
			*** id hotela este nie je pridelene, nerobim nic
			m.zoznamstrediskfood=m.zoznamstredisktiger
		ELSE
			m.zoznamstrediskfood=STRTRAN(m.zoznamstredisktiger, mojhotel+m.hladamidhotela+CHR(10),"")
			m.hladajmodul="FOOD_SET"
			m.hladajvarname="hotel_id"
			m.hladajsetupskup=""
			TRY
				IF m.issql
					m.otevira_se="rdefsuborvarname"
					rv('defsuborvarname',"food_set")
				ELSE
					m.otevira_se=(m.gchom_path+"food_set")
					USE (m.gchom_path + "food_set") IN 0 ALIAS defsubor
				ENDIF 
			CATCH
				m.zoznamstrediskfood=m.zoznamstredisktiger
			ENDTRY
			IF USED("food_set")
				SELECT food_set
				=CURSORSETPROP("Buffering",5,"food_set")
				IF RECCOUNT("food_set")=0
					IF m.issql
						INSERT INTO food_set (var_name,var_value, modul, setup_skup) VALUES (m.hladajvarname,m.hladamidhotela,m.hladajmodul,"")
					ELSE 
						INSERT INTO food_set (var_name,var_value) VALUES (m.hladajvarname,m.hladamidhotela)
					ENDIF 
				ELSE 
					UPDATE food_set SET var_value=m.hladamidhotela WHERE var_name=m.hladajvarname
				ENDIF 
				=tux(.t.,.t.,"food_set")
				DO pozavirej WITH "food_set, defsubor"
				m.hotel_id=VAL(m.hladamidhotela)
			ENDIF 
		ENDIF 
	ELSE
		m.zoznamstrediskfood=m.zoznamstredisktiger+m.mojhotel+"0"+CHR(13)+CHR(10)
	ENDIF 
	IF !(m.zoznamstredisktiger==m.zoznamstrediskfood)
		DIMENSION poslitigrovi(1,2)
		m.posielaj=1
		poslitigrovi(m.posielaj,1)='cf_1031'
		poslitigrovi(m.posielaj,2)=IIF(EMPTY(m.zoznamstrediskfood),"--"+CHR(13)+CHR(10),m.zoznamstrediskfood)
		IF !USED("setfooddat")
			DO open_database
			IF m.issql
				TRY
					rv("setfooddat2","setfooddat")
				CATCH
					rv("setfooddat","setfooddat")
				ENDTRY
			ELSE
				IF !USED("food_dat")
					USE (m.fn_food_dat) IN o ALIAS food_dat
				ENDIF
				TRY
					USE vsetfooddat2 IN 0 ALIAS setfooddat
				CATCH
					USE vsetfooddat IN 0 ALIAS setfooddat
				ENDTRY
			ENDIF
			SELECT setfooddat
			INDEX on id TAG id
			=CURSORSETPROP("Buffering", 5, "setfooddat")
		ENDIF
		SELECT setfooddat
		LOCATE FOR typ_inst=1
		IF FOUND()
			m.isfoodone=.T.
		ELSE
			m.isfoodone=.F.
		ENDIF 
		SELECT LEFT(pgm,1) AS pgm, CNT(pgm) AS pocet GROUP BY 1 ORDER BY 2 FROM setfooddat INTO CURSOR qwe
		o_pocet = 1
		m.strediska_sum=""
		SCAN
			IF qwe.pocet # o_pocet
				strediska_sum = strediska_sum + TRANS(qwe.pocet)
				o_pocet = qwe.pocet
			ENDIF
			strediska_sum = strediska_sum + qwe.pgm
		ENDSCAN
		USE IN qwe
		txtsprava="<b>Meno: </b>"+ALLTRIM(m.hotel_name)+"<br>"
		txtsprava=m.txtsprava+"<b>IČO: </b>"+ALLTRIM(m.hotel_ico)+"<br>"
		txtsprava=m.txtsprava+"<b>DIČ: </b>"+ALLTRIM(m.hotel_dico)+"<br>"
		txtsprava=m.txtsprava+"<b>Strediska: </b>"+ALLTRIM(m.strediska_sum)+"<br>"
		txtsprava=m.txtsprava+"<b>ONE: </b>"+IIF(m.isfoodone,"TRUE","FALSE")+"<br>"
		m.menocloveka="alto.alto"
		m.heslocloveka="alto"
		m.vysledokzapisu=update_vtiger(ALLTRIM(STR(378856,10,0)), m.menocloveka, m.heslocloveka, @poslitigrovi)
		IF VARTYPE(m.hotel_id)="N"
			IF m.hotel_id=0
				=poslimaildoalta("Vytvor hotel_id pre hotel: "+ALLTRIM(m.hotel_name),m.txtsprava)
			ELSE
				=poslimaildoalta("Priradene hotel_id pre hotel: "+ALLTRIM(m.hotel_name)+" ID: "+ALLTRIM(STR(m.hotel_id)),"")
			ENDIF 
		ELSE 
			=poslimaildoalta("Vytvor hotel_id pre hotel: "+ALLTRIM(m.hotel_name),m.txtsprava)
		ENDIF 
	ENDIF 
ENDIF
RELEASE m.vtigerodpoved
