*:*****************************************************************************
*: Procedure file: PRN_OBRA.PRG
*:*****************************************************************************
PARAMETER c_dokl
PRIVATE old_sel, o_oerr, aaaaa, m.hladajcdokl, m.hladajcpartner, m.bolikarty, m.bolipartneri, m.boliskupiny, m.bolidoklady, m.boliobraty, m.boladb, m.obrazok
PRIVATE m.hladajcstredisk
m.hladajcstredisk=m.gic_stredisk
m.obrazok=""
m.boladb=.F.
liold_sel = SELECT()
m.repo_txt=""
SET CENTURY ON
SET DATE GERMAN
SELECT 0
m.hladajcdokl=m.c_dokl
m.o_sel=SELECT()
SELECT 0
m.gctxt_summary=""
DO open_database
IF m.issql
	IF "SKL" $ m.gcpgm_param
		USE (m.sqlprefix+"rprnobraskl"+m.sqlsuffix) ALIAS doklad
	ELSE
		USE (m.sqlprefix+"rprnobra"+m.sqlsuffix) ALIAS doklad
	ENDIF
	IF RECCOUNT()=0
		INSERT INTO doklad (c_dokl, c_karty, nazev, spart) VALUES (m.hladajcdokl, 0, jaz("prg_doklad_stornovany"),"")
	ENDIF
ELSE
	IF USED("partneri")
		m.bolipartneri=.T.
	ELSE
		USE (m.fn_partneri) ALIAS partneri IN 0
		m.bolipartneri=.F.
	ENDIF
	IF USED("karty")
		m.bolikarty=.T.
	ELSE
		USE (m.fn_karty) ALIAS karty IN 0
		m.bolikarty=.F.
	ENDIF
	IF USED("skupiny")
		m.boliskupiny=.T.
	ELSE
		USE (m.fn_skupiny) ALIAS skupiny IN 0
		m.boliskupiny=.F.
	ENDIF
	IF USED("doklady")
		m.bolidoklady=.T.
	ELSE
		USE (m.fn_dokl_s) ALIAS doklady IN 0
		m.bolidoklady=.F.
	ENDIF
	IF USED("obraty")
		m.boliobraty=.T.
	ELSE
		USE (m.fn_obra_s) ALIAS obraty IN 0
		m.boliobraty=.F.
	ENDIF

	SELECT 0
	IF "SKL" $ m.gcpgm_param
		USE vprnobraskl ALIAS doklad
	ELSE
		USE vprnobra ALIAS doklad
	ENDIF
ENDIF
IF RECCOUNT() = 0
	WAIT jaz("prg_doklad")+"  " + ALLT(STR(m.c_dokl))+ " "+jaz("prg_stornovan") WINDOW TIME 1
