*   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   * 
*
* 2024-01-28 - 
*
*
*   *   *   *   *   *     #> ver. 2024-01-28 <#     *   *   *BEZ HADA*  *   *   *   *   *   *   *   *   *   *   *   *

#DEFINE CRLF          CHR(13)+CHR(10)
#DEFINE VYSSI_SAZBA   1.21
#DEFINE MIN_UZAV  "240101 12   "

gchom_path = "i:\d_televize\"
issql      = .F.





otazka  = "Chcete nastavit sazbu DPH 12% ?"

MESSAGEBOX("TOHLE JE VERZE, KTERA VYPLNI DPH2024 " + CHR(13) + "V ESKACKACH",1+64, "DPH20024" + " ver. 2024-01-28", 6666)

IF MESSAGEBOX(otazka, 3+32+256, "Nové sazby DPH v eskackach v adresari " + UPPER(m.gchom_path)) = 6
    CLOSE data
*    DO open_database


    IF m.issql
        nastav_sazby_v_sk()
    ELSE 
        SELECT 0
        USE (m.gchom_path + "data\skupiny") orde c_druh noupdate  
        SELECT 0
        USE (m.gchom_path + "data\karty")   orde c_karty noupdate
        SELECT 0
        USE (m.gchom_path + "data\sk_pol")
        SET FILTER TO uzaverka > MIN_UZAV

        WAIT "SK_POL - snizena DPH" WINDOW NOWAIT 
        SELECT sk_pol
        SET FILTER TO uzaverka > MIN_UZAV
        REPLACE FOR BETWEEN(dan, 1.10, 1.15) dan WITH 1.12
        WAIT CLEAR 
        SET RELATION TO c_karty INTO karty

        nastav_sk_vyssi_sazby()
        
    ENDIF 

ENDIF 
CLOSE data



*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *   
PROCEDURE nastav_sk_vyssi_sazby

SELECT druh, typ_kalk, c_druh WHERE typ_kalk = "K" FROM (m.gchom_path + "data\skupiny") INTO TABLE kalkulace

DEFINE POPUP nabidka PROMPT FIELD druh + " | " + nx(c_druh) FROM 1,22 TITLE "Vyber skupinu pro " + nx(VYSSI_SAZBA*100-100) + "%, pro konec [Esc]" FONT 'Courier NEW' FOOTER "pro konec [Esc]"
ON SELECTION POPUP nabidka deacti popup
ACTIVATE SCREEN
ACTIVATE POPUP nabidka
DO WHILE !EMPTY(PROMPT())
    vybranej_druh = PROMPT()
    vybranej_c_druh = kalkulace.c_druh

    SELECT sk_pol
    SET FILTER TO uzaverka > MIN_UZAV .and. karty.c_druhk = m.vybranej_c_druh

    ACTIVATE SCREEN
    BROWSE FIELDS uzaverka, c_karty, nazev, dan, karty.nazev, karty.c_druhk NOEDIT NOAPPEND NODELETE 

    IF MESSAGEBOX("Opravdu nastavit 21% pro skupinu " + UPPER(m.vybranej_druh) + "?",3+32,"DPH pro " + UPPER(m.vybranej_druh)) = 6
         REPLACE FOR karty.c_druhk = m.vybranej_c_druh dan WITH VYSSI_SAZBA
    ENDIF 

    ACTIVATE SCREEN
    SELECT kalkulace
    ACTIVATE POPUP nabidka
ENDDO
RELEASE POPUP nabidka


*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *   
PROCEDURE prepis_skupinu_vyssi_sazby
IF m.issql
    cmd = "SELECT table_schema, table_name, column_name, data_type, udt_name FROM information_schema.columns "
    sql_select(m.cmd, "list_columns", "schema C(33), table_name C(33), clm_name C(33), data_type C(33), udt_name C(33)")
    SELECT list_columns
    SCAN FOR schema = "food600" .and. table_name = "skupiny"  .and. LEFT(clm_name, 3) = "dan"
        sql_cmd = "UPDATE food600.skupiny SET " + ALLTRIM(clm_name) + " = " + nx(VYSSI_SAZBA,3) + " WHERE druh = '" + m.vybranej_druh + "' ;"
        proved(m.sql_cmd )
    ENDSCAN 
ENDIF 
WAIT CLEAR 


*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *   
PROCEDURE nastav_sazby_v_sk
IF m.issql
    cmd = "SELECT table_schema, table_name, column_name, data_type, udt_name FROM information_schema.columns "
    sql_select(m.cmd, "list_columns", "schema C(33), table_name C(33), clm_name C(33), data_type C(33), udt_name C(33)")
    SELECT list_columns
    SCAN FOR schema = "food600" .and. table_name = "skupiny"  .and. LEFT(clm_name, 3) = "dan"
        sql_cmd ="UPDATE food600.skupiny SET " + ALLTRIM(clm_name) + " = 1.12 WHERE " + ALLTRIM(clm_name) + " BETWEEN 1.10 AND 1.15 ;"
        proved(m.sql_cmd )
    ENDSCAN 

ENDIF 


*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
FUNCTION proved (co_udelat)
WAIT m.co_udelat WINDOW NOWAIT 
vysledek = sql_exec( m.co_udelat )
zprava_do_logu = m.co_udelat + STR(m.vysledek, 5)
IF m.vysledek < 0
    DIMENSION chybaexe(9)
    chybaexe(2) = "vsechno v poradku"
    AERROR(chybaexe)
    MESSAGEBOX("SQL Chyba" + CHR(10) + chybaexe(2),64)
    zprava_do_logu = m.zprava_do_logu + " " + chybaexe(2)
ENDIF
small_log (m.zprava_do_logu, "dane2024")
WAIT CLEAR 



********** vraci formatovane cislo  ********** delka se uplatni pouze je-li vetsi nez 
FUNCTION nx (cislo, des_mist, delka)

IF EMPTY(m.des_mist)
    des_mist = 0
ENDIF 

IF EMPTY(m.delka)
    delka = 0
ENDIF 

IF ISNULL(m.cislo)
    cislo = 0
ENDIF 
nxpolotovar = STRTRAN(ALLTRIM(STR(m.cislo, 15, m.des_mist)), ",", ".")    && tohle je alltrimovany

IF m.delka > LEN(m.nxpolotovar)
    nxpolotovar = PADL(m.nxpolotovar, m.delka)
ENDIF 
RETURN nxpolotovar
