dodavatel = sss(m.txtriadok, 3)
IF val_point(dodavatel) # 0 
	dodavatel = "LUNYS, s.r.o."
ENDIF
provozovna = SUBSTR(m.txtriadok, AT(";", m.txtriadok, 14)+1)
insert_edihlav()

DO WHILE !FEOF(m.edisubor) OR !EMPTY(m.txtriadok)
    DO CASE 
    CASE LEFT(m.txtriadok,3)="HDR"
        SELECT edihlav
        REPLACE c_faktury WITH sss(m.txtriadok, 1), partner WITH m.dodavatel
        REPLACE dat_vyst WITH CTOD(sss(m.txtriadok + ";", 2))

        IF "LUNYS"$UPPER(m.dodavatel)
            REPLACE c_faktury WITH SUBSTR(sss(m.txtriadok, 1),5)
            REPLACE icdph WITH "SK2020019518", ico WITH "36472549", ulica WITH "Hlavná 4512/96", mesto WITH "Poprad", psc WITH "059 51"
		ELSE
            REPLACE icdph WITH sss(m.txtriadok, 9)
            REPLACE dic WITH SUBSTR(icdph,3)
            REPLACE ulica WITH sss(m.txtriadok, 5), mesto WITH sss(m.txtriadok, 7), psc WITH sss(m.txtriadok, 6)
        ENDIF 

    CASE LEFT(m.txtriadok,3)="LIN"
        DO CASE 
            CASE "LUNYS"$UPPER(m.dodavatel)
                INSERT INTO edipol (id_edi, c_data, riadok, ean, kod_zak, mnozstvo, cena, cena_celk, dan, nazov) VALUES ;
                       (m.hladajidedi, m.cdata, v_sss(m.txtriadok, 1), "", sss(m.txtriadok, 14), v_sss(m.txtriadok, 3),;
                       v_sss(m.txtriadok, 6) / v_sss(m.txtriadok, 3),;
                       v_sss(m.txtriadok, 6), v_sss(m.txtriadok, 12), sss(m.txtriadok, 13))

			CASE EMPTY(m.dodavatel) && mozno asseco doklad
					IF OCCURS(";",m.txtriadok) > 8
                        INSERT INTO edipol (id_edi, c_data, riadok, ean, kod_zak, mnozstvo, cena, cena_celk, dan, nazov) VALUES ;
                               (m.hladajidedi, m.cdata, v_sss(m.txtriadok, 1),	"",	sss(m.txtriadok, 2),;
                               v_sss(m.txtriadok, 6),	v_sss(m.txtriadok, 7),	v_sss(m.txtriadok, 8), 0, ;
                               sss(m.txtriadok, 3) + sss(m.txtriadok, 4))
						SELECT edihlav
						REPLACE suma WITH suma + v_sss(m.txtriadok, 8)
					ELSE 
                        INSERT INTO edipol (id_edi, c_data, riadok, ean, kod_zak, mnozstvo, cena, cena_celk, dan, nazov) VALUES ;
                               (m.hladajidedi, m.cdata, v_sss(m.txtriadok, 1), "",	sss(m.txtriadok, 2), v_sss(m.txtriadok, 6), v_sss(m.txtriadok, 7),;
                               val_point(m.txtriadok,ATC(";",m.txtriadok,8)+1), 0, sss(m.txtriadok, 3) + sss(m.txtriadok, 4))
						SELECT edihlav
						REPLACE suma WITH suma + val_point(SUBSTR(m.txtriadok,ATC(";",m.txtriadok,8)+1))
					ENDIF 

            OTHERWISE 
                IF ATC(";",m.txtriadok,15) > 0
                    INSERT INTO edipol (id_edi, c_data, riadok, ean, kod_zak, mnozstvo, cena, cena_celk, dan, nazov) VALUES ;
                           (m.hladajidedi, m.cdata, v_sss(m.txtriadok, 1), sss(m.txtriadok, 2), sss(m.txtriadok, 14),;
                           v_sss(m.txtriadok, 5), v_sss(m.txtriadok, 8) / v_sss(m.txtriadok, 5),;
                           v_sss(m.txtriadok, 8), v_sss(m.txtriadok, 12), sss(m.txtriadok, 13))
                ELSE 
                    INSERT INTO edipol (id_edi, c_data, riadok, ean, kod_zak, mnozstvo, cena, cena_celk, dan, nazov) VALUES ;
                           (m.hladajidedi, m.cdata, v_sss(m.txtriadok, 1), sss(m.txtriadok, 2), SUBSTR(m.txtriadok,ATC(";",m.txtriadok,14)+1),;
                           v_sss(m.txtriadok, 5), v_sss(m.txtriadok, 8) / v_sss(m.txtriadok, 5),;
                           v_sss(m.txtriadok, 8), v_sss(m.txtriadok, 12), sss(m.txtriadok, 13))
                ENDIF 
        ENDCASE 

    CASE LEFT(m.txtriadok,3)="VAT"
        SELECT edihlav
        IF m.hotel_platca_dph
            REPLACE suma WITH suma + v_sss(m.txtriadok + ";", 3)
        ELSE
            REPLACE suma WITH suma + v_sss(m.txtriadok + ";", 3) + v_sss(m.txtriadok, 2)
        ENDIF 

    ENDCASE 
    txtriadok = FGETS(m.edisubor)
ENDDO
SELECT edipol
IF !m.hotel_platca_dph
    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("HDR hotel_ico " + m.dodavatel)
