*:*****************************************************************************
*: VYROBA_BOSORKA.PRG
*:
*: 2018-10-05 prestehovana sem z menu_def.prg definice menu (proc def_menu_vyroba)
*:
*:*****************************************************************************

*:*****************************************************************************
PROCEDURE def_menu_vyroba
DEFINE BAR  1 OF vyroba PROMPT jaz("m_prov_vyr_vypocet") MESSAGE jaz("m_prov_vyr_par_mssg")
DEFINE BAR  2 OF vyroba PROMPT jaz("m_prov_vyr_jidelak") MESSAGE jaz("m_prov_vyr_davka_mssg")
DEFINE BAR  3 OF vyroba PROMPT jaz("m_prov_vyr_rucni obj.jednotl") MESSAGE jaz("m_prov_vyr_davka_mssg")
DEFINE BAR  5 OF vyroba PROMPT jaz("m_prov_vyr_sestava objednano") MESSAGE jaz("m_prov_vyr_davka_mssg")

ON SELECTION BAR  1 OF vyroba DO vyr_2       IN vyroba_bosorka
ON SELECTION BAR  2 OF vyroba DO FORM jidelak_bosorka
ON SELECTION BAR  3 OF vyroba DO objed_1     IN vyroba_bosorka
ON SELECTION BAR  5 OF vyroba DO s_objed     IN vyroba_bosorka


*:*****************************************************************************
PROCEDURE s_objed

DO FORM s_objed_bosorka
RETURN




*:*****************************************************************************
PROCEDURE objed_1
HIDE POPUP vyroba
DO clos_data
PRIVATE m.gckre_path
m.gckre_path=m.gchom_path
LOCAL idkredit
DO sync_import IN sync_dbf
idkredit = get_ini("Objednavka", "KreditID")
IF !EMPTY(m.idkredit)
	SELECT 0
	USE (m.fn_food_dat) ALIAS food_dat
	LOCATE FOR pgm="KRE" AND ID=m.idkredit
	IF FOUND()
		m.gckre_path=ALLTRIM(food_dat.dat_path)
	ENDIF
	USE IN food_dat
ENDIF
fn_hk_oskar   = gckre_path + "hk_oskar"
fn_hot_kred   = gckre_path + "hot_kred"
fn_jidelak    = gchom_path + "jidelak"
fn_objednan  = gchom_path + "objednan"
DO pozavirej WITH "objednan, hot_kred, jidelak, hk_oskar"
IF f_acc('(fn_objednan) alias objednan') .AND. f_acc('(m.fn_hot_kred) alias hot_kred') .AND. ;
		f_acc('(m.fn_jidelak) alias jidelak') AND  f_acc('(m.fn_hk_oskar) alias hk_oskar')

	m.datum=INPUTBOX("Zadajte dátum:","Dátum",DTOC(DATE()+1),0,"","")
	IF !EMPTY(m.datum)
		TRY
			m.datum=CTOD(m.datum)
		CATCH 
			m.datum=""
		ENDTRY 
	ENDIF 
	IF !EMPTY(m.datum)
		
		SELECT jmeno,SPACE(20) as cis_kred, SPACE(20) as ident, id_ucet, jmeno+SPACE(42) AS meno ORDER BY meno ;
			WHERE DATE(VAL(LEFT(exp_date,4)), VAL(SUBSTR(exp_date,6,2)), VAL(SUBSTR(exp_date,9,2))) > DATE() - 44 ;
			FROM hot_kred INTO CURSOR jm_popu READWRITE 
		UPDATE jm_popu SET ident=hk_Oskar.ident, cis_kred=hk_oskar.cis_kred from hk_oskar WHERE jm_popu.id_ucet=hk_oskar.id_ucet AND !hk_oskar.storno
		SELECT jm_popu 
		REPLACE ALL meno WITH jmeno+" "+cis_kred+" "+ident
		INDEX on meno TAG meno

		DO WHILE .t.
			DO FORM dajdruh WITH "","jm_popu","meno",500 TO m.meno
			IF !EMPTY(m.meno)
				SELECT jm_popu
				LOCATE FOR meno=m.meno
				m.jmeno=ALLTRIM(jm_popu.jmeno)
				m.cis_kred=ALLTRIM(jm_popu.cis_kred)
				m.ident=ALLTRIM(jm_popu.ident)
				m.id_ucet=jm_popu.id_ucet


				SELECT  objednan
				REPLACE FOR o < "1" pocet_o WITH 0
				REPLACE FOR v < "1" pocet_v WITH 0
				REPLACE FOR s < "1" pocet_s WITH 0


				DO FORM objed_10 WITH m.datum, m.jmeno, m.cis_kred, m.id_ucet, m.ident
			ELSE
				EXIT 
			ENDIF
		ENDDO 
	ENDIF 
	DO pozavirej WITH "jm_popu, hot_kred, objednan, jidelak, hk_oskar"
