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

#DEFINE CRLF CHR(13)+CHR(10)

had = CREATEOBJECT("had", jaz("prg_kotrola_trzbovych_souboru"))
had.SHOW()


IF .not. m.slovenskaverzia
    chyby = ""
    hodne_stare_sk_a(m.gccen_path + "sk_sez_a.dbf")
    hodne_stare_sk_a(m.gccen_path + "sk_fin_a.dbf")
    hodne_stare_sk_a(m.gccen_path + "sk_plt_a.dbf")
    hodne_stare_sk_a(m.gccen_path + "sk_pol_a.dbf")
    hodne_stare_sk_a(m.gccen_path + "sk_txt_a.dbf")

    IF !EMPTY(m.chyby)
        STRTOFILE(CRLF + TTOC(DATETIME(), 3) + CRLF + m.chyby, m.gcpri_path+"chyby.txt", 1)
        had.HIDE()
        MODIFY COMMAND (m.gcpri_path+"chyby.txt")
        had.SHOW()
    ENDIF 
ENDIF 


IF m.slovenskaverzia
    SELECT uzaverka, u_cis, SUM(cena_slev) AS cena_fin, SUM(cena_celk) AS cena_celk, 1 AS je_v_fin, SUM(round50) AS round50;
        GROUP BY 1,2 FROM (m.fn_sk_fin_a) ;
        INTO CURSOR fin READWRITE
ELSE
    SELECT uzaverka, u_cis, SUM(cena_slev) AS cena_fin, SUM(cena_celk) AS cena_celk, 1 AS je_v_fin, 0.0 as round50 ;
        GROUP BY 1,2 FROM (m.fn_sk_fin_a) ;
        INTO CURSOR  fin READWRITE
ENDIF
had.set_had(22)
SELECT uzaverka, u_cis, SUM(cena_pl) AS cena_plt, 1 AS je_v_plt ;
    GROUP BY 1,2 FROM (m.fn_sk_plt_a) ;
    INTO CURSOR plt READWRITE

SELE uzaverka, u_cis, cena_pl AS cena_plt_m WHERE cena_pl # 0  AND cena_mena = 0 ;
    FROM (m.fn_sk_plt_a) ;
    INTO CURSOR plt_mena READWRITE

had.set_had(33)
SELECT uzaverka, u_cis, SUM(prachy) AS cena_pol, ;
    $0 AS cena_plt, $0 AS cena_fin, $0 AS cena_celk, 0000.00 AS round50, ;
    1 AS je_v_pol, 0 AS je_v_fin, 0 AS je_v_plt ;
    WHERE (not EMPT(k_odpoctu)) AND (not EMPT(id_man)) GROUP BY 1,2 FROM (m.fn_sk_pol_a) ;
    INTO CURSOR pol READWRITE

UPDATE (m.fn_sk_pol_a) SET dan = 1.21 WHERE dan > 1.5

had.set_had(44)

SELECT pol
INSERT INTO pol (uzaverka,u_cis,cena_fin,cena_celk,je_v_fin,round50) SELECT uzaverka,u_cis,cena_fin,cena_celk,je_v_fin,round50 FROM fin
had.set_had(55)
INSERT INTO pol (uzaverka,u_cis,cena_plt,je_v_plt) SELECT uzaverka,u_cis,cena_plt,je_v_plt FROM plt

had.set_had(66)
SELECT uzaverka, u_cis, "  " AS id_kas, SUM(cena_pol) AS cena_pol, SUM(cena_plt) AS cena_plt, ;
    SUM(cena_fin) AS cena_fin, SUM(cena_celk) AS cena_celk, $0 AS cena_plt_m, ;
    SUM(je_v_fin) AS je_v_fin, SUM(je_v_pol) AS je_v_pol, SUM(je_v_plt) AS je_v_plt, SUM(round50) AS round50 ;
    GROUP BY 1,2  FROM pol ;
    INTO CURSOR  sk_check READWRITE
SELECT sk_check

DELETE FOR (cena_pol = 0) .AND. (cena_plt = 0) .AND. (cena_fin = 0) .AND. (cena_celk = 0) IN sk_check

IF m.slovenskaverzia
    REPLACE ALL cena_celk WITH cena_celk+round50, cena_fin WITH cena_fin+round50, cena_pol WITH cena_pol+round50 IN sk_check
ENDIF

DELE FOR ABS(cena_pol - cena_celk)<1 .AND. ABS(cena_plt - cena_fin)<1 .AND. je_v_pol # 0 .AND. je_v_fin # 0 .AND. je_v_plt # 0 IN sk_check

SELECT sk_check
IF prazdna()
    INSERT INTO sk_check (uzaverka) VALUES (jaz("prg_rep_vsechno_ok"))
ENDIF
RELEASE had
SELECT sk_check
SELECT COUNT(*) AS kolko FROM sk_check WHERE NOT DELETED() INTO CURSOR sk_checks
SELECT sk_check
GO TOP
IF sk_checks.kolko > 10000
    MESSAGEBOX('Počet záznamov je '+ ALLT(STR(sk_checks.kolko))+" . Zostavu nezobrazujem, zobrazím len BROWSE.",0,"Pozor")
    BROW NORMAL
ELSE 
    DO pr_report WITH "sk_check"
ENDIF


USE (m.gccen_path + "sk_plt_a.dbf") AGAIN NOUPDATE
SET FILTER TO ABS(tip) > 9999
COUNT TO pocet_podezrelych
IF m.pocet_podezrelych > 0
    BROWSE  TITLE "Tip > 9999"
ENDIF 

DO clos_data


*     *      *      *      *      *     *      *      *      *      *     *      *      *      *      
PROCEDURE hodne_stare_sk_a
LPARAMETERS jmeno_eskacka
IF FILE(m.jmeno_eskacka)
    SELECT 0
    USE (m.jmeno_eskacka) EXCLUSIVE 
    WAIT DBF() WINDOW NOWAIT AT 22, 22
    had.set_txt2(m.jmeno_eskacka)

    COUNT FOR LEFT(uzaverka, 1) = "O" TO pocet_ocek
    IF m.pocet_ocek > 0
        chyby = m.chyby + DBF() + " " + STR(pocet_ocek, 7) + " radku s O v uzaverce" +CRLF
        REPLACE FOR LEFT(uzaverka, 1) = "O" uzaverka WITH "0" + SUBSTR(uzaverka, 2)
    ENDIF 

    COUNT FOR uzaverka > "777777 77:77" TO pocet_ocek
    IF m.pocet_ocek > 0
        chyby = m.chyby + DBF() + " " + STR(pocet_ocek, 7) + " radku s uzaverkou > 777777" +CRLF
        DELETE FOR uzaverka > "777777 77:77"
    ENDIF 
    PACK 
    USE 
    WAIT CLEAR 
    had.set_txt2("")
ENDIF 
