*       *       *       *       *       *       *       *       *       *       *       *       *       *       * 
*
* 2016-02-01 
* 2016-02-25 - pridana generace textoveho souboru
* 2022-01-05 - pro groseto se generuje jejich format XLS
* 2022-05-15 - pro groseto pridan konstantni sloupec exp_date
*
*       *       *       *       *       *     #> ver. 2022-01-05 <#     *       *       *       *       *       *

#DEFINE EXP_SOUBOR  "karty_do_vahy"

IF EMPTY(m.ean_path)
    WAIT "neni nastaven EANPATH v .ini souboru" WINDOW AT 22,22 TIMEOUT 9
ENDIF 

IF .not. DIRECTORY(m.ean_path)
    MKDIR (m.ean_path)
ENDIF 

WAIT "generating " + (m.ean_path + EXP_SOUBOR) WINDOW AT 22,22 TIMEOUT 2
WAIT "generating " + (m.ean_path + EXP_SOUBOR) WINDOW AT 22,22 NOWAIT 

DO CASE 
CASE ATC("d_gros", m.gchom_path) > 0
    SELECT cena01 * 100 as cena, ALLTRIM(kod) as kod, nazev, "28. mųj" as department, 3 as exp_date ;
           WHERE nazev1 # "xxx SMAZANO xxx " AND druh_kalk = "Vazene    " .and. VAL(kod) # 0 ;
           FROM (m.gccen_path + "karty") INTO CURSOR karty_do_vahy READWRITE 
    COPY ALL TO (m.ean_path + EXP_SOUBOR) TYPE XLS


OTHERWISE 
    SELECT nazev, c_karty, ALLTRIM(kod) as kod, 7 as typ_eanu, cena09, 4 as jedn_vahy, 21 as skupina, 0 as tolerance, 2 as dni_spotr, 0 as sloupec_j, 0 as sloupec_k, 5 as telerance, 000000 as cisloradku, 0 as sloupec_n, 0 as sloupec_o, 64 as typ_etik, 0 as sloupec_q, 0 as sloupec_r ;
           where nazev1 # "xxx SMAZANO xxx            " AND BETWEEN(VAL(kod), 21000, 21999);
           FROM (m.gccen_path + "karty") INTO CURSOR karty_do_vahy READWRITE 
    REPLACE ALL cisloradku WITH RECNO()
    COPY ALL TO (m.ean_path + EXP_SOUBOR) TYPE XLS

    SELECT v.cisloradku, v.c_karty, k.vyr_postup ;
           FROM karty_do_vahy v LEFT JOIN (m.gccen_path + "karty") k ON k.c_karty = v.c_karty ;
           ORDER BY cisloradku ;
           INTO CURSOR texty_do_vahy
    STRTOFILE("", m.ean_path + EXP_SOUBOR +".txt") && k smazani minule verze
    SCAN
        DO zapis_text_karty WITH ALLTRIM(vyr_postup)
    ENDSCAN 
ENDCASE 
WAIT CLEAR 


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
PROCEDURE zapis_text_karty 
PARAMETERS vyr_postup
#DEFINE DELKA_RADKU 52
#DEFINE CRLF        CHR(13)+CHR(10)

FOR ii = 1 TO 8
    delka = RAT(" ", PADR(m.vyr_postup, DELKA_RADKU+1))
    IF delka < 11
        delka = DELKA_RADKU
    ENDIF 
    radek = ALLTRIM(LEFT(m.vyr_postup, m.delka))
    ? m.delka, m.radek
    STRTOFILE(m.radek + CRLF, m.ean_path + EXP_SOUBOR +".txt", 1)
    vyr_postup = ALLTRIM(SUBSTR(m.vyr_postup, m.delka+1))
ENDFOR 
