#DEFINE PNT  "."
    IF LEN(m.txtriadok)=254
        txtriadok=m.txtriadok+FGETS(m.edisubor)
    ENDIF 
    DO WHILE !FEOF(m.edisubor) OR !EMPTY(m.txtriadok)
        DO CASE 
            CASE LEFT(m.txtriadok,3)="HDR" AND LOWER(m.txtriadok)<>"hdr;číslo dokladu;dátum dokladu;ičo dodávateľa;meno dodávateľa;id miesta dodania;"
                hladajidedi=i_max("id_edi") 
                insert_edihlav()
                SELECT edihlav
                REPLACE c_faktury WITH SUBSTR(m.txtriadok,AT(";",m.txtriadok,1)+1,AT(";",m.txtriadok,2)-AT(";",m.txtriadok,1)-1) FOR id_edi=m.hladajidedi
                REPLACE dat_vyst WITH CTOD(SUBSTR(m.txtriadok,AT(";",m.txtriadok,2)+1,AT(";",m.txtriadok,3)-AT(";",m.txtriadok,2)-1)) FOR id_edi=m.hladajidedi
                REPLACE ico WITH SUBSTR(m.txtriadok,AT(";",m.txtriadok,3)+1,AT(";",m.txtriadok,4)-AT(";",m.txtriadok,3)-1) FOR id_edi=m.hladajidedi
                REPLACE partner WITH SUBSTR(m.txtriadok,AT(";",m.txtriadok,4)+1,AT(";",m.txtriadok,5)-AT(";",m.txtriadok,4)-1) FOR id_edi=m.hladajidedi
                REPLACE edi_stred WITH SUBSTR(m.txtriadok,ATC(";",m.txtriadok,5)+1,ATC(";",m.txtriadok,6)-ATC(";",m.txtriadok,5)-1) FOR id_edi=m.hladajidedi
                riadok=0
            CASE LEFT(m.txtriadok,3)="ORD" AND LOWER(m.txtriadok)<>"ord;číslo dokladu;dátum dokladu;ičo dodávateľa;meno dodávateľa;id miesta dodania;"
                hladajidedi=i_max("id_edi") 
                insert_edihlav()
                SELECT edihlav
                REPLACE c_faktury WITH SUBSTR(m.txtriadok,AT(";",m.txtriadok,1)+1,AT(";",m.txtriadok,2)-AT(";",m.txtriadok,1)-1) FOR id_edi=m.hladajidedi
                REPLACE dat_vyst WITH CTOD(SUBSTR(m.txtriadok,AT(";",m.txtriadok,2)+1,AT(";",m.txtriadok,3)-AT(";",m.txtriadok,2)-1)) FOR id_edi=m.hladajidedi
                REPLACE ico WITH SUBSTR(m.txtriadok,AT(";",m.txtriadok,3)+1,AT(";",m.txtriadok,4)-AT(";",m.txtriadok,3)-1) FOR id_edi=m.hladajidedi
                REPLACE partner WITH SUBSTR(m.txtriadok,AT(";",m.txtriadok,4)+1,AT(";",m.txtriadok,5)-AT(";",m.txtriadok,4)-1) FOR id_edi=m.hladajidedi
                REPLACE edi_stred WITH SUBSTR(m.txtriadok,ATC(";",m.txtriadok,5)+1,ATC(";",m.txtriadok,6)-ATC(";",m.txtriadok,5)-1) FOR id_edi=m.hladajidedi
                REPLACE is_order WITH .t. FOR id_edi=m.hladajidedi
                riadok=0
            CASE LEFT(m.txtriadok,3)="LIN" AND LOWER(m.txtriadok)<>"lin;názov tovaru;ean;kód tovaru;merná jednotka;sadzba dph;počet balení;jednotková cena bez dph;cena celkom bez dph;jednotková cena s dph;cena celkom s dph;"
                riadok=m.riadok+1
                IF m.hotel_platca_dph
                    INSERT INTO edipol (id_edi, c_data, riadok, ean, kod_zak, mnozstvo, cena, cena_celk, dan, nazov) VALUES ;
                        (m.hladajidedi, m.cdata, m.riadok,;
                        SUBSTR(m.txtriadok,ATC(";",m.txtriadok,2)+1,ATC(";",m.txtriadok,3)-ATC(";",m.txtriadok,2)-1),;
                        SUBSTR(m.txtriadok,ATC(";",m.txtriadok,3)+1,ATC(";",m.txtriadok,4)-ATC(";",m.txtriadok,3)-1),;
                        VAL(STRTRAN(SUBSTR(m.txtriadok,ATC(";",m.txtriadok,6)+1,ATC(";",m.txtriadok,7)-ATC(";",m.txtriadok,6)-1),",",PNT)),;
                        VAL(STRTRAN(SUBSTR(m.txtriadok,ATC(";",m.txtriadok,7)+1,ATC(";",m.txtriadok,8)-ATC(";",m.txtriadok,7)-1),",",PNT)),;
                        VAL(STRTRAN(SUBSTR(m.txtriadok,ATC(";",m.txtriadok,8)+1,ATC(";",m.txtriadok,9)-ATC(";",m.txtriadok,8)-1),",",PNT)),;
                        VAL(STRTRAN(SUBSTR(m.txtriadok,ATC(";",m.txtriadok,5)+1,ATC(";",m.txtriadok,6)-ATC(";",m.txtriadok,5)-1),",",PNT)),;
                        SUBSTR(m.txtriadok,ATC(";",m.txtriadok,1)+1,ATC(";",m.txtriadok,2)-ATC(";",m.txtriadok,1)-1)+" "+SUBSTR(m.txtriadok,ATC(";",m.txtriadok,4)+1,ATC(";",m.txtriadok,5)-ATC(";",m.txtriadok,4)-1))
                    SELECT edihlav
                    REPLACE suma WITH suma+VAL(STRTRAN(SUBSTR(m.txtriadok,ATC(";",m.txtriadok,8)+1,ATC(";",m.txtriadok,9)-ATC(";",m.txtriadok,8)-1),",",PNT)) FOR id_edi=m.hladajidedi
                ELSE
                    INSERT INTO edipol (id_edi, c_data, riadok, ean, kod_zak, mnozstvo, cena, cena_celk, dan, nazov) VALUES ;
                        (m.hladajidedi, m.cdata, m.riadok,;
                        SUBSTR(m.txtriadok,ATC(";",m.txtriadok,2)+1,ATC(";",m.txtriadok,3)-ATC(";",m.txtriadok,2)-1),;
                        SUBSTR(m.txtriadok,ATC(";",m.txtriadok,3)+1,ATC(";",m.txtriadok,4)-ATC(";",m.txtriadok,3)-1),;
                        VAL(STRTRAN(SUBSTR(m.txtriadok,ATC(";",m.txtriadok,6)+1,ATC(";",m.txtriadok,7)-ATC(";",m.txtriadok,6)-1),",",PNT)),;
                        VAL(STRTRAN(SUBSTR(m.txtriadok,ATC(";",m.txtriadok,9)+1,ATC(";",m.txtriadok,10)-ATC(";",m.txtriadok,9)-1),",",PNT)),;
                        VAL(STRTRAN(SUBSTR(m.txtriadok,ATC(";",m.txtriadok,10)+1,ATC(";",m.txtriadok,11)-ATC(";",m.txtriadok,10)-1),",",PNT)),;
                        VAL(STRTRAN(SUBSTR(m.txtriadok,ATC(";",m.txtriadok,5)+1,ATC(";",m.txtriadok,6)-ATC(";",m.txtriadok,5)-1),",",PNT)),;
                        SUBSTR(m.txtriadok,ATC(";",m.txtriadok,1)+1,ATC(";",m.txtriadok,2)-ATC(";",m.txtriadok,1)-1)+" "+SUBSTR(m.txtriadok,ATC(";",m.txtriadok,4)+1,ATC(";",m.txtriadok,5)-ATC(";",m.txtriadok,4)-1))
                    REPLACE suma WITH suma+VAL(STRTRAN(SUBSTR(m.txtriadok,ATC(";",m.txtriadok,10)+1,ATC(";",m.txtriadok,11)-ATC(";",m.txtriadok,10)-1),",",PNT)) FOR id_edi=m.hladajidedi
                ENDIF  
        ENDCASE 
        txtriadok=FGETS(m.edisubor, 8192)
    ENDDO
    SELECT edipol
    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()
