
#DEFINE ODDELOVAC ","
#DEFINE PNT       "."

dodavatel="vino markuzzi"

DO WHILE !FEOF(m.edisubor) OR !EMPTY(m.txtriadok)
    txtriadok = m.txtriadok + REPLICATE(ODDELOVAC, 22)
    DO CASE 
    CASE ATC("CisloDokladu", m.txtriadok) + ATC("IdentCode", m.txtriadok) > 0     && tyhle radky se ignoruji

    CASE ATC("VINO MARKUZZI", m.txtriadok) > 0    && radek hlavicky
        c_faktury  = get_1_item()
        dat_vyst   = get_1_item()
        void       = get_1_item()
        pro_koho   = get_1_item()
        void       = get_1_item()
        provozovna = get_1_item()
        suma       = VAL(get_1_item())
        
        IF EMPTY(m.provozovna)
            provozovna = m.pro_koho
        ENDIF 

        insert_edihlav()

        dat_vyst = DATE(VAL(LEFT(m.dat_vyst, 4)), VAL(SUBSTR(m.dat_vyst, 6,2)), VAL(SUBSTR(m.dat_vyst, 9,2)))

        SELECT edihlav
        REPLACE c_faktury WITH m.c_faktury
        REPLACE dat_vyst  WITH m.dat_vyst
        REPLACE partner   WITH m.dodavatel
        REPLACE suma      WITH m.suma

    OTHERWISE                                   && radky dokladu
        riadok   = VAL(get_1_item()) + 6000
        ean      =     get_1_item()
        nazov    =     get_1_item()
        dan      = VAL(get_1_item()) 
        mnozstvo = VAL(get_1_item())
        void     =     get_1_item()  && MJ
        cena     = VAL(get_1_item())
        cena_celk = m.mnozstvo * m.cena

        INSERT INTO edipol (id_edi, c_data ,   riadok,   ean, kod_zak,  mnozstvo,   cena,   cena_celk,   dan,   nazov) ;
             VALUES (m.hladajidedi, m.cdata, m.riadok, m.ean,   ""   ,m.mnozstvo, m.cena, m.cena_celk, m.dan, m.nazov) 

    ENDCASE 
        txtriadok=FGETS(m.edisubor)
ENDDO
SELECT edipol
druhy_doklad_z_minusu()
uloz_a_zavri( "markuzzi" )


*  CisloDokladu, DatRealizace, CisloOrg, NazevOrg, CisloStrediska, NazevStrediska, SumaBezDPH,CisloDodavatele,NazevDodavatele
*  19101300,2019-03-26T00:00:00, 2134, Grosseto servis s.r.o., 388, Grosseto Prùhonice,10881.00, 28247663,VINO MARKUZZI s.r.o.  

*  Poradi,IdentCode,Nazev                      ,SazbaDPH,Mnozstvi,MJ,JCbezDPH,CCbezDPH,CCvcDPH
*  1,1013512,Nino Franco-Rustico                         ,21,18,ks, 261.00,  4698.00,  5684.58
*  2,1049456,Marchesi di Gresy Sauvignon Langhe 2017     ,21,12,ks, 342.00,  4104.00,  4965.84
*  3,1050064,Conterno Fantino Barbera d´Alba Vignota 2017,21, 6,ks, 346.50,  2079.00,  2515.59



*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 
FUNCTION get_1_item

pozice    = AT(ODDELOVAC, m.txtriadok)
retv      = ALLTRIM(LEFT( m.txtriadok, m.pozice - 1))
txtriadok = SUBSTR (      m.txtriadok, m.pozice + 1)
IF LEFT(m.retv, 1) = '"' .and. RIGHT(m.retv, 1) = '"'
    retv = SUBSTR(m.retv, 2, LEN(m.retv) - 2)
ENDIF 
RETURN m.retv