ELSE
	sc = "cena" + m.sankcnicena
	REPLACE sankcni WITH cena&sankcnicena ALL
	REPLACE FOR EMPTY(bar_kod2) bar_kod2 WITH ALLTRIM(kod)
	GO TOP
	m.hladajcpartner=doklad.c_stredisk
	SELECT 0
	IF m.issql
		USE (m.sqlprefix+"rpartner") ALIAS ddd
	ELSE
		USE vpartner ALIAS ddd
	ENDIF
	lcnazevstrediska = ddd.partner
	USE
	** tohle tady je, aby se na automaticke int. prijemce spravne tiskl nazev strediska ** konec

	SELECT doklad
	REPLACE FOR ISNULL(nazev)   nazev   WITH "   ---- zruseno ---- "
	REPLACE FOR ISNULL(partner) partner WITH "   ----   "
	REPLACE FOR ISNULL(druh)    druh    WITH "   ----   "
	REPLACE FOR ISNULL(c_karty) c_karty WITH 0
	REPLACE FOR ISNULL(poradi) 	poradi	WITH 0
	REPLACE FOR ISNULL(spart)   spart    WITH "---"
	GO TOP
	SCATTER FIELD c_partner, operace, ico, dic MEMVAR
	SET FILTER TO (mnozstvi # 0) .OR. (c_karty = 0)
	SUM mnozstvi * cena_part TO prachy_part_celkem

	DO CASE
		CASE m.operace = "PI"
			SELECT 0
			IF m.issql
				USE (m.sqlprefix+"rprnobramaxpi"+m.sqlsuffix) ALIAS minula_inv
			ELSE
				USE vprnobramaxpi ALIAS minula_inv
			ENDIF
			IF prazdna()
				c_dokl2 = 0
				datum_dok2 = {}
			ELSE
				GO TOP
				SCATTER MEMVAR
			ENDIF
			USE IN minula_inv
			SELECT doklad
			IF prazdna()
				SET FILTER TO
				GO TOP
				SCATTER MEMVAR
				INSERT INTO doklad FROM MEMVAR
				REPLACE nazev WITH jaz("prg_rep_neni_inv_rozdil"), c_karty WITH 999999999, mnozstvi WITH 0, cena WITH 0, zustatek WITH 0, cena_prum WITH 0
				SET FILTER TO c_karty >= 999999999
			ENDIF
			REPLACE ALL naz1 WITH IIF(mnozstvi<0, "A", "B")
			SELECT 0

			SELECT SPACE(30) AS sestava,.F. AS lbl,1 as volba INTO CURSOR selinvzost FROM doklad WHERE .F. READWRITE
			INSERT INTO selinvzost (sestava,lbl) VALUES (jaz("inv_zostava_1"),.F.)
			INSERT INTO selinvzost (sestava,lbl) VALUES (jaz("inv_zostava_2"),.F.)
			INSERT INTO selinvzost (sestava,lbl) VALUES (jaz("inv_zostava_3"),.F.)
			INSERT INTO selinvzost (sestava,lbl) VALUES (jaz("inv_zostava_4"),.F.)
			INSERT INTO selinvzost (sestava,lbl) VALUES (jaz("inv_zostava_5"),.F.)
			INSERT INTO selinvzost (sestava,lbl) VALUES (jaz("inv_zostava_6"),.F.)
			INSERT INTO selinvzost (sestava,lbl) VALUES (jaz("inv_zostava_7"),.F.)
			DO FORM selpartn WITH "selinvzost","sestava"
			SELECT selinvzost
			SCAN FOR !EMPTY(lbl)
				DO CASE
					CASE RECNO()=1
						SELECT doklad
						if !prazdna()
							DO CASE 
								CASE selinvzost.volba=1
									INDEX ON LEFT(naz1, 1) + druh + nazev TAG qwe
								CASE selinvzost.volba=2
									INDEX ON LEFT(naz1, 1) + nazev TAG qwe
								CASE selinvzost.volba=3
									INDEX ON LEFT(naz1, 1) + STR(mnozstvi,15,4) TAG qwe
								CASE selinvzost.volba=4
									INDEX ON LEFT(naz1, 1) + STR(cena,15,4) TAG qwe
								CASE selinvzost.volba=5
									INDEX ON LEFT(naz1, 1) + STR(round(mnozstvi * cena, 2),15,4) TAG qwe
							ENDCASE 
						ENDIF 
						m.gcrepo_txt = jaz("prg_rep_skladova_cena")
						DO pr_r_dokl WITH "dok_pi"
					CASE RECNO()=2
						SELECT doklad
						if !prazdna()
							DO CASE 
								CASE selinvzost.volba=1
									INDEX ON LEFT(naz1, 1) + druh + nazev TAG qwe
								CASE selinvzost.volba=2
									INDEX ON LEFT(naz1, 1) + nazev TAG qwe
								CASE selinvzost.volba=3
									INDEX ON LEFT(naz1, 1) + STR(mnozstvi,15,4) TAG qwe
								CASE selinvzost.volba=4
									INDEX ON LEFT(naz1, 1) + STR(cena,15,4) TAG qwe
								CASE selinvzost.volba=5
									INDEX ON LEFT(naz1, 1) + STR(round(mnozstvi * cena, 2),15,4) TAG qwe
							ENDCASE 
						ENDIF 
						m.gcrepo_txt = jaz("prg_rep_skladova_cena")
						DO pr_r_dokl WITH "dok_pi2"
					CASE RECNO()=3
						SELECT doklad
						if !prazdna()
							DO CASE 
								CASE selinvzost.volba=1
									INDEX ON druh + nazev TAG qwe
								CASE selinvzost.volba=2
									INDEX ON druh + nazev TAG qwe
								CASE selinvzost.volba=3
									INDEX ON druh + STR(mnozstvi,15,4) TAG qwe
								CASE selinvzost.volba=4
									INDEX ON druh + STR(cena,15,4) TAG qwe
								CASE selinvzost.volba=5
									INDEX ON druh + LEFT(naz1, 1) + STR(round(mnozstvi * cena, 2),15,4) TAG qwe
							ENDCASE 
						ENDIF 
						m.gcrepo_txt = jaz("prg_rep_sklad_cena_po_druzich")
						DO pr_r_dokl WITH "dok_pi3"
					CASE RECNO()=4
						SELECT doklad
						SET FILTER TO zustatek # 0 .OR. mnozstvi # 0
						if !prazdna()
							DO CASE 
								CASE selinvzost.volba=1
									INDEX ON LEFT(naz1, 1) + druh + nazev TAG qwe
								CASE selinvzost.volba=2
									INDEX ON LEFT(naz1, 1) + nazev TAG qwe
								CASE selinvzost.volba=3
									INDEX ON LEFT(naz1, 1) + STR(mnozstvi,15,4) TAG qwe
								CASE selinvzost.volba=4
									INDEX ON LEFT(naz1, 1) + STR(cena,15,4) TAG qwe
								CASE selinvzost.volba=5
									INDEX ON LEFT(naz1, 1) + STR(round(mnozstvi * cena, 2),15,4) TAG qwe
							ENDCASE 
						ENDIF 
						m.gcrepo_txt = jaz("prg_rep_skladova_cena_komplet")
						DO pr_r_dokl WITH "dok_pi2"
					CASE RECNO()=5
						SELECT doklad
						SET FILTER TO mnozstvi # 0
						if !prazdna()
							DO CASE 
								CASE selinvzost.volba=1
									INDEX ON LEFT(naz1, 1) + druh + nazev TAG qwe
								CASE selinvzost.volba=2
									INDEX ON LEFT(naz1, 1) + nazev TAG qwe
								CASE selinvzost.volba=3
									INDEX ON LEFT(naz1, 1) + STR(mnozstvi,15,4) TAG qwe
								CASE selinvzost.volba=4
									INDEX ON LEFT(naz1, 1) + STR(cena,15,4) TAG qwe
								CASE selinvzost.volba=5
									INDEX ON LEFT(naz1, 1) + STR(round(mnozstvi * cena, 2),15,4) TAG qwe
							ENDCASE 
						ENDIF 
						m.gcrepo_txt = jaz("prg_sankcni_cena")
						*    *    *    *    *    *    *  devcatka si myslej, ze je blbost plusy ukazovat v nakupce  *    *    *    *    * zacatek
						**                        REPL FOR mnozstvi < 0 cena WITH cena_part
						REPLACE ALL cena WITH sankcni
						*    *    *    *    *    *    *  devcatka si myslej, ze je blbost plusy ukazovat v nakupce  *    *    *    *    * konec
						DO pr_r_dokl WITH "dok_pi2"
					CASE RECNO()=6
						SELECT doklad
						if !prazdna()
							DO CASE 
								CASE selinvzost.volba=1
									INDEX ON LEFT(naz1, 1) + spart + nazev TAG qwe
								CASE selinvzost.volba=2
									INDEX ON LEFT(naz1, 1) + spart + nazev TAG qwe
								CASE selinvzost.volba=3
									INDEX ON LEFT(naz1, 1) + spart + STR(mnozstvi,15,4) TAG qwe
								CASE selinvzost.volba=4
									INDEX ON LEFT(naz1, 1) + spart + STR(cena,15,4) TAG qwe
								CASE selinvzost.volba=5
									INDEX ON LEFT(naz1, 1) + spart + STR(round(mnozstvi * cena, 2),15,4) TAG qwe
							ENDCASE 
						ENDIF 
						m.gcrepo_txt = jaz("prg_rep_sklad_cena_po_spartech")
						DO pr_r_dokl WITH "dok_pi3"
					CASE RECNO()=7
						SELECT doklad
						SET FILTER TO zustatek # 0 .OR. mnozstvi # 0
						if !prazdna()
							DO CASE 
								CASE selinvzost.volba=1
									INDEX ON druh + nazev TAG qwe
								CASE selinvzost.volba=2
									INDEX ON druh + nazev TAG qwe
								CASE selinvzost.volba=3
									INDEX ON druh + STR(mnozstvi,15,4) TAG qwe
								CASE selinvzost.volba=4
									INDEX ON druh + STR(cena,15,4) TAG qwe
								CASE selinvzost.volba=5
									INDEX ON druh + LEFT(naz1, 1) + STR(round(mnozstvi * cena, 2),15,4) TAG qwe
							ENDCASE 
						ENDIF 
						m.gcrepo_txt = jaz("prg_rep_sklad_cena_po_druzich")
						DO pr_r_dokl WITH "dok_pi3"
				ENDCASE
			ENDSCAN
			DO pozavirej WITH "selinvzost"
		CASE m.operace = "PE"
			SELECT doklad
			IF m.is_absolutereader
				PRIVATE ddid, ddvat, ddsubscriptionenddate, ddsubscriptionstartdate, ddontime
				PRIVATE ddtype,	ddnumber, dddocumentdate, ddservicedate, ddpaymentdue, ddreference, ddamount, ddinvoicereference, ddcurency, ddcomment, dditems, ddpieces, ddweight, dddiscount, ddsuperdiscount
				PRIVATE dcdname, dcdstreet, dcdcityarea, dcdcity, dcdcountry, dcdpostalcode, dcdbusinessunit, dcdbustreet, dcdbucityarea, dcdbucity, dcdbucountry, dcdbupostalcode, dcdtelephone, dcdfax, dcdemail, dcdwebpage, dcdvatid, dcdbusinessid, dcdbankaccounttype1, dcdbank1, dcdbankaccount1, dcdswift1, dcdiban1
				PRIVATE didean, didname, didlevel, didprice, didamount, didpacking, didunit, didweight, didvat, diddiscount, didsuperdiscount, didmanufacturedate, didexpirationdate, didcomment

				PRIVATE fddid, fddvat, fddsubscriptionenddate, fddsubscriptionstartdate, fddontime
				PRIVATE fddtype, fddnumber, fdddocumentdate, fddservicedate, fddpaymentdue, fddreference, fddamount, fddinvoicereference, fddcurency, fddcomment, fdditems, fddpieces, fddweight, fdddiscount, fddsuperdiscount
				PRIVATE fdcdname, fdcdstreet, fdcdcityarea, fdcdcity, fdcdcountry, fdcdpostalcode, fdcdbusinessunit, fdcdbustreet, fdcdbucityarea, fdcdbucity, fdcdbucountry, fdcdbupostalcode, fdcdtelephone, fdcdfax, fdcdemail, fdcdwebpage, fdcdvatid, fdcdbusinessid, fdcdbankaccounttype1, fdcdbank1, fdcdbankaccount1, fdcdswift1, fdcdiban1
				PRIVATE fdidean, fdidname, fdidlevel, fdidprice, fdidamount, fdidpacking, fdidunit, fdidweight, fdidvat, fdiddiscount, fdidsuperdiscount, fdidmanufacturedate, fdidexpirationdate, fdidcomment
				PRIVATE m.oldproc
				m.oldproc=SET("procedure")
				SET PROCEDURE TO ar ADDITIVE 

				ddid=0
				ddvat=1
				ddsubscriptionstartdate=2
				ddsubscriptionenddate=3
				ddontime=4

				ddtype=0
				ddnumber=1
				dddocumentdate=2
				ddservicedate=3
				ddpaymentdue=4
				ddreference=5
				ddamount=6
				ddinvoicereference=7
				ddcurency=8
				ddcomment=9
				dditems=10
				ddpieces=11
				ddweight=12
				dddiscount=13
				ddsuperdiscount=14

				dcdname = 0
				dcdstreet=1
				dcdcityarea=2
				dcdcity=3
				dcdcountry=4
				dcdpostalcode=5
				dcdbusinessunit=6
				dcdbustreet=7
				dcdbucityarea=8
				dcdbucity=9
				dcdbucountry=10
				dcdbupostalcode=11
				dcdtelephone=12
				dcdfax=13
				dcdemail=14
				dcdwebpage=15
				dcdvatid=16
				dcdbusinessid=17
				dcdbankaccounttype1=18
				dcdbank1=19
				dcdbankaccount1=20
				dcdswift1=21
				dcdiban1=22

				didean = 0
				didname=1
				didlevel=2
				didprice=3
				didamount=4
				didpacking=5
				didunit=6
				didweight=7
				didvat=8
				diddiscount=9
				didsuperdiscount=10
				didmanufacturedate=11
				didexpirationdate=12
				didcomment=19
				DO ar_ini IN ar
				SELECT doklad
				GO TOP 
				m.fddnumber=doklad.operace+" "+ALLTRIM(STR(doklad.doklad))
				m.fdddocumentdate=doklad.datum_dokl
				m.fddservicedate=doklad.datum_dokl
				m.fddpaymentdue=doklad.datum_dokl
				m.fddreference=ALLTRIM(STR(m.c_dokl))
				m.fddinvoicereference=doklad.pz1
				m.fddcomment=doklad.pz2
				m.fdcdname=doklad.partner
				m.fdcdstreet=doklad.naz1
				m.fdcdcity=doklad.naz2
				m.fdcdfax=doklad.naz3
				m.fdcdemail=doklad.naz4
				m.fdcdbusinessid=doklad.ico
				m.fdcdvatid=doklad.icdph
				m.obrazok=(m.gcpri_path+ALLTRIM(STR(m.c_dokl)))+ALLTRIM(m.semafor_id)
				DO createcode IN ar WITH m.obrazok
				IF !FILE(m.obrazok+".bmp")
					m.obrazok=""
				ELSE
					m.obrazok=m.obrazok+".bmp"
				ENDIF 
				RELEASE ddid, ddvat, ddsubscriptionenddate, ddsubscriptionstartdate, ddontime
				RELEASE ddtype,	ddnumber, dddocumentdate, ddservicedate, ddpaymentdue, ddreference, ddamount, ddinvoicereference, ddcurency, ddcomment, dditems, ddpieces, ddweight, dddiscount, ddsuperdiscount
				RELEASE dcdname, dcdstreet, dcdcityarea, dcdcity, dcdcountry, dcdpostalcode, dcdbusinessunit, dcdbustreet, dcdbucityarea, dcdbucity, dcdbucountry, dcdbupostalcode, dcdtelephone, dcdfax, dcdemail, dcdwebpage, dcdvatid, dcdbusinessid, dcdbankaccounttype1, dcdbank1, dcdbankaccount1, dcdswift1, dcdiban1
				RELEASE didean, didname, didlevel, didprice, didamount, didpacking, didunit, didweight, didvat, diddiscount, didsuperdiscount, didmanufacturedate, didexpirationdate, didcomment

				RELEASE fddid, fddvat, fddsubscriptionenddate, fddsubscriptionstartdate, fddontime
				RELEASE fddtype, fddnumber, fdddocumentdate, fddservicedate, fddpaymentdue, fddreference, fddamount, fddinvoicereference, fddcurency, fddcomment, fdditems, fddpieces, fddweight, fdddiscount, fddsuperdiscount
				RELEASE fdcdname, fdcdstreet, fdcdcityarea, fdcdcity, fdcdcountry, fdcdpostalcode, fdcdbusinessunit, fdcdbustreet, fdcdbucityarea, fdcdbucity, fdcdbucountry, fdcdbupostalcode, fdcdtelephone, fdcdfax, fdcdemail, fdcdwebpage, fdcdvatid, fdcdbusinessid, fdcdbankaccounttype1, fdcdbank1, fdcdbankaccount1, fdcdswift1, fdcdiban1
				RELEASE fdidean, fdidname, fdidlevel, fdidprice, fdidamount, fdidpacking, fdidunit, fdidweight, fdidvat, fdiddiscount, fdidsuperdiscount, fdidmanufacturedate, fdidexpirationdate, fdidcomment
				SET PROCEDURE TO &oldproc
			ENDIF 
			IF !prazdna()
				INDE ON EVAL(m.doklrazeni) TAG qwe
			ENDIF 
			PUBLIC m.haccp1, m.haccp2,m.haccp3, m.haccp4,m.haccp5, m.haccp6, m.haccp7, m.haccp_poznamka
			PRIVATE tlachaccp
			IF m.is_haccp
				m.haccp1=1
				m.haccp2=1
				m.haccp3=1
				m.haccp4=1
				m.haccp5=1
				m.haccp6=1
				m.haccp7=1
				m.haccp_poznamka=""
				DO FORM haccp TO m.tlachaccp
				IF m.tlachaccp
					DO CASE
						CASE "DRUH" $ UPPER(m.doklrazeni)
							DO pr_r_dokl WITH "dok_PEB_haccp"
						CASE "SPART" $ UPPER(m.doklrazeni)
							DO pr_r_dokl WITH "dok_PEC_haccp"
						OTHERWISE 
							DO pr_r_dokl WITH "dok_PE_haccp"
					ENDCASE 
				ELSE
					DO CASE
						CASE "DRUH" $ UPPER(m.doklrazeni)
							DO pr_r_dokl WITH "dok_PEB"
						CASE "SPART" $ UPPER(m.doklrazeni)
							DO pr_r_dokl WITH "dok_PEC"
						OTHERWISE 
							DO pr_r_dokl WITH "dok_PE"
					ENDCASE 
				ENDIF
			ELSE
				DO CASE
					CASE "DRUH" $ UPPER(m.doklrazeni)
						DO pr_r_dokl WITH "dok_PEB"
					CASE "SPART" $ UPPER(m.doklrazeni)
						DO pr_r_dokl WITH "dok_PEC"
					OTHERWISE 
						DO pr_r_dokl WITH "dok_PE"
				ENDCASE 
			ENDIF
			RELEASE m.haccp1, m.haccp2,m.haccp3, m.haccp4,m.haccp5, m.haccp6, m.haccp7, m.haccp_poznamka
			IF m.pe_objed
				SELECT doklad
				DO pr_report WITH "objed_pe"
			ENDIF
			IF m.is_shop
				DO tlac_cenovky
			ENDIF
		CASE m.operace = "PB" .OR. operace = "VB"
			SELECT doklad
			REPL ALL cena_part WITH cena
			if !prazdna()
				INDEX ON poradi*1000000+mnozstvi TAG mnozstvi
			ENDIF 
			DO pr_r_dokl WITH "dok_" + operace

		CASE m.operace = "VR"        && stejny report pro vratku a ext.vydejku
			SELECT doklad
			if !prazdna()
				INDE ON EVAL(m.doklrazeni) TAG qwe
			ENDIF 
			IF "DRUH" $ UPPER(m.doklrazeni)
				DO pr_r_dokl WITH "dok_veb"
			ELSE
				DO pr_r_dokl WITH "dok_ve"
			ENDIF

		CASE m.operace = "VV"
			SELECT doklad
			IF .NOT. "kod" $ LOWER(menaz_c_karty)
				REPLACE ALL kod WITH ALLTRIM(STR(c_karty))
			ENDIF
			repo_txt = IIF(ALLTRIM(m.gczadan_prn) = ALLTRIM(m.dic), "", "  DO JINE OJ")
            TRY     
                cmd = "repo_txt = spocti_cerpani_budgetu(m.c_dokl)"
                &cmd
            CATCH 
            FINALLY
            ENDTRY 

			if !prazdna()
				INDE ON EVAL(m.doklrazeni) TAG qwe
			ENDIF 
            
            IF ATC("D_TELEVIZE", m.gchom_path) > 0
                REPLACE ALL cena WITH 0, cena_part WITH 0
            ENDIF 

			IF "DRUH" $ UPPER(m.doklrazeni)
				DO pr_r_dokl WITH "dok_VVB"
			ELSE
				DO pr_r_dokl WITH "dok_VV"
			ENDIF
			IF "D_FELIX" $ UPPER(m.gchom_path)
				DO pr_r_dokl WITH "dok_VV_piz"
			ENDIF 
			IF m.is_shop
				SELECT doklad
				GO TOP
				m.hladajcstredisk=doklad.c_partner
				SELECT 0
				IF m.issql
					USE (m.sqlprefix+"rfooddatriadok") ALIAS bour_skup
					m.bolfooddat=.T.
				ELSE
					IF !USED("food_dat")
						USE (m.fn_food_dat) ALIAS food_dat IN 0
						m.bolfooddat=.F.
					ELSE
						m.bolfooddat=.T.
					ENDIF
					SELECT 0
					USE vfooddatriadokstrucny ALIAS bour_skup
				ENDIF
				m.hladajmodul="MAN"
				m.hladajsetupskup=ALLTRIM(bour_skup.setup_skup)
				m.hladajvarname="is_shop"
				m.hladajbourskup=ALLTRIM(bour_skup.bour_skup)
				IF m.issql
					USE (m.sqlprefix+"rdefsuborvarname") ALIAS defsubriadok IN 0
				ELSE
					USE (m.gchom_path+"s_"+ALLTRIM(bour_skup.pgm)+"_"+ALLTRIM(bour_skup.setup_skup)) IN 0 ALIAS defsubor
					USE vdefsuborvarname ALIAS defsubriadok IN 0
				ENDIF
				SELECT defsubriadok
				IF RECCOUNT("defsubriadok")=1 .AND. ALLTRIM(LOWER(var_value))=".t."
					SELECT doklad
					DO tlac_cenovky
				ENDIF
				DO pozavirej WITH "bour_skup, defsubriadok, defsubor, bour_skup"
				IF !m.bolfooddat
					USE IN food_dat
				ENDIF
			ENDIF
		CASE m.operace = "PV"
			SELECT doklad
			GO TOP
			m.hladajpz2=INT(VAL(doklad.pz2))
			SELECT 0
			IF m.issql
				USE (m.sqlprefix+"rprnobrapv"+m.sqlsuffix) ALIAS intvydej AGAIN
			ELSE
				USE vprnobrapv ALIAS intvydej AGAIN
			ENDIF
			if !prazdna()
				INDEX ON poradi TAG poradi
			ENDIF 
			SELECT doklad

			IF m.vv_vnitcen    && tisk int.prijemky v sankcni cene
				REPLACE ALL cena WITH sankcni
				SET RELATION TO
			ENDIF

			SET RELATION TO poradi INTO intvydej
			if !prazdna()
				INDEX ON EVALUATE(m.doklrazeni) TAG qwe
			ENDIF 
			IF "DRUH" $ UPPER(m.doklrazeni)
				DO pr_r_dokl WITH "dok_PVB"
			ELSE
				DO pr_r_dokl WITH "dok_PV"
			ENDIF
			USE IN intvydej
		CASE m.operace = "VE"

			PRIVATE tlacitzaruky, hladajctr
			m.tlacitzaruky=.f.
			STORE 0 TO _dan1, _dan2, _dan3, _dan_zakl1, _dan_zakl2, _dan_zakl3
			STORE 1 TO _dansazba1, _dansazba2, _dansazba3
			SELECT 0
			IF m.issql
				USE (m.sqlprefix+"rusersname") ALIAS po_users
			ELSE
				IF !USED("users")
					USE (m.fn_users) ALIAS USERS
				ENDIF 
				USE vusersname ALIAS po_users IN 0
			ENDIF
			SELECT dan, SUM(mnozstvi*cena_part) AS dan_zakl, halere, sleva_abs, sleva_proc, provedl, po_users.username GROUP BY dan ;
				FROM doklad LEFT JOIN po_users ON po_users.user_id == doklad.provedl ;
				INTO CURSOR dane

			SCATTER FIELD halere, sleva_abs, sleva_proc, username MEMVAR
			_iii = 1
			SCAN
				_ccc = STR(_iii,1)
				_iii = _iii + 1
				_dansazba&_ccc = dane.dan
				_dan_zakl&_ccc = ROUND(dane.dan_zakl, 2)
			ENDSCAN
			_dan1 = ROUND(_dan_zakl1 * (_dansazba1 - 1), 2)
			_dan2 = ROUND(_dan_zakl2 * (_dansazba2 - 1), 2)
			_dan3 = ROUND(_dan_zakl3 * (_dansazba3 - 1), 2)
			DO pozavirej WITH "users, po_users, dane"
			SELECT doklad
			if !prazdna()
				INDEX ON EVALUATE(m.doklrazeni) TAG qwe
			ENDIF 
            
            STORE "" TO bkp, fik
            IF !m.issql
	            IF FILE(m.fn_doklady + "_eet.dbf")
	                SELECT 0
	                USE (m.fn_doklady + "_eet") ALIAS doklady_eet NOUPDATE 
	                LOCATE FOR c_dokl = m.c_dokl
	                IF FOUND()
	                    fik = "FIK: " + fik
	                    bkp = "BKP: " + bkp
	                ENDIF 
                    USE 
	            ENDIF 
			ENDIF 
            SELECT doklad

			IF ATC("MNAMKA", m.wi_zakaz) > 0
				IF ("id_limit="$doklad.poznamka) AND ("id_den="$doklad.poznamka) AND ("id_rov="$doklad.poznamka)
					m.hladajidlimit=VAL(STRTRAN(LEFT(doklad.poznamka, AT(";",doklad.poznamka)-1),"id_limit=",""))
					IF m.issql
						USE (m.sqlprefix+"rlimhl") IN 0 ALIAS limit
					ELSE
						USE (m.fn_limit_hl) ALIAS nlimit_hl IN 0
						USE vlimhl IN 0 ALIAS limit
					ENDIF 
					SELECT limit
					GO TOP 
					IF !EMPTY(limit.adr1)
						REPLACE doklad.naz1 WITH limit.adr1
					ENDIF 
					IF !EMPTY(limit.adr2)
						REPLACE doklad.naz2 WITH limit.adr2
					ENDIF 
					IF !EMPTY(limit.adr3)
						REPLACE doklad.naz3 WITH limit.adr3
					ENDIF 
					IF !EMPTY(limit.adr4)
						REPLACE doklad.naz4 WITH limit.adr4
					ENDIF 
					DO pozavirej WITH "limit, nlimit_hl"
				ENDIF 
					
				SELECT 0
				IF m.issql
					rv("triedenia","vtriedenia")
				ELSE 
					IF !USED("tried")
						USE (m.fn_tried) ALIAS tried IN 0
					ENDIF 
					IF !USED("ktried")
						USE (m.fn_ktried) ALIAS ktried IN 0
					ENDIF 
					USE vtriedenia ALIAS vtriedenia IN 0
				ENDIF 
				SELECT vtriedenia
				LOCATE FOR LOWER(popis)="záruka"
				IF FOUND()
					m.hladajctr=vtriedenia.c_tr
					IF m.issql
						rv("kartyktriedeniushodnotou","kartytr")
					ELSE 
						USE vkartyktriedeniushodnotou ALIAS kartytr IN 0
					ENDIF 
					SELECT kartytr
					INDEX on c_karty TAG c_karty	
					SELECT doklad
					SET RELATION TO c_karty INTO kartytr
					m.tlacitzaruky=.t.
				ENDIF 				
				SELECT doklad
			ENDIF 
            
            IF ATC("D_TELEVIZE", m.gchom_path) > 0
                REPLACE ALL cena WITH 0, cena_part WITH 0
            ENDIF 
            
			IF "DRUH" $ UPPER(m.doklrazeni)
				DO pr_r_dokl WITH "dok_veb"
			ELSE
				IF ATC("MNAMKA", m.wi_zakaz) > 0
					DO pr_r_dokl WITH "dok_ve_mnamka"
				ELSE
					DO pr_r_dokl WITH "dok_ve"
				ENDIF 
			ENDIF
			SELECT doklad
			GO TOP
			IF FSIZE("sscc","doklad")>0
				LOCATE FOR !ISNULL(sscc) AND !EMPTY(sscc)
				IF FOUND()
					IF MESSAGEBOX(jaz("form_vytlacit_sscc_stitky"),4+32+256,"FoodMan")=6
						DO tlac_sscc
					ENDIF
				ENDIF 
			ENDIF 
			SELECT doklad
			GO TOP
			IF m.is_stitky
				IF RECCOUNT("doklad")=0 OR (RECCOUNT("doklad")=1 AND doklad.c_karty=0)
				ELSE
					IF MESSAGEBOX(jaz("form_vytlacit_stitky"),4+32+256,"FoodMan")=6
						DO tlac_stitkov
					ENDIF
				ENDIF
			ENDIF

			SELECT doklad
			GO TOP
			IF doklad.splatnost = 0
				txt_splatnost = "HOTOVE"
				zaokrouhlit_platbu = 0
			ELSE
				txt_splatnost = DTOC(datum_dokl + splatnost)
				zaokrouhlit_platbu = 2
			ENDIF
			IF m.dodak_taky
				DO CASE
					CASE "ALFA" $ UPPER(m.gchom_path)
						DO pr_r_dokl WITH "dodak_alfa"
					CASE "HAJEK" $ UPPER(m.gchom_path)
						DO pr_r_dokl WITH "dodak_hajek"
					CASE m.spotrebnadan<>0
						DO pr_r_dokl WITH "dodak_sp"
					CASE ATC("MNAMKA", m.wi_zakaz) > 0
						DO pr_r_dokl WITH "dodak_mnamka"
					CASE ATC("sushitime", LOWER(m.wi_zakaz)) > 0 OR ATC("agro", LOWER(m.wi_zakaz)) > 0
						hladajcpartner=doklad.c_partner
						SELECT 0
						IF ATC("agro", LOWER(m.wi_zakaz)) > 0 AND m.faktu_prev>0
							USE (m.sqlprefix+"redi_prev") IN 0 ALIAS dodpartner
							SELECT dodpartner
							SET FILTER TO idriadok=m.faktu_prev
						ELSE 
							USE (m.sqlprefix+"rediprevpartnera") IN 0 ALIAS dodpartner
						ENDIF 
						IF RECCOUNT("dodpartner")>0
							SELECT dodpartner
							GO TOP 
							dodhotel_name=dodpartner.meno
							dodhotel_naz1=dodpartner.ulica
							dodhotel_naz2=dodpartner.mesto
							dodhotel_naz3=dodpartner.psc
							dodhotel_ico=dodpartner.ico
							dodhotel_dico=dodpartner.dic
							m.hhotel_banka=ALLTRIM(dodpartner.banka)
							m.hhotel_ucet=ALLTRIM(dodpartner.ucet)
							m.hhotel_swift=ALLTRIM(dodpartner.swift)
						ELSE
							dodhotel_name=m.hotel_name
							dodhotel_naz1=m.hotel_naz1
							dodhotel_naz2=m.hotel_naz2
							dodhotel_naz3=m.hotel_naz3
							dodhotel_ico=m.hotel_ico
							dodhotel_dico=m.hotel_dico
							m.hhotel_banka=m.hotel_bank
							m.hhotel_ucet=m.hotel_ucet
							m.hhotel_swift=m.hotel_swift
						ENDIF 
						USE IN dodpartner
						SELECT doklad
						IF ATC("agro", LOWER(m.wi_zakaz)) > 0
							DO pr_r_dokl WITH "dodak_agro"
						ELSE
							DO pr_r_dokl WITH "dodak_sushitime"
						ENDIF 
					OTHERWISE
						DO pr_r_dokl WITH "dodak"
				ENDCASE
			ENDIF
			IF prachy_part_celkem <= 0
				IF VARTYPE(m.faktura_hlavicka)=="C" AND !EMPTY(m.faktura_hlavicka)
					txt_faktura = m.faktura_hlavicka
				ELSE
					txt_faktura = "F A K T Ú R A - D A Ò O V Ý  D O K L A D"
				ENDIF 
			ELSE
				IF VARTYPE(m.dobropis_hlavicka)=="C" AND !EMPTY(m.dobropis_hlavicka)
					txt_faktura = m.dobropis_hlavicka
				ELSE
					txt_faktura = "D O B R O P I S - D A Ò O V Ý  D O K L A D"
				ENDIF 
			ENDIF

			IF m.faktu_taky .AND. .NOT. "SF" $ platba
				GO TOP
				IF UPPER(LEFT(serial_no, 3)) = "EUR"
					IF SET("point") = "."
						REPLACE ALL serial_no WITH STRTRAN(serial_no, ",", ".")
					ELSE
						REPLACE ALL serial_no WITH STRTRAN(serial_no, ".", ",")
					ENDIF
					DO pr_r_dokl WITH "faktura_eur"
				ELSE
					IF m.spotrebnadan<>0
						DO pr_r_dokl WITH "faktura_sp"
					ELSE
						DO CASE 
							CASE ATC("MNAMKA", m.wi_zakaz) > 0
								DO pr_r_dokl WITH "faktura_mnamka"
							CASE ATC("sushitime", LOWER(m.wi_zakaz)) > 0 OR ATC("agro", LOWER(m.wi_zakaz)) > 0
								hladajcpartner=doklad.c_partner
								SELECT 0
								IF ATC("agro", LOWER(m.wi_zakaz)) > 0 AND m.faktu_prev>0
									USE (m.sqlprefix+"redi_prev") IN 0 ALIAS dodpartner
									SELECT dodpartner
									SET FILTER TO idriadok=m.faktu_prev
								ELSE 
									USE (m.sqlprefix+"rediprevpartnera") IN 0 ALIAS dodpartner
								ENDIF 
								IF FILE(m.gcpri_path+"faktura_podpis.pct")
									ERASE (m.gcpri_path+"faktura_podpis.pct")
								ENDIF 
								IF FILE(m.gcpri_path+"faktura_logo.pct")
									ERASE (m.gcpri_path+"faktura_logo.pct")
								ENDIF 
								IF RECCOUNT("dodpartner")>0
									SELECT dodpartner
									GO TOP 
									dodhotel_name=dodpartner.meno
									dodhotel_naz1=dodpartner.ulica
									dodhotel_naz2=dodpartner.mesto
									dodhotel_naz3=dodpartner.psc
									dodhotel_ico=dodpartner.ico
									dodhotel_dico=dodpartner.dic
									dodhot_icdph=dodpartner.ic_dph
									dod_username=dodpartner.osoba
									IF ISNULL(dodpartner.peciatka) OR EMPTY(dodpartner.peciatka)
									ELSE
										STRTOFILE(dodpartner.peciatka,(m.gcpri_path+"faktura_podpis.pct"))
									ENDIF 
									IF ISNULL(dodpartner.logo) OR EMPTY(dodpartner.logo)
									ELSE
										STRTOFILE(dodpartner.logo,(m.gcpri_path+"faktura_logo.pct"))
									ENDIF 
								ELSE
									dodhotel_name=m.hotel_name
									dodhotel_naz1=m.hotel_naz1
									dodhotel_naz2=m.hotel_naz2
									dodhotel_naz3=m.hotel_naz3
									dodhotel_ico=m.hotel_ico
									dodhotel_dico=m.hotel_dico
									dodhot_icdph=m.hot_icdph
									dod_username=m.username
								ENDIF 
								USE IN dodpartner
								SELECT doklad
								DO CASE 
									CASE ATC("agro", LOWER(m.wi_zakaz)) > 0 AND EMPTY(doklad.pz2)
									CASE ATC("agro", LOWER(m.wi_zakaz)) > 0
										DO pr_r_dokl WITH "faktura_agro"
									OTHERWISE 
										DO pr_r_dokl WITH "faktura_sushitime"
								ENDCASE 
						OTHERWISE 
							DO pr_r_dokl WITH "faktura"
						ENDCASE 
					ENDIF
				ENDIF
			ENDIF

		CASE m.operace = "SF"
			PRIVATE m.hladajstrcdokl
			m.hladajstrcdokl=STR(m.c_dokl,10,0)
			SELECT 0
			IF m.issql
				USE (m.sqlprefix+"rprnobrasf"+m.sqlsuffix) ALIAS sf_dokl
			ELSE
				USE vprnobrasf ALIAS sf_dokl
			ENDIF
			if !prazdna()
				INDEX ON c_dokl TAG c_dokl
			ENDIF
			STORE 0 TO _dan1, _dan2, _dan3, _dan_zakl1, _dan_zakl2, _dan_zakl3
			STORE 1 TO _dansazba1, _dansazba2, _dansazba3
			SELECT 0
			IF m.issql
				USE (m.sqlprefix+"rusersname") ALIAS po_users
			ELSE
				IF !USED("users")
					USE (m.fn_users) ALIAS USERS
				ENDIF 
				USE vusersname ALIAS po_users IN 0
			ENDIF
			SELECT dan, SUM(mnozstvi*cena_part) AS dan_zakl, halere, sleva_abs, sleva_proc, provedl, po_users.username GROUP BY dan ;
				FROM doklad LEFT JOIN po_users ON po_users.user_id == doklad.provedl ;
				INTO CURSOR dane
			SCATT FIELD halere, sleva_abs, sleva_proc, username MEMVAR
			_iii = 1
			SCAN
				_ccc = STR(_iii,1)
				_iii = _iii + 1
				_dansazba&_ccc = dane.dan
				_dan_zakl&_ccc = ROUND(dane.dan_zakl, 2)
			ENDSCAN
			_dan1 = ROUND(_dan_zakl1 * (_dansazba1 - 1), 2)
			_dan2 = ROUND(_dan_zakl2 * (_dansazba2 - 1), 2)
			_dan3 = ROUND(_dan_zakl3 * (_dansazba3 - 1), 2)
			DO pozavirej WITH "users, po_users, dane"
			SELECT doklad
			if !prazdna()
				INDEX ON serial_no + nazev TAG qwe
			ENDIF 

			IF splatnost = 0
				txt_splatnost = "HOTOVE"
				zaokrouhlit_platbu = 0
			ELSE
				txt_splatnost = DTOC(datum_dokl + splatnost)
				zaokrouhlit_platbu = 2
			ENDIF
			IF prachy_part_celkem <= 0
				txt_faktura = "F A K T U R A - D A N O V Y  D O K L A D"
			ELSE
				txt_faktura = "D O B R O P I S - D A N O V Y  D O K L A D"
			ENDIF
			SET RELATION TO VAL(serial_no) INTO sf_dokl
			GO TOP

			o_gctxt_summary = gctxt_summary
			gctxt_summary = IIF("summ" $ LOWER(m.sf_tisk_summary), " SUMMARY", "")
						DO CASE 
							CASE ATC("MNAMKA", m.wi_zakaz) > 0
								DO pr_r_dokl WITH "faktura_mnamka"
							CASE ATC("sushitime", LOWER(m.wi_zakaz)) > 0 OR ATC("agro", LOWER(m.wi_zakaz)) > 0
								hladajcpartner=doklad.c_partner
								SELECT 0
								IF ATC("agro", LOWER(m.wi_zakaz)) > 0 AND m.faktu_prev>0
									USE (m.sqlprefix+"redi_prev") IN 0 ALIAS dodpartner
									SELECT dodpartner
									SET FILTER TO idriadok=m.faktu_prev
								ELSE 
									USE (m.sqlprefix+"rediprevpartnera") IN 0 ALIAS dodpartner
								ENDIF 
								IF FILE(m.gcpri_path+"faktura_podpis.pct")
									ERASE (m.gcpri_path+"faktura_podpis.pct")
								ENDIF 
								IF FILE(m.gcpri_path+"faktura_logo.pct")
									ERASE (m.gcpri_path+"faktura_logo.pct")
								ENDIF 
								IF RECCOUNT("dodpartner")>0
									SELECT dodpartner
									GO TOP 
									dodhotel_name=dodpartner.meno
									dodhotel_naz1=dodpartner.ulica
									dodhotel_naz2=dodpartner.mesto
									dodhotel_naz3=dodpartner.psc
									dodhotel_ico=dodpartner.ico
									dodhotel_dico=dodpartner.dic
									dodhot_icdph=dodpartner.ic_dph
									dod_username=dodpartner.osoba
									IF ISNULL(dodpartner.peciatka) OR EMPTY(dodpartner.peciatka)
									ELSE
										STRTOFILE(dodpartner.peciatka,(m.gcpri_path+"faktura_podpis.pct"))
									ENDIF 
									IF ISNULL(dodpartner.logo) OR EMPTY(dodpartner.logo)
									ELSE
										STRTOFILE(dodpartner.logo,(m.gcpri_path+"faktura_logo.pct"))
									ENDIF 
									m.hhotel_banka=ALLTRIM(dodpartner.banka)
									m.hhotel_ucet=ALLTRIM(dodpartner.ucet)
									m.hhotel_swift=ALLTRIM(dodpartner.swift)
								ELSE
									dodhotel_name=m.hotel_name
									dodhotel_naz1=m.hotel_naz1
									dodhotel_naz2=m.hotel_naz2
									dodhotel_naz3=m.hotel_naz3
									dodhotel_ico=m.hotel_ico
									dodhotel_dico=m.hotel_dico
									dodhot_icdph=m.hot_icdph
									dod_username=m.username
									m.hhotel_banka=m.hotel_bank
									m.hhotel_ucet=m.hotel_ucet
									m.hhotel_swift=m.hotel_swift
								ENDIF 
								USE IN dodpartner
								SELECT doklad
								DO CASE 
									CASE ATC("agro", LOWER(m.wi_zakaz)) > 0 AND EMPTY(doklad.pz2)
									CASE ATC("agro", LOWER(m.wi_zakaz)) > 0
										DO pr_r_dokl WITH "faktura_agro"
									OTHERWISE 
										DO pr_r_dokl WITH "faktura_sushitime"
								ENDCASE 
						OTHERWISE 
							DO pr_r_dokl WITH "faktura"
						ENDCASE 
			gctxt_summary = o_gctxt_summary
			DO pozavirej WITH "sf_dokl"

		CASE m.operace = "VP" .OR. operace = "PP"
			SELECT doklad
			if !prazdna()
				INDEX ON SIGN(mnozstvi) TAG mn
			ENDIF 
			DO pr_r_dokl WITH "dok_pp"

		OTHERWISE
			SELECT doklad
			if !prazdna()
				INDEX ON EVALUATE(m.doklrazeni) TAG qwe
			ENDIF 
			DO pr_r_dokl WITH "dok_" + operace

	ENDCASE

ENDIF
IF m.is_absolutereader AND !EMPTY(m.obrazok) AND FILE(m.obrazok)
	ERASE (m.obrazok)
ENDIF 
WAIT CLEAR
IF !m.issql
	IF !m.bolikarty
		DO pozavirej WITH "karty"
	ENDIF
	IF !m.bolipartneri
		DO pozavirej WITH "partneri"
	ENDIF
	IF !m.boliskupiny
		DO pozavirej WITH "skupiny"
	ENDIF
	IF !m.bolidoklady
		DO pozavirej WITH "doklady"
	ENDIF
	IF !m.boliobraty
		DO pozavirej WITH "obraty"
	ENDIF
ENDIF
DO pozavirej WITH "doklad"
SELECT (m.liold_sel)



*!*****************************************************************************
PROCEDURE pr_r_dokl
PARAMETERS repo_name
IF VARTYPE(m.repo_txt)<>"C"
	m.repo_txt=""
ENDIF 
IF FILE (m.gcrepo_path + m.repo_name + ".frx")
	DO pr_report WITH m.repo_name
ELSE
	IF UPPE(LEFT(operace, 1)) = "V"
		IF "bystrina"$LOWER(m.gchom_path)
			DO pr_report WITH "dok_VEB"
		ELSE
			DO pr_report WITH "dok_VE"
		ENDIF
	ELSE
		IF "bystrina"$LOWER(m.gchom_path)
			DO pr_report WITH "dok_XXB"
		ELSE
			DO pr_report WITH "dok_XX"
		ENDIF
	ENDIF
ENDIF


*!*****************************************************************************
PROCEDURE tlac_stitkov
SELECT 0
CREATE CURSOR stitky (nazev1 c(30),c_karty1 Y, popis1 m,nazev2 c(30),c_karty2 Y,popis2 m,nazev3 c(30),c_karty3 Y, popis3 m)
SELECT doklad
IF !m.issql
	part_used = USED("karty")
	IF ! m.part_used
		=f_acc('(m.gccen_path + "karty") ORDER c_karty AGAIN')
	ELSE
		SELECT karty
		SET ORDER TO c_karty
	ENDIF
	polk_used = USED("polozky")
	IF ! m.polk_used
		=f_acc('(m.gccen_path + "polozky") ORDER c_karty AGAIN')
	ELSE
		SELECT polozky
		SET ORDER TO c_karty
	ENDIF
ENDIF
m.x="1"
SCAN ALL
	FOR m.i=1 TO INT(ABS(doklad.mnozstvi))
		IF m.x="1"
			INSERT INTO stitky (nazev1,c_karty1) VALUES (doklad.nazev, doklad.c_karty)
			m.x="2"
		ELSE
			IF m.x="2"
				REPLACE stitky.nazev2 WITH doklad.nazev, stitky.c_karty2 WITH doklad.c_karty
				m.x="3"
			ELSE
				REPLACE stitky.nazev3 WITH doklad.nazev, stitky.c_karty3 WITH doklad.c_karty
				m.x="1"
			ENDIF
		ENDIF
	ENDFOR
ENDSCAN
SELECT DISTINCT c_karty, nazev FROM doklad INTO CURSOR doklkarty
SCAN ALL
	m.hladajckarty=doklkarty.c_karty
	SELECT 0
	CREATE CURSOR stx (c_karty Y, popis m)
	INSERT INTO stx (c_karty) VALUES (m.hladajckarty)
	SELECT 0
	IF m.issql
		USE (m.sqlprefix+"rpolozkynazvy") ALIAS rpol
	ELSE
		USE vpolozkynazvy ALIAS rpol
	ENDIF
	IF RECCOUNT("rpol")>0
		IF EMPTY(stx.popis)
			REPLACE stx.popis WITH ALLTRIM(LEFT(rpol.nazev,27))
		ELSE
			REPLACE stx.popis WITH ALLTRIM(stx.popis)+","+ALLTRIM(LEFT(rpol.nazev,27))
		ENDIF
	ELSE
		REPLACE stx.popis WITH ALLTRIM(LEFT(doklkarty.nazev,27))
	ENDIF
	SELECT stitky
	UPDATE stitky SET popis1=stx.popis FROM stx WHERE stitky.c_karty1=stx.c_karty
	UPDATE stitky SET popis2=stx.popis FROM stx WHERE stitky.c_karty2=stx.c_karty
	UPDATE stitky SET popis3=stx.popis FROM stx WHERE stitky.c_karty3=stx.c_karty
	USE IN rpol
	USE IN stx
	SELECT doklkarty
ENDSCAN

SET MEMOWIDTH TO 50
GO TOP
SELECT doklad
GO TOP
m.rep_part=doklad.partner
m.rep_st1=ALLTRIM(doklad.naz1)+", "+ALLTRIM(doklad.naz2)
m.rep_st2=ALLTRIM(doklad.naz3)+", "+ALLTRIM(doklad.naz4)
m.rep_dat=doklad.datum_dokl

SELECT stitky
DO pr_report WITH "stitky"

USE IN stitky
IF USED("polozky")
	USE IN polozky
ENDIF



PROCEDURE tlac_cenovky
PRIVATE m.x
SELECT doklad
GO TOP
IF RECCOUNT()=0 OR (RECCOUNT()=1 AND c_karty=0)
ELSE
	SELECT 0
	CREATE CURSOR stitky (nazev1 c(30),cena1 Y, objem1 N(10,4), c_mena1 i, nazev2 c(30),cena2 Y, objem2 N(10,4), c_mena2 i, nazev3 c(30),cena3 Y, objem3 N(10,4), c_mena3 i)
	SELECT doklad
	m.x="1"
	SCAN ALL
		IF m.x="1"
			INSERT INTO stitky (nazev1,cena1,objem1,c_mena1) VALUES (doklad.nazev, doklad.cena01,doklad.objem,doklad.c_mena)
			m.x="2"
		ELSE
			IF m.x="2"
				REPLACE stitky.nazev2 WITH doklad.nazev, stitky.cena2 WITH doklad.cena01, stitky.objem2 WITH doklad.objem, stitky.c_mena2 WITH doklad.c_mena
				m.x="3"
			ELSE
				REPLACE stitky.nazev3 WITH doklad.nazev, stitky.cena3 WITH doklad.cena01, stitky.objem3 WITH doklad.objem, stitky.c_mena3 WITH doklad.c_mena
				m.x="1"
			ENDIF
		ENDIF
	ENDSCAN
	SELECT stitky
	REPLACE c_mena1 WITH 1 FOR EMPTY(c_mena1)
	REPLACE c_mena2 WITH 1 FOR EMPTY(c_mena2)
	REPLACE c_mena3 WITH 1 FOR EMPTY(c_mena3)
	REPLACE objem1 WITH 1 FOR EMPTY(objem1)
	REPLACE objem2 WITH 1 FOR EMPTY(objem2)
	REPLACE objem3 WITH 1 FOR EMPTY(objem3)
	GO TOP
	m.girep_mena=m.giakt_mena
	SELECT 0
	SELECT SPACE(30) AS sestava,.F. AS lbl INTO CURSOR selzost FROM stitky READWRITE WHERE .F.
	INSERT INTO selzost (sestava,lbl) VALUES (jaz("rep_stitky_1"),.F.)
	INSERT INTO selzost (sestava,lbl) VALUES (jaz("rep_stitky_2"),.F.)
	INSERT INTO selzost (sestava,lbl) VALUES (jaz("rep_stitky_3"),.F.)
	INSERT INTO selzost (sestava,lbl) VALUES (jaz("rep_stitky_4"),.F.)
	DO FORM selpartn WITH "selzost","sestava"
	SELECT selzost
	SCAN FOR !EMPTY(lbl)
		DO CASE
			CASE RECNO()=1
				SELECT stitky
				DO pr_report WITH "cenovky"
			CASE RECNO()=2
				SELECT stitky
				DO pr_report WITH "cenovky1"
			CASE RECNO()=3
				USE IN stitky
				SELECT 0
				CREATE CURSOR stitky (nazev1 c(30),cena1 Y, objem1 N(10,4), c_mena1 i, kod1 c(20), nazev2 c(30),cena2 Y, objem2 N(10,4), c_mena2 i, kod2 c(20), nazev3 c(30),cena3 Y, objem3 N(10,4), c_mena3 i, kod3 c(20), nazev4 c(30),cena4 Y, objem4 N(10,4), c_mena4 i, kod4 c(20))
				SELECT doklad
				REPLACE serial_no WITH kod FOR EMPTY(serial_no)
				m.x="1"
				SCAN ALL
					FOR m.i=1 TO INT(ABS(doklad.mnozstvi))
						IF m.x="1"
							INSERT INTO stitky (nazev1,cena1,objem1,c_mena1, kod1) VALUES (doklad.nazev, doklad.cena01,doklad.objem,doklad.c_mena, doklad.serial_no)
							m.x="2"
						ELSE
							IF m.x="2"
								REPLACE stitky.nazev2 WITH doklad.nazev, stitky.cena2 WITH doklad.cena01, stitky.objem2 WITH doklad.objem, stitky.c_mena2 WITH doklad.c_mena, stitky.kod2 WITH doklad.serial_no
								m.x="3"
							ELSE
								IF m.x="3"
									REPLACE stitky.nazev3 WITH doklad.nazev, stitky.cena3 WITH doklad.cena01, stitky.objem3 WITH doklad.objem, stitky.c_mena3 WITH doklad.c_mena, stitky.kod3 WITH doklad.serial_no
									m.x="4"
								ELSE
									REPLACE stitky.nazev4 WITH doklad.nazev, stitky.cena4 WITH doklad.cena01, stitky.objem4 WITH doklad.objem, stitky.c_mena4 WITH doklad.c_mena, stitky.kod4 WITH doklad.serial_no
									m.x="1"
								ENDIF
							ENDIF
						ENDIF
					ENDFOR
				ENDSCAN
				SELECT stitky
				DO pr_report WITH "cenovky2"
			CASE RECNO()=4
				USE IN stitky
				SELECT 0
				CREATE CURSOR stitky (nazev1 c(30),cena1 Y, objem1 N(10,4), c_mena1 i, kod1 c(20), nazev2 c(30),cena2 Y, objem2 N(10,4), c_mena2 i, kod2 c(20), nazev3 c(30),cena3 Y, objem3 N(10,4), c_mena3 i, kod3 c(20), nazev4 c(30),cena4 Y, objem4 N(10,4), c_mena4 i, kod4 c(20), nazev5 c(30),cena5 Y, objem5 N(10,4), c_mena5 i, kod5 c(20))
				SELECT doklad
				REPLACE serial_no WITH kod FOR EMPTY(serial_no)
				m.x="1"
				SCAN ALL
					FOR m.i=1 TO INT(ABS(doklad.mnozstvi))
						IF m.x="1"
							INSERT INTO stitky (nazev1,cena1,objem1,c_mena1, kod1) VALUES (doklad.nazev, doklad.cena01,doklad.objem,doklad.c_mena, doklad.serial_no)
							m.x="2"
						ELSE
							IF m.x="2"
								REPLACE stitky.nazev2 WITH doklad.nazev, stitky.cena2 WITH doklad.cena01, stitky.objem2 WITH doklad.objem, stitky.c_mena2 WITH doklad.c_mena, stitky.kod2 WITH doklad.serial_no
								m.x="3"
							ELSE
								IF m.x="3"
									REPLACE stitky.nazev3 WITH doklad.nazev, stitky.cena3 WITH doklad.cena01, stitky.objem3 WITH doklad.objem, stitky.c_mena3 WITH doklad.c_mena, stitky.kod3 WITH doklad.serial_no
									m.x="4"
								ELSE
									IF m.x="4"
										REPLACE stitky.nazev4 WITH doklad.nazev, stitky.cena4 WITH doklad.cena01, stitky.objem4 WITH doklad.objem, stitky.c_mena4 WITH doklad.c_mena, stitky.kod4 WITH doklad.serial_no
										m.x="5"
									ELSE
										REPLACE stitky.nazev5 WITH doklad.nazev, stitky.cena5 WITH doklad.cena01, stitky.objem5 WITH doklad.objem, stitky.c_mena5 WITH doklad.c_mena, stitky.kod5 WITH doklad.serial_no
										m.x="1"
									ENDIF
								ENDIF
							ENDIF
						ENDIF
					ENDFOR
				ENDSCAN
				SELECT stitky
				DO pr_report WITH "cenovky3"
		ENDCASE
		SELECT selzost
	ENDSCAN
	USE IN selzost
	USE IN stitky
ENDIF


PROCEDURE tlac_sscc
PRIVATE m.x, m.mutacia
IF VARTYPE(m.def_cen_hl_prijem)=="C" AND !EMPTY(m.def_cen_hl_prijem)
	m.def_cen_hl_prijem = PADL(ALLTRIM(m.def_cen_hl_prijem), 2, "0")
ELSE
	m.def_cen_hl_prijem="01"
ENDIF 
IF !(BETWEEN(kontrolahladiny(m.def_cen_hl_prijem), 1, 40))
	m.def_cen_hl_prijem="01"
ENDIF 	
IF m.issql
	rv("extpartneri_obj","part_ze")
ELSE
	USE vextpartneri_obj IN 0 ALIAS part_ze
ENDIF 
SELECT part_ze
LOCATE FOR c_partner=doklad.c_partner
IF FOUND()
	m.mutacia=ALLTRIM(part_ze.mutacia)
ELSE
	m.mutacia="1"
ENDIF 
IF EMPTY(m.mutacia)
	m.mutacia="1"
ENDIF 
DO pozavirej WITH "part_ze"
SELECT doklad
GO TOP
IF RECCOUNT()=0 OR (RECCOUNT()=1 AND c_karty=0)
ELSE
	IF !EMPTY(m.gczebraprinter)
		PRIVATE o_prn, o_prn1
		o_prn = SET("PRINTER")
		o_prn1= SET("PRINTER", 1)
		SELECT doklad
		SCAN FOR !ISNULL(sscc)
			SET PRINTER TO NAME (m.gczebraprinter)
			??? '^XA'
			??? '^CF0,60'
			??? ' ^FO220,50^FD'+ALLTRIM(m.hotel_name)+'^FS'
			??? '^CFA,30'
			DO CASE 
				CASE m.mutacia="1"
					??? '^FO50,110,0^FD'+ALLTRIM(doklad.nazev1)+'^FS'
				CASE m.mutacia="2"
					??? '^FO50,110,0^FD'+ALLTRIM(doklad.nazev2)+'^FS'
				CASE m.mutacia="3"
					??? '^FO50,110,0^FD'+ALLTRIM(doklad.nazev3)+'^FS'
				CASE m.mutacia="4"
					??? '^FO50,110,0^FD'+ALLTRIM(doklad.nazev4)+'^FS'
				CASE m.mutacia="5"
					??? '^FO50,110,0^FD'+ALLTRIM(doklad.nazev5)+'^FS'
				OTHERWISE 
					??? '^FO50,110,0^FD'+ALLTRIM(doklad.nazev)+'^FS'
			ENDCASE 
			??? '^FO50,150^GB700,3,3^FS'
			??? '^FX Second section with recipient address'
			??? '^CFA,30'
			??? '^FO50,170^FD'+ALLTRIM(doklad.naz1)+'^FS'
			??? '^FO50,210^FD'+ALLTRIM(doklad.naz2)+'^FS'
			??? '^FO50,250^FD'+ALLTRIM(doklad.naz3)+'^FS'
			??? '^FO50,290^FD'+ALLTRIM(doklad.naz4)+'^FS'
			??? '^FO50,330^GB700,3,3^FS'
			??? '^FX Third section with sscc fields'
			??? '^CFA,30'
			??? '^FO50,360^FDSSCC:^FS'
			??? '^CF0,40'
			??? '^FO50,390^FD'+ALLTRIM(doklad.sscc)+'^FS'
			??? '^CFA,30'
			??? '^FO50,460^FDContent:^FS'
			??? '^FO550,460^FDCount:^FS'
			??? '^CF0,40'
			??? '^FO50,490^FD'+ALLTRIM(doklad.serial_no)+'^FS'
			??? '^FO550,490^FD'+ALLTRIM(STR(-doklad.mnozstvi,10,4))+'^FS'
			??? '^CFA,30'
			??? '^FO50,550^FDBest before:^FS'
			??? '^FO550,550^FDProd Date:^FS'
			??? '^CF0,40'
			??? '^FO50,580^FD'+DTOC(doklad.datum_dokl+doklad.zaruka)+'^FS'
			??? '^FO550,580^FD'+DTOC(doklad.datum_dokl)+'^FS'
			??? '^FO50,620^GB700,3,3^FS'
			??? '^FX Fourth section with bar code.'
			??? '^BY4,3,250'
			??? '^FO50,630^BCN,,,,,D^FD'+ALLTRIM(doklad.sscc)+'^FS'
			??? '^BY3,3,150'
			??? '^FO50,970^BCN,,,,,D^FD(02)'+ALLTRIM(doklad.serial_no)+'(15)'+SUBSTR(DTOS(doklad.datum_dokl+doklad.zaruka),3,6)+'(37)'+PADL(ALLTRIM(STR(-doklad.mnozstvi,4,0)),4,"0")+'^FS'
			??? '^FO50,1190^GB700,3,3^FS'
			??? '^PQ2'		
			??? '^XZ'	
			SET PRINTER &o_prn
			SET PRINTER TO &o_prn1
		ENDSCAN 
	ELSE 
		SELECT 0
		CREATE CURSOR stitky (nazev1 c(30), ean1 c(30), pocet1 N(10,4), spotreba1 D, sscc1 c(50), sscc_kod1 c(50), nazev2 c(30), ean2 c(30), pocet2 N(10,4), spotreba2 D, sscc2 c(50), sscc_kod2 c(50), nazev3 c(30), ean3 c(30), pocet3 N(10,4), spotreba3 D, sscc3 c(50), sscc_kod3 c(50))
		SELECT doklad
		m.x="1"
		SCAN FOR !ISNULL(sscc)
			IF m.x="1"
				INSERT INTO stitky (nazev1, ean1, pocet1, spotreba1, sscc1) VALUES (doklad.nazev, doklad.serial_no, -doklad.mnozstvi, doklad.datum_dokl+doklad.zaruka, doklad.sscc)
				m.x="2"
			ELSE
				IF m.x="2"
					REPLACE stitky.nazev2 WITH doklad.nazev, stitky.ean2 WITH doklad.serial_no, stitky.pocet2 WITH -doklad.mnozstvi, stitky.spotreba2 WITH doklad.datum_dokl+doklad.zaruka, stitky.sscc2 WITH doklad.sscc
	*				m.x="3"
	*			ELSE
	*				REPLACE stitky.nazev3 WITH doklad.nazev, stitky.ean3 WITH doklad.serial_no, stitky.pocet3 WITH doklad.mnozstvi, stitky.spotreba3 WITH doklad.datum_dokl+doklad.zaruka, stitky.sscc3 WITH doklad.sscc
					m.x="1"
				ENDIF
			ENDIF
		ENDSCAN
		SELECT stitky
		REPLACE ALL sscc_kod1 WITH "(02)"+ALLTRIM(ean1)+"(15)"+SUBSTR(DTOS(spotreba1),3,6)+"(37)"+PADL(ALLTRIM(STR(pocet1,4,0)),4,"0")
		SELECT stitky
		GO TOP
		SELECT 0
		SELECT SPACE(30) AS sestava,.F. AS lbl INTO CURSOR selzost FROM stitky READWRITE WHERE .F.
		INSERT INTO selzost (sestava,lbl) VALUES (jaz("rep_stitky_1"),.F.)
	*!*		INSERT INTO selzost (sestava,lbl) VALUES (jaz("rep_stitky_2"),.F.)
	*!*		INSERT INTO selzost (sestava,lbl) VALUES (jaz("rep_stitky_3"),.F.)
	*!*		DO FORM selpartn WITH "selzost","sestava"
	*!*		SELECT selzost
	*!*		SCAN FOR !EMPTY(lbl)
	*!*			DO CASE
	*!*				CASE RECNO()=1
					SELECT stitky
					DO pr_report WITH "sscc1", .f.
	*!*				CASE RECNO()=2
	*!*					SELECT stitky
	*!*					DO pr_report WITH "sscc1", m.spajaj
	*!*				CASE RECNO()=3
	*!*					SELECT stitky
	*!*					DO pr_report WITH "sscc1", m.spajaj
	*!*			ENDCASE
	*!*			SELECT selzost
	*!*		ENDSCAN
	*!*		USE IN selzost
		USE IN stitky
	ENDIF 
ENDIF
