*:*****************************************************************************
*: Procedure file: SK_OUT
*:
*: 2006-01-26: opravena podminka kopirovani z ">" na ">="
*: 2006-09-08: pocet_uzaverek je interpretovan jako pocet DNU od dnesniho data
*: 2007-08-14: soubory SK nejsou otevirany exclusive
*: 2007-10-30: je-li uveden 4. parametr, posilaji se jen uzaverky v nem vyjmenovanych kas, 
*:             oddelenych mezerou nebo carkou
*:
*: 2011-08-05: pokud ctvrty parametr obsahuje "\", je interpretovan jako cesta, kam se data exportuji, jinak jako seznam kas viz 2007-10-30
*: 2011-11-25: slovenska verze s uzaverkou ve tvaru RRRRMMDD HH:MM
*: 2011-12-07: opraveno jmeno promenne pocet_uzaverek na pocet_dni
*:             on error nahrazeno try-catch
*:
*:*****************************************************************************
param sk_path, pocet_dni, ext, ctvrty_parametr

seznam_kas = ""
exp_path = "c:\ftp\data\"

DO CASE 
CASE EMPTY(m.ctvrty_parametr)
    * nic
CASE "\" $ m.ctvrty_parametr    && parametrem je cesta, kam data exportovat
    exp_path = m.ctvrty_parametr
OTHERWISE                       && parametrem je seznam kas
    seznam_kas = m.ctvrty_parametr
ENDCASE 

exp_path = exp_path + IIF(RIGHT(m.exp_path,1)="\", "", "\")
if ! directory(m.exp_path)
   mkdir (m.exp_path)
ENDIF

if empty(m.ext)
  ext = "_x"
endif

if empty(m.pocet_dni)
  m.pocet_dni = 10
endif

uz1 = RIGHT(DTOS(DATE() - m.pocet_dni), 8) + " 00:00"
vysledek = " v.12-1116: odesilano od " + m.uz1 + " "

CLOSE ALL
clos data
CLEAR WINDOW
set Safety Off

sk_path = sk_path + IIF(RIGHT(m.sk_path,1)="\", "", "\")

sk_otevreno = ""
TRY     
     use (m.sk_path + "SK_PLT ") in 0 excl
     use (m.sk_path + "SK_POL ") in 0 excl
     use (m.sk_path + "SK_FIN ") in 0 excl
     use (m.sk_path + "SK_TXT ") in 0 excl
     use (m.sk_path + "SK_SEZ ") in 0 excl
CATCH 
     sk_otevreno = m.sk_otevreno + " nelze otevrit velka SK"
FINALLY
ENDTRY 

IF EMPTY(m.sk_otevreno)
    IF EMPTY(m.seznam_kas)
       sele sk_sez
       copy FOR BETW(uzaverka, m.uz1, "999999") to (m.exp_path + "sk_sez" + m.ext) type fox2x
       sele sk_plt
       copy for BETW(uzaverka, m.uz1, "999999") to (m.exp_path + "sk_plt" + m.ext) type fox2x
       sele sk_pol
       copy for BETW(uzaverka, m.uz1, "999999") to (m.exp_path + "sk_pol" + m.ext) type fox2x
       sele sk_fin
       copy for BETW(uzaverka, m.uz1, "999999") to (m.exp_path + "sk_fin" + m.ext) type fox2x
       sele sk_txt
       copy for BETW(uzaverka, m.uz1, "999999") to (m.exp_path + "sk_txt" + m.ext) type fox2x
    ELSE 
       sele sk_sez
       copy FOR BETW(uzaverka, m.uz1, "999999") .and. (id_kas        $ m.seznam_kas) to (m.exp_path + "sk_sez" + m.ext) type fox2x
       sele sk_plt
       copy FOR BETW(uzaverka, m.uz1, "999999") .and. (LEFT(u_cis,2) $ m.seznam_kas) to (m.exp_path + "sk_plt" + m.ext) type fox2x
       sele sk_pol
       copy FOR BETW(uzaverka, m.uz1, "999999") .and. (id_kas        $ m.seznam_kas) to (m.exp_path + "sk_pol" + m.ext) type fox2x
       sele sk_fin
       copy FOR BETW(uzaverka, m.uz1, "999999") .and. (id_kas        $ m.seznam_kas) to (m.exp_path + "sk_fin" + m.ext) type fox2x
       sele sk_txt
       copy FOR BETW(uzaverka, m.uz1, "999999") .and. (id_kas        $ m.seznam_kas) to (m.exp_path + "sk_txt" + m.ext) type fox2x
    ENDIF 

else
    vysledek = m.vysledek + m.crlf + "[1B#R]  " + " NEPROVEDENO, nelze otevrit " + m.sk_otevreno + "  ... "
endif
clos data
