*/* ************************************************
*/* *** export dodav. faktur do uctovnictva KROS ***
*/* ************************************************
PARAMETERS bezkecov
PRIVATE m.chyb_pri_otevirani, m.pocet_faktur, m.hladajpartnerkod, m.hldajcdokl, m.hladajidman, m.hladajoperace, m.hladajcenhlad, m.hladajdruh, m.hladajpartner, m.hladajplatba
PRIVATE m.pokracuj, m.mazpolozky, m.recordnoheader, m.otevira_se, m.hladajcpartner
LOCAL m.hladajdruh2, m.dph_10, m.dph_20, m.dph10, m.dph20, m.hsstred, m.hladajidman
m.hsstred=""
chyba_pri_otevirani = .f.
DO open_database
TRY
	IF m.issql
		DO CASE 
			CASE INLIST(LOWER(m.gcuct_typ), "orion","asseco")
		    	otevira_se = "rdokladypeneprenesene"
				USE (m.sqlprefix+"rdokladypeneprenesene")	ALIAS expfaktura  IN 0
			CASE INLIST(LOWER(m.gcuct_typ), "pohoda")
		    	otevira_se = "rdokladyveneprenesene"
				USE (m.sqlprefix+"rdokladyveneprenesene")	ALIAS expfaktura  IN 0
			OTHERWISE 
		    	otevira_se = "rexpfakturaneprenesene"
				USE (m.sqlprefix+"rexpfakturaneprenesene")	ALIAS expfaktura  IN 0
		ENDCASE 
    	otevira_se = "rskupiny"
		USE (m.sqlprefix+"rskupiny") ALIAS skupiny  IN 0
		SELECT skupiny
		INDEX on druh TAG druh
		INDEX on c_druh TAG c_druh
		USE (m.sqlprefix+"rfooddat") ALIAS food_dat IN 0		
		USE (m.sqlprefix+"rpartneriucto") ALIAS partneri IN 0
		SELECT partneri
		INDEX on partner TAG partner
		INDEX on c_partner TAG c_partner
	ELSE
    	otevira_se = m.fn_karty
		USE (m.fn_karty) IN 0 ALIAS karty
    	otevira_se = m.fn_doklady
		USE (m.fn_doklady) IN 0 ALIAS doklady
    	otevira_se = m.fn_obraty
		USE (m.fn_obraty) IN 0 ALIAS obraty
    	otevira_se = m.fn_partneri
		USE (m.fn_partneri) IN 0 ALIAS partneri
		DO CASE 
			CASE INLIST(LOWER(m.gcuct_typ), "orion", "asseco")
		    	otevira_se = "vdokladypeneprenesene"
				USE vdokladypeneprenesene ALIAS expfaktura  IN 0
				=CURSORSETPROP("Buffering",5,"expfaktura")
			OTHERWISE 
		    	otevira_se = m.fn_expfaktura
				USE (m.fn_expfaktura) ALIAS expfaktura IN 0 AGAIN
		ENDCASE 
    	otevira_se = m.fn_skupiny
		USE (m.fn_skupiny) ALIAS skupiny IN 0
    	otevira_se = m.fn_food_dat
		USE (m.fn_food_dat) ALIAS food_dat 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",2000)
	DO zurnal_log WITH "OPERA", "Export faktúr", jaz("nejde_otevrit") + m.otevira_se
	RETURN .F.
ENDIF
SELECT expfaktura
DO CASE 
	CASE INLIST(LOWER(m.gcuct_typ),"orion","asseco","pohoda")
		m.pocet_faktur=RECCOUNT()
	OTHERWISE 
		COUNT TO pocet_faktur FOR EMPTY(prenesene) AND EMPTY(zasoby)
ENDCASE 
IF pocet_faktur>0
	DO CASE 
		CASE LOWER(m.gcuct_typ)=="pohoda"
		SET ASSERTS on
		ASSERT .f.
			SELECT disti c_stredisk FROM expfaktura INTO CURSOR zoznamstredisk
			m.pokracuj=.t.
			LOCAL aktstredisko
			SCAN ALL 
				m.aktstredisko=zoznamstredisk.c_stredisk
				SELECT expfaktura.c_stredisk, expfaktura.c_partner, expfaktura.c_dokl,expfaktura.operace,expfaktura.datum_dokl,expfaktura.c_mena,expfaktura.pz1, expfaktura.pz2, expfaktura.platba, expfaktura.typ_pohybu,;
					expfaktura.uctexport, expfaktura.cen_hlad, expfaktura.doklad, expfaktura.provedl, partneri.partner FROM expfaktura INNER JOIN partneri ON expfaktura.c_partner=partneri.c_partner INTO CURSOR uctexpo WHERE c_stredisk=m.aktstredisko READWRITE 
				*REPLACE ALL operace WITH "FA"
				m.pokracuj=m.pokracuj and vytvor_obr_uex(.t., m.aktstredisko, 0, 0, .t., m.cdata, m.bezkecov)
				IF !m.pokracuj
					EXIT
				ENDIF 
			ENDSCAN 
			USE IN zoznamstredisk
			RELEASE m.aktstredisko
			IF m.pokracuj
				LOCAL menoexportu
				IF USED("u_ex_obraty")
					SELECT u_ex_obraty
					DELETE FOR operace<>"FA"
					m.menoexportu=DTOS(DATE())+"_"+STRTRAN(STRTRAN(STRTRAN(STRTRAN(TTOC(DATETIME())," ",""),".",""),":",""),"/","")+"_"+SYS(2015)
					DO gen_exp_pohoda WITH .f.,STR(YEAR(DATE()),4,0),PADL(ALLTRIM(STR(MONTH(DATE()),2,0)),2,"0") IN uctoexp
				ENDIF 
			ENDIF 
		CASE LOWER(m.gcuct_typ)=="orion"
			SELECT disti c_stredisk FROM expfaktura INTO CURSOR zoznamstredisk
			m.pokracuj=.t.
			LOCAL aktstredisko
			SCAN ALL 
				m.aktstredisko=zoznamstredisk.c_stredisk
				SELECT expfaktura.c_stredisk, expfaktura.c_partner, expfaktura.c_dokl,expfaktura.operace,expfaktura.datum_dokl,expfaktura.c_mena,expfaktura.pz1, expfaktura.pz2, expfaktura.platba, expfaktura.typ_pohybu,;
					expfaktura.uctexport, expfaktura.cen_hlad, expfaktura.doklad, expfaktura.provedl, partneri.partner FROM expfaktura INNER JOIN partneri ON expfaktura.c_partner=partneri.c_partner INTO CURSOR uctexpo WHERE c_stredisk=m.aktstredisko
				m.pokracuj=m.pokracuj and vytvor_obr_uex(.t., m.aktstredisko, 0, 0)
				IF !m.pokracuj
					EXIT
				ELSE 
					IF USED("u_ex_obraty")
						IF USED("uexobratyxx")
							SELECT uexobratyxx
							APPEND FROM DBF("u_ex_obraty")
						ELSE
							SELECT * FROM u_ex_obraty INTO CURSOR uexobratyxx READWRITE 
						ENDIF 
						DO pozavirej WITH "u_ex_obraty"
					ENDIF 
				ENDIF 
			ENDSCAN 
			USE IN zoznamstredisk
			RELEASE m.aktstredisko
			IF USED("uexobratyxx")
				DO pozavirej WITH "u_ex_obraty"
				SELECT * FROM uexobratyxx INTO CURSOR u_ex_obraty READWRITE 
				DO pozavirej WITH "uexobratyxx"
			ENDIF 
			IF m.pokracuj
				LOCAL menoexportu
				m.menoexportu=DTOS(DATE())+"_"+STRTRAN(STRTRAN(STRTRAN(STRTRAN(TTOC(DATETIME())," ",""),".",""),":",""),"/","")+"_"+SYS(2015)
				DO gen_exp_chemosvit WITH m.menoexportu,STR(YEAR(DATE()),4,0),PADL(ALLTRIM(STR(MONTH(DATE()),2,0)),2,"0") IN uctoexp
			ENDIF 
		CASE LOWER(m.gcuct_typ)=="asseco"
			SELECT disti c_stredisk FROM expfaktura INTO CURSOR zoznamstredisk
			m.pokracuj=.t.
			LOCAL aktstredisko
			SCAN ALL 
				m.aktstredisko=zoznamstredisk.c_stredisk
				SELECT expfaktura.c_stredisk, expfaktura.c_partner, expfaktura.c_dokl,expfaktura.operace,expfaktura.datum_dokl,expfaktura.c_mena,expfaktura.pz1, expfaktura.pz2, expfaktura.platba, expfaktura.typ_pohybu,;
					expfaktura.uctexport, expfaktura.cen_hlad, expfaktura.doklad, expfaktura.provedl, partneri.partner FROM expfaktura INNER JOIN partneri ON expfaktura.c_partner=partneri.c_partner INTO CURSOR uctexpo WHERE c_stredisk=m.aktstredisko
				m.pokracuj=m.pokracuj and vytvor_obr_uex(.t., m.aktstredisko, 0, 0, .t.)
				IF !m.pokracuj
					EXIT
				ENDIF 
			ENDSCAN 
			USE IN zoznamstredisk
			RELEASE m.aktstredisko
			IF m.pokracuj
				LOCAL menoexportu
				m.menoexportu=DTOS(DATE())+"_"+STRTRAN(STRTRAN(STRTRAN(STRTRAN(TTOC(DATETIME())," ",""),".",""),":",""),"/","")+"_"+SYS(2015)
				DO gen_exp_asseco WITH m.menoexportu,STR(YEAR(DATE()),4,0),PADL(ALLTRIM(STR(MONTH(DATE()),2,0)),2,"0"),.t. IN uctoexp
			ENDIF 
		CASE LOWER(m.gcuct_typ)=="navision"
			SELECT c_dokl, 0000000000 as c_partner, SPACE(15) as pz1, SPACE(50) as no, SPACE(2) as operace, $0 as suma, SPACE(1) as doctyp, SPACE(2) as rectyp FROM expfaktura WHERE .f. INTO CURSOR prenosy READWRITE 
			SELECT expfaktura
			SCAN FOR EMPTY(prenesene) AND EMPTY(zasoby)
				m.hladajpartnerkod=ALLTRIM(expfaktura.part_kod)
				m.hladajcdokl=expfaktura.c_dokl
				m.dph_10=expfaktura.dph_10
				m.dph_20=expfaktura.dph_20
				
				IF USED("dokl1")
					=REQUERY("dokl1")
					=REQUERY("obr1")
				ELSE 
					IF m.issql
						USE (m.sqlprefix+"r1doklady") ALIAS dokl1 IN 0
						USE (m.sqlprefix+"r1obraty") ALIAS obr1 IN 0
					ELSE
						USE v1doklady ALIAS dokl1 IN 0
						USE v1obraty ALIAS obr1 IN 0
					ENDIF 
				ENDIF 
				SELECT dokl1
				IF RECCOUNT()>0
					GO TOP 
					m.hladajoperace=dokl1.operace
					m.hladajplatba=dokl1.platba
					m.hladajcpartner=dokl1.c_partner
					IF !EMPTY(dokl1.pz1)
						SELECT prenosy
						LOCATE FOR pz1=dokl1.pz1 AND c_partner=dokl1.c_partner
						IF FOUND()
							m.hladajno=ALLTRIM(prenosy.no)
							m.hladajdoctyp=ALLTRIM(prenosy.doctyp)
							m.hladajrectyp=ALLTRIM(prenosy.rectyp)
							m.doplnenie=.t.
						ELSE
							m.doplnenie=.f.
						ENDIF 
					ELSE
						m.doplnenie=.f.
					ENDIF 
					IF !m.doplnenie
						DO CASE 
							CASE m.hladajoperace="PE"
								m.hladajno="NF"+PADL(ALLTRIM(STR(m.hladajcdokl,10,0)),10,"0")
								m.hladajdoctyp="F"
								m.hladajrectyp="NF"
							CASE INLIST(m.hladajoperace,"VE","VR")
								m.hladajno="ND"+PADL(ALLTRIM(STR(m.hladajcdokl,10,0)),10,"0")
								m.hladajdoctyp="F"
								m.hladajrectyp="ND"
						ENDCASE 
					ENDIF 
					SELECT food_dat
					LOCATE FOR c_stredisk=dokl1.c_stredisk
					m.hladajidman=food_dat.id
					m.hladajcenhlad="*"
					IF otvor_navision_hlavicky(m.navision_firma,"nav_hlav","documentheader.No='"+m.hladajno+"'") AND otvor_navision_partneri(m.navision_firma,"ompartneri","customervendor.No='"+m.hladajpartnerkod+"'")
						=CURSORSETPROP("Buffering",5,"nav_hlav")
						SELECT *, SPACE(m.sirkastlpcadruh) as druh, SPACE(10) as ucet, SPACE(10) as hs, SPACE(m.sirkastlpcadruh) as spart, 0.000 as dph, .f. as samozdan, 1.00 as dan_samo FROM obr1 INTO CURSOR obrpol READWRITE 
						UPDATE obrpol SET druh=skupiny.druh, spart=skupiny.spart, dph=skupiny.dan01, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo from skupiny WHERE obrpol.c_druhs=skupiny.c_druh
						UPDATE obrpol SET druh=skupiny.druh, spart=skupiny.spart, dph=skupiny.dan01, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo from skupiny WHERE obrpol.c_druh=skupiny.c_druh AND EMPTY(obrpol.druh)
						UPDATE obrpol SET druh=skupiny.druh, spart=skupiny.spart, dph=skupiny.dan01, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo from skupiny WHERE obrpol.c_druhk=skupiny.c_druh AND EMPTY(obrpol.druh)
						SELECT obrpol
						REPLACE FOR EMPTY(dan_samo) dan_samo WITH 1
						REPLACE dph WITH dan_samo FOR !EMPTY(samozdan)
						REPLACE druh WITH m.hladajplatba+" "+druh FOR operace="PE"
						REPLACE spart WITH m.hladajplatba+" "+spart FOR operace="PE"
						IF LOWER(m.gcuct_pole)="druh"
							SELECT disti druh FROM obrpol INTO CURSOR obrdruhy READWRITE 
						ELSE
							SELECT disti spart as druh FROM obrpol INTO CURSOR obrdruhy READWRITE 
						ENDIF 
						m.pokracuj=.t.
						SELECT obrdruhy
						SCAN ALL 
							m.hladajdruh2=obrdruhy.druh
							m.hladajdruh=obrdruhy.druh
							m.hladajpartner=LEFT(ompartneri.meno,30)
							m.hladajpartner2=m.hladajpartner
							IF USED("uexobr1")
								=REQUERY("uexobr1")
							ELSE
								IF m.issql
									USE (m.sqlprefix+"ruexobr1") ALIAS uexobr1 IN 0
								ELSE
									IF !USED("u_ex_obr")
										USE (m.gcucto_path+"u_ex_obr") IN 0
									ENDIF 
									USE vuexobr1 ALIAS uexobr1 IN 0
								ENDIF 
							ENDIF
							IF RECCOUNT("uexobr1")>0
								SELECT uexobr1
								GO TOP 
								IF !EMPTY(uexobr1.stare)
									SELECT obrpol
									IF LOWER(m.gcuct_pole)="druh"
										 REPLACE ucet WITH uexobr1.md, hs WITH uexobr1.hs_md FOR druh=m.hladajdruh2
									ELSE
										 REPLACE ucet WITH uexobr1.md, hs WITH uexobr1.hs_md FOR spart=m.hladajdruh2
									ENDIF 
								ELSE
									IF m.pokracuj
										=MESSAGEBOX(jaz("form_neda_sa_urobit_export")+CHR(10)+jaz("form_nastavte_ucty_pre")+CHR(10)+jaz("rep_manager")+m.hladajidman+", "+jaz("rep_operacia")+":"+m.hladajoperace+CHR(10)+jaz("form partner")+":"+ALLTRIM(m.hladajpartner2)+CHR(10)+;
											IIF(LOWER(m.gcuct_pole)="druh",jaz("rep_druh")+":",jaz("rep_spart")+":")+ALLTRIM(m.hladajdruh2),64,"FoodMan",2000)
									ENDIF 
									m.pokracuj=.f.
								ENDIF 
							ELSE
								m.hladajpartner="*"
								=REQUERY("uexobr1")
								IF RECCOUNT("uexobr1")>0
									SELECT uexobr1
									GO TOP 
									IF !EMPTY(uexobr1.stare)
										SELECT obrpol
										IF LOWER(m.gcuct_pole)="druh"
											 REPLACE ucet WITH uexobr1.md, hs WITH uexobr1.hs_md FOR druh=m.hladajdruh2
										ELSE
											 REPLACE ucet WITH uexobr1.md, hs WITH uexobr1.hs_md FOR spart=m.hladajdruh2
										ENDIF 
									ELSE 
										IF m.pokracuj
											=MESSAGEBOX(jaz("form_neda_sa_urobit_export")+CHR(10)+jaz("form_nastavte_ucty_pre")+CHR(10)+jaz("rep_manager")+m.hladajidman+", "+jaz("rep_operacia")+":"+m.hladajoperace+CHR(10)+jaz("form partner")+":"+ALLTRIM(m.hladajpartner2)+CHR(10)+;
												IIF(LOWER(m.gcuct_pole)="druh",jaz("rep_druh")+":",jaz("rep_spart")+":")+ALLTRIM(m.hladajdruh2),64,"FoodMan",2000)
										ENDIF 
										m.pokracuj=.f.
									ENDIF 
								ELSE
									m.hladajdruh="*"
									m.hladajpartner=LEFT(ompartneri.meno,30)
									=REQUERY("uexobr1")
									IF RECCOUNT("uexobr1")>0
										SELECT uexobr1
										GO TOP 
										IF !EMPTY(uexobr1.stare)
											SELECT obrpol
											IF LOWER(m.gcuct_pole)="druh"
												 REPLACE ucet WITH uexobr1.md, hs WITH uexobr1.hs_md FOR druh=m.hladajdruh2
											ELSE
												 REPLACE ucet WITH uexobr1.md, hs WITH uexobr1.hs_md FOR spart=m.hladajdruh2
											ENDIF 
										ELSE 
											IF m.pokracuj
												=MESSAGEBOX(jaz("form_neda_sa_urobit_export")+CHR(10)+jaz("form_nastavte_ucty_pre")+CHR(10)+jaz("rep_manager")+m.hladajidman+", "+jaz("rep_operacia")+":"+m.hladajoperace+CHR(10)+jaz("form partner")+":"+ALLTRIM(m.hladajpartner2)+CHR(10)+;
													IIF(LOWER(m.gcuct_pole)="druh",jaz("rep_druh")+":",jaz("rep_spart")+":")+ALLTRIM(m.hladajdruh2),64,"FoodMan",2000)
											ENDIF 
											m.pokracuj=.f.
										ENDIF 
											
									ELSE
										m.hladajpartner="*"
										=REQUERY("uexobr1")
										IF RECCOUNT("uexobr1")>0
											SELECT uexobr1
											GO TOP 
											SELECT obrpol
											IF LOWER(m.gcuct_pole)="druh"
												 REPLACE ucet WITH uexobr1.md, hs WITH uexobr1.hs_md FOR druh=m.hladajdruh2
											ELSE
												 REPLACE ucet WITH uexobr1.md, hs WITH uexobr1.hs_md FOR spart=m.hladajdruh2
											ENDIF 
										ELSE
											INSERT INTO uexobr1 (id_man, operace, druh, partner, cen_hlad, co, pz, poznamka) VALUES ;
												(m.hladajidman, m.hladajoperace, m.hladajdruh2, ompartneri.meno, "","prachy",'operace +"|"+partner+"|"+druh',"OBR "+m.hladajidman+" "+m.hladajoperace+" "+ompartneri.meno)
											=tux(.t.,.t.,"uexobr1")
											=REQUERY("uexobr1")
											IF m.pokracuj
												=MESSAGEBOX(jaz("form_neda_sa_urobit_export")+CHR(10)+jaz("form_nastavte_ucty_pre")+CHR(10)+jaz("rep_manager")+m.hladajidman+", "+jaz("rep_operacia")+":"+m.hladajoperace+CHR(10)+jaz("form partner")+":"+ALLTRIM(m.hladajpartner2)+CHR(10)+;
													IIF(LOWER(m.gcuct_pole)="druh",jaz("rep_druh")+":",jaz("rep_spart")+":")+ALLTRIM(m.hladajdruh2),64,"FoodMan",2000)
											ENDIF 
											m.pokracuj=.f.
										ENDIF 
									ENDIF 
								ENDIF 
							ENDIF 	
							SELECT obrdruhy
						ENDSCAN 
						IF m.pokracuj
							SELECT obrpol
							GO TOP 
							m.hsstred=obrpol.hs
							REPLACE hs WITH ALLTRIM(hs)+"Y" FOR !EMPTY(samozdan)
							GO TOP 
							SELECT nav_hlav
							IF RECCOUNT()>0
								LOCATE FOR nav_hlav.rstat="N"
								IF FOUND()
									IF m.doplnenie
										REPLACE cvno WITH m.hladajpartnerkod, postdate WITH expfaktura.dat_dodani, postdesc WITH ALLTRIM(SUBSTR(expfaktura.cislo_fa,3)), duedate WITH expfaktura.dat_splat, curcode WITH en__meny(dokl1.c_mena,3), name WITH ompartneri.meno, name2 WITH ompartneri.name2,;
											adresa WITH ompartneri.adresa, adresa2 WITH ompartneri.adresa2, city WITH ompartneri.city, contact WITH ompartneri.contact, psc WITH ompartneri.psc, regcode WITH ompartneri.regcode, vatcislo WITH ompartneri.vatcislo, regcislo WITH ompartneri.regcislo,;
											taxcislo WITH ompartneri.taxcislo, docdate WITH expfaktura.dat_vyst, vatdate WITH expfaktura.dat_vyst, ucetno WITH ompartneri.ucetno, iban WITH ompartneri.iban, swift WITH ompartneri.swift, nasdoklad WITH ALLTRIM(SUBSTR(expfaktura.cislo_fa,3)), platba WITH IIF("hoto"$LOWER(m.hladajplatba),"HOTOVOST","FAKTURA"), faktura WITH ALLTRIM(faktura)+","+expfaktura.cislo_pe
									ELSE
										REPLACE cvno WITH m.hladajpartnerkod, postdate WITH expfaktura.dat_dodani, postdesc WITH ALLTRIM(SUBSTR(expfaktura.cislo_fa,3)), duedate WITH expfaktura.dat_splat, curcode WITH en__meny(dokl1.c_mena,3), name WITH ompartneri.meno, name2 WITH ompartneri.name2,;
											adresa WITH ompartneri.adresa, adresa2 WITH ompartneri.adresa2, city WITH ompartneri.city, contact WITH ompartneri.contact, psc WITH ompartneri.psc, regcode WITH ompartneri.regcode, vatcislo WITH ompartneri.vatcislo, regcislo WITH ompartneri.regcislo,;
											taxcislo WITH ompartneri.taxcislo, docdate WITH expfaktura.dat_vyst, vatdate WITH expfaktura.dat_vyst, ucetno WITH ompartneri.ucetno, iban WITH ompartneri.iban, swift WITH ompartneri.swift, nasdoklad WITH ALLTRIM(SUBSTR(expfaktura.cislo_fa,3)), platba WITH IIF("hoto"$LOWER(m.hladajplatba),"HOTOVOST","FAKTURA"), faktura WITH expfaktura.cislo_pe
									ENDIF 
									m.recordnoheader=nav_hlav.rno
									m.mazpolozky=!m.doplnenie
									=tux(.t.,.t.,"nav_hlav")
									=REQUERY("nav_hlav")
								ELSE
									INSERT INTO nav_hlav(rtyp, rstat, doctyp, cvno, no, postdate, postdesc, duedate, curcode, name, name2, adresa, adresa2, city, contact, psc, regcode, vatcislo, regcislo, taxcislo, docdate, vatdate, ucetno, iban, swift, nasdoklad, oprava, gdc1, gdc2, povdocno, platba, faktura, canceled) VALUES ;
										(m.hladajrectyp, "N", m.hladajdoctyp, m.hladajpartnerkod, m.hladajno, expfaktura.dat_dodani, ALLTRIM(SUBSTR(expfaktura.cislo_fa,3)), expfaktura.dat_splat, en__meny(dokl1.c_mena,3), ompartneri.meno, ompartneri.name2,;
										ompartneri.adresa, ompartneri.adresa2, ompartneri.city, ompartneri.contact, ompartneri.psc, ompartneri.regcode, ompartneri.vatcislo, ompartneri.regcislo,;
										ompartneri.taxcislo, expfaktura.dat_vyst, expfaktura.dat_vyst, ompartneri.ucetno, ompartneri.iban, ompartneri.swift, ALLTRIM(SUBSTR(expfaktura.cislo_fa,3)),.t.,m.hsstred, "", "",IIF("hoto"$LOWER(m.hladajplatba),"HOTOVOST","FAKTURA"),expfaktura.cislo_pe, .f.)
									=tux(.t.,.t.,"nav_hlav")
									=REQUERY("nav_hlav")
									LOCATE FOR nav_hlav.rstat="N"
									m.recordnoheader=nav_hlav.rno
									m.mazpolozky=.f.
								ENDIF 
							ELSE 
								INSERT INTO nav_hlav(rtyp, rstat, doctyp, cvno, no, postdate, postdesc, duedate, curcode, name, name2, adresa, adresa2, city, contact, psc, regcode, vatcislo, regcislo, taxcislo, docdate, vatdate, ucetno, iban, swift, nasdoklad, oprava, gdc1, gdc2, povdocno, platba, faktura, canceled) VALUES ;
									(m.hladajrectyp, "N", m.hladajdoctyp, m.hladajpartnerkod, m.hladajno, expfaktura.dat_dodani, ALLTRIM(SUBSTR(expfaktura.cislo_fa,3)), expfaktura.dat_splat, en__meny(dokl1.c_mena,3), ompartneri.meno, ompartneri.name2,;
									ompartneri.adresa, ompartneri.adresa2, ompartneri.city, ompartneri.contact, ompartneri.psc, ompartneri.regcode, ompartneri.vatcislo, ompartneri.regcislo,;
									ompartneri.taxcislo, expfaktura.dat_vyst, expfaktura.dat_vyst, ompartneri.ucetno, ompartneri.iban, ompartneri.swift, ALLTRIM(SUBSTR(expfaktura.cislo_fa,3)),.f.,m.hsstred, "", "",IIF("hoto"$LOWER(m.hladajplatba),"HOTOVOST","FAKTURA"),expfaktura.cislo_pe, .f.)
								=tux(.t.,.t.,"nav_hlav")
								=REQUERY("nav_hlav")
								LOCATE FOR nav_hlav.rstat="N"
								m.recordnoheader=nav_hlav.rno
								m.mazpolozky=.f.
							ENDIF 
							IF otvor_navision_polozky(m.navision_firma,"nav_pol","documentline.RecordNoHeader="+ALLTRIM(STR(m.recordnoheader,10,0)))
								=CURSORSETPROP("Buffering",5,"nav_pol")
								IF m.mazpolozky
									DELETE ALL 
								ENDIF 
								SELECT obrpol
								IF m.nav_posli_pol_fakt
									SELECT nazev, ucet, mnozstvi, cena, cena_part, hs, dph FROM obrpol INTO CURSOR obrpol1 
								ELSE 
									SELECT SPACE(30) as nazev, ucet, 01 as mnozstvi, SUM(mnozstvi*cena) as cena, SUM(mnozstvi*cena_part) as cena_part, hs, dph FROM obrpol INTO CURSOR obrpol1 GROUP BY ucet, hs, dph READWRITE 
									IF m.hladajoperace<>"PE"
										REPLACE ALL mnozstvi WITH -mnozstvi, cena WITH -cena, cena_part WITH -cena_part
									ENDIF 
								ENDIF 
								LOCAL sumasdph, sumabezdph, sumacelkomsdph
								m.sumacelkomsdph=0
								IF m.doplnenie
									m.hladajporadie=RECCOUNT("nav_pol")+1
									SCAN ALL 
										IF prenosy.operace="PE"
											IF m.hladajoperace="PE"
												m.sumasdph=ROUND(obrpol1.mnozstvi*obrpol1.cena*obrpol1.dph,2)
												m.sumabezdph=ROUND(obrpol1.mnozstvi*obrpol1.cena,2)
												INSERT INTO nav_pol (rtyp, rstat, rno_head, docno, line_no, no, descript, mj, mnozstvo, jed_cena, dph, gdc1, gdc2, sdph, vatsuma) VALUES ;
													(m.hladajrectyp, "N", m.recordnoheader, m.hladajno, m.hladajporadie*10000, obrpol1.ucet, LEFT(obrpol1.nazev,27), RIGHT(obrpol1.nazev,3), obrpol1.mnozstvi, obrpol1.cena, obrpol1.dph*100-100, obrpol1.hs, "", m.sumasdph, m.sumasdph-m.sumabezdph)
											ELSE
												m.sumasdph=ROUND(obrpol1.mnozstvi*obrpol1.cena_part*obrpol1.dph,2)
												m.sumabezdph=ROUND(obrpol1.mnozstvi*obrpol1.cena_part,2)
												INSERT INTO nav_pol (rtyp, rstat, rno_head, docno, line_no, no, descript, mj, mnozstvo, jed_cena, dph, gdc1, gdc2, sdph, vatsuma) VALUES ;
													(m.hladajrectyp, "N", m.recordnoheader, m.hladajno, m.hladajporadie*10000, obrpol1.ucet, LEFT(obrpol1.nazev,27), RIGHT(obrpol1.nazev,3), obrpol1.mnozstvi, obrpol1.cena_part, obrpol1.dph*100-100, obrpol1.hs, "", m.sumasdph, m.sumasdph-m.sumabezdph)
											ENDIF 
										ELSE
											IF m.hladajoperace="PE"
												m.sumasdph=ROUND(obrpol1.mnozstvi*obrpol1.cena*obrpol1.dph,2)
												m.sumabezdph=ROUND(obrpol1.mnozstvi*obrpol1.cena,2)
												INSERT INTO nav_pol (rtyp, rstat, rno_head, docno, line_no, no, descript, mj, mnozstvo, jed_cena, dph, gdc1, gdc2, sdph, vatsuma) VALUES ;
													(m.hladajrectyp, "N", m.recordnoheader, m.hladajno, m.hladajporadie*10000, obrpol1.ucet, LEFT(obrpol1.nazev,27), RIGHT(obrpol1.nazev,3), -obrpol1.mnozstvi, obrpol1.cena, obrpol1.dph*100-100, obrpol1.hs, "", m.sumasdph, m.sumasdph-m.sumabezdph)
											ELSE
												m.sumasdph=ROUND(-obrpol1.mnozstvi*obrpol1.cena_part*obrpol1.dph,2)
												m.sumabezdph=ROUND(-obrpol1.mnozstvi*obrpol1.cena_part,2)
												INSERT INTO nav_pol (rtyp, rstat, rno_head, docno, line_no, no, descript, mj, mnozstvo, jed_cena, dph, gdc1, gdc2, sdph, vatsuma) VALUES ;
													(m.hladajrectyp, "N", m.recordnoheader, m.hladajno, m.hladajporadie*10000, obrpol1.ucet, LEFT(obrpol1.nazev,27), RIGHT(obrpol1.nazev,3), -obrpol1.mnozstvi, obrpol1.cena_part, obrpol1.dph*100-100, obrpol1.hs, "", m.sumasdph, m.sumasdph-m.sumabezdph)
											ENDIF 
										ENDIF 
										m.hladajporadie=m.hladajporadie+1
										m.sumacelkomsdph=m.sumacelkomsdph+IIF(m.hladajoperace="PE",m.sumasdph,-m.sumasdph)
									ENDSCAN 
								ELSE 
									m.hladajporadie=1
									SCAN ALL 
										IF m.hladajoperace="PE"
											m.sumasdph=ROUND(obrpol1.mnozstvi*obrpol1.cena*obrpol1.dph,2)
											m.sumabezdph=ROUND(obrpol1.mnozstvi*obrpol1.cena,2)
											INSERT INTO nav_pol (rtyp, rstat, rno_head, docno, line_no, no, descript, mj, mnozstvo, jed_cena, dph, gdc1, gdc2, sdph, vatsuma) VALUES ;
												(m.hladajrectyp, "N", m.recordnoheader, m.hladajno, m.hladajporadie*10000, obrpol1.ucet, LEFT(obrpol1.nazev,27), RIGHT(obrpol1.nazev,3), obrpol1.mnozstvi, obrpol1.cena, obrpol1.dph*100-100, obrpol1.hs, "", m.sumasdph, m.sumasdph-m.sumabezdph)
										ELSE
											m.sumasdph=ROUND(-obrpol1.mnozstvi*obrpol1.cena_part*obrpol1.dph,2)
											m.sumabezdph=ROUND(-obrpol1.mnozstvi*obrpol1.cena_part,2)
											INSERT INTO nav_pol (rtyp, rstat, rno_head, docno, line_no, no, descript, mj, mnozstvo, jed_cena, dph, gdc1, gdc2, sdph, vatsuma) VALUES ;
												(m.hladajrectyp, "N", m.recordnoheader, m.hladajno, m.hladajporadie*10000, obrpol1.ucet, LEFT(obrpol1.nazev,27), RIGHT(obrpol1.nazev,3), -obrpol1.mnozstvi, obrpol1.cena_part, obrpol1.dph*100-100, obrpol1.hs, "", m.sumasdph, m.sumasdph-m.sumabezdph)
										ENDIF 
										m.hladajporadie=m.hladajporadie+1
										m.sumacelkomsdph=m.sumacelkomsdph+IIF(m.hladajoperace="PE",m.sumasdph,-m.sumasdph)
									ENDSCAN 
								ENDIF 
								SELECT nav_pol
								SUM vatsuma TO m.dph10 FOR dph=m.uctdphlo*100-100
								SUM vatsuma TO m.dph20 FOR dph=m.uctdphhi*100-100
								IF m.dph10<>m.dph_10
									GO TOP 
									LOCATE FOR dph=m.uctdphlo*100-100
									IF FOUND()
										REPLACE vatsuma WITH vatsuma+m.dph_10-m.dph10, sdph WITH sdph+m.dph_10-m.dph10
									ENDIF 
								ENDIF 
								IF m.dph20<>m.dph_20
									GO TOP 
									LOCATE FOR dph=m.uctdphhi*100-100
									IF FOUND()
										REPLACE vatsuma WITH vatsuma+m.dph_20-m.dph20, sdph WITH sdph+m.dph_20-m.dph20
									ENDIF 
								ENDIF 
								SELECT obr1
								SUM mnozstvi*cena TO m.sumabezdph ALL 
								SELECT prenosy
								IF !m.doplnenie
									INSERT INTO prenosy (c_dokl, pz1, operace, suma, no, doctyp, rectyp, c_partner) VALUES (m.hladajcdokl, dokl1.pz1, m.hladajoperace, m.sumacelkomsdph, m.hladajno, m.hladajdoctyp, m.hladajrectyp, m.hladajcpartner)
								ELSE
									SELECT prenosy
									IF SIGN(prenosy.suma)<>SIGN(prenosy.suma+m.sumacelkomsdph)
										IF prenosy.rectyp="NF"
											REPLACE rectyp WITH "ND", no WITH STRTRAN(no,"NF","ND")
											SELECT nav_hlav
											REPLACE rtyp WITH "ND", no WITH STRTRAN(no,"NF","ND")
											SELECT nav_pol
											REPLACE ALL rtyp WITH "ND", docno WITH STRTRAN(docno,"NF","ND"), mnozstvo WITH -mnozstvo
										ELSE 
											REPLACE rectyp WITH "NF", no WITH STRTRAN(no,"ND","NF")
											SELECT nav_hlav
											REPLACE rtyp WITH "NF", no WITH STRTRAN(no,"ND","NF")
											SELECT nav_pol
											REPLACE ALL rtyp WITH "NF", docno WITH STRTRAN(docno,"ND","NF"), mnozstvo WITH -mnozstvo
										ENDIF 
										=tux(.t.,.t.,"nav_hlav")
										=tux(.t.,.t.,"nav_pol")
									ENDIF 
									SELECT prenosy
									REPLACE suma WITH suma+m.sumacelkomsdph
								ENDIF 				
								SELECT expfaktura

								=tux(.t.,.t.,"nav_pol")
								DO pozavirej WITH "nav_pol, obrpol1"
								SELECT expfaktura
								REPLACE prenesene WITH .t.
								IF m.issql
									=tux(.f.,.t.,"expfaktura")
								ENDIF 
							ELSE
								=MESSAGEBOX("Navision "+jaz("form_neodpoveda"),64,"FoodMan",2000)
								SELECT nav_hlav
								REPLACE rstat WITH "E" FOR rstat="N"
								=tux(.t.,.t.,"nav_hlav")
								=REQUERY("nav_hlav")
							ENDIF 
						ENDIF 
					ELSE
						=MESSAGEBOX("Navision "+jaz("form_neodpoveda"),64,"FoodMan",2000)
					ENDIF 
					DO pozavirej WITH "nav_hlav, ompartneri"
				ENDIF 
				DO pozavirej WITH "obrdruhy, obrpol"
			ENDSCAN 
			DO pozavirej WITH "uexobr1, dokl1, obr1, food_dat, skupiny,exp_faktura, expfaktura, prenosy"

		CASE LOWER(m.gcuct_typ)=="kros" AND INLIST(LOWER(m.gcuct_spec),"masaryk")
			*/* generovanie suboru
			sfile=m.gcuexp_path + "dodfaktury_"
			sfilehotovost=m.gcuexp_path + "hotovost_"
			poradie=1
			DO WHILE FILE(sfile+ALLTRIM(STR(poradie))+".txt")=.t.
				poradie=poradie+1
			ENDDO
			m.lihandle= FCREATE(sfile+ALLTRIM(STR(poradie))+".txt")
			m.lihandle_hot= FCREATE(sfilehotovost+ALLTRIM(STR(poradie))+".txt")
			IF m.lihandle>0 AND m.lihandle_hot>0
				IF !INLIST(LOWER(m.gcuct_spec),"masaryk")
					m.uct00="R00"+CHR(9)+"T01"
					= FPUTS(m.lihandle, m.uct00)
				ELSE
					SELECT id, part_meno, part_ico, part_kod, part_extid, dat_vyst, dat_splat, dat_dodani, cislo_pe+SPACE(200) as cislo_pe, cislo_fa, cislo_vs, cislo_fa as cislofa, cislo_vs as cislovs, cislo_st,;
						SUM(zakl_0) as zakl_0, SUM(zakl_10) as zakl_10, SUM(zakl_20) as zakl_20, SUM(zakl_celk) as zakl_celk,;
						SUM(dph_10) as dph_10, SUM(dph_20) as dph_20, SUM(dph_celk) as dph_celk, COUNT(cislo_fa) as pocetriadkov, prenesene, zasoby, $0 as zaklsamo10, $0 as zaklsamo20, $0 as zaklsamo0, c_dokl, SPACE(2) as id_man, SPACE(3) as spart, mattov FROM expfaktura INTO CURSOR expfa GROUP BY cislo_fa, part_extid READWRITE WHERE EMPTY(prenesene) AND EMPTY(zasoby) and id<>1;
						UNION ;
						SELECT id, part_meno, part_ico, part_kod, part_extid, dat_vyst, dat_splat, dat_dodani, cislo_pe+SPACE(200) as cislo_pe, "" as cislo_fa, "" as cislo_vs, cislo_fa as cislofa, cislo_vs as cislovs, cislo_st, ;
							zakl_0, zakl_10, zakl_20, zakl_celk, dph_10, dph_20, dph_celk, 1 as pocetriadkov, prenesene, zasoby, $0 as zaklsamo10, $0 as zaklsamo20, $0 as zaklsamo0, c_dokl, SPACE(2) as id_man, SPACE(3) as spart, mattov FROM expfaktura WHERE EMPTY(prenesene) AND EMPTY(zasoby) and id=1
					SCAN ALL 
						IF  pocetriadkov>1
							m.cislofa=expfa.cislo_fa
							REPLACE cislo_pe WITH ""
							SELECT expfaktura
							SCAN FOR cislo_fa=m.cislofa
								m.hladajcdokl=expfaktura.c_dokl
								SELECT expfa
								REPLACE cislo_pe WITH ALLTRIM(cislo_pe)+","+ALLTRIM(expfaktura.cislo_pe)
								IF USED("dokl1")
									=REQUERY("dokl1")
									=REQUERY("obr1")
								ELSE 
									IF m.issql
										USE (m.sqlprefix+"r1doklady") ALIAS dokl1 IN 0
										USE (m.sqlprefix+"r1obraty") ALIAS obr1 IN 0
									ELSE
										USE v1doklady ALIAS dokl1 IN 0
										USE v1obraty ALIAS obr1 IN 0
									ENDIF 
								ENDIF 
								SELECT *, SPACE(m.sirkastlpcadruh) as druh, .f. as samozdan, 1.00 as dan_samo, 1.00 as dan1, SPACE(3) as spart FROM obr1 INTO CURSOR obrpol READWRITE 
								IF expfaktura.id<>1
									UPDATE obrpol SET druh=skupiny.druh, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo, dan1=skupiny.dan01, spart=skupiny.spart from skupiny WHERE obrpol.c_druhs=skupiny.c_druh
									UPDATE obrpol SET druh=skupiny.druh, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo, dan1=skupiny.dan01, spart=skupiny.spart from skupiny WHERE obrpol.c_druh=skupiny.c_druh AND EMPTY(obrpol.druh)
									UPDATE obrpol SET druh=skupiny.druh, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo, dan1=skupiny.dan01, spart=skupiny.spart from skupiny WHERE obrpol.c_druhk=skupiny.c_druh AND EMPTY(obrpol.druh)
									SELECT SUM(mnozstvi*cena) as suma, dan_samo, dan1 FROM obrpol GROUP BY dan_samo, dan1 INTO CURSOR sumysamozdan WHERE samozdan
									SCAN FOR suma<>0
										DO CASE 
											CASE sumysamozdan.dan_samo=m.uctdphlo
												SELECT expfa
												REPLACE zaklsamo10 WITH zaklsamo10+ABS(sumysamozdan.suma)
											CASE sumysamozdan.dan_samo=m.uctdphhi
												SELECT expfa
												REPLACE zaklsamo20 WITH zaklsamo20+ABS(sumysamozdan.suma)
											CASE sumysamozdan.dan_samo=1
												SELECT expfa
												REPLACE zaklsamo0 WITH zaklsamo0+ABS(sumysamozdan.suma)
										ENDCASE 
										DO CASE 
											CASE sumysamozdan.dan1=m.uctdphlo									
												SELECT expfa
												REPLACE zakl_10 WITH zakl_10-ABS(sumysamozdan.suma)
											CASE sumysamozdan.dan1=m.uctdphhi									
												SELECT expfa
												REPLACE zakl_20 WITH zakl_20-ABS(sumysamozdan.suma)
											CASE sumysamozdan.dan1=1
												SELECT expfa
												REPLACE zakl_0 WITH zakl_0-ABS(sumysamozdan.suma)
										ENDCASE 
										SELECT sumysamozdan
									ENDSCAN 
									USE IN sumysamozdan
								ELSE 
									UPDATE obrpol SET druh=skupiny.druh, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo, dan1=skupiny.dan01, spart=skupiny.spart from skupiny WHERE obrpol.c_druhs=skupiny.c_druh
									UPDATE obrpol SET druh=skupiny.druh, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo, dan1=skupiny.dan01, spart=skupiny.spart from skupiny WHERE obrpol.c_druh=skupiny.c_druh AND EMPTY(obrpol.druh)
									UPDATE obrpol SET druh=skupiny.druh, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo, dan1=skupiny.dan01, spart=skupiny.spart from skupiny WHERE obrpol.c_druhk=skupiny.c_druh AND EMPTY(obrpol.druh)
								ENDIF 
								SELECT expfaktura
							ENDSCAN 
							SELECT expfa
							IF LEFT(expfa.cislo_pe,1)=","
								REPLACE cislo_pe WITH SUBSTR(cislo_pe,2)
							ENDIF 
						ELSE 
							m.hladajcdokl=expfa.c_dokl
							IF USED("dokl1")
								=REQUERY("dokl1")
								=REQUERY("obr1")
							ELSE 
								IF m.issql
									USE (m.sqlprefix+"r1doklady") ALIAS dokl1 IN 0
									USE (m.sqlprefix+"r1obraty") ALIAS obr1 IN 0
								ELSE
									USE v1doklady ALIAS dokl1 IN 0
									USE v1obraty ALIAS obr1 IN 0
								ENDIF 
							ENDIF 
							SELECT *, SPACE(m.sirkastlpcadruh) as druh, .f. as samozdan, 1.00 as dan_samo, 1.00 as dan1, SPACE(3) as spart FROM obr1 INTO CURSOR obrpol READWRITE 
							IF expfa.id<>1
								UPDATE obrpol SET druh=skupiny.druh, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo, dan1=skupiny.dan01, spart=skupiny.spart from skupiny WHERE obrpol.c_druhs=skupiny.c_druh
								UPDATE obrpol SET druh=skupiny.druh, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo, dan1=skupiny.dan01, spart=skupiny.spart from skupiny WHERE obrpol.c_druh=skupiny.c_druh AND EMPTY(obrpol.druh)
								UPDATE obrpol SET druh=skupiny.druh, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo, dan1=skupiny.dan01, spart=skupiny.spart from skupiny WHERE obrpol.c_druhk=skupiny.c_druh AND EMPTY(obrpol.druh)
								SELECT SUM(mnozstvi*cena) as suma, dan_samo, dan1 FROM obrpol GROUP BY dan_samo, dan1 INTO CURSOR sumysamozdan WHERE samozdan
								SCAN FOR suma<>0
									DO CASE 
										CASE sumysamozdan.dan_samo=m.uctdphlo
											SELECT expfa
											REPLACE zaklsamo10 WITH zaklsamo10+ABS(sumysamozdan.suma)
										CASE sumysamozdan.dan_samo=m.uctdphhi
											SELECT expfa
											REPLACE zaklsamo20 WITH zaklsamo20+ABS(sumysamozdan.suma)
										CASE sumysamozdan.dan_samo=1
											SELECT expfa
											REPLACE zaklsamo0 WITH zaklsamo0+ABS(sumysamozdan.suma)
									ENDCASE 
									DO CASE 
										CASE sumysamozdan.dan1=m.uctdphlo									
											SELECT expfa
											REPLACE zakl_10 WITH zakl_10-ABS(sumysamozdan.suma)
										CASE sumysamozdan.dan1=m.uctdphhi									
											SELECT expfa
											REPLACE zakl_20 WITH zakl_20-ABS(sumysamozdan.suma)
										CASE sumysamozdan.dan1=1
											SELECT expfa
											REPLACE zakl_0 WITH zakl_0-ABS(sumysamozdan.suma)
									ENDCASE 
									SELECT sumysamozdan
								ENDSCAN 
								USE IN sumysamozdan
							ELSE 
								UPDATE obrpol SET druh=skupiny.druh, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo, dan1=skupiny.dan01, spart=skupiny.spart from skupiny WHERE obrpol.c_druhs=skupiny.c_druh
								UPDATE obrpol SET druh=skupiny.druh, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo, dan1=skupiny.dan01, spart=skupiny.spart from skupiny WHERE obrpol.c_druh=skupiny.c_druh AND EMPTY(obrpol.druh)
								UPDATE obrpol SET druh=skupiny.druh, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo, dan1=skupiny.dan01, spart=skupiny.spart from skupiny WHERE obrpol.c_druhk=skupiny.c_druh AND EMPTY(obrpol.druh)
							ENDIF 
						ENDIF
						DO pozavirej WITH "obr1, dokl1" 
					ENDSCAN 
				ENDIF 
				SELECT expfa
				SCAN FOR EMPTY(prenesene) AND EMPTY(zasoby)
					SCATTER MEMVAR 
					m.uct00=IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"","R01"+CHR(9)) &&udaje
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",CHR(9)) &&cislo faktury
					m.uct00=m.uct00+ALLTRIM(m.part_meno)+CHR(9) &&partner
					m.uct00=m.uct00+ALLTRIM(m.part_ico)+CHR(9) &&partner_ico
					m.uct00=m.uct00+DTOC(m.dat_vyst)+CHR(9) &&datum
					m.uct00=m.uct00+DTOC(m.dat_splat)+CHR(9) &&datum
					m.uct00=m.uct00+DTOC(m.dat_dodani)+CHR(9) &&datum
					m.uct00=m.uct00+STR(zakl_10,10,2)+CHR(9) &&zaklad_10
					m.uct00=m.uct00+STR(zakl_20,10,2)+CHR(9) &&zaklad_20
					m.uct00=m.uct00+STR(zakl_0,10,2)+CHR(9) &&zaklad_0
					m.uct00=m.uct00+STR(0,10,2)+CHR(9) &&zaklad_neobsahuje
					m.uct00=m.uct00+STR(m.uctdphlo*100-100,10,2)+CHR(9) &&sadzba DPH nizsia
					m.uct00=m.uct00+STR(m.uctdphhi*100-100,10,2)+CHR(9) &&sadzba DPH vyssia
					m.uct00=m.uct00+STR(dph_10,10,2)+CHR(9) &&dph_10
					m.uct00=m.uct00+STR(dph_20,10,2)+CHR(9) &&dph_20
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",STR(0,10,2)+CHR(9)) &&halierove vyrovnanie
					m.uct00=m.uct00+STR(zakl_celk+dph_celk,10,2)+CHR(9) &&celkom suma
					m.uct00=m.uct00+"14"+CHR(9) &&typ dokladu
					m.uct00=m.uct00+m.gcuct_evidencia3+CHR(9) &&kod evidencia
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",m.gcuct_cisrad3+CHR(9)) &&kod ciselna rada			
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",m.part_kod+CHR(9)) &&partner_kod externy
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C021_PartnerKod
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C045_PartnerFirmaStredisko
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C046_PartnerFirmaPrevadzka
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C047_PartnerUlica
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C048_PartnerPSC
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C049_PartnerMesto
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C053_PartnerDIC
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C059_CasVyst
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C095_DodaciePodmienky
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C098_Uvod
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C099_Zaver
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C104_DodaciList
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C105_Objednavka
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C106_Vystavil
					m.uct00=m.uct00+"0008"+CHR(9) &&C111_Konstantny
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C112_Specificky
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C114_FormaUhrady
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C115_SposobDopravy
					m.uct00=m.uct00+"EUR"+CHR(9) &&C200_Mena
					m.uct00=m.uct00+"1"+CHR(9) &&C201_Mnozstvo_Jednotky
					m.uct00=m.uct00+"1"+CHR(9) &&C202_Kurz
					m.uct00=m.uct00+STR(zakl_celk+dph_celk,10,2)+CHR(9) &&C211_SumaSpolu
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",SUBSTR(m.cislo_vs,3)+CHR(9)) &&C117_ZakazkovyList
					m.uct00=m.uct00+"Prijemka "+ALLTRIM(m.cislo_pe)+CHR(9) &&C097_Poznamka
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C116_PredmetFakturacie
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C050_PartnerStat
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C024_KodStatuDPH
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C025_PartnerIDpreDPH
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C155_DodCisloUctu
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C156_DodBanka
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C157_DodPobocka
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C180_PAStat
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C028_KodVystavil
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C041_PartnerMenoSkratka
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C158_DodSWIFT
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C159_DodIBAN
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C160_DodKodStatuDPH
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C161_DodIDpreDPH
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C150_DodStat
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"","-2"+CHR(9)) &&C221_Zaokruhlenie
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"","3"+CHR(9)) &&C222_SposobZaokruhlenia
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C052_PartnerICOPoradoveCislo
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C225_ZaokruhleniePolozky
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C096_ZalohaMemo
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C224_Zaloha
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"","1"+CHR(9)) &&C120_SposobVypoctuDPH
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C235_StarySposobVypoctuDPHAkoKasa
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",DTOC(m.dat_vyst)+CHR(9)) &&C069_DenVystDF; 
					m.uct00=m.uct00+IIF(INLIST(LOWER(m.gcuct_spec),"masaryk"),"",""+CHR(9)) &&C236_UhradeneCezECR
					m.uct00=m.uct00+ALLTRIM(m.cislo_vs)+" "+CHR(9) &&C110_VariabilnySymbol
					m.uct00=m.uct00+ALLTRIM(m.cislo_fa)+" "+CHR(9) &&Cislo faktury
					m.uct00=m.uct00+STR(zaklsamo10,10,2)+CHR(9) &&zaklad_10 - samozdanenie
					m.uct00=m.uct00+STR(zaklsamo20,10,2)+CHR(9) &&zaklad_20 - samozdanenie
					m.uct00=m.uct00+STR(zaklsamo0,10,2)+CHR(9) &&zaklad_0 - samozdanenie
					m.uct00=m.uct00+ALLTRIM(m.cislo_st)+CHR(9) &&zaklad_0 - samozdanenie
