DO open_database
USE (m.sqlprefix+"rinternationalexport") IN 0 ALIAS export
SELECT disti LEFT(uzaverka,4) as rok, SUBSTR(uzaverka,5,2) as mes, SPACE(20) as mesiac FROM export ORDER BY  rok desc, mes desc INTO CURSOR vybr READWRITE 
IF RECCOUNT("vybr")>0
	REPLACE ALL mesiac WITH rok+" "+jaz("januar") FOR mes='01'
	REPLACE ALL mesiac WITH rok+" "+jaz("februar") FOR mes='02'
	REPLACE ALL mesiac WITH rok+" "+jaz("marec") FOR mes='03'
	REPLACE ALL mesiac WITH rok+" "+jaz("april") FOR mes='04'
	REPLACE ALL mesiac WITH rok+" "+jaz("maj") FOR mes='05'
	REPLACE ALL mesiac WITH rok+" "+jaz("jun") FOR mes='06'
	REPLACE ALL mesiac WITH rok+" "+jaz("jul") FOR mes='07'
	REPLACE ALL mesiac WITH rok+" "+jaz("august") FOR mes='08'
	REPLACE ALL mesiac WITH rok+" "+jaz("september") FOR mes='09'
	REPLACE ALL mesiac WITH rok+" "+jaz("oktober") FOR mes='10'
	REPLACE ALL mesiac WITH rok+" "+jaz("november") FOR mes='11'
	REPLACE ALL mesiac WITH rok+" "+jaz("december") FOR mes='12'
	DO FORM dajdruh WITH "","vybr","mesiac",250 TO m.mesiac
	IF !EMPTY(m.mesiac)
		SELECT vybr
		LOCATE FOR mesiac=m.mesiac
		IF FOUND()
			LOCAL m.prmesiac, m.prrok
			m.prmesiac=vybr.mes
			m.prrok=vybr.rok
			SELECT ean, kod, nazov, velkost, SUM(mnozstvi) as mnozstvi FROM export GROUP BY ean, kod, nazov WHERE LEFT(uzaverka,6)=m.prrok+m.prmesiac INTO CURSOR predaj
			m.cesta=m.gchom_path
			m.cesta=GETDIR(m.cesta,jaz("form_adresar"),jaz("form_vyber_adresar_na_export"))
			IF !EMPTY(m.cesta)
				SELECT predaj
				EXPORT FIELDS kod, velkost, ean, nazov, mnozstvi TO (m.cesta+"export_"+m.prrok+m.prmesiac+SYS(2015)) TYPE XLS 
			ENDIF 
		ENDIF 
	ENDIF 
ENDIF 
DO pozavirej WITH "vybr, export, predaj"


		
