***********  ***********  ***********  ***********  ***********
** PROCEDURE prepni_sklad
***********  ***********  ***********  ***********  ***********
PARAMETERS testzalohy
PRIVATE bolazaloha
IF m.testzalohy
    m.bolazaloha=.f.
ELSE
    m.bolazaloha=("buf"$m.fn_obraty)
ENDIF 

gcdat_path  = ALLTRIM(food_dat.dat_path)
gccen_path   = ALLTRIM(food_dat.cen_path)
gcpgm_id     = ALLTRIM(food_dat.ID)
gcpgm        = ALLTRIM(food_dat.pgm)
gcid_zkratka = ALLTRIM(food_dat.id_zkratka)
gcpgm_param  = ALLTRIM(food_dat.pgm_param)
gcsetup_skup = ALLTRIM(food_dat.setup_skup)
gcbour_skup  = food_dat.bour_skup

publikuj    ("hladaj_ean_bour_skup", "  ")
DO CASE 
CASE m.slovenskaverzia
     * nic
CASE ATC("D_GROS", m.gchom_path) > 0
    publikuj("hladaj_ean_bour_skup", m.gcbour_skup)
ENDCASE 



gcpgmskupina = food_dat.skupina
gcstredskup  = food_dat.stredskup
gczadan_prn  = food_dat.zadan_prn
gcera_cen    = food_dat.era_cen
gic_stredisk = food_dat.c_stredisk
gcprava_skup = food_dat.prava_skup
IF m.issql
    m.cdata=food_dat.c_data
    IF EMPTY(m.cdata)
    	REPLACE c_data WITH 1
    	m.cdata=1
    ENDIF 
    IF USED("fooddatedi")
        SELECT fooddatedi
        LOCATE FOR c_stredisk=m.gic_stredisk
        m.man_edi_kod=ALLTRIM(fooddatedi.edi_kod)
        USE IN fooddatedi
    ENDIF 
ELSE
    IF FSIZE("edi_kod","food_dat")>0
        m.man_edi_kod=ALLTRIM(food_dat.edi_kod)
    ENDIF 
ENDIF 

TRY 
    sankcnicena  = IIF(BETWEEN(VAL(food_dat.sankcnicen), 1, 20), PADL(ALLTRIM(STR(VAL(food_dat.sankcnicen),2,0)),2,"0"), "20")
CATCH
    m.sankcnicena="20"
ENDTRY 