***					14.05.2019 pan Cienik zistil, ze cislo skladu mu nepomoze a radsej tam davame spart. Ak je na doklade iba jeden spart, bude tam uvedeny on, ak nie pisem tam "X"
***					27.06.2019 nepomoze ani spart. Do exp_faktura som doplnil policko MATTOV, kam si mozu napisat co chcu a to im tu napisem - mali by tam davat M,T, alebo nic
*					m.uct00=m.uct00+ALLTRIM(m.id_man)+CHR(9) &&cislo skladu
					m.uct00=m.uct00+ALLTRIM(m.mattov)+CHR(9) &&spart
					m.uct00=m.uct00+ALLTRIM(STR(round50(zakl_celk+dph_celk,5)-zakl_celk-dph_celk,10,2))+CHR(9) &&zaokruhlenie na 5 centov
					DO CASE 
						CASE m.id=0
							= FPUTS(m.lihandle, m.uct00)		
						CASE m.id=1
							= FPUTS(m.lihandle_hot, m.uct00)		
						CASE m.id=2
							= FPUTS(m.lihandle, m.uct00)		
							= FPUTS(m.lihandle_hot, m.uct00)		
						OTHERWISE 
							= FPUTS(m.lihandle, m.uct00)		
					ENDCASE 
					if zakl_0>0	AND !INLIST(LOWER(m.gcuct_spec),"masaryk")
						m.uct00="R02"+CHR(9) &&udaje / polozky faktury
						m.uct00=m.uct00+"Tovar 0%DPH"+CHR(9) 		&&C109_Nazov
						m.uct00=m.uct00+"1"+CHR(9) 					&&C100_Mnozstvo
						m.uct00=m.uct00+"ks"+CHR(9) 				&&C111_Jednotka
						m.uct00=m.uct00+STR(zakl_0,10,2)+CHR(9) 	&&C104_JCenaKonecnaBezDPH
						m.uct00=m.uct00+"0"+CHR(9) 					&&C107_SadzbaDPH
						m.uct00=m.uct00+""+CHR(9) 					&&C101_JCenaSkladova
						m.uct00=m.uct00+""+CHR(9) 					&&C102_JCenaCennikova
						m.uct00=m.uct00+""+CHR(9) 					&&C103_PercZlava
						m.uct00=m.uct00+"V"+CHR(9) 					&&C108_TypPolozky
						m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)
						m.uct00=m.uct00+""+CHR(9) 					&&C225_SyntetickyUcet
						m.uct00=m.uct00+""+CHR(9) 					&&C226_AnalytickyUcet
						m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)
						m.uct00=m.uct00+"V"+CHR(9)					&&C021_Kod(T033_TypCiastka)
						m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)
						m.uct00=m.uct00+"ks"+CHR(9) 				&&C124_MJ
						m.uct00=m.uct00+"1"+CHR(9) 					&&C125_MJ_Mnozstvo
						m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)
						m.uct00=m.uct00+"-2"+CHR(9) 				&&C105_Zaokruhlenie
						m.uct00=m.uct00+"3"+CHR(9) 					&&C106_SposobZaokruhlenia
						= FPUTS(m.lihandle, m.uct00)
					endif
		*!*				if zakl_vo>0			
		*!*					m.uct00="R02"+CHR(9) &&udaje / polozky faktury
		*!*					m.uct00=m.uct00+"Vratne obaly 0%DPH"+CHR(9) 		&&C109_Nazov
		*!*					m.uct00=m.uct00+"1"+CHR(9) 					&&C100_Mnozstvo
		*!*					m.uct00=m.uct00+"ks"+CHR(9) 				&&C111_Jednotka
		*!*					m.uct00=m.uct00+STR(zakl_vo,10,2)+CHR(9) 	&&C104_JCenaKonecnaBezDPH
		*!*					m.uct00=m.uct00+"0"+CHR(9) 					&&C107_SadzbaDPH
		*!*					m.uct00=m.uct00+""+CHR(9) 					&&C101_JCenaSkladova
		*!*					m.uct00=m.uct00+""+CHR(9) 					&&C102_JCenaCennikova
		*!*					m.uct00=m.uct00+""+CHR(9) 					&&C103_PercZlava
		*!*					m.uct00=m.uct00+"V"+CHR(9) 					&&C108_TypPolozky
		*!*					m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)
		*!*					m.uct00=m.uct00+""+CHR(9) 					&&C225_SyntetickyUcet
		*!*					m.uct00=m.uct00+""+CHR(9) 					&&C226_AnalytickyUcet
		*!*					m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)
		*!*					m.uct00=m.uct00+"V"+CHR(9)					&&C021_Kod(T033_TypCiastka)
		*!*					m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)
		*!*					m.uct00=m.uct00+"ks"+CHR(9) 				&&C124_MJ
		*!*					m.uct00=m.uct00+"1"+CHR(9) 					&&C125_MJ_Mnozstvo
		*!*					m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)
		*!*					m.uct00=m.uct00+"-2"+CHR(9) 				&&C105_Zaokruhlenie
		*!*					m.uct00=m.uct00+"3"+CHR(9) 					&&C106_SposobZaokruhlenia
		*!*					= FPUTS(m.lihandle, m.uct00)
		*!*				endif
					if zakl_10>0 AND !INLIST(LOWER(m.gcuct_spec),"masaryk")
						m.uct00="R02"+CHR(9) &&udaje / polozky faktury			
						m.uct00=m.uct00+"Tovar "+ALLTRIM(STR(m.uctdphlo*100-100,2,0))+"%DPH"+CHR(9) 		&&C109_Nazov
						m.uct00=m.uct00+"1"+CHR(9) 					&&C100_Mnozstvo
						m.uct00=m.uct00+"ks"+CHR(9) 				&&C111_Jednotka
						m.uct00=m.uct00+STR(zakl_10,10,2)+CHR(9) 	&&C104_JCenaKonecnaBezDPH
						m.uct00=m.uct00+"N"+CHR(9) 					&&C107_SadzbaDPH
						m.uct00=m.uct00+""+CHR(9) 					&&C101_JCenaSkladova
						m.uct00=m.uct00+""+CHR(9) 					&&C102_JCenaCennikova
						m.uct00=m.uct00+""+CHR(9) 					&&C103_PercZlava
						m.uct00=m.uct00+"V"+CHR(9) 					&&C108_TypPolozky
						m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)
						m.uct00=m.uct00+""+CHR(9) 					&&C225_SyntetickyUcet
						m.uct00=m.uct00+""+CHR(9) 					&&C226_AnalytickyUcet
						m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)
						m.uct00=m.uct00+"XA"+CHR(9)					&&C021_Kod(T033_TypCiastka)
						m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)
						m.uct00=m.uct00+"ks"+CHR(9) 				&&C124_MJ
						m.uct00=m.uct00+"1"+CHR(9) 					&&C125_MJ_Mnozstvo
						m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)
						m.uct00=m.uct00+"-2"+CHR(9) 				&&C105_Zaokruhlenie
						m.uct00=m.uct00+"3"+CHR(9) 					&&C106_SposobZaokruhlenia
						= FPUTS(m.lihandle, m.uct00)
					endif
					if zakl_20>0 AND !INLIST(LOWER(m.gcuct_spec),"masaryk")	
						m.uct00="R02"+CHR(9) &&udaje / polozky faktury
						m.uct00=m.uct00+"Tovar "+ALLTRIM(STR(m.uctdphhi*100-100,2,0))+"%DPH"+CHR(9) 		&&C109_Nazov
						m.uct00=m.uct00+"1"+CHR(9) 					&&C100_Mnozstvo
						m.uct00=m.uct00+"ks"+CHR(9) 				&&C111_Jednotka
						m.uct00=m.uct00+STR(zakl_20,10,2)+CHR(9) 	&&C104_JCenaKonecnaBezDPH
						m.uct00=m.uct00+"V"+CHR(9) 					&&C107_SadzbaDPH
						m.uct00=m.uct00+""+CHR(9) 					&&C101_JCenaSkladova
						m.uct00=m.uct00+""+CHR(9) 					&&C102_JCenaCennikova
						m.uct00=m.uct00+""+CHR(9) 					&&C103_PercZlava
						m.uct00=m.uct00+"V"+CHR(9) 					&&C108_TypPolozky
						m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)
						m.uct00=m.uct00+"501"+CHR(9) 					&&C225_SyntetickyUcet
						m.uct00=m.uct00+"100"+CHR(9) 					&&C226_AnalytickyUcet
						m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)
						m.uct00=m.uct00+"A"+CHR(9)					&&C021_Kod(T033_TypCiastka)
						m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)
						m.uct00=m.uct00+"ks"+CHR(9) 				&&C124_MJ
						m.uct00=m.uct00+"1"+CHR(9) 					&&C125_MJ_Mnozstvo
						m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)
						m.uct00=m.uct00+"-2"+CHR(9) 				&&C105_Zaokruhlenie
						m.uct00=m.uct00+"3"+CHR(9) 					&&C106_SposobZaokruhlenia	
						= FPUTS(m.lihandle, m.uct00)
					endif	
					IF !INLIST(LOWER(m.gcuct_spec),"masaryk")
						replace prenesene WITH .t.
					ELSE
						SELECT expfaktura
						IF m.id=1
							REPLACE prenesene WITH .t. FOR ALLTRIM(cislo_fa)=ALLTRIM(m.cislofa) AND ALLTRIM(cislo_pe)=ALLTRIM(m.cislo_pe) AND ALLTRIM(cislo_vs)=ALLTRIM(m.cislovs)  AND EMPTY(prenesene) AND EMPTY(zasoby)
						ELSE
							REPLACE prenesene WITH .t. FOR cislo_fa=m.cislo_fa AND EMPTY(prenesene) AND EMPTY(zasoby)
						ENDIF 
						SELECT expfa
					ENDIF 
				ENDSCAN
				=FCLOSE(m.lihandle)
				IF m.lihandle_hot<>0
					=FCLOSE(m.lihandle_hot)
				ENDIF 
				MESSAGEBOX(jaz("form_vyexportovane_faktury"),64,"FoodMan",2000)
			ELSE
				MESSAGEBOX(jaz("form_nepod_otvorit_exp_subor"),64,"FoodMan",2000)
			ENDIF
		CASE LOWER(m.gcuct_typ)=="kros"
			SELECT disti YEAR(dat_dodani) as rok, MONTH(dat_dodani) as mes, SPACE(20) as mesiac FROM expfaktura ORDER BY  rok desc, mes desc INTO CURSOR vybr READWRITE WHERE EMPTY(prenesene)
			IF RECCOUNT("vybr")>0
				REPLACE ALL mesiac WITH ALLTRIM(STR(rok,4,0))+" "+jaz("januar") FOR mes=1
				REPLACE ALL mesiac WITH ALLTRIM(STR(rok,4,0))+" "+jaz("februar") FOR mes=2
				REPLACE ALL mesiac WITH ALLTRIM(STR(rok,4,0))+" "+jaz("marec") FOR mes=3
				REPLACE ALL mesiac WITH ALLTRIM(STR(rok,4,0))+" "+jaz("april") FOR mes=4
				REPLACE ALL mesiac WITH ALLTRIM(STR(rok,4,0))+" "+jaz("maj") FOR mes=5
				REPLACE ALL mesiac WITH ALLTRIM(STR(rok,4,0))+" "+jaz("jun") FOR mes=6
				REPLACE ALL mesiac WITH ALLTRIM(STR(rok,4,0))+" "+jaz("jul") FOR mes=7
				REPLACE ALL mesiac WITH ALLTRIM(STR(rok,4,0))+" "+jaz("august") FOR mes=8
				REPLACE ALL mesiac WITH ALLTRIM(STR(rok,4,0))+" "+jaz("september") FOR mes=9
				REPLACE ALL mesiac WITH ALLTRIM(STR(rok,4,0))+" "+jaz("oktober") FOR mes=10
				REPLACE ALL mesiac WITH ALLTRIM(STR(rok,4,0))+" "+jaz("november") FOR mes=11
				REPLACE ALL mesiac WITH ALLTRIM(STR(rok,4,0))+" "+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
						sfile=m.gcuexp_path + "dodfaktury_"
						poradie=1
						DO WHILE FILE(sfile+ALLTRIM(STR(poradie))+".txt")=.t.
							poradie=poradie+1
						ENDDO
						m.lihandle= FCREATE(sfile+ALLTRIM(STR(poradie))+".txt")
						IF !(m.lihandle>0) 
							=MESSAGEBOX(jaz("form_neda_vytvorit_exp_subor"),16,"FoodMan",2000)
							RETURN
						ENDIF 
						m.uct00="R00"+CHR(9)+"T01"
						= FPUTS(m.lihandle, m.uct00)

						SELECT id, part_meno, part_ico, part_kod, part_extid, dat_vyst, dat_splat, dat_dodani, cislo_pe+SPACE(200) as cislo_pe, cislo_fa, cislo_vs, cislo_fa as cislofa, cislo_vs as cislovs, ;
							SUM(zakl_0) as zakl_0, SUM(zakl_10) as zakl_10, SUM(zakl_20) as zakl_20, SUM(zakl_celk) as zakl_celk, zaokruhlen,;
							SUM(dph_10) as dph_10, SUM(dph_20) as dph_20, SUM(dph_celk) as dph_celk, COUNT(cislo_fa) as pocetriadkov, prenesene, zasoby, $0 as zaklsamo10, $0 as zaklsamo20, $0 as zaklsamo0, c_dokl FROM expfaktura INTO CURSOR expfa GROUP BY cislo_fa, part_extid READWRITE WHERE EMPTY(prenesene) AND EMPTY(zasoby) and id<>1 AND YEAR(dat_dodani)=m.prrok AND MONTH(dat_dodani)=m.prmesiac;
							UNION ;
							SELECT id, part_meno, part_ico, part_kod, part_extid, dat_vyst, dat_splat, dat_dodani, cislo_pe+SPACE(200) as cislo_pe, "" as cislo_fa, "" as cislo_vs, cislo_fa as cislofa, cislo_vs as cislovs, ;
								zakl_0, zakl_10, zakl_20, zakl_celk, zaokruhlen, dph_10, dph_20, dph_celk, 1 as pocetriadkov, prenesene, zasoby, $0 as zaklsamo10, $0 as zaklsamo20, $0 as zaklsamo0, c_dokl FROM expfaktura WHERE EMPTY(prenesene) AND EMPTY(zasoby) and id=1  AND YEAR(dat_dodani)=m.prrok AND MONTH(dat_dodani)=m.prmesiac
						INDEX ON dat_vyst TAG dat_vyst
						SCAN ALL 
							DO pozavirej WITH "d1, o1"
							m.cislofa=expfa.cislo_fa
							IF  pocetriadkov>1
								REPLACE cislo_pe WITH ""
								SELECT expfaktura
								SCAN FOR cislo_fa=m.cislofa
									m.hladajcdokl=expfaktura.c_dokl
									SELECT expfa
									REPLACE cislo_pe WITH ALLTRIM(cislo_pe)+","+ALLTRIM(expfaktura.cislo_pe)
									IF USED("dokl1")
										=REQUERY("dokl1")
										=REQUERY("obr1")
									ELSE 
										IF m.issql
											USE (m.sqlprefix+"r1doklady") ALIAS dokl1 IN 0
											USE (m.sqlprefix+"r1obraty") ALIAS obr1 IN 0
										ELSE
											USE v1doklady ALIAS dokl1 IN 0
											USE v1obraty ALIAS obr1 IN 0
										ENDIF 
									ENDIF 
									IF USED("d1")
										SELECT d1
										APPEND FROM DBF("dokl1")
									ELSE
										SELECT * FROM dokl1 INTO CURSOR d1 READWRITE 
									ENDIF 
									IF USED("o1")
										SELECT o1
										APPEND FROM DBF("obr1")
									ELSE
										SELECT * FROM obr1 INTO CURSOR o1 READWRITE 
									ENDIF 
								ENDSCAN
							ELSE
								m.hladajcdokl=expfa.c_dokl
								SELECT expfa
								IF USED("dokl1")
									=REQUERY("dokl1")
									=REQUERY("obr1")
								ELSE 
									IF m.issql
										USE (m.sqlprefix+"r1doklady") ALIAS dokl1 IN 0
										USE (m.sqlprefix+"r1obraty") ALIAS obr1 IN 0
									ELSE
										USE v1doklady ALIAS dokl1 IN 0
										USE v1obraty ALIAS obr1 IN 0
									ENDIF 
								ENDIF 
								SELECT * FROM dokl1 INTO CURSOR d1 READWRITE 
								SELECT * FROM obr1 INTO CURSOR o1 READWRITE 
							ENDIF 
							m.hladajpartnerkod=ALLTRIM(expfa.part_kod)
							m.hladajcdokl=expfa.c_dokl
							m.dph_10=expfa.dph_10
							m.dph_20=expfa.dph_20
							m.typexportu=expfa.id				
							SELECT d1
							IF RECCOUNT()>0
								GO TOP 
								m.hladajoperace=d1.operace
								m.hladajplatba=d1.platba
								m.hladajcpartner=d1.c_partner
								SELECT food_dat
								LOCATE FOR c_stredisk=d1.c_stredisk
								m.hladajidman=food_dat.id
								m.hladajcenhlad=""
								
								SELECT *, SPACE(m.sirkastlpcadruh) as druh, SPACE(10) as ucet1, SPACE(10) as ucet, SPACE(10) as hs_md, SPACE(10) as hs_dal, SPACE(10) as md2, SPACE(10) as dal2, SPACE(m.sirkastlpcadruh) as spart, 0.000 as dph, .f. as samozdan, 1.00 as dan_samo FROM o1 INTO CURSOR obrpol READWRITE 
								UPDATE obrpol SET druh=skupiny.druh, spart=skupiny.spart, dph=skupiny.dan01, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo from skupiny WHERE obrpol.c_druhs=skupiny.c_druh
								UPDATE obrpol SET druh=skupiny.druh, spart=skupiny.spart, dph=skupiny.dan01, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo from skupiny WHERE obrpol.c_druh=skupiny.c_druh AND EMPTY(obrpol.druh)
								UPDATE obrpol SET druh=skupiny.druh, spart=skupiny.spart, dph=skupiny.dan01, samozdan=skupiny.samozdan, dan_samo=skupiny.dan_samo from skupiny WHERE obrpol.c_druhk=skupiny.c_druh AND EMPTY(obrpol.druh)
								SELECT obrpol
								REPLACE FOR EMPTY(dan_samo) dan_samo WITH 1
								REPLACE dph WITH dan_samo FOR !EMPTY(samozdan)
								REPLACE druh WITH m.hladajplatba+" "+druh FOR operace="PE"
								REPLACE spart WITH m.hladajplatba+" "+spart FOR operace="PE"
								IF LOWER(m.gcuct_pole)="druh"
									SELECT disti druh FROM obrpol INTO CURSOR obrdruhy READWRITE 
								ELSE
									SELECT disti spart as druh FROM obrpol INTO CURSOR obrdruhy READWRITE 
								ENDIF 
								m.pokracuj=.t.
								SELECT obrdruhy
								SCAN ALL 
									m.hladajdruh2=obrdruhy.druh
									m.hladajdruh=obrdruhy.druh
									m.hladajpartner=LEFT(expfa.part_meno,30)
									m.hladajpartner2=LEFT(expfa.part_meno,30)
									IF USED("uexobr1")
										=REQUERY("uexobr1")
									ELSE
										IF m.issql
											USE (m.sqlprefix+"ruexobr1") ALIAS uexobr1 IN 0
										ELSE
											IF !USED("u_ex_obr")
												USE (m.gcucto_path+"u_ex_obr") IN 0
											ENDIF 
											USE vuexobr1 ALIAS uexobr1 IN 0
										ENDIF 
									ENDIF
									IF RECCOUNT("uexobr1")>0
										SELECT uexobr1
										GO TOP 
										IF !EMPTY(uexobr1.stare)
											SELECT obrpol
											IF LOWER(m.gcuct_pole)="druh"
												 REPLACE ucet WITH uexobr1.md, ucet1 WITH uexobr1.dal, hs_md WITH uexobr1.hs_md, hs_dal WITH uexobr1.hs_dal, md2 WITH uexobr1.md2, dal2 WITH uexobr1.dal2 FOR druh=m.hladajdruh2
											ELSE
												 REPLACE ucet WITH uexobr1.md, ucet1 WITH uexobr1.dal, hs_md WITH uexobr1.hs_md, hs_dal WITH uexobr1.hs_dal, md2 WITH uexobr1.md2, dal2 WITH uexobr1.dal2 FOR spart=m.hladajdruh2
											ENDIF 
										ELSE
											IF m.pokracuj
												=MESSAGEBOX(jaz("form_neda_sa_urobit_export")+CHR(10)+jaz("form_nastavte_ucty_pre")+CHR(10)+jaz("rep_manager")+m.hladajidman+", "+jaz("rep_operacia")+":"+m.hladajoperace+CHR(10)+jaz("form partner")+":"+ALLTRIM(m.hladajpartner2)+CHR(10)+;
													IIF(LOWER(m.gcuct_pole)="druh",jaz("rep_druh")+":",jaz("rep_spart")+":")+ALLTRIM(m.hladajdruh2),64,"FoodMan",2000)
											ENDIF 
											m.pokracuj=.f.
										ENDIF 
									ELSE
										m.hladajpartner="*"
										=REQUERY("uexobr1")
										IF RECCOUNT("uexobr1")>0
											SELECT uexobr1
											GO TOP 
											IF !EMPTY(uexobr1.stare)
												SELECT obrpol
												IF LOWER(m.gcuct_pole)="druh"
													 REPLACE ucet WITH uexobr1.md, ucet1 WITH uexobr1.dal, hs_md WITH uexobr1.hs_md, hs_dal WITH uexobr1.hs_dal, md2 WITH uexobr1.md2, dal2 WITH uexobr1.dal2 FOR druh=m.hladajdruh2
												ELSE
													 REPLACE ucet WITH uexobr1.md, ucet1 WITH uexobr1.dal, hs_md WITH uexobr1.hs_md, hs_dal WITH uexobr1.hs_dal, md2 WITH uexobr1.md2, dal2 WITH uexobr1.dal2 FOR spart=m.hladajdruh2
												ENDIF 
											ELSE 
												IF m.pokracuj
													=MESSAGEBOX("Nedá sa urobiť export."+CHR(10)+"Nastavte najprv účty pre:"+CHR(10)+"Sklad:"+m.hladajidman+", Operácia:"+m.hladajoperace+CHR(10)+"Partner:"+ALLTRIM(m.hladajpartner2)+CHR(10)+;
														IIF(LOWER(m.gcuct_pole)="druh","Druh:","Spart:")+ALLTRIM(m.hladajdruh2),64,"FoodMan",2000)
												ENDIF 
												m.pokracuj=.f.
											ENDIF 
										ELSE
											m.hladajdruh=ALLTRIM(m.hladajplatba+" "+"*")
											m.hladajpartner=m.hladajpartner2
											=REQUERY("uexobr1")
											IF RECCOUNT("uexobr1")>0
												SELECT uexobr1
												GO TOP 
												IF !EMPTY(uexobr1.stare)
													SELECT obrpol
													IF LOWER(m.gcuct_pole)="druh"
														 REPLACE ucet WITH uexobr1.md, ucet1 WITH uexobr1.dal, hs_md WITH uexobr1.hs_md, hs_dal WITH uexobr1.hs_dal, md2 WITH uexobr1.md2, dal2 WITH uexobr1.dal2 FOR druh=m.hladajdruh2
													ELSE
														 REPLACE ucet WITH uexobr1.md, ucet1 WITH uexobr1.dal, hs_md WITH uexobr1.hs_md, hs_dal WITH uexobr1.hs_dal, md2 WITH uexobr1.md2, dal2 WITH uexobr1.dal2 FOR spart=m.hladajdruh2
													ENDIF 
												ELSE 
													IF m.pokracuj
														=MESSAGEBOX("Nedá sa urobiť export."+CHR(10)+"Nastavte najprv účty pre:"+CHR(10)+"Sklad:"+m.hladajidman+", Operácia:"+m.hladajoperace+CHR(10)+"Partner:"+ALLTRIM(m.hladajpartner2)+CHR(10)+;
															IIF(LOWER(m.gcuct_pole)="druh","Druh:","Spart:")+ALLTRIM(m.hladajdruh2),64,"FoodMan",2000)
													ENDIF 
													m.pokracuj=.f.
												ENDIF 
													
											ELSE
												m.hladajpartner="*"
												=REQUERY("uexobr1")
												IF RECCOUNT("uexobr1")>0
													SELECT uexobr1
													GO TOP 
													SELECT obrpol
													IF LOWER(m.gcuct_pole)="druh"
														 REPLACE ucet WITH uexobr1.md, ucet1 WITH uexobr1.dal, hs_md WITH uexobr1.hs_md, hs_dal WITH uexobr1.hs_dal, md2 WITH uexobr1.md2, dal2 WITH uexobr1.dal2 FOR druh=m.hladajdruh2
													ELSE
														 REPLACE ucet WITH uexobr1.md, ucet1 WITH uexobr1.dal, hs_md WITH uexobr1.hs_md, hs_dal WITH uexobr1.hs_dal, md2 WITH uexobr1.md2, dal2 WITH uexobr1.dal2 FOR spart=m.hladajdruh2
													ENDIF 
												ELSE
													INSERT INTO uexobr1 (id_man, operace, druh, partner, cen_hlad, co, pz, poznamka) VALUES ;
														(m.hladajidman, m.hladajoperace, m.hladajdruh2, m.hladajpartner2, "","prachy",'operace +"|"+partner+"|"+druh',"OBR "+m.hladajidman+" "+m.hladajoperace+" "+m.hladajpartner2)
													=tux(.t.,.t.,"uexobr1")
													=REQUERY("uexobr1")
													IF m.pokracuj
														=MESSAGEBOX(jaz("form_neda_sa_urobit_export")+CHR(10)+jaz("form_nastavte_ucty_pre")+CHR(10)+jaz("rep_manager")+m.hladajidman+", "+jaz("rep_operacia")+":"+m.hladajoperace+CHR(10)+jaz("form partner")+":"+ALLTRIM(m.hladajpartner2)+CHR(10)+;
															IIF(LOWER(m.gcuct_pole)="druh",jaz("rep_druh")+":",jaz("rep_spart")+":")+ALLTRIM(m.hladajdruh2),64,"FoodMan",2000)
													ENDIF 
													m.pokracuj=.f.
												ENDIF 
											ENDIF 
										ENDIF 
									ENDIF 	
									SELECT obrdruhy
								ENDSCAN 
								IF m.pokracuj
									SELECT obrpol
									GO TOP 
									m.ucet1=obrpol.ucet1
									IF INLIST(m.typexportu, 0, 2)
										DO kros_faktura_01
									ENDIF 
									IF INLIST(m.typexportu, 1)
										DO kros_intdokl_01
									ENDIF 
									SELECT obrpol
									SELECT ucet, SUM(mnozstvi*cena) as ciastka, SUM(mnozstvi*cena_part) as ciastka_part, hs_md, dph, hs_dal, md2, dal2 FROM obrpol INTO CURSOR obrpol1 GROUP BY ucet, dph, hs_md, hs_dal, md2, dal2
									DO kros_intdokl_02
									USE IN obrpol1
								ENDIF 
								USE IN obrpol
								SELECT expfaktura
								REPLACE prenesene WITH .t. FOR cislo_fa=m.cislofa
								IF m.issql
									=tux(.f.,.t.,"expfaktura")
								ENDIF 
							ENDIF 
							DO pozavirej WITH "obrdruhy, obrpol"
						ENDSCAN 
						= FCLOSE(m.lihandle)
						IF FILE(m.sfile)
							IF !EMPTY(m.uct_email_sklady)
								DO odosli_export_mailom WITH m.sfile, m.hotel_name, m.uct_email_sklady
							ENDIF
						ENDIF 
						DO pozavirej WITH "uexobr1, dokl1, obr1, food_dat, skupiny, exp_faktura, expfaktura, prenosy"
					ENDIF 
				ENDIF 
			ENDIF 
			DO pozavirej WITH "vybr"
	ENDCASE 
