*:*****************************************************************************
*: Procedure file: HK_HOTOUT
*: 
*: Export hot_kred, event.hk_oskar
*: 05.04.2017 zavedeno nooptimize, zruseno zamykani, otevirani moupdate
*:*****************************************************************************
param sk_path, pocet_dnu, ext, exp_path
IF EMPTY(exp_path)
  exp_path = "c:\ftp\data\"
ENDIF 
sk_path = sk_path + IIF(RIGHT(m.sk_path,1)="\", "", "\")
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_dnu)
  m.pocet_dnu = 10
endif

CLOSE ALL
clos data
CLEAR WINDOW
set Safety Off

vysledek = crlf

IF FILE(m.sk_path + "hot_kred.dbf")
  use (m.sk_path + "hot_kred") NOUPDATE 
  *do zamkni
  m.od_date = DTOS(DATE() - m.pocet_dnu)
  COPY TO (m.exp_path + "hotout" + m.ext) ALL FOR datum > m.od_date NOOPTIMIZE TYPE FOX2X
ENDIF 

IF FILE(m.sk_path + "hk_oskar.dbf")
  use (m.sk_path + "hk_oskar") NOUPDATE 
  *do zamkni
  m.od_date = DTOS(DATE() - m.pocet_dnu)
  COPY TO (m.exp_path + "oskout" + m.ext) ALL FOR datum > m.od_date NOOPTIMIZE TYPE FOX2X
ENDIF 

clos data



*!*****************************************************************************
*function zamkni
*private _iii
*_iii = 1
*do while ! flock() .and. m._iii < 33 .and. ! empt(dbf())
*    wait "Cekejte, zamykam " + dbf() + str(m._iii,6) wind time m._iii
*    _iii = m._iii + 1
*enddo
*return flock()

FUNCTION str_datum
PARAMETERS c_date
PRIVATE cs_datum
* c_date ve tvaru rrrrmmdd
 m.cs_datum = RIGHT(m.c_date,2) + "." + SUBSTR(c_date,5,2) + "." + LEFT(c_date,4)
RETURN m.cs_datum
