sk_path = m.gcdat_path

CLOSE DATABASES 
DO votevri_eskacka

SELECT id_kas, uzaverka, COUNT(*) as pocet GROUP BY 1,2 FROM (m.sk_path + "sk_sez") WHERE "*" $ uzaverka INTO TABLE sez

SELECT id_kas, id_man, uzaverka, odecteno, lastuzav, idriadok, uzaverka as uzaverka_n ;
       FROM sk_sez WHERE id_kas+uzaverka IN (SELECT id_kas+uzaverka FROM sez WHERE pocet > 1) INTO TABLE uzaverky
INDEX ON idriadok TAG idriadok
minuta = 1
SCAN
    SCATTER MEMVAR
    uzaverka_n = LEFT(m.uzaverka, 10) + TRANSFORM(m.minuta, "@L 99")
    minuta = (m.minuta + 1) % 99
    IF m.minuta = 0
        minuta = 1
    ENDIF 

    SELECT sk_fin
    GO TOP
    LOCATE FOR id_kas = m.id_kas .and. uzaverka = m.uzaverka
    SCATTER FIELDS u_cis MEMVAR
    REPLACE FOR uzaverka = m.uzaverka .and. u_cis = m.u_cis uzaverka WITH m.uzaverka_n

    SELECT sk_plt
    REPLACE FOR uzaverka = m.uzaverka .and. u_cis = m.u_cis uzaverka WITH m.uzaverka_n
    
    SELECT sk_pol
    REPLACE FOR uzaverka = m.uzaverka .and. u_cis = m.u_cis uzaverka WITH m.uzaverka_n
    
    SELECT sk_sez
    GO TOP
    LOCATE FOR id_kas = m.id_kas .and. uzaverka = m.uzaverka
    REPLACE uzaverka WITH m.uzaverka_n

    SELECT doklady
    REPLACE FOR c_dokl = VAL(m.odecteno) pz2 WITH m.uzaverka_n + RIGHT(pz2, 3)

    ? m.id_kas + " " + m.uzaverka + "/" + m.u_cis + " --> " + m.uzaverka_n
ENDSCAN

CLOSE DATABASES


*********************************************************
PROCEDURE votevri_eskacka

USE (m.sk_path + "sk_sez") EXCLUSIVE 
INDEX ON idriadok TAG idriadok

SELECT 0
USE (m.sk_path + "sk_fin") EXCLUSIVE 
INDEX ON idriadok TAG idriadok

SELECT 0
USE (m.sk_path + "sk_plt") EXCLUSIVE 

SELECT 0
USE (m.sk_path + "sk_pol") EXCLUSIVE 

SELECT 0
USE (m.sk_path + "doklady") EXCLUSIVE 
