PARAMETERS p_kar, p_path
PRIVATE zavrihotkred, zavriobjednan, zavritmhkobr, zavrihkredobr, rtn
*
m.rtn = m.p_kar 
IF LEN(ALLTRIM(m.p_kar)) = 12
  zavrihotkred = .f.
  zavriobjednan = .f.
  zavritmhkobr = .f.
  zavrihkredobr = .f.
  *
  IF !USED("hot_kred")
    SELECT 0
    USE (m.p_path+"hot_kred")
    zavrihotkred = .t.
  ENDIF 
  *
  IF !USED('objednan')
    SELECT 0
    USE (m.p_path+"objednan")
    zavriobjednan = .t.
  ENDIF 
  *
  IF !USED('_tmhkobr')
    IF FILE(m.p_path+"_tmhkobr.dbf")
      SELECT 0
      USE (m.p_path+"_tmhkobr")
      zavritmhkobr = .t.
    ENDIF 
  ENDIF 
  *
  IF !USED('hkredobr')
    SELECT 0
    USE (m.p_path+"hkredobr")
    zavrihkredobr = .t.
  ENDIF 
  *
  SELECT hot_kred
  LOCATE FOR hot_kred.cis_kred = m.p_kar
  IF FOUND()
    m.rtn = m.p_kar
  ELSE
    m.pomkar = PADR(RIGHT(m.p_kar, 7), 12)
    LOCATE FOR hot_kred.cis_kred  = m.pomkar
    IF FOUND()
      REPLACE FOR hot_kred.cis_kred = m.pomkar hot_kred.cis_kred WITH m.p_kar, hot_kred.datum WITH DTOS(DATE())
      SELECT objednan
      REPLACE FOR objednan.cis_kred = m.pomkar objednan.cis_kred WITH m.p_kar
      IF m.zavritmhkobr
        SELECT _tmhkobr
        REPLACE FOR _tmhkobr.cis_kred = m.pomkar _tmhkobr.cis_kred WITH m.p_kar
      ENDIF   
      SELECT hkredobr
      REPLACE FOR hkredobr.cis_kred = m.pomkar hkredobr.cis_kred WITH m.p_kar
    ENDIF 
  ENDIF 
  *
  IF m.zavrihotkred
    USE IN hot_kred
  ENDIF 
  IF m.zavriobjednan
    USE IN objednan
  ENDIF
  IF m.zavritmhkobr
    USE IN _tmhkobr
  ENDIF 
  IF m.zavrihkredobr
    USE IN hkredobr
  ENDIF
ELSE
  m.rtn = m.p_kar
ENDIF 
RETURN m.rtn
