*:*****************************************************************************
*: Procedure file: HK_OUT
*: Uprava pro prenost dotaci (EGAP) 7.1.2008
*: Uprava vypisu pro kontrolu 30.3.2009
*:*****************************************************************************
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

m.od_date = DATE() - m.pocet_dnu
m.od_dats = DTOS(DATE() - m.pocet_dnu)

IF FILE(m.sk_path + "hk_doch.dbf")
  use (m.sk_path + "hk_doch")
  do zamkni
  m.od_date = DATE() - m.pocet_dnu
  copy for d_date > m.od_date to (m.exp_path + "hk_doch" + m.ext) type fox2x
ENDIF 

clos data

IF FILE(m.sk_path + "hk_bony.dbf")
  use (m.sk_path + "hk_bony")
  do zamkni
  m.od_dats = DTOS(DATE() - m.pocet_dnu)
  copy FOR(datum > m.od_dats) AND (u_cis # "ARCHIV") to (m.exp_path + "hk_bony" + m.ext) type fox2x
  * Zmena, pac doposilani na web udela v prenosech, popr. v kreditu
  *USE (m.exp_path + "hk_bony" + m.ext)
  *REPLACE ALL zapsano WITH .T.	&& aby to nestrasilo na provozech
ENDIF 

clos data

use (m.sk_path + "hkredobr")
do zamkni
m.od_dats = DTOS(DATE() - m.pocet_dnu)
copy for datum > m.od_dats to (m.exp_path + "hk_obrt" + m.ext) type fox2x
IF FILE(m.sk_path + "_tmhkobr.dbf")
  USE (m.sk_path + "_tmhkobr")
  copy for datum > m.od_dats AND u_cis # "PRENOS" to (m.exp_path + "hk_obr1" + m.ext) type fox2x
  USE (m.exp_path + "hk_obrt" + m.ext)
  APPEND FROM (m.exp_path + "hk_obr1" + m.ext)
  * Zmena, pac doposilani na web udela v prenosech, popr. v kreditu
  *REPLACE ALL zapsano WITH .T.		&& aby na provozech se to nesralo
ELSE
  * Zmena, pac doposilani na web udela v prenosech, popr. v kreditu
  *USE (m.exp_path + "hk_obrt" + m.ext)
  *REPLACE ALL zapsano WITH .T.		&& aby na provozech se to nesralo
ENDIF 

clos data

IF FILE(m.sk_path + "hk_dotace.dbf")
  use (m.sk_path + "hk_dotace")
  do zamkni
  m.od_dats = DTOS(DATE() - m.pocet_dnu)
  copy for datum > m.od_dats to (m.exp_path + "hk_dotc" + m.ext) type fox2x
ENDIF 

clos data

IF FILE(m.sk_path + "hk_hodn.dbf")
  use (m.sk_path + "hk_hodn")
  vysledek = vysledek + "[1]" + "          Sumar bodu (HK_HODN)" + m.ext + " " + DTOC(d_date) + " " + cas + crlf
ENDIF 

clos data

IF FILE(m.sk_path + "hot_kred.dbf") AND ("D_STRAH" $ UPPER(m.sk_path))
   use (m.sk_path + "hot_kred")
   SET ORDER TO TAG datum
   GO BOTTOM 
   m.pomdate = DATE(VAL(LEFT(datum,4)), VAL(SUBSTR(datum,5,2)), VAL(RIGHT(datum,2)))
   DO CASE 
   CASE m.pomdate < DATE()-10
     vysledek = vysledek + "[2#R]          Posledni karta z (HOT_KRED) " + m.ext + str_datum(datum) + " " + LEFT(cas,5) + crlf
   CASE m.pomdate < DATE()-5
     vysledek = vysledek + "[2#r]          Posledni karta z (HOT_KRED) " + m.ext + str_datum(datum) + " " + LEFT(cas,5) + crlf
   OTHERWISE 
     vysledek = vysledek + "[2#g]          Posledni karta z (HOT_KRED) " + m.ext + str_datum(datum) + " " + LEFT(cas,5) + crlf
   ENDCASE   
ENDIF 

clos data

IF FILE(m.sk_path + "hk_odmvyb.dbf")
  use (m.sk_path + "hk_odmvyb")
  do zamkni
  m.od_dats = DTOS(DATE() - m.pocet_dnu)
  copy FOR(datum > m.od_dats) AND (u_cis # "ARCHIV") to (m.exp_path + "hk_odmv" + m.ext)
ELSE
  IF FILE(m.exp_path + "hk_odmvyb.dbf")
    COPY FILE (m.exp_path + "hk_odmvyb.dbf") TO (m.sk_path + "hk_odmvyb.dbf")
    COPY FILE (m.exp_path + "hk_odmvyb.cdx") TO (m.sk_path + "hk_odmvyb.cdx")
    vysledek = vysledek + "[1]" + "           Zalozen novy HK_ODMVYB" + crlf
  ENDIF 
ENDIF 

clos data

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
