* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
*
* program cte vsechny soubory z disposu, karty, ktere nenajde v eany.dbf, doplni
* potom kontroluje, zda vsechny karty v eany.dbf maji vyplnenu bouranou kartu, kdyz ne, upozorni obsluhu
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

ean_path = "s:\dispos\"

DO clos_data
SET REPROCESS TO AUTOMATIC
chyba_pri_otevirani = .F.
TRY
    IF m.issql
        otevira_se = "milanovo SQL"
    ELSE
        otevira_se = m.fn_eany
        USE (m.fn_eany)     ALIAS eany     IN 0 ORDER ean
    ENDIF
CATCH
    chyba_pri_otevirani = .T.
ENDTRY

IF chyba_pri_otevirani
    =MESSAGEBOX(jaz("prg_dbf_neprist_skuste_pozdeji")+CHR(13)+m.otevira_se,64,"Food600",2222)
    DO zurnal_log WITH "OPERA", "globus_imp", jaz("nejde_otevrit") + m.otevira_se
    RETURN .F.
ENDIF

pocet_souboru = ADIR(soubory, m.ean_path + "GASTRO_" + "???" + "_*.csv")
FOR iii = 1 TO pocet_souboru
    m.soubor_ean = m.ean_path + soubory(iii, 1)
    fh = FOPEN(m.soubor_ean)
    IF m.fh > 0 
            oddelovac = ";"
            DO while ! feof(m.fh)
*** "WGRNRCHILD";"WGRTXT";"ZID";"INFOWERT";"VANR";"ARTTXT";"ANZ";"HERSTELLER";"HERSTNAME";"DATUM";"VORGANGSNR";"LIEFNR";"MENGE1";"DUEKINV";"DUEKNETTONETTO";"VKBRUTTO"
*** 6152115;"SLANÉ OŘÍŠKY";7;"735";689980006;"G1 ARAŠÍDY SOL. 500G";1;80751;"ENCINGER S.R.O.";18.11.13;0;65000075;6;23,2072;23,2072;29,9

              radek      = fgets(m.fh,333)
              at1        = at(m.oddelovac, m.radek, 4)
              ean        = ALLTRIM(STR(INT(VAL(substr(m.radek, m.at1+1))),15))    && VANR

              at1        = at(m.oddelovac, m.radek, 12)
              mnozstvi   = VAL(substr(m.radek, m.at1+1))    && MENGE1

              at1        = at(m.oddelovac, m.radek, 14)
              cena       = VAL(substr(m.radek, m.at1+1))    && DUEKNETTONETTO

              at1        = at(';"', m.radek, 3)
              at2        = at('";', m.radek, 3)
              nazev      = substr(m.radek, m.at1+2, m.at2-m.at1-2)    && ARTTXT

              IF .not. EMPTY(m.ean) .and. m.mnozstvi # 0
                  SELECT eany
                  LOCATE FOR ALLTRIM(ean) = m.ean
                  IF .not. FOUND()
                     koef = 1
                     c_karty = 0
                     ? "     inserted " + m.ean + "   " + m.nazev + "   from " + m.soubor_ean 
                     INSERT INTO (m.gcdat_path + "eany") (ean, popis, c_karty, koef) VALUES (m.ean, m.nazev, m.c_karty, m.koef)
                  ENDIF 
              ENDIF 
            ENDDO 
            FCLOSE(m.fh)
    ELSE
          WAIT "nelze otevrit soubor " + m.soubor_ean WINDOW TIMEOUT 3 AT 22,22
    ENDIF 
ENDFOR

SELECT eany
LOCATE FOR EMPTY(c_karty)
IF FOUND()
    MESSAGEBOX("Doplnte EANy, jinak nepujde prijimat zbozi z Disposu" + CHR(13) + "(Vzorniky - EANy)", 1+48, "Import DISPOS")
ENDIF 
DO clos_data
