*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
*  export stravniku pro automaty 
*  2020-11-22 - 
*
*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    

gchom_path = "i:\d_faurecia\"

#DEFINE ODD " ; "
#DEFINE CRLF CHR(13)+CHR(10)

USE (m.gchom_path + "hot_kred") AGAIN NOUPDATE ALIAS hot_kred
INDEX on cis_kred TO eeqweqwe

exportni_soubor       = "c:\ima\importexport\stravnici.csv"
exportni_soubor_firem = "c:\ima\importexport\firmy.csv"

STRTOFILE("os.cislo     ;    jmeno                       ;   chip           ;   limit   ; " + CRLF, m.exportni_soubor)

limit_expirace =  TRANSFORM(YEAR(DATE()), "9999") + "/" + TRANSFORM(MONTH(DATE()), "@L 99") + "/" + TRANSFORM(DAY(DATE()), "@L 99")

SCAN FOR exp_date > m.limit_expirace
    IF is_os_c_ok(cis_kred)
        retez = PADL(ALLTRIM(cis_kred), 12) + ODD + tx(jmeno, 30) + ODD + tx(chipcode, 16) + ODD + nx(200) + ODD
        STRTOFILE(m.retez + CRLF, m.exportni_soubor, 1)
    ENDIF 
ENDSCAN 

SELECT disti firma FROM hot_kred INTO CURSOR firmy ORDER BY 1
STRTOFILE   ("firma"      + CRLF, m.exportni_soubor_firem)
SCAN 
    STRTOFILE(firma + ODD + CRLF, m.exportni_soubor_firem, 1)
ENDSCAN 
USE IN hot_kred


*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
FUNCTION is_os_c_ok(txt)
txt = ALLTRIM(m.txt)
FOR iii = 1 TO LEN(m.txt)
    IF .not. BETWEEN(SUBSTR(m.txt, m.iii, 1), "0", "9")
        RETURN .F.
    ENDIF 
ENDFOR 
RETURN .T.


*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
FUNCTION nx(castka)
pom = STRTRAN(STR(m.castka, 9, 2), ",", ".")
RETURN m.pom

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

*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
FUNCTION tx(texticek, delka)
pom = PADR(STRTRAN(ALLT(m.texticek), '"', "'"), m.delka)
RETURN m.pom