ELSE
	MESSAGEBOX(jaz("form_no_faktury_na_export"),64,"FoodMan",2000)
ENDIF
DO pozavirej WITH "expfaktura, doklady, obraty, skupiny, food_dat, partneri, karty, expfa, uctexpo"



PROCEDURE kros_faktura_01
m.uct00="R01"+CHR(9) &&udaje
m.uct00=m.uct00+CHR(9) &&cislo faktury
IF EMPTY(expfa.part_ico)
	m.uct00=m.uct00+ALLTRIM(expfa.part_meno)+CHR(9) &&partner
ELSE
	m.uct00=m.uct00+""+CHR(9) &&partner
ENDIF 
m.uct00=m.uct00+ALLTRIM(expfa.part_ico)+CHR(9) &&partner_ico
m.uct00=m.uct00+DTOC(expfa.dat_vyst)+CHR(9) &&datum
m.uct00=m.uct00+DTOC(expfa.dat_splat)+CHR(9) &&datum
m.uct00=m.uct00+DTOC(expfa.dat_dodani)+CHR(9) &&datum
m.uct00=m.uct00+STR(expfa.zakl_10,10,2)+CHR(9) &&zaklad_10
m.uct00=m.uct00+STR(expfa.zakl_20,10,2)+CHR(9) &&zaklad_20
m.uct00=m.uct00+STR(expfa.zakl_0,10,2)+CHR(9) &&zaklad_0
m.uct00=m.uct00+STR(0,10,2)+CHR(9) &&zaklad_neobsahuje
m.uct00=m.uct00+STR(m.uctdphlo*100-100,10,2)+CHR(9) &&sadzba DPH nizsia
m.uct00=m.uct00+STR(m.uctdphhi*100-100,10,2)+CHR(9) &&sadzba DPH vyssia
m.uct00=m.uct00+STR(expfa.dph_10,10,2)+CHR(9) &&dph_10
m.uct00=m.uct00+STR(expfa.dph_20,10,2)+CHR(9) &&dph_20
m.uct00=m.uct00+STR(expfa.zaokruhlen,10,2)+CHR(9) &&halierove vyrovnanie
m.uct00=m.uct00+STR(expfa.zakl_celk+expfa.dph_celk,10,2)+CHR(9) &&celkom suma
m.uct00=m.uct00+"14"+CHR(9) &&typ dokladu
m.uct00=m.uct00+m.gcuct_evidencia3+CHR(9) &&kod evidencia
m.uct00=m.uct00+m.gcuct_cisrad3+CHR(9) &&kod ciselna rada			
m.uct00=m.uct00+""+CHR(9) &&partner_kod externy
m.uct00=m.uct00+""+CHR(9) &&C021_PartnerKod
m.uct00=m.uct00+""+CHR(9) &&C045_PartnerFirmaStredisko
m.uct00=m.uct00+""+CHR(9) &&C046_PartnerFirmaPrevadzka
m.uct00=m.uct00+""+CHR(9) &&C047_PartnerUlica
m.uct00=m.uct00+""+CHR(9) &&C048_PartnerPSC
m.uct00=m.uct00+""+CHR(9) &&C049_PartnerMesto
m.uct00=m.uct00+""+CHR(9) &&C053_PartnerDIC
m.uct00=m.uct00+""+CHR(9) &&C059_CasVyst
m.uct00=m.uct00+""+CHR(9) &&C095_DodaciePodmienky
m.uct00=m.uct00+""+CHR(9) &&C098_Uvod
m.uct00=m.uct00+""+CHR(9) &&C099_Zaver
m.uct00=m.uct00+""+CHR(9) &&C104_DodaciList
m.uct00=m.uct00+""+CHR(9) &&C105_Objednavka
m.uct00=m.uct00+""+CHR(9) &&C106_Vystavil
m.uct00=m.uct00+"0008"+CHR(9) &&C111_Konstantny
m.uct00=m.uct00+""+CHR(9) &&C112_Specificky
m.uct00=m.uct00+""+CHR(9) &&C114_FormaUhrady
m.uct00=m.uct00+""+CHR(9) &&C115_SposobDopravy
m.uct00=m.uct00+"EUR"+CHR(9) &&C200_Mena
m.uct00=m.uct00+"1"+CHR(9) &&C201_Mnozstvo_Jednotky
m.uct00=m.uct00+"1"+CHR(9) &&C202_Kurz
m.uct00=m.uct00+STR(expfa.zakl_celk+expfa.dph_celk,10,2)+CHR(9) &&C211_SumaSpolu
m.uct00=m.uct00+SUBSTR(expfa.cislo_vs,3)+CHR(9) &&C117_ZakazkovyList
m.uct00=m.uct00+"Prijemka "+ALLTRIM(expfa.cislo_pe)+CHR(9) &&C097_Poznamka
m.uct00=m.uct00+ALLTRIM(m.kros_text_faktury)+CHR(9) &&C116_PredmetFakturacie
m.uct00=m.uct00+""+CHR(9) &&C050_PartnerStat
m.uct00=m.uct00+""+CHR(9) &&C024_KodStatuDPH
m.uct00=m.uct00+""+CHR(9) &&C025_PartnerIDpreDPH
m.uct00=m.uct00+""+CHR(9) &&C155_DodCisloUctu
m.uct00=m.uct00+""+CHR(9) &&C156_DodBanka
m.uct00=m.uct00+""+CHR(9) &&C157_DodPobocka
m.uct00=m.uct00+""+CHR(9) &&C180_PAStat
m.uct00=m.uct00+""+CHR(9) &&C028_KodVystavil
m.uct00=m.uct00+""+CHR(9) &&C041_PartnerMenoSkratka
m.uct00=m.uct00+""+CHR(9) &&C158_DodSWIFT
m.uct00=m.uct00+""+CHR(9) &&C159_DodIBAN
m.uct00=m.uct00+""+CHR(9) &&C160_DodKodStatuDPH
m.uct00=m.uct00+""+CHR(9) &&C161_DodIDpreDPH
m.uct00=m.uct00+""+CHR(9) &&C150_DodStat
m.uct00=m.uct00+"-2"+CHR(9) &&C221_Zaokruhlenie
m.uct00=m.uct00+"3"+CHR(9) &&C222_SposobZaokruhlenia
m.uct00=m.uct00+""+CHR(9) &&C052_PartnerICOPoradoveCislo
m.uct00=m.uct00+""+CHR(9) &&C225_ZaokruhleniePolozky
m.uct00=m.uct00+""+CHR(9) &&C096_ZalohaMemo
m.uct00=m.uct00+""+CHR(9) &&C224_Zaloha
m.uct00=m.uct00+"1"+CHR(9) &&C120_SposobVypoctuDPH
m.uct00=m.uct00+""+CHR(9) &&C235_StarySposobVypoctuDPHAkoKasa
m.uct00=m.uct00+DTOC(expfa.dat_vyst)+CHR(9) &&C069_DenVystDF; 
m.uct00=m.uct00+""+CHR(9) &&C236_UhradeneCezECR
m.uct00=m.uct00+ALLTRIM(expfa.cislo_vs)+" "+CHR(9) &&C110_VariabilnySymbol
m.uct00=m.uct00+ALLTRIM(expfa.cislo_fa)+" "+CHR(9) &&Cislo faktury
m.uct01=m.uct00+" "+CHR(9) &&C110_VariabilnySymbol
m.uct01=m.uct00+" "+CHR(9) &&Cislo faktury
= FPUTS(m.lihandle, m.uct00)

