PRIVATE m.hladajoperace, m.hladajcstredisk, m.hladajcpartner, m.cdata, m.hladajidlist, m.menobuffera, m.hladajpz1, m.hladajpz2
PRIVATE m.aktmena
DO nastavsety
DO clos_data
DO open_database
chyba_pri_otevirani = .f.
m.hladajoperace="ZV"
m.aktmena=m.giakt_mena
TRY
	IF m.issql
		otevira_se = "listovanie_hlavicky_all"
		rv("listovanie_hlavicky_all","zoznam")
	ELSE
    	otevira_se = m.fn_buff_r
		USE (m.fn_buff_r)     ALIAS buff_r     IN 0 
    	otevira_se = m.fn_buff_d
		USE (m.fn_buff_d)     ALIAS buff_d     IN 0 
		otevira_se = (m.gccen_path+"listovanie") 
		USE (m.gccen_path+"listovanie") IN 0
		otevira_se = "listovanie_hlavicky_all"
		use vlistovanie_hlavicky_all alias zoznam in 0
	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",2)
	DO zurnal_log WITH "OPERA", "Generovanie prednastavenych ziadaniek", jaz("nejde_otevrit") + m.otevira_se
	RETURN
ENDIF
SELECT zoznam
IF LOWER(m.wi_zakaz)="sushitime"
	DO CASE 
		CASE DOW(DATE(),2)=1
			SET FILTER TO "utorok"$LOWER(zoznam.meno_list) OR zoznam.c_stredisk>0
		CASE DOW(DATE(),2)=2
			SET FILTER TO "streda"$LOWER(zoznam.meno_list) OR zoznam.c_stredisk>0
		CASE DOW(DATE(),2)=3
			SET FILTER TO "štvrtok"$LOWER(zoznam.meno_list) OR zoznam.c_stredisk>0
		CASE DOW(DATE(),2)=4
			SET FILTER TO "piatok"$LOWER(zoznam.meno_list) OR zoznam.c_stredisk>0
		CASE DOW(DATE(),2)=5
			SET FILTER TO "sobota"$LOWER(zoznam.meno_list) OR zoznam.c_stredisk>0
		CASE DOW(DATE(),2)=6
			SET FILTER TO "nedeľa"$LOWER(zoznam.meno_list) OR zoznam.c_stredisk>0
		CASE DOW(DATE(),2)=7
			SET FILTER TO "pondelok"$LOWER(zoznam.meno_list) OR zoznam.c_stredisk>0
	ENDCASE 
ENDIF  
SCAN ALL 
	m.hladajcstredisk=zoznam.c_stredisk
	m.hladajcpartner=zoznam.c_partner
	m.hladajpz1=zoznam.pz1
	m.hladajpz2=zoznam.pz2
	m.cdata=zoznam.c_data
	m.hladajidlist=zoznam.id_list
	m.menobuffera=LOWER(SUBSTR(SYS(2015),4))
	IF USED("polozky")
		=REQUERY("polozky")
	ELSE
		IF m.issql
			USE (m.sqlprefix+"rlistovanie") IN 0 ALIAS polozky
		ELSE
			USE vlistovanie IN 0 ALIAS polozky
		ENDIF 
		=CURSORSETPROP("Buffering",5,"polozky")
	ENDIF 
	IF RECCOUNT("polozky")>0
		IF USED("buffer")
			=REQUERY("buffer")
		ELSE 
			IF m.issql 
		    	otevira_se = "rbuffer"
				USE (m.sqlprefix+"rbuffer")	ALIAS buffer IN 0
			ELSE
		    	otevira_se = "vbuffer"
				USE vbuffer  ALIAS buffer IN 0
			ENDIF 
			=CURSORSETPROP("Buffering",5,"buffer")
		ENDIF 
		IF USED("buf_dokl")
			=REQUERY("buffer")
		ELSE 
			IF m.issql 
		    	otevira_se = "rbufferd"
				USE (m.sqlprefix+"rbufferd")	ALIAS buf_dokl IN 0
			ELSE
		    	otevira_se = "vbufferd"
				USE vbufferd  ALIAS buf_dokl IN 0
			ENDIF 
			=CURSORSETPROP("Buffering",5,"buf_dokl")
		ENDIF 
		INSERT INTO buf_dokl (datum_dokl, c_data, menobuf, operace, c_stredisk, c_partner, pz1, pz2) VALUES (DATE()+1, m.cdata, m.menobuffera, m.hladajoperace, m.hladajcpartner, m.hladajcstredisk, m.hladajpz1, "")
		INSERT INTO BUFFER (c_stredisk, c_karty, cena, nazev, c_druh, druh, na_sklade, pov_objem, mnozstvi, operace, menobuf, c_data) SELECT m.hladajcpartner, c_karty, 0, "", 0, "", 0, 0, mnozstvi, m.hladajoperace, m.menobuffera, m.cdata FROM polozky
		=tux(.t.,.t.,"buf_dokl")
		=REQUERY("buf_dokl")
		=tux(.t.,.t.,"buffer")
		=REQUERY("buffer")
		SELECT buffer
		REPLACE ALL poradi WITH RECNO()
		=tux(.t.,.t.,"buffer")
		=REQUERY("buffer")
		DO buff_out2 WITH .f.,m.aktmena, m.hladajcpartner, 0,.f.,m.menobuffera
		DO vymaz_buffer WITH m.menobuffera,.f.
	ENDIF 
ENDSCAN 
CLOSE DATABASES
CLOSE DATABASES
RETURN 
