*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
*   konverze u_ex pro budvar/SAP
*
* 2023-12-11 - radky pro ta strediska, co se nemaji exportovat, zustavaji, jen se jim smaze to cislo strediska (UTVAR)
* 2024-04-08 - pridano textove zurnalovani
*            - 
*            - 
*
*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
PARAMETERS soubor_in        && (m.gcucto_path + "u_ex")

small_log(m.soubor_in, "ucto_exp")
IF .not. FILE(m.soubor_in + ".dbf")
    MESSAGEBOX("soubor " + UPPER(m.soubor_in) + " neexistuje",1+16,PROGRAM(), 6666)
    RETURN 
ENDIF 

soubor_out = STRTRAN(m.soubor_in, JUSTSTEM(m.soubor_in), JUSTSTEM(m.soubor_in) + "_sap")
small_log(m.soubor_out, "ucto_exp")

SELECT *, dal as ucet, dal2 as ucetsap, hs_dal as utvar, 1 as strana WHERE NOT EMPTY(dal) FROM (m.soubor_in) INTO TABLE (m.gcpri_path + "u_ex_dal")
REPLACE ALL castka WITH ROUND(castka, 2)

SELECT *, md  as ucet, md2  as ucetsap, hs_md  as utvar, SPACE(3) as znak_dane, 0 as strana WHERE NOT EMPTY(md) FROM (m.soubor_in) INTO TABLE (m.soubor_out)
REPLACE ALL castka WITH ROUND(castka, 2)

APPEND FROM (m.gcpri_path + "u_ex_dal")

ALTER table (m.soubor_out) DROP COLUMN md
ALTER table (m.soubor_out) DROP COLUMN dal
ALTER table (m.soubor_out) DROP COLUMN hs_md
ALTER table (m.soubor_out) DROP COLUMN hs_dal
ALTER table (m.soubor_out) DROP COLUMN md2
ALTER table (m.soubor_out) DROP COLUMN dal2

ALTER table (m.soubor_out) ALTER castka N(9,2)
DELETE FILE (JUSTPATH(m.soubor_out) + "\*.bak")
DELETE FOR ATC("EXPORT", ucet) > 0

IF FSIZE("dan") > 0
    REPLACE znak_dane WITH "A0" FOR dan = 1.00
    REPLACE znak_dane WITH "A1" FOR dan = 1.21
    REPLACE znak_dane WITH "A2" FOR dan = 1.15
    REPLACE znak_dane WITH "AC" FOR dan = 1.12
    REPLACE znak_dane WITH "A3" FOR dan = 1.10
ENDIF 

REPLACE ALL utvar WITH LEFT(utvar, 2)
REPLACE FOR .not. INLIST(LEFT(utvar, 2), "24", "26", "27", "30") utvar WITH ""

REPLACE utvar WITH "109024" FOR ATC("24", utvar) > 0
REPLACE utvar WITH "109026" FOR ATC("26", utvar) > 0
REPLACE utvar WITH "109027" FOR ATC("27", utvar) > 0
REPLACE utvar WITH "109020" FOR ATC("30", utvar) > 0

small_log("uz jen dbf2csv", "ucto_exp")
dbf2csv()
small_log("=========   hotovo   =========", "ucto_exp")
