*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
*  export dat do mezd pro faurecii a katastr - spolecna cast
*
*    *    *    *    *    *    *    *    *      #> ver. 2022-03-31 <#       *    *    *    *    *    *    *    *    *    *

SET ENGINEBEHAVIOR 70
CLOSE DATABASES 

STORE "" TO datsk1, datsk2, mesicek

nastav_obdobi()

druh_hl_jidla = "Hl. jidla "
DO CASE 
CASE ATC("faurecia\"    , m.gchom_path) > 0
    zacatek_nazvu_souboru = m.gcexportpath + "faurecia_bakov_"

CASE ATC("faurecia_bez\", m.gchom_path) > 0
    zacatek_nazvu_souboru = m.gcexportpath + "faurecia_bezdecin_"
    druh_hl_jidla = "Hl. jidla "

CASE ATC("d_of_faurecia_mb\"    , m.gchom_path) > 0
    zacatek_nazvu_souboru = m.gcexportpath + "faurecia_sas_"

CASE ATC("d_of_rez\", m.gchom_path) > 0
    zacatek_nazvu_souboru = m.gcexportpath + "officefood_rez_"

    o_set_point = SET("POINT")

    DO ppgm_http 
    SET PROCEDURE TO ppgm_stravnici ADDITIVE 
    DO get_clients      IN stravovani_ppgm
    DO get_transactions IN stravovani_ppgm

    SELECT client as idklienta, - amount as castka, u_cis, client_id as cis_kred, LEFT(trans_at, 4) + SUBSTR(trans_at, 6,2) AS datum ;
           WHERE kind = "KC " FROM transactions INTO TABLE (m.gchom_path + "hkredobr")

    SELECT id, client_id as cis_kred, client_id as jmeno, firma, address FROM clients INTO TABLE (m.gchom_path + "hot_kred")
    REPLACE FOR firma # "HPP" firma WITH IIF( VAL(cis_kred) < 8000000, "UJV", "CVR")
    
    DO pozavirej WITH "hot_kred, hkredobr"

OTHERWISE 
    MESSAGEBOX("pro vase data se tento export negeneruje" + CHR(13) + m.gchom_path, 1+16, "Export faurecia/katastr", 3333)
    RETURN 
ENDCASE 

ERASE (m.zacatek_nazvu_souboru + "*.*")

SELECT 0
USE (m.gchom_path + "hot_kred")
REPLACE FOR EMPTY(jmeno) jmeno WITH cis_kred
INDEX on cis_kred TO (m.gcpri_path + "hk_cis_kred") 

SELECT 0
USE (m.gchom_path + "hkredobr") NOUPDATE
INDEX on u_cis TO (m.gcpri_path + "hk_ucis") FOR LEFT(datum, 6) = "20" + m.mesicek && sestimistne RRRRMM

USE (m.gccen_path + "karty")  NOUPDATE IN 0
USE (m.gccen_path + "sk_pol") NOUPDATE IN 0
USE (m.gccen_path + "sk_plt") NOUPDATE IN 0
USE (m.gccen_path + "sk_txt") NOUPDATE IN 0

DO CASE 
CASE ATC("d_of_ku\", m.gchom_path) > 0
    DO (LOWER(JUSTPATH(sys(16))) + "\ppgm_export_katastr")

CASE ATC("d_of_rez\", m.gchom_path) > 0
    DO (LOWER(JUSTPATH(sys(16))) + "\ppgm_export_rez")

OTHERWISE
    DO (LOWER(JUSTPATH(sys(16))) + "\ppgm_export_faurecia")

ENDCASE 
WAIT CLEAR 


*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
FUNCTION nn(castka)
pom = STRTRAN(STR(m.castka, 11, 2), ",", ".")
pom = STRTRAN(m.pom, " 0.00", " 0   ")
RETURN m.pom


*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
FUNCTION nn0(castka)
pom = STRTRAN(STR(m.castka, 5, 0), ",", ".")
RETURN m.pom


*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
PROCEDURE nastav_obdobi
IF DAY(DATE()) < 20
    datsk2  = LEFT(TTOC(DATE(YEAR(DATE()   ), MONTH(DATE()   ), 1) - 1, 3), 10)     && "2021-09-30"
ELSE
    datsk2  = LEFT(TTOC(DATE(YEAR(DATE()+27), MONTH(DATE()+27), 1) - 1, 3), 10)     && "2021-09-30"
ENDIF
datsk1  = LEFT(m.datsk2, 8) + "01"                                        && "2021-08-01"
mesicek = SUBSTR(datsk1, 3, 2) + SUBSTR(datsk1, 6, 2)                     && "2108", cili ctyrmistne RRMM

WAIT "exportuje se obdobi: " + m.datsk1 + " - " + m.datsk2 + "   ( " + m.mesicek + " )" WINDOW NOWA AT 22,22
?    "exportuje se obdobi: " + m.datsk1 + " - " + m.datsk2 + "   ( " + m.mesicek + " )"
