*:*****************************************************************************
*: Procedure file: OBJ_IN
*: 
*: Import objednanych jidel. Rozliseni provozu se dela 
*:*****************************************************************************
param sk_path, pripona, 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

CLOSE ALL
clos data
CLEAR WINDOW
set Safety Off
SET CPDIALOG OFF

vysledek = crlf


if file(m.exp_path + "objout" + m.pripona + ".dbf")
    use (m.sk_path + "objednan")
    sele 0
    use (m.exp_path + "objout" + m.pripona) Alias objout_x Exclusive
    IF FSIZE('label') = 0
        ALTER TABLE (m.exp_path + "objout" + m.pripona) ADD COLUMN label C(1)
    ENDIF     
    inde on DTOS(datum) + cis_kred tag datkr
    REPLACE ALL objednal with m.pripona		&& Rozliseni mista, odkud se objednalo
    REPLACE ALL label WITH "X"
    SELECT * from (m.exp_path + "objout" + m.pripona) a INTO TABLE (m.exp_path+"pribylo");
     WHERE .NOT. exists (select * from (m.sk_path+"objednan") b;
     WHERE (a.datum=b.datum) AND (a.cis_kred=b.cis_kred))
    scan
      sele objednan
      locate for DTOS(datum) + cis_kred = DTOS(objout_x.datum) + objout_x.cis_kred
      if found()
        sele objout_x
        repl label with ""
      else
        sele objout_x
      endif
    endscan
    DELETE FOR EMPTY(label)
    PACK 
    sele objednan 
    APPEND FROM (m.exp_path + "pribylo")
    USE IN pribylo
    vysledek = vysledek + "[1#G]       appendovano " + "OBJEDNAN" + m.pripona + crlf
else
    vysledek = vysledek + "[2#R]       ... " + "neexistuje soubor " + m.exp_path + "objout" + m.pripona
endif

CLOSE DATABASES 
