PARAMETERS edimeno, edipor, orimeno, m.kodedistred
#DEFINE PNT  "."
    LOCAL cisloriadku
    cisloriadku=1
    insert_edihlav()
*HDR;45326533;STRACHAN, s.r.o;BACHLEDOVÁ Strachan, s.r.o;3221104229;23.05.2022;;;;;;;
*LIN;;;;3221104229;;ST328 Olej fritovací 10l Fritol;8585000777050;ks;20;2;30,62;61,24

    DO WHILE !FEOF(m.edisubor) OR !EMPTY(m.txtriadok)
        DO CASE 
            CASE LEFT(m.txtriadok,3)="HDR"
                SELECT edihlav
                REPLACE c_faktury WITH SUBSTR(m.txtriadok,AT(";",m.txtriadok,4)+1,AT(";",m.txtriadok,5)-AT(";",m.txtriadok,4)-1)
                REPLACE dat_vyst WITH CTOD(SUBSTR(m.txtriadok,AT(";",m.txtriadok,5)+1,AT(";",m.txtriadok,6)-AT(";",m.txtriadok,5)-1))
                REPLACE ico WITH "51801540", partner WITH "Food Logistic s.r.o.", dic WITH "2120803927", icdph WITH "SK2120803927"
                REPLACE ulica WITH "Jelšová 16"
                REPLACE mesto WITH "Košice"
                REPLACE psc WITH "04022"
            CASE LEFT(m.txtriadok,3)="LIN"
                INSERT INTO edipol (id_edi, c_data, riadok, ean, kod_zak, mnozstvo, cena, cena_celk, dan, nazov) VALUES ;
                    (m.hladajidedi, m.cdata, m.cisloriadku,;
                    SUBSTR(m.txtriadok,ATC(";",m.txtriadok,7)+1,ATC(";",m.txtriadok,8)-ATC(";",m.txtriadok,7)-1),;
                    "",;
                    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,11)+1,ATC(";",m.txtriadok,12)-ATC(";",m.txtriadok,11)-1),",",PNT)),;
                    VAL(STRTRAN(SUBSTR(m.txtriadok,ATC(";",m.txtriadok,12)+1),",",PNT)),;
                    VAL(STRTRAN(SUBSTR(m.txtriadok,ATC(";",m.txtriadok,9)+1,ATC(";",m.txtriadok,10)-ATC(";",m.txtriadok,9)-1),",",PNT)),;
                    STRCONV(SUBSTR(m.txtriadok,ATC(";",m.txtriadok,6)+1,ATC(";",m.txtriadok,7)-ATC(";",m.txtriadok,6)-1),11)+" "+SUBSTR(m.txtriadok,ATC(";",m.txtriadok,8)+1,ATC(";",m.txtriadok,9)-ATC(";",m.txtriadok,8)-1))
                IF m.hotel_platca_dph
                    REPLACE suma WITH suma+VAL(STRTRAN(SUBSTR(m.txtriadok,ATC(";",m.txtriadok,12)+1),",",PNT))
                ELSE
                    REPLACE suma WITH suma+VAL(STRTRAN(SUBSTR(m.txtriadok,ATC(";",m.txtriadok,12)+1),",",PNT))*(VAL(STRTRAN(SUBSTR(m.txtriadok,ATC(";",m.txtriadok,9)+1,ATC(";",m.txtriadok,10)-ATC(";",m.txtriadok,9)-1),",",PNT))/100+1)
                ENDIF  
        ENDCASE 
        txtriadok=FGETS(m.edisubor)
        cisloriadku=m.cisloriadku+1
    ENDDO
    SELECT edipol
    IF !m.hotel_platca_dph
        REPLACE ALL cena WITH cena*(dan/100+1), cena_celk WITH cena_celk*(dan/100+1)
        REPLACE ALL dan WITH 0
    ENDIF 
    druhy_doklad_z_minusu()
    uloz_a_zavri()