ELSE
	WAIT jaz("ted nelze, zkuste pozdeji") WINDOW NOWAIT
ENDIF
DO clos_data
SHOW POPUP vyroba


*:*****************************************************************************
PROCEDURE vyr_2
HIDE POPUP vyroba
DO clos_data
datum = ""
naz_davky = ""
operace = "VYD_K"
DO sync_import IN sync_dbf
DO pozavirej WITH "objednan, hot_kred, jidelak, hk_oskar, karty, davky, polozky, sklad"
IF f_acc('(fn_objednan) alias objednan') .AND. f_acc('(m.fn_karty) alias karty ORDER nazev') ;
		.AND. f_acc('(m.fn_davky) alias davky') .AND. f_acc('(m.fn_polozky) alias polozky ORDER c_karty') ;
		.AND. f_acc('(m.fn_sklad) alias sklad ORDER c_karty')


	m.dat_davk=INPUTBOX("Zadajte dátum:","Dátum",DTOC(DATE()+1),0,"","")
	IF !EMPTY(m.dat_davk)
		TRY
			m.dat_davk=CTOD(m.dat_davk)
		CATCH 
			m.dat_davk=""
		ENDTRY 
	ENDIF 
	IF EMPTY(m.dat_davk)
		DO pozavirej WITH "objednan, karty, davky, polozky, sklad"
		RETURN
	ENDIF 	
*!*		dat_davk = DATE()+1

*!*		DEFINE WINDOW datum FROM 10,25 TO 14, 55
*!*		ACTI WIND datum
*!*		@ 1,5 SAY "Datum:" GET m.dat_davk
*!*		READ
*!*		RELE WIND datum


	naz_davky = "VYR_" + LEFT(DTOS(m.dat_davk), 4) + "-" + SUBST(DTOS(m.dat_davk), 5,2) + "-" + SUBST(DTOS(m.dat_davk), 7,2)
	SELE *, m.naz_davky AS davka, 00000.0000 AS mnozstvi, m.gic_stredisk AS c_stredisk, m.giakt_mena as c_mena ;
		WHERE datum = m.dat_davk FROM (m.gchom_path + "jidelak") INTO TABLE (m.gcpri_path + "dd")

	CREA TABLE (m.gcpri_path + "objedn") FREE (nazev c(30), c_karty i, j1 N(3), j2 N(3), j3 N(3), j4 N(3), j5 N(3)  )

	SELECT s, o, v, pocet_s, pocet_o, pocet_v ;
		WHERE datum = m.dat_davk FROM (fn_objednan) INTO TABLE (m.gcpri_path + "objed1")

	FOR iii = 1 TO 10
		jjjidlo = dtohex(m.iii)

		SUM pocet_s FOR s = m.jjjidlo TO s1
		SUM pocet_o FOR o = m.jjjidlo TO o1
		SUM pocet_v FOR v = m.jjjidlo TO v1
		SELE dd
		LOCATE FOR s_o_v = "S" .AND. cislojidla = m.jjjidlo
		REPL mnozstvi WITH m.s1
		LOCATE FOR s_o_v = "O" .AND. cislojidla = m.jjjidlo
		REPL mnozstvi WITH m.o1
		LOCATE FOR s_o_v = "V" .AND. cislojidla = m.jjjidlo
		REPL mnozstvi WITH m.v1
		SELE objed1
	ENDFOR
	SELE dd
	SET RELATION TO nazev INTO karty
	REPL ALL c_karty WITH karty.c_karty

	*!*    IF RECCOUNT() = 0
	*!*        APPEND BLANK
	*!*        REPLACE davka WITH m.naz_davky, c_stredisk WITH m.gic_stredisk, c_mena WITH m.giakt_mena
	*!*    ENDIF

	SET RELATION TO
	SELE davky
	DELE FOR davka = m.naz_davky
	APPE FROM (m.gcpri_path + "dd")

	DO FORM davka WITH m.naz_davky
	*do form davkavyr with m.naz_davky

ELSE
	WAIT jaz("ted nelze, zkuste pozdeji") WINDOW NOWAIT
ENDIF
DO clos_data
SHOW POPUP vyroba


