*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
*  export stravniku pro automaty 
*  2020-12-31 - neposilaji se stravnici s prazdnym chipcode
*  2021-04-25 - misto cis_kred se posila idklienta
*  2021-05-05 - neposilaji se firmy lintar a netmarks
*
*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
vysledek = "  v.2021-05-05 "


gchom_path = "i:\d_faurecia\"

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

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

USE (m.gchom_path + "hot_kred") AGAIN NOUPDATE ALIAS hot_kred
INDEX on cis_kred TO eeqweqwe
SET FILTER TO ATC("NETMARKS", firma) + ATC("LINTAR", firma) = 0

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")

pocet_lidi = 0
prazdne_chipcodes = ""
SCAN FOR exp_date > m.limit_expirace
    IF is_os_c_ok(cis_kred)
        IF .not. empt(chipcode)
*            retez = PADL(ALLTRIM(cis_kred), 12) + ODD + tx(jmeno, 30) + ODD + tx(chipcode, 16) + ODD + nx(200) + ODD
            retez = STR(idklienta, 9)            + ODD + tx(jmeno, 30) + ODD + tx(chipcode, 16) + ODD + nx(200) + ODD
            STRTOFILE(m.retez + CRLF, m.exportni_soubor, 1)
            pocet_lidi = pocet_lidi + 1
        ELSE
            prazdne_chipcodes = m.prazdne_chipcodes + ALLT(cis_kred) + ":" + ALLT(jmeno) + ", "
        ENDIF 
    ELSE 
        vysledek = m.vysledek + CRLF + "[2#R]      CHYBA V CIS_KRED " + cis_kred + "  " + jmeno
    ENDIF 
ENDSCAN 
IF .not. EMPT(m.prazdne_chipcodes)
    vysledek = m.vysledek + CRLF + "[2#R]    PRAZDNY CHIPCODE: " + m.prazdne_chipcodes
ENDIF 
vysledek = m.vysledek + CRLF + "exportovano " + nx0(pocet_lidi) + "clientu do " + m.exportni_soubor

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
