
IF "ALFA" $ UPPER(m.gchom_path)
	WAIT "Export ALFA" WINDOW AT 22,22 TIMEOUT .5
	WAIT "Export ALFA" WINDOW AT 22,22 NOWAIT
	IF m.issql
		USE (m.sqlprefix+"rexportf5alfadoklady") ALIAS doklady IN 0
		USE (m.sqlpartneri+"rpartneri") IN 0 ALIAS partneri
		USE (m.sqlprefix+"rexportf5alfaobraty") ALIAS dane IN 0 NODATA
	ELSE
		USE (m.fn_doklady) ALIAS doklady IN 0
		USE (m.fn_partneri) ALIAS partneri IN 0
		USE (m.fn_obraty) ALIAS obraty IN 0
		USE vexportf5alfaobraty ALIAS dane IN 0 NODATA
	ENDIF
	SELECT doklady.c_dokl, STR(ABS(doklady.c_stredisk), 2) AS pgm_id, partneri.partner, ALLTRIM(STR(doklady.doklad, 15)) + "/VYDEJ" AS doklad, doklady.datum_dokl, TTOC(doklady.kdy,1) + "  " AS datum, ;
		SPACE(1) AS zakazka, STR(doklady.doklad,6) + "   " + LEFT(doklady.platba, 3) AS fakturovan, ;
		partneri.naz1, partneri.naz2, partneri.naz3, partneri.naz4, partneri.ico, partneri.dic, partneri.banka, partneri.ucet, partneri.telefon, doklady.datum_dokl + partneri.splatnost AS dat_splat, ;
		0.000 AS dph_sazba1, 000000.00 AS trzba1, 0.000 AS dph_sazba2, 000000.00 AS trzba2, 0.000 AS dph_sazba3, 000000.00 AS trzba3, 0 AS dph_sazba4, 0 AS trzba4, 0 AS dph_sazba5, 0 AS trzba5, 0000000.00 AS trzba ;
		FROM doklady LEFT JOIN partneri ON partneri.c_partner = doklady.c_partner WHERE doklady.operace = "VE" INTO TABLE (m.gchom_path + "faktury")
	REPLACE ALL datum WITH LEFT(datum, 8) + " " + SUBSTR(datum, 9,2) + ":" + SUBSTR(datum, 11)
	SCAN
		SCATTER FIELDS c_dokl MEMVAR
		STORE 0 TO _dan1, _dan2, _dan3, _dan_zakl1, _dan_zakl2, _dan_zakl3
		STORE 0 TO dph_sazba1, dph_sazba2, dph_sazba3
		SELECT dane
		=REQUERY("dane")
		_iii = 1
		SCAN
			_ccc = STR(_iii,1)
			_iii = _iii + 1
			dph_sazba&_ccc = dane.dan - 1
			_dan_zakl&_ccc = ROUND(dane.dan_zakl, 2)
		ENDSCAN
		_dan1 = ROUND(_dan_zakl1 * (dph_sazba1), 2)
		_dan2 = ROUND(_dan_zakl2 * (dph_sazba2), 2)
		_dan3 = ROUND(_dan_zakl3 * (dph_sazba3), 2)
		SELECT faktury
		GATHER FIELDS dph_sazba1, dph_sazba2, dph_sazba3 MEMVAR
		REPLACE trzba1 WITH _dan_zakl1 + _dan1, trzba2 WITH _dan_zakl2 + _dan2, trzba3 WITH _dan_zakl3 + _dan3
		REPLACE trzba WITH ROUND(trzba1 + trzba2 + trzba3, 0)
	ENDSCAN
	DO pozavirej WITH "dane, faktury, obraty, doklady, partneri"
	WAIT CLEAR
ENDIF
