LOCAL partnerico
PRIVATE m.mesiac
PRIVATE m.edicesta, otvorenyfooddat, m.hladajidediprev, m.typ_obj, m.cdata, m.hladajpz2
PRIVATE m.hhotel_naz1, m.x_partner, m.x_stredisk, m.menostrediska, m.hhotel_ulica, m.hhotel_psc, m.hhotel_mesto, m.hhotel_telefon, m.hhotel_osoba, m.hhotel_mail, m.hhotel_gln
PRIVATE m.menopartnera, m.mailovaadresa, m.pokecdodavatela, m.partneredikod, m.ii, m.partneredikoddodania, m.cislo_objednavky
m.partnerico="31377971"
m.menopartnera="CORNER SK spol. s r.o."
m.mailovaadresa="milan@alto.sk"
m.partneredikod=""
m.partneredikoddodania=""
m.partneredikod=""
m.partneredikoddodania=""
m.pokecdodavatela=""
#DEFINE CRLF CHR(13)+CHR(10)
m.otvorenydokl=.t.
m.otvorenyobr=.t.
m.otvorenyfooddat=.t.
m.hhotel_naz1=m.hotel_naz1
m.hhotel_ulica=m.hotel_naz2
m.hhotel_psc=m.hotel_naz4
m.hhotel_mesto=m.hotel_naz3
m.hhotel_osoba=""
m.hhotel_telefon=""
m.hhotel_mail=""
m.hhotel_ico=m.hotel_ico
m.hhotel_icdph=m.hot_icdph
m.hhotel_gln=IIF(EMPTY(m.hotel_edikod), ALLTRIM(m.hotel_ico), ALLTRIM(m.hotel_edikod))

