*     *     *     *     *     *     *     *     *     *  *BEZ HADA*     *     *     *     *     *     *     *     *

IF m.issql

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

    DO open_database

    had.increment("Položky")
    lsql="SELECT           c_uzaverka,   ucet,   c_karty,   prachy,         prachy_puv,         dan,         dan_sazba,        mnozstvi,         k_odpoctu,      poradi,   dotacia,      dil_porce,      kompez,   sleva_pol FROM food600.sk__pol WHERE c_data=?m.cdata "
    sql_select(lsql,"pol","c_uzaverka I, ucet I, c_karty I, prachy N(12,2), prachy_puv N(12,2), dan N(11,2), dan_sazba N(6,2), mnozstvi N(12,3), k_odpoctu c(1), poradi I, dotacia C(1), dil_porce N(3), kompez L, sleva_pol N(12,2) ")
    IF USED("pol")

        had.increment("Platby")
        lsql="SELECT           c_uzaverka,   ucet,   druh_pl,       cena_pl,         tip,         mena,      cena_mena,         poradi,      kompez FROM food600.sk__plt WHERE c_data=?m.cdata "
        sql_select(lsql,"plt","c_uzaverka I, ucet I, druh_pl c(10), cena_pl N(14,2), tip N(12,2), mena C(3), cena_mena N(14,2), poradi N(4), kompez L")
        IF USED("plt")

            had.increment("Sez")
            lsql="SELECT           c_uzaverka,   uzaverka,       uz_cislo,   c_kas,   id_kas FROM food600.sk__sez WHERE c_data=?m.cdata "
            sql_select(lsql,"sez","c_uzaverka I, uzaverka C(17), uz_cislo I, c_kas I, id_kas C(2)")
            IF USED("sez")

                DO pokracuj_v_kontrole

            ELSE
                MESSAGEBOX("nejde otevrit sk__sez",16+1,"kontrola SK", 2222)
            ENDIF 
        ELSE
            MESSAGEBOX("nejde otevrit sk__plt",16+1,"kontrola SK", 2222)
        ENDIF 
    ELSE
        MESSAGEBOX("nejde otevrit sk__pol",16+1,"kontrola SK", 2222)
    ENDIF 
    RELEASE had
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 

