#DEFINE PNT  "."
    c_faktury=SUBSTR(m.orimeno,ATC(".",m.orimeno)-8,8)
    IF !EMPTY(m.c_faktury)
        hladajidedi=i_max("id_edi") 
        insert_edihlav()
        SELECT edihlav
        REPLACE c_faktury WITH m.c_faktury, ico WITH "51230666", partner WITH "FreshBox s.r.o. ", ulica WITH "Klincová 35", mesto WITH "Bratislava", psc WITH "82108" FOR id_edi=m.hladajidedi
        DO WHILE !EMPTY(m.txtriadok)
            DO CASE 
                CASE LEFT(m.txtriadok,14)="[date-record]:" OR LEFT(m.txtriadok,18)="Dátum vyhotovenia:"
                    IF LEFT(m.txtriadok,14)="[date-record]:"
                        txtdatum=ALLTRIM(SUBSTR(m.txtriadok,15))
                    ELSE
                        txtdatum=ALLTRIM(SUBSTR(m.txtriadok,19))
                    ENDIF 
                    txtden=LEFT(m.txtdatum,2)
                    DO CASE 
                        CASE "jan"$LOWER(m.txtdatum)
                            txtmesiac="01"
                        CASE "feb"$LOWER(m.txtdatum)
                            txtmesiac="02"
                        CASE "mar"$LOWER(m.txtdatum)
                            txtmesiac="03"
                        CASE "apr"$LOWER(m.txtdatum)
                            txtmesiac="04"
                        CASE "máj"$LOWER(m.txtdatum)
                            txtmesiac="05"
                        CASE "jún"$LOWER(m.txtdatum)
                            txtmesiac="06"
                        CASE "júl"$LOWER(m.txtdatum)
                            txtmesiac="07"
                        CASE "aug"$LOWER(m.txtdatum)
                            txtmesiac="08"
                        CASE "sep"$LOWER(m.txtdatum)
                            txtmesiac="09"
                        CASE "okt"$LOWER(m.txtdatum)
                            txtmesiac="10"
                        CASE "nov"$LOWER(m.txtdatum)
                            txtmesiac="11"
                        OTHERWISE 
                            txtmesiac="12"
                    ENDCASE 
                    txtrok=SUBSTR(m.txtdatum,AT(" ",m.txtdatum,2)+1,4)
                    REPLACE dat_vyst WITH CTOD(m.txtden+"."+m.txtmesiac+"."+m.txtrok) FOR id_edi=m.hladajidedi
                 CASE LEFT(m.txtriadok,19)="[sn];[name];[code];" OR m.txtriadok="P.Č.;Názov;Kód;PN;Množstvo;MJ;DPH;Cena MJ Bez DPH;Spolu Bez DPH;"
                     txtriadok1="xx"
                     DO WHILE !EMPTY(m.txtriadok1)
*[sn];[name];[code];[part-no];[amount];MJ;DPH;Cena MJ bez DPH;Spolu bez DPH
                        IF m.txtriadok1<>"xx"
                            txtcena=VAL(STRTRAN(STRTRAN(STRTRAN(SUBSTR(m.txtriadok1,ATC(";",m.txtriadok1,7)+1,ATC(";",m.txtriadok1,8)-ATC(";",m.txtriadok1,7)-1),'"',''),'€',''),",",PNT))
                            txtdan=VAL(STRTRAN(STRTRAN(STRTRAN(SUBSTR(m.txtriadok1,ATC(";",m.txtriadok1,6)+1,ATC(";",m.txtriadok1,7)-ATC(";",m.txtriadok1,6)-1),'"',''),'%',''),",",PNT))                                            
                            IF m.hotel_platca_dph
                                INSERT INTO edipol (id_edi, c_data, riadok, ean, kod_zak, mnozstvo, cena, nazov) VALUES ;
                                    (m.hladajidedi, m.cdata, VAL(LEFT(m.txtriadok1,ATC(";",m.txtriadok1,1)-1)),;
                                    "",;
                                    SUBSTR(m.txtriadok1,ATC(";",m.txtriadok1,2)+1,ATC(";",m.txtriadok1,3)-ATC(";",m.txtriadok1,2)-1),;
                                    VAL(STRTRAN(SUBSTR(m.txtriadok1,ATC(";",m.txtriadok1,4)+1,ATC(";",m.txtriadok1,5)-ATC(";",m.txtriadok1,4)-1),",",PNT)),;
                                    m.txtcena,;
                                    STRTRAN(SUBSTR(m.txtriadok1,ATC(";",m.txtriadok1,1)+1,ATC(";",m.txtriadok1,2)-ATC(";",m.txtriadok1,1)-1)+" "+SUBSTR(m.txtriadok1,ATC(";",m.txtriadok1,5)+1,ATC(";",m.txtriadok1,6)-ATC(";",m.txtriadok1,5)-1),'"',''))
                            ELSE
                                INSERT INTO edipol (id_edi, c_data, riadok, ean, kod_zak, mnozstvo, cena, nazov) VALUES ;
                                    (m.hladajidedi, m.cdata, VAL(LEFT(m.txtriadok1,ATC(";",m.txtriadok1,1)-1)),;
                                    "",;
                                    SUBSTR(m.txtriadok1,ATC(";",m.txtriadok1,2)+1,ATC(";",m.txtriadok1,3)-ATC(";",m.txtriadok1,2)-1),;
                                    VAL(STRTRAN(SUBSTR(m.txtriadok1,ATC(";",m.txtriadok1,4)+1,ATC(";",m.txtriadok1,5)-ATC(";",m.txtriadok1,4)-1),",",PNT)),;
                                    m.txtcena*(m.txtdan/100+1),;
                                    STRTRAN(SUBSTR(m.txtriadok1,ATC(";",m.txtriadok1,1)+1,ATC(";",m.txtriadok1,2)-ATC(";",m.txtriadok1,1)-1)+" "+SUBSTR(m.txtriadok1,ATC(";",m.txtriadok1,5)+1,ATC(";",m.txtriadok1,6)-ATC(";",m.txtriadok1,5)-1),'"',''))
                            ENDIF 
                        ENDIF 
                        txtriadok1=FGETS(m.edisubor)
                    ENDDO 
            ENDCASE 
            txtriadok=FGETS(m.edisubor)
        ENDDO
        SELECT edipol
        REPLACE ALL cena_celk WITH cena*mnozstvo
        SELECT disti id_edi INTO CURSOR idedi FROM edihlav READWRITE 
        SELECT edihlav
        SCAN ALL 
            SELECT idedi
            LOCATE FOR id_edi=edihlav.id_edi
            IF !FOUND()
                INSERT INTO idedi (id_edi) VALUES (edihlav.id_edi)
            ENDIF 
            SELECT edipol
            SUM cena_celk TO m.sumadokladu FOR id_edi=edihlav.id_edi
            SELECT edihlav 
            REPLACE suma WITH m.sumadokladu
        ENDSCAN 
        SELECT edipol
        SCAN FOR mnozstvo<0
            hladajidedi=edipol.id_edi
            SELECT idedi
            LOCATE FOR id_edi=m.hladajidedi
            IF !FOUND()
                INSERT INTO idedi (id_edi) VALUES (m.hladajidedi)
            ENDIF 
        ENDSCAN 
        SELECT idedi
        SCAN ALL 
            hladajidedi=idedi.id_edi
            druhy_doklad_z_minusu()
        ENDSCAN 

        uloz_a_zavri()
    ENDIF 