IF !m.issql
    IF !DIRECTORY(m.gccen_path)
        MKDIR(m.gccen_path)
    ENDIF
    IF !DIRECTORY(m.gcdat_path)
        MKDIR(m.gcdat_path)
    ENDIF
    SELECT 0
    IF !FILE(m.gchom_path + "edi_prev.dbf")
        DO creafile WITH (m.gchom_path + "edi_prev")
    ENDIF 
    IF !FILE(m.gchom_path + "z_horca.dbf")
        DO creafile WITH (m.gchom_path + "z_horca")
    ENDIF 
    IF !FILE(m.gchom_path + "typypohybov.dbf")
        DO creafile WITH (m.gchom_path + "typypohybov")
    ENDIF 
    IF !FILE(m.gcdat_path + "inv_uloz.dbf")
        DO creafile WITH (m.gcdat_path + "inv_uloz")
    ENDIF 
    IF !FILE(m.gcdat_path + "inventur.dbf")
        DO creafile WITH (m.gcdat_path + "inventur")
    ENDIF 
    IF !FILE(m.gccen_path + "edi_part.dbf")
        DO creafile WITH (m.gccen_path + "edi_part")
    ENDIF 
    m.fn_limity = m.gccen_path + "nlimity"
    IF !FILE(m.gccen_path + "nlimity.dbf")
        DO creafile WITH (m.gccen_path + "nlimity")
    ENDIF 
    m.fn_limit_hl = m.gccen_path + "nlimit_hl"
    IF !FILE(m.gccen_path + "nlimit_hl.dbf")
        DO creafile WITH (m.gccen_path + "nlimit_hl")
    ENDIF 
    m.fn_limitdni = m.gccen_path + "nlimitdni"
    IF !FILE(m.gccen_path + "nlimitdni.dbf")
        DO creafile WITH (m.gccen_path + "nlimitdni")
    ENDIF 
    m.fn_limitrov = m.gccen_path + "nlimitrov"
    IF !FILE(m.gccen_path + "nlimitrov.dbf")
        DO creafile WITH (m.gccen_path + "nlimitrov")
    ENDIF 
    m.fn_limitstrava = m.gccen_path + "nlimitstrava"
    IF !FILE(m.gccen_path + "nlimitstrava.dbf")
        DO creafile WITH (m.gccen_path + "nlimitstrava")
    ENDIF 
    m.fn_limitstravnici = m.gccen_path + "nlimitstravnici"
    IF !FILE(m.gccen_path + "nlimitstravnici.dbf")
        DO creafile WITH (m.gccen_path + "nlimitstravnici")
    ENDIF 
    m.fn_limitstatus = m.gccen_path + "nlimitstatus"
    IF !FILE(m.gccen_path + "nlimitstatus.dbf")
        DO creafile WITH (m.gccen_path + "nlimitstatus")
    ENDIF 
    m.fn_limitchody = m.gccen_path + "nlimitchody"
    IF !FILE(m.gccen_path + "nlimitchody.dbf")
        DO creafile WITH (m.gccen_path + "nlimitchody")
    ENDIF 
    m.fn_limithladiny = m.gccen_path + "nlimit_hladiny"
    IF !FILE(m.gccen_path + "nlimit_hladiny.dbf")
        DO creafile WITH (m.gccen_path + "nlimit_hladiny")
    ENDIF 
    m.fn_limitrovhladiny = m.gccen_path + "nlimitrov_hladiny"
    IF !FILE(m.gccen_path + "nlimitrov_hladiny.dbf")
        DO creafile WITH (m.gccen_path + "nlimitrov_hladiny")
    ENDIF 
    m.fn_limittypy = m.gccen_path + "nlimittypy"
    IF !FILE(m.gccen_path + "nlimittypy.dbf")
        DO creafile WITH (m.gccen_path + "nlimittypy")
    ENDIF 
    m.fn_limittypchody = m.gccen_path + "nlimittypchody"
    IF !FILE(m.gccen_path + "nlimittypchody.dbf")
        DO creafile WITH (m.gccen_path + "nlimittypchody")
    ENDIF 
    m.fn_limitsablhl = m.gccen_path + "nlimitsablonyhl"
    IF !FILE(m.gccen_path + "nlimitsablonyhl.dbf")
        DO creafile WITH (m.gccen_path + "nlimitsablonyhl")
    ENDIF 
    m.fn_limitsabldni = m.gccen_path + "nlimitsablonydni"
    IF !FILE(m.gccen_path + "nlimitsablonydni.dbf")
        DO creafile WITH (m.gccen_path + "nlimitsablonydni")
    ENDIF 
    m.fn_limitsablpol = m.gccen_path + "nlimitsablonypol"
    IF !FILE(m.gccen_path + "nlimitsablonypol.dbf")
        DO creafile WITH (m.gccen_path + "nlimitsablonypol")
    ENDIF 
    fn_hh_hlav    = gccen_path + "hh_hlav"
    IF !FILE(m.gccen_path+"hh_hlav.dbf")
        DO creafile WITH (m.gccen_path+"hh_hlav")
        USE
    ENDIF
    fn_hh_druhy    = gccen_path + "hh_druhy"
    IF !FILE(m.gccen_path+"hh_druhy.dbf")
        DO creafile WITH (m.gccen_path+"hh_druhy")
        USE
    ENDIF
    fn_hh_kalky    = gccen_path + "hh_kalky"
    IF !FILE(m.gccen_path+"hh_kalky.dbf")
        DO creafile WITH (m.gccen_path+"hh_kalky")
        USE
    ENDIF
    fn_cas_hlav    = gccen_path + "cas_hlav"
    IF !FILE(m.gccen_path+"cas_hlav.dbf")
        DO creafile WITH (m.gccen_path+"cas_hlav")
        USE
    ENDIF
    fn_cas_pol    = gccen_path + "cas_pol"
    IF !FILE(m.gccen_path+"cas_pol.dbf")
        DO creafile WITH (m.gccen_path+"cas_pol")
        USE
    ENDIF
    IF !FILE(m.gchom_path+"prevadzkarne.dbf")
        DO creafile WITH (m.gchom_path+"prevadzkarne")
        USE
    ENDIF
    IF !FILE(m.gccen_path+"limit_hl.dbf")
        DO creafile WITH (m.gccen_path+"limit_hl")
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.gccen_path+"limit_hl.cdx")
            DO opr_index WITH (m.gccen_path+"limit_hl")
        ENDIF
    ENDIF
    IF !FILE(m.gccen_path+"limitdni.dbf")
        DO creafile WITH (m.gccen_path+"limitdni")
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.gccen_path+"limitdni.cdx")
            DO opr_index WITH (m.gccen_path+"limitdni")
        ENDIF
    ENDIF
    IF !FILE(m.gccen_path+"limity.dbf")
        DO creafile WITH (m.gccen_path+"limity")
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.gccen_path+"limity.cdx")
            DO opr_index WITH (m.gccen_path+"limity")
        ENDIF
    ENDIF
    fn_eany     = gccen_path + "eany"
    IF !FILE(m.fn_eany+".dbf")
        DO creafile WITH m.fn_eany
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_eany+".cdx")
            DO opr_index WITH m.fn_eany
        ENDIF
    ENDIF

    IF !FILE(m.gccen_path+"sortiment_dodavatelu.dbf")
        DO creafile WITH (m.gccen_path+"sortiment_dodavatelu.dbf")
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.gccen_path+"sortiment_dodavatelu.cdx")
            DO opr_index WITH (m.gccen_path+"sortiment_dodavatelu")
        ENDIF
    ENDIF
    IF !FILE(m.gccen_path+"zmenadph.dbf")
        DO creafile WITH (m.gccen_path+"zmenadph.dbf")
        USE
    ENDIF


    fn_buff_r    = gcdat_path + "buff_r"
    IF !FILE(m.fn_buff_r+".dbf")
        DO creafile WITH m.fn_buff_r
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_buff_r+".cdx")
            DO opr_index WITH m.fn_buff_r
        ENDIF
    ENDIF
    fn_buff_d    = gcdat_path + "buff_d"
    IF !FILE(m.fn_buff_d+".dbf")
        DO creafile WITH m.fn_buff_d
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_buff_d+".cdx")
            DO opr_index WITH m.fn_buff_d
        ENDIF
    ENDIF
    fn_karty     = gccen_path + "karty"
    IF !FILE(m.fn_karty+".dbf")
        DO creafile WITH m.fn_karty
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_karty+".cdx")
            DO opr_index WITH m.fn_karty
        ENDIF
    ENDIF
    fn_krest     = gccen_path + "krest"
    IF !FILE(m.fn_krest+".dbf")
        DO creafile WITH m.fn_krest
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_krest+".cdx")
            DO opr_index WITH m.fn_krest
        ENDIF
    ENDIF
    fn_ktried     = gccen_path + "ktried"
    IF !FILE(m.fn_ktried+".dbf")
        DO creafile WITH m.fn_ktried
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_ktried+".cdx")
            DO opr_index WITH m.fn_ktried
        ENDIF
    ENDIF
    fn_tried     = gccen_path + "tried"
    IF !FILE(m.fn_tried+".dbf")
        DO creafile WITH m.fn_tried
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_tried+".cdx")
            DO opr_index WITH m.fn_tried
        ENDIF
    ENDIF
    fn_edipol     = gccen_path + "edi_pol"
    IF !FILE(m.fn_edipol+".dbf")
        DO creafile WITH m.fn_edipol
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_edipol+".cdx")
            DO opr_index WITH m.fn_edipol
        ENDIF
    ENDIF
    fn_edihlav     = gccen_path + "edi_hlav"
    IF !FILE(m.fn_edihlav+".dbf")
        DO creafile WITH m.fn_edihlav
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_edihlav+".cdx")
            DO opr_index WITH m.fn_edihlav
        ENDIF
    ENDIF

    fn_expfaktura     = gcdat_path + "exp_faktura"
    IF !FILE(m.fn_expfaktura+".dbf")
        DO creafile WITH m.fn_expfaktura
        DO indexuj IN indexy
        USE
    ENDIF
    fn_kkarty     = gccen_path + "kkarty"
    IF !FILE(m.fn_kkarty+".dbf")
        DO creafile WITH m.fn_kkarty
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_kkarty+".cdx")
            DO opr_index WITH m.fn_kkarty
        ENDIF
    ENDIF
    fn_kceny     = gccen_path + "kceny"
    IF !FILE(m.fn_kceny+".dbf")
        DO creafile WITH m.fn_kceny
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_karty+".cdx")
            DO opr_index WITH m.fn_kceny
        ENDIF
    ENDIF
    fn_ktexty     = gccen_path + "ktexty"
    IF !FILE(m.fn_ktexty+".dbf")
        DO creafile WITH m.fn_ktexty
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_ktexty+".cdx")
            DO opr_index WITH m.fn_ktexty
        ENDIF
    ENDIF
    fn_skupiny   = gccen_path + "skupiny"
    IF !FILE(m.fn_skupiny+".dbf")
        DO creafile WITH m.fn_skupiny
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_skupiny+".cdx")
            DO opr_index WITH m.fn_skupiny
        ENDIF
    ENDIF
    fn_vypocty   = gccen_path + "vypocty"
    IF FILE(m.fn_vypocty+".dbf")
        IF !FILE(m.fn_vypocty+".cdx")
            DO opr_index WITH m.fn_vypocty
        ENDIF
    ENDIF

    fn_bourak    = gccen_path + "bourak"
    IF !FILE(m.fn_bourak+".dbf")
        DO creafile WITH m.fn_bourak
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_bourak+".cdx")
            DO opr_index WITH m.fn_bourak
        ENDIF
    ENDIF
    fn_umisteni  = gccen_path + "umisteni"
    IF !FILE(m.fn_umisteni+".dbf")
        DO creafile WITH m.fn_umisteni
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_umisteni+".cdx")
            DO opr_index WITH m.fn_umisteni
        ENDIF
    ENDIF
    fn_listovanie  = gccen_path + "listovanie"
    IF !FILE(m.fn_listovanie+".dbf")
        DO creafile WITH m.fn_listovanie
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_listovanie+".cdx")
            DO opr_index WITH m.fn_listovanie
        ENDIF
    ENDIF
    IF !FILE(m.gccen_path+"uexarchobraty.dbf")
        DO creafile WITH (m.gccen_path+"uexarchobraty.dbf")
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.gccen_path+"uexarchobraty.cdx")
            DO opr_index WITH (m.gccen_path+"uexarchobraty.dbf")
        ENDIF
    ENDIF
    IF !FILE(m.gccen_path+"uexarchpolozky.dbf")
        DO creafile WITH (m.gccen_path+"uexarchpolozky.dbf")
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.gccen_path+"uexarchpolozky.cdx")
            DO opr_index WITH (m.gccen_path+"uexarchpolozky.dbf")
        ENDIF
    ENDIF
    IF !FILE(m.gccen_path+"uexarchplatby.dbf")
        DO creafile WITH (m.gccen_path+"uexarchplatby.dbf")
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.gccen_path+"uexarchplatby.cdx")
            DO opr_index WITH (m.gccen_path+"uexarchplatby.dbf")
        ENDIF
    ENDIF
    fn_partneri  = gccen_path + "partneri"
    IF !FILE(m.fn_partneri+".dbf")
        DO creafile WITH m.fn_partneri
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_partneri+".cdx")
            DO opr_index WITH m.fn_partneri
        ENDIF
    ENDIF
    fn_polozky   = gccen_path + "polozky"
    IF !FILE(m.fn_polozky+".dbf")
        DO creafile WITH m.fn_polozky
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_polozky+".cdx")
            DO opr_index WITH m.fn_polozky
        ENDIF
    ENDIF
    fn_sklad     = gcdat_path + "sklad"
    IF !FILE(m.fn_sklad+".dbf")
        DO creafile WITH m.fn_sklad
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_sklad+".cdx")
            DO opr_index WITH m.fn_sklad
        ENDIF
    ENDIF
    fn_doklady   = gcdat_path + "doklady"
    IF !FILE(m.fn_doklady+".dbf")
        DO creafile WITH m.fn_doklady
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_doklady+".cdx")
            DO opr_index WITH m.fn_doklady
        ENDIF
    ENDIF
    fn_obr_alk    = gccen_path + "obr_alk"
    IF !FILE(m.fn_obr_alk+".dbf")
        DO creafile WITH m.fn_obr_alk
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_obr_alk+".cdx")
            DO opr_index WITH m.fn_obr_alk
        ENDIF
    ENDIF
    fn_obraty    = gcdat_path + "obraty"
    IF !FILE(m.fn_obraty+".dbf")
        DO creafile WITH m.fn_obraty
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_obraty+".cdx")
            DO opr_index WITH m.fn_obraty
        ENDIF
    ENDIF
    fn_dokl_a    = gcdat_path + "dokl_a"
    IF !FILE(m.fn_dokl_a+".dbf")
        DO creafile WITH m.fn_dokl_a
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_dokl_a+".cdx")
            DO opr_index WITH m.fn_dokl_a
        ENDIF
    ENDIF
    fn_obra_a    = gcdat_path + "obra_a"
    IF !FILE(m.fn_obra_a+".dbf")
        DO creafile WITH m.fn_obra_a
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_obra_a+".cdx")
            DO opr_index WITH m.fn_obra_a
        ENDIF
    ENDIF
    fn_dokl_sto  = gcdat_path + "dokl_sto"
    IF !FILE(m.fn_dokl_sto+".dbf")
        DO creafile WITH m.fn_dokl_sto
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_dokl_sto+".cdx")
            DO opr_index WITH m.fn_dokl_sto
        ENDIF
    ENDIF
    fn_obra_sto  = gcdat_path + "obra_sto"
    IF !FILE(m.fn_obra_sto+".dbf")
        DO creafile WITH m.fn_obra_sto
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_obra_sto+".cdx")
            DO opr_index WITH m.fn_obra_sto
        ENDIF
    ENDIF
    fn_davky     = gccen_path + "davky"
    IF !FILE(m.fn_davky+".dbf")
        DO creafile WITH m.fn_davky
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_davky+".cdx")
            DO opr_index WITH m.fn_davky
        ENDIF
    ENDIF
    fn_dluhy     = gcdat_path + "dluhy"
    IF !FILE(m.fn_dluhy+".dbf")
        DO creafile WITH m.fn_dluhy
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_dluhy+".cdx")
            DO opr_index WITH m.fn_dluhy
        ENDIF
    ENDIF
    fn_uzav      = gcdat_path + "uzaverka"
    IF !FILE(m.fn_uzav+".dbf")
        DO creafile WITH m.fn_uzav
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_uzav+".cdx")
            DO opr_index WITH m.fn_uzav
        ENDIF
    ENDIF
    fn_uzav_pohyby = gcdat_path + "uzaverka_pohyby"
    IF !FILE(m.fn_uzav_pohyby+".dbf")
        DO creafile WITH m.fn_uzav_pohyby
        IF USED("uzaverka_pohyby")
            IF !USED("uzaverka")
                USE (m.fn_uzav) ALIAS uzaverka IN 0
            ENDIF 
            DELETE FROM uzaverka_pohyby WHERE operace='VE' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'VE', ve FROM uzaverka WHERE ve<>0
            DELETE FROM uzaverka_pohyby WHERE operace='ZE' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'ZE', ze FROM uzaverka WHERE ze<>0
            DELETE FROM uzaverka_pohyby WHERE operace='VV' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'VV', vv FROM uzaverka WHERE vv<>0
            DELETE FROM uzaverka_pohyby WHERE operace='VR' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'VR', vr FROM uzaverka WHERE vr<>0
            DELETE FROM uzaverka_pohyby WHERE operace='ZV' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'ZV', zv FROM uzaverka WHERE zv<>0
            DELETE FROM uzaverka_pohyby WHERE operace='VK' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'VK', vk FROM uzaverka WHERE vk<>0
            DELETE FROM uzaverka_pohyby WHERE operace='PE' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'PE', pe FROM uzaverka WHERE pe<>0
            DELETE FROM uzaverka_pohyby WHERE operace='PV' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'PV', PV FROM uzaverka WHERE pv<>0
            DELETE FROM uzaverka_pohyby WHERE operace='PI' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'PI', PI FROM uzaverka WHERE pi<>0
            DELETE FROM uzaverka_pohyby WHERE operace='PO' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'PO', po FROM uzaverka WHERE po<>0
            DELETE FROM uzaverka_pohyby WHERE operace='VO' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'VO', vo FROM uzaverka WHERE vo<>0
            DELETE FROM uzaverka_pohyby WHERE operace='PR' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'PR', pr FROM uzaverka WHERE pr<>0
            DELETE FROM uzaverka_pohyby WHERE operace='VP' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'VP', vp FROM uzaverka WHERE vp<>0
            DELETE FROM uzaverka_pohyby WHERE operace='PP' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'PP', pp FROM uzaverka WHERE pp<>0
            DELETE FROM uzaverka_pohyby WHERE operace='VB' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'VB', vb FROM uzaverka WHERE vb<>0
            DELETE FROM uzaverka_pohyby WHERE operace='PB' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'PB', pb FROM uzaverka WHERE pb<>0
            DELETE FROM uzaverka_pohyby WHERE operace='VC' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'VC', vc FROM uzaverka WHERE vv<>0
            DELETE FROM uzaverka_pohyby WHERE operace='PC' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'PC', pc FROM uzaverka WHERE pc<>0
            DELETE FROM uzaverka_pohyby WHERE operace='PS' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'PS', ps FROM uzaverka 
            DELETE FROM uzaverka_pohyby WHERE operace='KS' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'KS', ks FROM uzaverka
            DELETE FROM uzaverka_pohyby WHERE operace='ER' AND (mesiac+rok+STR(c_stredisk,10,0) IN (SELECT mesiac+rok+STR(c_stredisk,10,0) FROM uzaverka))
            INSERT INTO uzaverka_pohyby (mesiac, rok, c_stredisk, operace, suma) SELECT mesiac, rok, c_stredisk, 'ER', err FROM uzaverka
            USE IN uzaverka
        ENDIF 

        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_uzav_pohyby+".cdx")
            DO opr_index WITH m.fn_uzav_pohyby
        ENDIF
    ENDIF
    fn_parovaky  = gcdat_path + "parovaky"
    IF !FILE(m.fn_parovaky+".dbf")
        DO creafile WITH m.fn_parovaky
        DO indexuj IN indexy
        USE
    ENDIF
    fn_uctobd  = gchom_path + "uctobd"
    IF !FILE(m.fn_uctobd+".dbf")
        DO creafile WITH m.fn_uctobd
    ENDIF

    fn_vahinv    = gccen_path + "vahinv"

    fn_dokl_s    = m.fn_doklady    && tyhle 2 promenne se pouzivaji v sestavach, resi se jimi prepinani archivu
    fn_obra_s    = m.fn_obraty

    fn_sk_sez    = gccen_path + "sk_sez"
    IF !FILE(m.fn_sk_sez+".dbf")
        DO creafile WITH m.fn_sk_sez
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_sk_sez+".cdx")
            DO opr_index WITH m.fn_sk_sez
        ENDIF
    ENDIF
    fn_sk_pol    = gccen_path + "sk_pol"
    IF !FILE(m.fn_sk_pol+".dbf")
        DO creafile WITH m.fn_sk_pol
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_sk_pol+".cdx")
            DO opr_index WITH m.fn_sk_pol
        ENDIF
    ENDIF
    fn_sk_fin    = gccen_path + "sk_fin"
    IF !FILE(m.fn_sk_fin+".dbf")
        DO creafile WITH m.fn_sk_fin
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_sk_fin+".cdx")
            DO opr_index WITH m.fn_sk_fin
        ENDIF
    ENDIF
    fn_sk_plt    = gccen_path + "sk_plt"
    IF !FILE(m.fn_sk_plt+".dbf")
        DO creafile WITH m.fn_sk_plt
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_sk_plt+".cdx")
            DO opr_index WITH m.fn_sk_plt
        ENDIF
    ENDIF
    fn_sk_txt    = gccen_path + "sk_txt"
    IF !FILE(m.fn_sk_txt+".dbf")
        DO creafile WITH m.fn_sk_txt
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_sk_txt+".cdx")
            DO opr_index WITH m.fn_sk_txt
        ENDIF
    ENDIF
    fn_sk_fis    = gccen_path + "sk_fis"
    IF !FILE(m.fn_sk_fis+".dbf")
        DO creafile WITH m.fn_sk_fis
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_sk_fis+".cdx")
            DO opr_index WITH m.fn_sk_fis
        ENDIF
    ENDIF
    fn_sk_vklvy    = gccen_path + "sk_vklvy"
    IF !FILE(m.fn_sk_vklvy+".dbf")
        DO creafile WITH m.fn_sk_vklvy
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_sk_vklvy+".cdx")
            DO opr_index WITH m.fn_sk_vklvy
        ENDIF
    ENDIF

    fn_sk_sez_a  = gccen_path + "sk_sez_a"
    IF !FILE(m.fn_sk_sez_a+".dbf")
        DO creafile WITH m.fn_sk_sez_a
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_sk_sez_a+".cdx")
            DO opr_index WITH m.fn_sk_sez_a
        ENDIF
    ENDIF
    fn_sk_pol_a  = gccen_path + "sk_pol_a"
    IF !FILE(m.fn_sk_pol_a+".dbf")
        DO creafile WITH m.fn_sk_pol_a
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_sk_pol_a+".cdx")
            DO opr_index WITH m.fn_sk_pol_a
        ENDIF
    ENDIF
    fn_sk_fin_a  = gccen_path + "sk_fin_a"
    IF !FILE(m.fn_sk_fin_a+".dbf")
        DO creafile WITH m.fn_sk_fin_a
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_sk_fin_a+".cdx")
            DO opr_index WITH m.fn_sk_fin_a
        ENDIF
    ENDIF
    fn_sk_plt_a  = gccen_path + "sk_plt_a"
    IF !FILE(m.fn_sk_plt_a+".dbf")
        DO creafile WITH m.fn_sk_plt_a
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_sk_plt_a+".cdx")
            DO opr_index WITH m.fn_sk_plt_a
        ENDIF
    ENDIF
    fn_sk_txt_a  = gccen_path + "sk_txt_a"
    IF !FILE(m.fn_sk_txt_a+".dbf")
        DO creafile WITH m.fn_sk_txt_a
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_sk_txt_a+".cdx")
            DO opr_index WITH m.fn_sk_txt_a
        ENDIF
    ENDIF
    fn_sk_fis_a    = gccen_path + "sk_fis_a"
    IF !FILE(m.fn_sk_fis_a+".dbf")
        DO creafile WITH m.fn_sk_fis_a
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_sk_fis_a+".cdx")
            DO opr_index WITH m.fn_sk_fis_a
        ENDIF
    ENDIF
    fn_sk_vklvy_a    = gccen_path + "sk_vklvy_a"
    IF !FILE(m.fn_sk_vklvy_a+".dbf")
        DO creafile WITH m.fn_sk_vklvy_a
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_sk_vklvy_a+".cdx")
            DO opr_index WITH m.fn_sk_vklvy_a
        ENDIF
    ENDIF

    fn_umdruhy     = gccen_path + "umdruhy"
    IF !FILE(m.fn_umdruhy+".dbf")
        DO creafile WITH m.fn_umdruhy
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_umdruhy+".cdx")
            DO opr_index WITH m.fn_umdruhy
        ENDIF
    ENDIF

    fn_spotrebnadan = gccen_path + "spdan"
    IF !FILE(m.fn_spotrebnadan+".dbf")
        DO creafile WITH m.fn_spotrebnadan
        DO indexuj IN indexy
        USE
    ELSE
        IF !FILE(m.fn_spotrebnadan+".cdx")
            DO opr_index WITH m.fn_spotrebnadan
        ENDIF
    ENDIF

    fn_objednan  = gchom_path + "objednan"
    fn_jidelak   = gchom_path + "jidelak"
    fn_users     = gchom_path + "users"
