*     *     *     *     *     *     *     *     *     *  *B-E-Z H-A-D-A*     *     *     *     *     *     *     *     *

IF m.issql

    had = createobject("had", PROGRAM())
    had.show()
    had.set_max(5)
    CLOSE DATABASES 
    CLOSE DATABASES 

    DO open_database

    had.increment("Obraty")
    lsql="SELECT DISTINCT c_stredisk, c_karty, c_data FROM food600.obraty WHERE c_data=?m.cdata "
    sql_select(lsql,"obr","c_stredisk I, c_karty I, c_data I ")
    SELECT obr
    INDEX on c_stredisk TAG c_stredisk
    INDEX on c_karty    TAG c_karty
    

    lsql="SELECT           c_stredisk  , c_karty  , c_data  , zustatek        , vycisleni, '       ' as co_delat FROM food600.sklad WHERE c_data=?m.cdata AND max_zaso=0 AND min_zaso=0"    && max_zaso, mini_zaso, vycisleni, rezervace
    sql_select(lsql,"skl","c_stredisk I, c_karty I, c_data I, zustatek N(11,4), vycisleni C(3), co_delat C(8) ")

    RELEASE had

    SELECT skl
    SCAN
        SCATTER MEMVAR 
        SELECT obr
        LOCATE FOR c_stredisk = m.c_stredisk .and. c_karty = m.c_karty .AND. c_data = m.c_data
        IF .not. FOUND()
            SELECT skl
            REPLACE co_delat WITH "CHYBI"
        ENDIF 
    ENDSCAN 

ELSE
    MESSAGEBOX("tohle je jen pro SQL data",16+1,"kontrola SK", 2222)
ENDIF 

*************************************************************************************************
PROCEDURE pokracuj_v_kontrole

had.increment("pokracovani")

SELECT c_uzaverka, ucet, c_karty, prachy, prachy_puv, dan, dan_sazba, mnozstvi, k_odpoctu, poradi, dotacia, dil_porce, SPACE(2) as id_kas, SPACE(2) as id_man, sleva_pol, SPACE(14) as uzaverka FROM pol INTO CURSOR sk_pol_ READWRITE WHERE EMPTY(kompez)
SELECT c_uzaverka, ucet, c_karty, prachy, prachy_puv, dan, dan_sazba, mnozstvi, k_odpoctu, poradi, dotacia, dil_porce, SPACE(2) as id_kas, SPACE(2) as id_man, sleva_pol, SPACE(14) as uzaverka FROM pol INTO CURSOR sk_pol_kompez READWRITE WHERE !EMPTY(kompez)

SELECT c_uzaverka, ucet, SUM(prachy) as prachy, SUM(prachy_puv) as prachy_puv, SUM(dan) as dan, SPACE(2) as id_kas, SUM(sleva_pol) as sleva_pol, SPACE(14) as uzaverka, 00000000.00 as cena_pl, 00000000.00 as tip GROUP BY 1,2 FROM sk_pol_ into CURSOR pol__ READWRITE


SELECT c_uzaverka, ucet, druh_pl, cena_pl, tip, mena, cena_mena, poradi FROM plt INTO CURSOR sk_plt_ READWRITE WHERE EMPTY(kompez)
SELECT c_uzaverka, ucet, druh_pl, cena_pl, tip, mena, cena_mena, poradi FROM plt INTO CURSOR sk_plt_kompez READWRITE WHERE !EMPTY(kompez)

SELECT c_uzaverka, ucet, SUM(cena_pl) as cena_pl, SUM(tip) as tip GROUP BY 1,2 FROM sk_plt_ into CURSOR plt__ READWRITE


UPDATE pol__ SET cena_pl  = plt__.cena_pl, tip = plt__.tip    FROM plt__ WHERE pol__.c_uzaverka = plt__.c_uzaverka AND pol__.ucet = plt__.ucet
UPDATE pol__ SET uzaverka = sez.uzaverka, id_kas = sez.id_kas FROM sez   WHERE pol__.c_uzaverka = sez.c_uzaverka 

SELECT pol__
DELETE FOR prachy = cena_pl
had.hide()
ACTIVATE SCREEN 
BROWSE TITLE "Ucty s rozdily mezi castkami v sk__plt a sk__pol" FIELDS c_uzaverka, uzaverka, id_kas, ucet, prachy_puv, prachy, cena_pl, tip NOMODIFY 


*************************************************************************************************
FUNCTION precisluj_ucty (cislo_uctu)
posledni_znak = RIGHT(cislo_uctu, 1)
IF m.posledni_znak > "9"
    RETURN VAL(STR((VAL(SUBSTR(m.cislo_uctu,3,1))+5)%10, 1) + SUBSTR(m.cislo_uctu,4,3) + CHR(ASC(m.posledni_znak)-17))
ELSE
    RETURN VAL(SUBSTR(m.cislo_uctu, 3))
ENDIF 

