*:*****************************************************************************
*:
*: Procedure file: VAH_OUT 
*:
*: Kopiruje zaznamy vazene inventury
*: 2012-11-27: upravy formatovani, pridan parametr exp_path
*: 2012-12-27: snese i chybejici backslash u exp_path
*:             otevirani vahinv.dbf osetreno TRY_CATCH
*:
*:*****************************************************************************
param sk_path, pocet_dni, pripona, exp_path

vysledek = " v.12-1227: "

IF EMPTY(m.exp_path)
  m.exp_path = "c:\ftp\data\"
ENDIF 

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

if empty(m.pocet_dni)
  m.pocet_dni = 10
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

otevreno = .F.
IF FILE(m.sk_path + "vahinv.dbf")
    TRY     
        use (m.sk_path + "vahinv") exclusive
        otevreno = .T.
    CATCH 
        vysledek = m.vysledek + crlf + "[1#R] nelze otevrit " + m.sk_path + "VAHINV"
    FINALLY
    ENDTRY 
ELSE 
    vysledek = m.vysledek + " neexistuje " + m.sk_path + "VAHINV"
ENDIF 

if m.otevreno
    uzaverka = RIGHT(DTOS(DATE() - m.pocet_dni), 6) + " 00:00"
    copy for uzaverka >= m.uzaverka to (m.exp_path + "vahinv" + m.pripona) type fox2x

    m.uz_del = RIGHT(DTOS(DATE() - 90), 6) + " 00:00"
    DELETE FOR vahinv.uzaverka < m.uz_del OR "O" $ vahinv.uzaverka
    PACK 
    vysledek = m.vysledek + " ... EXEC OK "
endif
clos data