ELSE
    fn_uctobd    ='ps_ructobd'
    m.fn_doklady ='ps_rdoklady'
    m.fn_obraty  ='ps_robraty'
ENDIF 

SELECT food_dat
gcid_klapky = m.gcpgm_id
radek_food_datu = RECNO()
SCAN FOR ATC("*MAN", comment) > 0
    pozice_manageru = ATC(m.gcpgm_id + " ", comment)
    IF m.pozice_manageru > 5
        master_manager = SUBSTR(comment, m.pozice_manageru - 2, 2)
        IF ATC(m.master_manager, m.gcid_klapky) = 0
            gcid_klapky = m.gcid_klapky + "  " + m.master_manager 
        ENDIF 
    ENDIF 
ENDSCAN 
GOTO (m.radek_food_datu )

IF m.bolazaloha
    fn_obraty   = STRTR(m.fn_obraty,  "obraty",  "obra_buf")
    fn_doklady  = STRTR(m.fn_doklady, "doklady", "dokl_buf")
    fn_dokl_s    = m.fn_doklady
    fn_obra_s    = m.fn_obraty
    fn_sklad    = m.gcpri_path + "skla_buf"
ENDIF 

STORE "NIC" TO operace, operace_txt, d1_txt, d1_dat_dokl, d2_txt, d2_dat_dokl