PROCEDURE kros_intdokl_01
* Export do KROSu - pokladnicny doklad
m.uct00="R01"+CHR(9) &&druhy riadok
m.uct00=m.uct00+"160"+CHR(9) &&typ dokladu - pokladnicny doklad
m.uct00=m.uct00+m.gcuct_evidencia4+CHR(9) &&kod evidencie
m.uct00=m.uct00+m.gcuct_cisrad4+CHR(9) &&kod cisleneho radu
m.uct00=m.uct00+ALLTRIM(expfa.cislo_pe)+CHR(9) &&cislo externe
m.uct00=m.uct00+""+CHR(9) &&cislo interne - skusim nechat praydne, nech si to ocisluje kros sam
m.uct00=m.uct00+CHR(9) &&meno firmy
m.uct00=m.uct00+CHR(9) &&ICO
m.uct00=m.uct00+CHR(9) &&DIC
m.uct00=m.uct00+DTOC(expfa.dat_vyst)+CHR(9) &&datum vystavenia
m.uct00=m.uct00+CHR(9) &&datum prijatia
m.uct00=m.uct00+DTOC(expfa.dat_splat)+CHR(9) &&datum splatnosti
m.uct00=m.uct00+DTOC(expfa.dat_dodani)+CHR(9) &&datum uskutocnenia zdanitelneho plnenia
m.uct00=m.uct00+DTOC(expfa.dat_dodani)+CHR(9) &&datum uskutocnenia uctovneho pripadu
m.uct00=m.uct00+"EUR"+CHR(9) &&mena
m.uct00=m.uct00+"1"+CHR(9) &&mnozstvo jednotky
m.uct00=m.uct00+"1"+CHR(9) &&kurz NBS
m.uct00=m.uct00+"0"+CHR(9) &&kurz banka
m.uct00=m.uct00+ALLTRIM(STR(exp.zakl_celk+exp.dph_celk,15,2))+CHR(9) &&suma spolu CM
m.uct00=m.uct00+ALLTRIM(STR(expfa.zakl_celk+expfa.dph_celk,15,2))+CHR(9) &&suma spolu TM
m.uct00=m.uct00+ALLTRIM(STR(m.uctdphlo*100-100,5,0))+CHR(9) &&sadzba nizsia
m.uct00=m.uct00+ALLTRIM(STR(m.uctdphhi*100-100,5,0))+CHR(9) &&sadzba vyssia
m.uct00=m.uct00+ALLTRIM(STR(expfa.zakl_10,15,2))+CHR(9) &&zaklad nizsia
m.uct00=m.uct00+ALLTRIM(STR(expfa.zakl_20,15,2))+CHR(9) &&zaklad vyssia
m.uct00=m.uct00+ALLTRIM(STR(expfa.zakl_0,15,2))+CHR(9) &&zaklad 0
m.uct00=m.uct00+ALLTRIM(STR(0,15,2))+CHR(9) &&zaklad neobsahuje
m.uct00=m.uct00+ALLTRIM(STR(expfa.dph_10,15,2))+CHR(9) &&suma DPH nizsia
m.uct00=m.uct00+ALLTRIM(STR(expfa.dph_20,15,2))+CHR(9) &&suma DPH vyssia
m.uct00=m.uct00+ALLTRIM(STR(expfa.zaokruhlen,15,2))+CHR(9) &&halierove vyrovnanie
m.uct00=m.uct00+"FoodMan"+CHR(9)  && zaevidoval
*!*	m.uct00=m.uct00+""+CHR(9)  && konstantny symbol
*!*	m.uct00=m.uct00+""+CHR(9)  && specificky symbol
*!*	m.uct00=m.uct00+""+CHR(9)  && interne cislo uhradzaneho dokladu
*!*	m.uct00=m.uct00+""+CHR(9)  && externe cislo uhradzaneho dokladu
*!*	IF UPPER(m.tdkl)="PD"
*!*		m.uct00=m.uct00+IIF(uct_polozky.ciastka>=0,"+","-")+CHR(9)  && pre pokladnicne doklady znamienko dokladu
*!*	ELSE 
*!*		m.uct00=m.uct00+""+CHR(9)  &&  pre pokladnicne doklady znamienko dokladu
*!*	ENDIF 
*!*	m.uct00=m.uct00+""+CHR(9)  && cislo uctu partnera
*!*	m.uct00=m.uct00+""+CHR(9)  && interne cislo partnera
*!*	m.uct00=m.uct00+""+CHR(9)  && kod partnera
*!*	m.uct00=m.uct00+""+CHR(9)  && cas vystavenia
*!*	m.uct00=m.uct00+""+CHR(9)  && poznamka
*!*	m.uct00=m.uct00+""+CHR(9)  && text hlavicky
*!*	m.uct00=m.uct00+"0"+CHR(9) && splatnost
*!*	m.uct00=m.uct00+""+CHR(9)  && prijate od
*!*	m.uct00=m.uct00+""+CHR(9)  && kod ic dph 
*!*	m.uct00=m.uct00+""+CHR(9)  && ic dph 
*!*	m.uct00=m.uct00+"0"+CHR(9)  && suma preddavku
*!*	m.uct00=m.uct00+""+CHR(9)  && ico poradove cislo
*!*	m.uct00=m.uct00+""+CHR(9)  && kod schvalil
*!*	m.uct00=m.uct00+""+CHR(9)  && schvalil
*!*	m.uct00=m.uct00+""+CHR(9)  && kod zeavidoval
*!*	m.uct00=m.uct00+"0"+CHR(9)  && priznak neuctovat
*!*	m.uct00=m.uct00+""+CHR(9)  && kod zauctoval 
*!*	m.uct00=m.uct00+""+CHR(9)  && zauctoval
m.uct00=STRTRAN(m.uct00,",",".")
= FPUTS(m.lihandle, m.uct00)


