typ_special="xx UTF8"

insert_edihlav()
DO WHILE !FEOF(m.edisubor)
    txtriadok = FGETS(m.edisubor, 8192)
    
    IF m.typ_special="UTF8"
         txtriadok = STRCONV(m.txtriadok,11)
    ENDIF 
    
    DO CASE 
    CASE LEFT(m.txtriadok,3)="HDR"
        SELECT edihlav
        REPLACE c_faktury WITH alsu(4,15), dat_vyst WITH DATE(valsu(25,4), valsu(29,2), valsu(31,2)), edi_stred WITH alsu(273, 17)
        REPLACE ico   WITH alsu(324, 15), dic WITH alsu(339, 15), iban  WITH alsu(442, 34), icdph WITH "", swift WITH alsu(546, 10)

    CASE LEFT(m.txtriadok,3)="HDD"
        SELECT edihlav
        REPLACE partner WITH alsu(360,35), ulica WITH alsu(535,35), mesto WITH alsu(675,35), psc WITH alsu(710,6), edi_stred WITH alsu(716, 34) + alsu(1031, 33)
        IF EMPTY(edihlav.edi_stred)
            REPLACE edi_stred WITH alsu(716, 34) + alsu(1031, 33)
        ENDIF 

    CASE LEFT(m.txtriadok,3)="LIN"
        INSERT INTO edipol (id_edi, c_data, riadok,     ean,        kod_zak,   mnozstvo,      cena,            cena_celk,    dan) ;
           VALUES (m.hladajidedi, m.cdata, valsu(4,6), alsu(10,25), alsu(35,25), valsu(63,12), valsu(75,12), valsu(118,12), valsu(130,5))
        SELECT edipol
        REPLACE nazov WITH alsu(358,70)
        IF LEN(ALLTRIM(ean))=1
            REPLACE ean WITH ""
        ENDIF 

    CASE LEFT(m.txtriadok,3)="SUM"
        SELECT edihlav
        IF m.hotel_platca_dph
            REPLACE suma WITH valsu(40,12)
        ELSE 
            REPLACE suma WITH valsu(40,12) + valsu(86,12)
        ENDIF 
    ENDCASE 
ENDDO
IF !m.hotel_platca_dph
    SELECT edipol
    REPLACE ALL cena WITH cena*(dan/100+1), cena_celk WITH cena_celk*(dan/100+1), dan WITH 0
ENDIF 
druhy_doklad_z_minusu()
uloz_a_zavri("SYS INVOIC")