DO open_database
DO pozavirej WITH "vybr, export, predaj, eany, karty, sk_pol, edi_pol, edi_hlav"
USE (m.gccen_path+"eany.dbf") IN 0 ALIAS eany
USE (m.gccen_path+"karty.dbf") IN 0 ALIAS karty
USE (m.gccen_path+"sk_pol.dbf") IN 0 ALIAS sk_pol
USE (m.gccen_path+"edi_pol.dbf") IN 0 ALIAS edi_pol
USE (m.gccen_path+"edi_hlav.dbf") IN 0 ALIAS edi_hlav
USE ("vdonovalskypivovar_export") IN 0 ALIAS export
SELECT distinct ean, kod_zak, nazov FROM edi_pol WHERE id_edi in (SELECT id_edi FROM edi_hlav WHERE ico=m.partnerico) INTO CURSOR edikody
SELECT eany.c_karty, eany.ean, edikody.kod_zak, edikody.nazov FROM eany INNER JOIN edikody ON ALLTRIM(eany.ean)==ALLTRIM(edikody.ean) OR ALLTRIM(eany.ean)==ALLTRIM(edikody.kod_zak) INTO CURSOR sortiment
SELECT disti LEFT(uzaverka,4) as rok, SUBSTR(uzaverka,5,2) as mes, SPACE(20) as mesiac FROM export ORDER BY  rok desc, mes desc INTO CURSOR vybr READWRITE 
IF RECCOUNT("vybr")>0
	REPLACE ALL mesiac WITH rok+" "+jaz("januar") FOR mes='01'
	REPLACE ALL mesiac WITH rok+" "+jaz("februar") FOR mes='02'
	REPLACE ALL mesiac WITH rok+" "+jaz("marec") FOR mes='03'
	REPLACE ALL mesiac WITH rok+" "+jaz("april") FOR mes='04'
	REPLACE ALL mesiac WITH rok+" "+jaz("maj") FOR mes='05'
	REPLACE ALL mesiac WITH rok+" "+jaz("jun") FOR mes='06'
	REPLACE ALL mesiac WITH rok+" "+jaz("jul") FOR mes='07'
	REPLACE ALL mesiac WITH rok+" "+jaz("august") FOR mes='08'
	REPLACE ALL mesiac WITH rok+" "+jaz("september") FOR mes='09'
	REPLACE ALL mesiac WITH rok+" "+jaz("oktober") FOR mes='10'
	REPLACE ALL mesiac WITH rok+" "+jaz("november") FOR mes='11'
	REPLACE ALL mesiac WITH rok+" "+jaz("december") FOR mes='12'
	DO FORM dajdruh WITH "","vybr","mesiac",250 TO m.mesiac
	IF !EMPTY(m.mesiac)
		SELECT vybr
		LOCATE FOR mesiac=m.mesiac
		IF FOUND()
			LOCAL m.prmesiac, m.prrok
			m.prmesiac=vybr.mes
			m.prrok=vybr.rok
			SELECT export.mnozstvi, export.c_karty, sortiment.ean, sortiment.kod_zak, sortiment.nazov FROM export INNER JOIN sortiment ON export.c_karty=sortiment.c_karty  WHERE LEFT(export.uzaverka,6)=m.prrok+m.prmesiac INTO CURSOR predaj
			m.cesta=m.gchom_path
			m.cesta=GETDIR(m.cesta,jaz("form_adresar"),jaz("form_vyber_adresar_na_export"))
			IF !EMPTY(m.cesta)
				SELECT predaj
				**** Nasleduje vytvorenie edi objednavky ***
				m.menosuboru=m.cesta+"DESADV_"+ALLTRIM(m.prrok)+ALLTRIM(m.prmesiac)+"_"+STRTRAN(STRTRAN(STRTRAN(TTOC(DATETIME())," ",""),".",""),":","")+"_"+SYS(2015)+".txt"
				m.menoriadok="SYS"+PADR(ALLTRIM(m.partneredikod),14)+"E"+"D  96A"+"DESADV"+"P"+CHR(13)+CHR(10)
				=STRTOFILE(m.menoriadok,m.menosuboru,1)
		       DO zapis_radek_hlavicky96
				SELECT predaj
				m.poradie=0
				SCAN ALL 
					m.poradie=m.poradie+1
					DO zapis_radek_telicka96
				ENDSCAN
				=MESSAGEBOX(jaz("form_vytvoreny_subor")+":"+CHR(10)+m.menosuboru,64,"FoodMan",2000)
				IF FILE(m.menosuboru) AND (!EMPTY(man_email_from) OR !EMPTY(food_email_from)) AND !EMPTY(m.mailovaadresa)
					DO poslimailhocikam WITH "Dodaci list c:"+ALLTRIM(STR(dokladxx.c_dokl,10,0))+" "+m.hotel_name, "", m.menosuboru,"","",m.mailovaadresa
					IF !EMPTY(m.hhotel_mail)
						DO poslimailhocikam WITH "Dodaci list c:"+ALLTRIM(STR(dokladxx.c_dokl,10,0))+" "+m.hotel_name, "", m.menosuboru,"","",m.hhotel_mail
					ENDIF 				
				ENDIF 
			ENDIF 
		ENDIF 
	ENDIF 
ENDIF 
DO pozavirej WITH "vybr, export, predaj, eany, karty, sk_pol, edi_pol, edi_hlav"


		
PROCEDURE  zapis_radek_hlavicky96
menoriadok = "HDR"                                            &&  1 C3  P
menoriadok = m.menoriadok + PADR(m.mesiac						,15)  &&  2 C15 P cislo dodaciho listu
menoriadok = m.menoriadok + PADR(DTOS(DATE())					,8)  &&  3 C8  P datum vystaveni
menoriadok = m.menoriadok + SPACE(								8)  &&  4 C8  N datum odjezdu dodavky  - nic 
menoriadok = m.menoriadok + SPACE(								4)  &&  5 C4  N cas odjezdu dodavky  - nic
menoriadok = m.menoriadok + SPACE(								8)  &&  6 C8  P datum ocekavane dodavky - nic
menoriadok = m.menoriadok + SPACE(								4)  &&  7 C4  N cas ocekavanedodavky - nic
menoriadok = m.menoriadok + SPACE(								17)  &&  8 C17 N doprava - nic
menoriadok = m.menoriadok + SPACE(								15)  &&  9 C15 P cislo objednavky zakaznika  - nic
menoriadok = m.menoriadok + PADR(m.mesiac						,15)  && 10 C15 N cislo faktury

