* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
*
*   2021-02-05  dozapsani zaznamu v lokalnich errors.dbf na sql server
*   2023-08-15  nastavi, ktere zurnaly od pepina se budou brat v SQL verzi v cechach
*   2023-09-25  z errors.dbf se odmazavaji stare dozapsane radky
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
#DEFINE CRLF  CHR(13)+CHR(10)

IF m.issql
    old_machine = m.machine

    DO open_database

    IF FILE(m.gchom_path + "errors.dbf")
        pomaz_stare_chyby()
        doposli()
    ENDIF 

    *   nastavit zurnaly pro SQL
    IF slovenskaverzia = .f.
        hladajmodul="FOOD_SET"
        hladajsetupskup=""
        rv('defsubor',"food_set")
        CURSORSETPROP("Buffering",5,"food_set")
        SELECT food_set
        REPLACE FOR var_name = "zurnaly_kasy_v_dbf" var_value WITH ".T."
        tux(.t.,.t.,"food_set")
    ENDIF

    machine = m.old_machine
ENDIF 


*************************************************************************************
PROCEDURE pomaz_stare_chyby
chybicka = ""
TRY
    SELECT 0
    USE (m.gchom_path + "errors") EXCLUSIVE

    COUNT  FOR ATC("DOZA", err_h_info) # 0 .and. cas < (DATE() - 33) TO stary_reccount
    DELETE FOR ATC("DOZA", err_h_info) # 0 .and. cas < (DATE() - 33)
    PACK 
    COUNT FOR ATC("DOZA", err_h_info) # 0 TO   zapsane
    COUNT FOR ATC("DOZA", err_h_info) = 0 TO nezapsane
    chybicka = m.chybicka + "dozapsanych:" + nx(m.zapsane) + " NEdozapsanych:" + nx(m.nezapsane) + "   reccount:" + nx(RECCOUNT()) + "  puvodni reccount:" + nx(m.stary_reccount)
    small_log (m.chybicka, "autoexec")
    DO autoexec_log with m.chybicka
    USE 
CATCH 
ENDTRY 

*************************************************************************************
PROCEDURE doposli
rv("errors", "errorsr")
CURSORSETPROP("Buffering",5,"errorsr")
chybicka = ""

TRY
    SELECT 0
    USE (m.gchom_path + "errors") ALIAS errors_local
    SCAN FOR ATC("DOZA", err_h_info) = 0
        SCATTER MEMVAR 
        SELECT errorsr
        LOCATE FOR LEFT(machine, 15) = LEFT(m.machine, 15) .and. err_h_info = "DOZA" + nx(m.idriadok)
        IF FOUND()
            SELECT errors_local
            REPLACE err_h_info WITH ALLTRIM(LEFT(err_h_info, 200)) + "DOZA" + nx(errorsr.idriadok)
            DELETE 
        ELSE 
            err_h_info = "DOZA" + nx(m.idriadok)
            INSERT INTO errorsr FROM MEMVAR                 
            small_log ("inserted " + ALLTRIM(STR(m.idriadok)), "autoexec")
        ENDIF 
    ENDSCAN 
    tux(.t.,.t.,"errorsr")
    USE IN errors_local 
CATCH TO oErr 
    chybicka = m.chybicka + ALLTRIM(STR(oErr.ErrorNo)) + " " + oErr.Message + " Line:" + ALLTRIM(STR(oErr.LineNo))
FINALLY
    DO autoexec_log with m.chybicka
ENDTRY 
