    insert_edihlav()
    DO WHILE !FEOF(m.edisubor)
        txtriadok=FGETS(m.edisubor)
        DO CASE 
            CASE LEFT(m.txtriadok,3)="HDR" AND SUBSTR(m.txtriadok,149,13)="8594007910001" &&Bidvest
                lastline="X"
                typ_special="Bidvest"
                SELECT edihlav
                REPLACE c_faktury WITH alsu(4,15),dat_vyst WITH CTOD(SUBSTR(m.txtriadok,25,2)+"."+SUBSTR(m.txtriadok,23,2)+"."+SUBSTR(m.txtriadok,19,4))
                REPLACE ico WITH "28234642",partner WITH "Bidfood Czech Republic s.r.o."

            CASE LEFT(m.txtriadok,3)="HDR" AND SUBSTR(m.txtriadok,149,13)="34152199" &&Bidvest
                lastline="X"
                typ_special="UTF8"
                SELECT edihlav
                REPLACE c_faktury WITH alsu(4,15),dat_vyst WITH CTOD(SUBSTR(m.txtriadok,25,2)+"."+SUBSTR(m.txtriadok,23,2)+"."+SUBSTR(m.txtriadok,19,4))
                REPLACE ico WITH "28234642",partner WITH "Bidfood Czech Republic s.r.o."

            CASE LEFT(m.txtriadok,3)="HDR" &&Standard
                lastline="HDR"
                SELECT edihlav
                REPLACE c_faktury WITH alsu(4,15),dat_vyst WITH CTOD(SUBSTR(m.txtriadok,25,2)+"."+SUBSTR(m.txtriadok,23,2)+"."+SUBSTR(m.txtriadok,19,4))
                IF !EMPTY(ALLTRIM(SUBSTR(m.txtriadok,115,17)))
                    REPLACE edi_kod WITH alsu(115,17)
                ENDIF 
                        REPLACE ico WITH alsu(149,17)
                        PRIVATE m.hladajico
                        hladajico = alsu(149,17)
                        IF !EMPTY(m.hladajico)
                            SELECT 0
                            IF m.issql
                                USE (m.sqlprefix+"rpartnerico") ALIAS rpart
                            ELSE
                                IF !USED("partneri")
                                    USE (m.fn_partneri) IN 0 ALIAS partneri
                                ENDIF 
                                USE vpartnerico ALIAS rpart IN 0
                            ENDIF 
                            IF RECCOUNT("rpart")>0
                                SELECT rpart
                                GO TOP 
                                SELECT edihlav
                                REPLACE partner WITH rpart.partner
                            ELSE
                                USE IN rpart
                                IF m.issql
                                    USE (m.sqlprefix+"rpartner_edikod") ALIAS rpart
                                ELSE
                                    USE vpartner_edikod ALIAS rpart IN 0
                                ENDIF 
                                IF RECCOUNT("rpart")>0
                                    SELECT rpart
                                    GO TOP 
                                    SELECT edihlav
                                    REPLACE partner WITH rpart.partner
                                ENDIF 
                            ENDIF 
                        ENDIF 
                        DO pozavirej WITH "partneri, rpart"
                        SELECT edihlav
            CASE LEFT(m.txtriadok,3)="LIN" AND m.typ_special="Bidvest" &&Bidvest
                lastline="LIN"
                IF SUBSTR(m.txtriadok,75,1)="," && Bidvest
                    INSERT INTO edipol (id_edi, c_data, riadok, ean, kod_zak, mnozstvo, cena, cena_celk, dan, nazov) VALUES ;
                        (m.hladajidedi, m.cdata, valsu(4,6), alsu(10,25), alsu(35,25), valsu(64,15), ;
                        valsu(80,13), valsu(64,15) * valsu(80,13), valsu(94,6), alsu(184,45))
                ELSE
	                INSERT INTO edipol (id_edi, c_data, riadok, ean, kod_zak, mnozstvo, cena, cena_celk, dan, nazov) VALUES ;
                        (m.hladajidedi, m.cdata, valsu(4,6), alsu(10,25), alsu(35,25), valsu(93,12), ;
                        valsu(76,12), valsu(76,12) * valsu(93,12), valsu(88,5), alsu(177,45))
                ENDIF 
            CASE LEFT(m.txtriadok,3)="LIN" &&Standard
                lastline="LIN"
                INSERT INTO edipol (id_edi, c_data, riadok, ean, kod_zak, mnozstvo, cena, cena_celk, dan, nazov) VALUES ;
                    (m.hladajidedi, m.cdata, VAL(SUBSTR(m.txtriadok,4,6)),ALLTRIM(SUBSTR(m.txtriadok,10,25)),ALLTRIM(SUBSTR(m.txtriadok,35,25)), VAL(ALLTRIM(SUBSTR(m.txtriadok,93,12))),;
                    valsu(76,12), valsu(76,12) * valsu(93,12), valsu(88,5), alsu(177,45))
            CASE LEFT(m.txtriadok,3)="SUM"
                lastline="SUM"
                SELECT edihlav
                IF m.hotel_platca_dph
                    REPLACE suma WITH valsu(40,12)
                ELSE 
                    REPLACE suma WITH valsu(40,12) + valsu(74,12)
                ENDIF 
            OTHERWISE 
                IF lastline="HDR"
                    SELECT edihlav
                    REPLACE ico WITH alsu(328-254,15),partner WITH alsu(293-254,35)
                    m.lastline=""
                ENDIF 
        ENDCASE 
    ENDDO
    druhy_doklad_z_minusu_a_suma()
    uloz_a_zavri("SYS ")