menoriadok = m.menoriadok + SPACE(								17)  && 11 C17 P ean kupujiciho - ICO
menoriadok = m.menoriadok + SPACE(								17)  && 12 C17 P ean provozovny - partneri.edikod nebo pokud je prazdny, tak partneri.ico
menoriadok = m.menoriadok + SPACE(								17)  && 13 C17 N ean fakturacniho mista - nic
menoriadok = m.menoriadok + SPACE(								17)  && 14 C17 P ean dodavatele - ICO
menoriadok = m.menoriadok + SPACE(								17)  && 15 C17 N ean distribuc.skladu dodavatele - nic
menoriadok = m.menoriadok + PADR(m.menopartnera					,70)  && 16 C70 N nazev kupujiciho
menoriadok = m.menoriadok + SPACE(								17)  && 17 C17 N ean objednatele - nic 
menoriadok = m.menoriadok + SPACE(								15)  && 18 C15 N int. cislo dodavatele - nic
menoriadok = m.menoriadok + SPACE(								8)  && 19 C8  N datum vystaveni objednavky - nic
menoriadok = m.menoriadok + PADR(m.hotel_name					,35)  && 20 C35 N obch jmeno dodavatele
menoriadok = m.menoriadok + PADR(ALLTRIM(m.hotel_ico)+"-2"		,15)  && 21 C15 N ICO dodavatele 
STRTOFILE(m.menoriadok + CRLF, m.menosuboru, 1)


*    *    *    *    *    *    *    *    *    *    *    *    *    *



*    *    *    *    *    *    *    *    *    *    *    *    *    *
PROCEDURE  zapis_radek_telicka96
PRIVATE m.serial_no, m.hladajckarty
m.serial_no=ALLTRIM(predaj.ean)
menoriadok = "LIN"												&&  1 C3
menoriadok = m.menoriadok + nx(m.poradie, 0, 6)				&&  2 N6    cislo radku
menoriadok = m.menoriadok + PADR(m.serial_no, 25)				&&  3 C25   EAN zbozi
menoriadok = m.menoriadok + PADR(ALLTRIM(predaj.kod_zak), 25)		&&  4 C25   cislo zbozi dodavatele
menoriadok = m.menoriadok + PADR("Z", 4)						&&  5 C4    typ polozky: Z:zbozi, O:obal
menoriadok = m.menoriadok + nx(1.0, 3, 12)						&&  6 N12,3 pocet jednotek v baleni
menoriadok = m.menoriadok + nx(0, 2, 12)		&&  7 N12,2 cena za jednotku
menoriadok = m.menoriadok + nx(20, 2,  5)	&&  8 N5,2  sazba dph
menoriadok = m.menoriadok + nx(predaj.mnozstvi, 3, 12)		&&  9 N12,3 dodane mnozstvi
menoriadok = m.menoriadok + SPACE(3)							&& 10 C3    merna jednotka mnozstvi
menoriadok = m.menoriadok + SPACE(15)							&& 11 C15   cislo sarze
menoriadok = m.menoriadok + SPACE(8)							&& 12 C8    datum vyroby
menoriadok = m.menoriadok + SPACE(8)							&& 13 C8    datum trvanlivosti
menoriadok = m.menoriadok + SPACE(8)							&& 14 C8    datum pouzitelnosti
menoriadok = m.menoriadok + SPACE(15)							&& 15 C15   cislo objednavky zakaznika
menoriadok = m.menoriadok + SPACE(15)							&& 16 C15   cislo faktury
menoriadok = m.menoriadok + PADR(predaj.nazov, 45)			&& 17 C45   specifikace
menoriadok = m.menoriadok + SPACE(18)							&& 18 C18   sscc kod palety
STRTOFILE(m.menoriadok + CRLF, m.menosuboru, 1)
