DO clos_data
chyba_pri_otevirani = .F.
TRY  
   	otevira_se = m.fn_doklady
	USE (m.fn_doklady) ALIAS doklady	IN 0 SHARED
   	otevira_se = m.fn_sk_pol
	USE (m.fn_sk_pol)   ALIAS sk_pol   IN 0
   	otevira_se = m.fn_sk_plt
	USE (m.fn_sk_plt)   ALIAS sk_plt   IN 0
   	otevira_se = m.fn_sk_fin
	USE (m.fn_sk_fin)   ALIAS sk_fin   IN 0
   	otevira_se = m.fn_sk_sez
	USE (m.fn_sk_sez)   ALIAS sk_sez   IN 0
   	otevira_se = m.fn_sklad
   	USE (m.fn_sklad)    ALIAS sklad    IN 0 ORDER c_karty
   	otevira_se = m.fn_obraty
	USE (m.fn_obraty)   ALIAS obraty   IN 0
   	otevira_se = m.fn_dluhy
	USE (m.fn_dluhy)    ALIAS dluhy    IN 0
CATCH TO oErr 
    otevira_se = m.otevira_se + CHR(13) + ALLTRIM(STR(oErr.ErrorNo)) + " " + oErr.Message 
   	chyba_pri_otevirani = .T.
ENDTRY 
IF chyba_pri_otevirani
	=MESSAGEBOX(jaz("prg_dbf_neprist_skuste_pozdeji")+CHR(13)+m.otevira_se,64,"Food600",2)
   	 DO zurnal_log WITH "OPERA", "Storno odpoctu pokladni", jaz("nejde_otevrit") + m.otevira_se
	 CLOSE DATABASES 
   	 RETURN .F.
ENDIF 

	******  opravovatelnost jen od KK dale  ****** zacatek
    min_c_dokl = od_kdy_smi_opravit_doklady()
	******  opravovatelnost jen od KK dale  ****** konec

SELECT DISTINCT pz1 + " " + pz2 +  " " + DTOC(datum_dokl) AS vyber_uz ;
	WHERE c_stredisk = m.gic_stredisk AND operace = "VK" AND c_dokl > m.min_c_dokl ;
	FROM (m.fn_doklady) INTO TABLE (m.gcpri_path + "vyber_uz")

IF ! prazdna(.T.)
	DEFINE POPUP vyber_uz PROMPT FIELD vyber_uz ;
		MARGIN RELATIVE SHADOW COLOR SCHEME 4 FONT "Courier New"
	ON SELE POPUP vyber_uz DEACTI POPUP
	ACTI POPUP vyber_uz
	IF ! EMPTY(PROMPT())
		IF MESSAGEBOX(jaz("form opravdu stornovat")+"  " + PROMPT() + " ?", 3+32+256, jaz("m_opr_storno odp kasy")) = 6
			DO st_odp WITH PROMPT()
			DO zurnal_log WITH "OPERA", "STORNO", "ODP KAS " + PROMPT(), m.gic_stredisk
		ENDIF
	ENDIF
	RELE POPUP vyber_uz
ENDIF
DO clos_data
RETU

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
PROC st_odp
PARAM kterou
IF ! EMPT(m.kterou)
	sto_had = CREATEOBJECT("had")
	sto_had.SHOW()
	SELE c_dokl WHERE pz1 + " " + pz2 +  " " + DTOC(datum_dokl) = m.kterou AND c_stredisk = m.gic_stredisk ;
		FROM (m.fn_doklady) INTO TABLE (m.gcpri_path +  "smaz_dokl")
	SELE DISTI c_karty WHERE c_dokl IN (SELECT c_dokl FROM (m.gcpri_path +  "smaz_dokl")) ;
		FROM (m.fn_obraty) INTO CURSOR smaz_obr

	sto_had.set_had(22)
	SELE smaz_dokl
	SCAN
		SCATT FIELD c_dokl MEMVAR
		SELE obraty
		DELE FOR c_dokl = m.c_dokl
		SELE doklady
		DELE FOR c_dokl = m.c_dokl
		SELE dluhy
		DELE FOR c_dokl = m.c_dokl
		SELE smaz_dokl
	ENDSCAN

	sto_had.set_had(55)
	SELE smaz_obr
	SCAN
		SCATT FIELD c_karty MEMVAR
		DO prepocet WITH m.gic_stredisk, c_karty, 999999999
		SELE smaz_obr
	ENDSCAN

	lcuzaverka = SUBST(m.kterou, 17, 12)
	sto_had.set_had(77)
	**** L.L. (23.8.2005) Oprava storna, pre slovensku verziu to nezrusilo priznak odecteno, pri. nevymazalo
	#IF 'SLOVAK' $ UPPER(GETENV('Language'))
		IF "*" $ m.lcuzaverka
			SELE sk_sez
			DELE FOR SUBSTR(uzaverka,3,12) = m.lcuzaverka
			SELE sk_fin
			DELE FOR SUBSTR(uzaverka,3,12) = m.lcuzaverka
			sto_had.set_had(88)
			SELE sk_plt
			DELE FOR SUBSTR(uzaverka,3,12) = m.lcuzaverka
			sto_had.set_had(94)
			SELE sk_pol
			DELE FOR SUBSTR(uzaverka,3,12) = m.lcuzaverka
		ELSE
			SELE sk_sez
			REPL FOR id_man = gcpgm_id .AND. SUBSTR(uzaverka,3,12) = m.lcuzaverka odecteno WITH ""
		ENDIF
	#ELSE
		IF "*" $ m.lcuzaverka
			SELE sk_sez
			DELE FOR uzaverka = m.lcuzaverka
			SELE sk_fin
			DELE FOR uzaverka = m.lcuzaverka
			sto_had.set_had(88)
			SELE sk_plt
			DELE FOR uzaverka = m.lcuzaverka
			sto_had.set_had(94)
			SELE sk_pol
			DELE FOR uzaverka = m.lcuzaverka
		ELSE
			SELE sk_sez
			REPL FOR id_man = gcpgm_id .AND. uzaverka = m.lcuzaverka odecteno WITH ""
		ENDIF
	#ENDIF
	RELEASE sto_had
ENDIF
