PRIVATE m.hladajdatum
DO open_database 
IF !EMPTY(m.gcdatumzmenydph)
	DO CASE 
		CASE gcdatumzmenydph  = "2023-01-01"
*** Zmena DPH z 20% na 10%
*** Do tabulky ZMENADPH si odkladam aktualny stav DPH, aby som to vedel vratit nazad, kedze tato zmena ma platit 3 mesiace
			m.hladajdatum=CTOD("01.01.2023")
			IF DATE()>=m.hladajdatum
				IF m.issql
					USE (m.sqlprefix+"rzmenadph_datumy") IN 0 ALIAS datumy
				ELSE 
					IF !FILE(m.gccen_path+"zmenadph.dbf")
						=creafile(m.gccen_path+"zmenadph.dbf")
						DO pozavirej WITH "zmenadph"
					ENDIF 
					USE (m.gccen_path+"zmenadph") IN 0
					USE vzmenadph_datumy IN 0 ALIAS datumy
				ENDIF 
				IF m.issql
					USE (m.sqlprefix+"rzmenadph_datum") IN 0 ALIAS datum
					USE (m.sqlprefix+"rskupiny") IN 0 ALIAS rskupiny
				ELSE
					USE (m.gccen_path+"skupiny") IN 0 SHARED AGAIN 
					USE vzmenadph_datum IN 0 ALIAS datum
					USE vskupiny IN 0 ALIAS rskupiny
				ENDIF 
				=CURSORSETPROP("Buffering",5,"datum")
				=CURSORSETPROP("Buffering",5,"rskupiny")
				SELECT *, .t. as lbl FROM rskupiny WHERE !EMPTY(typ_kalk) AND (dan01=1.2 OR dan02=1.2 OR dan03=1.2 OR dan04=1.2 OR dan05=1.2 OR dan06=1.2 OR dan07=1.2 OR dan08=1.2 OR dan09=1.2 OR dan10=1.2) INTO CURSOR druhy READWRITE 
				IF RECCOUNT()>0
					DO FORM seldruhy WITH "druhy","druhy_na_zmenu"
					SELECT druhy
					DELETE FOR EMPTY(lbl)
					IF RECCOUNT()>0
						SELECT datum
						APPEND FROM DBF("druhy")
						REPLACE ALL datum WITH m.hladajdatum
						SELECT druhy
						SCAN FOR lbl
							SELECT rskupiny
							FOR m.i=1 TO 160
								m.ii=cislohladiny(m.i)
								REPLACE dan&ii WITH 1.1 FOR dan&ii=1.2 AND c_druh=druhy.c_druh
							ENDFOR 
							SELECT druhy
						ENDSCAN 
						DO pozavirej WITH "druhy"
						=tux(.t.,.t.,"datum")
						=tux(.t.,.t.,"rskupiny")
						=MESSAGEBOX(jaz("form_hotovo_vybavene"),64,"FoodMan")
					ELSE
						=MESSAGEBOX(jaz("form_nic_nevybrane"),64,"FoodMan")
					ENDIF 
				ELSE
					=MESSAGEBOX(jaz("form_nic_nevybrane"),64,"FoodMan")
				ENDIF 
				DO pozavirej WITH "datumy, datum, rskupiny, skupiny, zmenadph"
			ELSE 
				=MESSAGEBOX(jazparam("form_mozesaspustitaz",m.gcdatumzmenydph),64,"FoodMan")
			ENDIF 
		CASE gcdatumzmenydph  = "2023-04-01"
*** Zmena DPH z 10% nazad na 20%
*** V tabulke ZMENADPH mam odlozeny stav dph k 1.1.2023, tak ho len prekopirujem. Nove druhy bude treba zmenit manualne
			m.hladajdatum=CTOD("01.04.2023")
			IF DATE()>=m.hladajdatum
*			IF .t.
				IF m.issql
					USE (m.sqlprefix+"rzmenadph_datumy") IN 0 ALIAS datumy
				ELSE 
					IF !FILE(m.gccen_path+"zmenadph.dbf")
						=creafile(m.gccen_path+"zmenadph.dbf")
						DO pozavirej WITH "zmenadph"
					ENDIF 
					USE (m.gccen_path+"zmenadph") IN 0
					USE vzmenadph_datumy IN 0 ALIAS datumy
				ENDIF 
				SELECT datumy
				LOCATE FOR datum=m.hladajdatum
				IF !FOUND()
					m.hladajdatum=CTOD("01.01.2023")
					IF m.issql
						USE (m.sqlprefix+"rzmenadph_datum") IN 0 ALIAS datum
						USE (m.sqlprefix+"rskupiny") IN 0 ALIAS rskupiny
					ELSE
						USE (m.gccen_path+"skupiny") IN 0
						USE vzmenadph_datum IN 0 ALIAS datum
						USE vskupiny IN 0 ALIAS rskupiny
					ENDIF 
					=CURSORSETPROP("Buffering",5,"datum")
					=CURSORSETPROP("Buffering",5,"rskupiny")
					SELECT rskupiny
					FOR m.i=1 TO 160
						m.ii=cislohladiny(m.i)
						UPDATE rskupiny SET dan&ii=datum.dan&ii FROM datum WHERE rskupiny.c_druh=datum.c_druh AND !EMPTY(rskupiny.typ_kalk)
						UPDATE rskupiny SET dan&ii=1.2 WHERE dan&ii=1.1 AND !EMPTY(rskupiny.typ_kalk) AND !(c_druh IN (SELECT c_druh FROM datum))
					ENDFOR 
					INSERT INTO datum (datum) VALUES (CTOD("1.4.2023"))
					=tux(.t.,.t.,"datum")
					=tux(.t.,.t.,"rskupiny")
					DO pozavirej WITH "datumy, datum, rskupiny, skupiny, zmenadph"
					=MESSAGEBOX(jaz("form_hotovo_vybavene"),64,"FoodMan")
				ELSE 
					=MESSAGEBOX(jaz("form_zmena_uz_prebehla"),64,"FoodMan")
				ENDIF 
			ELSE 
				=MESSAGEBOX(jazparam("form_mozesaspustitaz",m.gcdatumzmenydph),64,"FoodMan")
			ENDIF 
	ENDCASE 
ENDIF 