PROCEDURE kros_intdokl_02
* Export do KROSu - sklady
SELECT obrpol1
SCAN ALL 
	m.uct00="R02"+CHR(9) &&udaje / polozky faktury
	m.uct00=m.uct00+"Tovar "+ALLTRIM(STR(obrpol1.dph*100-100,2,0))+"%DPH"+CHR(9) 		&&C109_Nazov
	m.uct00=m.uct00+"1"+CHR(9) 					&&C100_Mnozstvo
	m.uct00=m.uct00+"ks"+CHR(9) 				&&C111_Jednotka
	m.uct00=m.uct00+ALLTRIM(STR(obrpol1.ciastka,10,2))+CHR(9) 	&&C104_JCenaKonecnaBezDPH
	DO CASE 
		CASE obrpol1.dph=m.uctdphhi
			m.uct00=m.uct00+"V"+CHR(9) 					&&C107_SadzbaDPH
		CASE obrpol1.dph=m.uctdphlo
			m.uct00=m.uct00+"N"+CHR(9) 					&&C107_SadzbaDPH
		CASE obrpol1.dph=1.00
			m.uct00=m.uct00+"X"+CHR(9) 					&&C107_SadzbaDPH
		OTHERWISE 
			m.uct00=m.uct00+"V"+CHR(9) 					&&C107_SadzbaDPH
	ENDCASE 
	m.uct00=m.uct00+ALLTRIM(STR(obrpol1.ciastka,10,2))+CHR(9) 					&&C101_JCenaSkladova
	m.uct00=m.uct00+""+CHR(9) 					&&C102_JCenaCennikova
	m.uct00=m.uct00+""+CHR(9) 					&&C103_PercZlava
	m.uct00=m.uct00+"V"+CHR(9) 					&&C108_TypPolozky
	m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)
	m.uct00=m.uct00+LEFT(obrpol1.ucet,3)+CHR(9) 					&&C225_SyntetickyUcet
	m.uct00=m.uct00+SUBSTR(obrpol1.ucet,4,3)+CHR(9) 					&&C226_AnalytickyUcet
	m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)
	m.uct00=m.uct00+ALLTRIM(obrpol1.hs_md)+CHR(9)+""+CHR(9) && kod strediska
	m.uct00=m.uct00+ALLTRIM(obrpol1.hs_dal)+CHR(9)+""+CHR(9) && kod zakazky
	m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)
	DO CASE 
		CASE obrpol1.dph=m.uctdphhi
			m.uct00=m.uct00+ALLTRIM(m.kros_fa_hi_dp_riadok)+CHR(9)					&&C245_OddielKVDPH
		CASE obrpol1.dph=m.uctdphlo
			m.uct00=m.uct00+ALLTRIM(m.kros_fa_lo_dp_riadok)+CHR(9)					&&C245_OddielKVDPH
		CASE obrpol1.dph=1.00
			m.uct00=m.uct00+ALLTRIM(m.kros_fa_0_dp_riadok)+CHR(9)					&&C245_OddielKVDPH
		OTHERWISE 
			m.uct00=m.uct00+ALLTRIM(m.kros_fa_hi_dp_riadok)+CHR(9)					&&C245_OddielKVDPH
	ENDCASE 
	m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)
	m.uct00=m.uct00+"ks"+CHR(9) 				&&C124_MJ
	m.uct00=m.uct00+"1"+CHR(9) 					&&C125_MJ_Mnozstvo
	m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)
	m.uct00=m.uct00+"-2"+CHR(9) 				&&C105_Zaokruhlenie
	m.uct00=m.uct00+"3"+CHR(9) 					&&C106_SposobZaokruhlenia	
	m.uct00=m.uct00+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)+""+CHR(9)
	DO CASE 
		CASE obrpol1.dph=m.uctdphhi
			m.uct00=m.uct00+ALLTRIM(m.kros_fa_hi_kv_dph)+CHR(9)					&&C245_OddielKVDPH
		CASE obrpol1.dph=m.uctdphlo
			m.uct00=m.uct00+ALLTRIM(m.kros_fa_lo_kv_dph)+CHR(9)					&&C245_OddielKVDPH
		CASE obrpol1.dph=1.00
			m.uct00=m.uct00+ALLTRIM(m.kros_fa_0_kv_dph)+CHR(9)					&&C245_OddielKVDPH
		OTHERWISE 
			m.uct00=m.uct00+ALLTRIM(m.kros_fa_hi_kv_dph)+CHR(9)					&&C245_OddielKVDPH
	ENDCASE 
	= FPUTS(m.lihandle, m.uct00)
ENDSCAN 
