// Copyright (c) 1993-2005 "Компания БЭСТ". Все права сохраняются.


#include "my.ch"
#include "s_public.ch"

#undef _TMP_DIR
#define _TMP_DIR M_TempPath()
/*  Закроем базы если они открыты */
PROCEDURE M_Close_Base( aBase )
 aEval( aBase, {|cAlias| IF( ValType(cAlias)=='A',cAlias:=cAlias[1],),;
                IF( SELECT(cAlias)<>0, (cAlias)->(dbCloseArea()) ,NIL)} )
RETURN
***********************************************
/*   Открытие баз : Баланс, Арм ГлавБух      */
/*   aTmpfile - вернем по ссылке             */
***********************************************
FUNCTION M_Open_Base( aBase, aFileTmp, lNoAllPath, lNoProces)
 FIELD Valuta, Schet, Code, Os_Schet, Os_Anal, Kor_Schet,  Kor_Anal,;
       DATE, NDOC, ORDER, KSCHET, REC_TMP1, STATUS, KEY, DT_KT, STATIA,ANALIT
 LOCAL nProces, lRez := .F., bWork, nI
 LOCAL nLen  := LEN( aBase ),lReadyOnly := .F.
 LOCAL aParamdbf, lUseExc := .F., cBase
 LOCAL cTempDbf, cTempNtx, lAllParam := .F.,;
       cPath := IF( GlobalTask=='00', LoadPath(), '' )
 Local uRdd
 aFileTmp := {}

 IF EMPTY(lNoProces)
   PROCES TO nProces MAX nLen PROMPT "Открытие баз данных"
 ENDIF

 BEGIN SEQUENCE
 FOR nI := 1 TO nLen
   lReadyOnly := .F.
   lUseExc := .F.
   IF ValType(aBase[ nI ]) == "A"
     IF LEN( aBase[ nI ] ) > 2
       lAllParam := .T.          // Есть все параметры
     ELSE

       cBase   := UPPER(aBase[ nI ][1] )
       IF ValType(aBase[ nI ][2]) <> 'L'
        // lReadyOnly := .T. 
       ELSE
        lUseExc := aBase[ nI ][2]
       ENDIF
     ENDIF
   ELSE
     cBase :=  UPPER(aBase[ nI ])
   ENDIF
   DO CASE
     CASE lAllParam
       aParamdbf := { UPPER(aBase[ nI ][1]), aBase[ nI ][2], aBase[ nI ][3] }
       IF LEN( aBase[ nI ] ) > 3
         IF ValType(aBase[ nI ][4]) <> 'L'
           // lReadyOnly := .T. // V@
         ELSE
           lUseExc := aBase[ nI ][4]
         ENDIF
       ENDIF
       lAllParam := .F.
     CASE cBase == "A_MAIN"
       aParamdbf := { 'MAIN', cPath+'ARC\A_MAIN',  }
     CASE cBase == "PLAN" .OR. cBase == "KPLAN"
       aParamdbf := { cBase, cPath+'PLAN_Sch',  }
     CASE cBase == "ANALIT" .OR. cBase == "KANALIT"
       aParamdbf := { cBase, cPath+'ANALIT', }
     CASE cBase == "ARXIV"
       aParamdbf := { 'Arxiv', cPath+'Form_Arc',}
     CASE cBase == "MY_METKA"
       SELECT( 0 )
       cTempDbf := TEMPFILE( _TMP_DIR, )
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'CDX'
       cTempDbf += 'DBF'
       dbCreate( cTempDbf,{                      ;
                   {'RECNO',    'N',  6, 0},;
                   {'METKA',    'C',  1, 0};
                          }) // ,'DBFCDX')
       USE
       USE (cTempDbf) ALIAS (cBase) // VIA 'DBFCDX'
       #ifndef __HARBOUR__
       INDEX ON FIELD->RECNO TAG RECNO TO (cTempNtx)
       #else
       INDEX ON FIELD->RECNO TAG MyRECNO TO (cTempNtx)
       #endif
       USE
       aParamdbf := { cBase, cTempDbf, }
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       lUseExc := .T.
     CASE cBase == "INDEXTMP"
       SELECT( 0 )
       cTempDbf := TEMPFILE( _TMP_DIR, )
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'CDX'
       cTempDbf += 'DBF'
       // V@
       while aScan(aFileTmp,cTempDbf) != 0
         cTempDbf := TEMPFILE(_TMP_DIR,)
         FERASE( cTempDbf )
         cTempNtx := cTempDbf+'CDX'
         cTempDbf+= 'DBF'
       end

       dbCreate( cTempDbf,{                      ;
                   {'KEY',      'C', 24, 0},;
                   {'DT_KT',    'C',  1, 0},;
                   {'MAIN_REC', 'N',  6, 0}, ;
                   {'NAME',     'C',  25, 0} ;
                          }) // ,'DBFCDX')
       USE
       FERASE( cTempNtx )
       USE (cTempDbf) ALIAS (cBase) //VIA 'DBFCDX'
       INDEX ON KEY+DT_KT TAG MY_TAG TO (cTempNtx)
       USE
       aParamdbf := { cBase, cTempDbf, }
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       lUseExc := .T.
     CASE cBase == "PROVTMP"
       SELECT( 0 )
       cTempDbf := TEMPFILE( _TMP_DIR, )
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'CDX'
       cTempDbf += 'DBF'
       dbCreate( cTempDbf,{                      ;
                   {'SCHET',  'C', 10, 0},;
                   {'CODE',   'C',  6, 0},;
                   {'NAME',   'C', 50, 2},;
                   {'SUMMA',  'N', 19, 3} ;
                          }) //,'DBFCDX')
       USE
       FERASE( cTempNtx )
       USE (cTempDbf) ALIAS (cBase) //VIA 'DBFCDX'
       INDEX ON UPPER(SCHET+CODE) TAG SCHET TO (cTempNtx)
       USE
       aParamdbf := { cBase, cTempDbf, }
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       lUseExc := .T.
     CASE cBase == "TMP_KANAL"
       SELECT( 0 )
       cTempDbf := TEMPFILE( _TMP_DIR, )
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'CDX'
       cTempDbf += 'DBF'
       dbCreate( cTempDbf,{                      ;
                            {'DATE',     'D',  8, 0},;
                            {'NDOC',     'C',  6, 0},;
                            {'CODE',     'C',  6, 0},;
                            {'DT_SUMMA', 'N', 19, 3},;
                            {'KT_SUMMA', 'N', 19, 3},;
                            {'NAME',     'C', 50, 0},;
                            {'STATIA',   'C',  6, 0} ;
                          }) // ,'DBFCDX')
       USE
       FERASE( cTempNtx )
       USE (cTempDbf) ALIAS (cBase) //VIA 'DBFCDX'
       INDEX ON DTOS(DATE)+NDOC+CODE+STATIA TAG DATE TO (cTempNtx)
       USE
       aParamdbf := { cBase, cTempDbf, }
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       lUseExc := .T.
     CASE cBase == "TMP_KAN"
       SELECT( 0 )
       cTempDbf := TEMPFILE( _TMP_DIR, )
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'CDX'
       cTempDbf += 'DBF'
       dbCreate( cTempDbf,{                      ;
                            {'DATE',     'D',  8, 0},;
                            {'NDOC',     'C',  6, 0},;
                            {'CODE',     'C', 10, 0},;
                            {'DT_SUMMA', 'N', 19, 3},;
                            {'KT_SUMMA', 'N', 19, 3},;
                            {'NAME',     'C', 50, 0},;
                            {'STATIA',   'C',  6, 0} ;
                          }) // ,'DBFCDX')
       USE
       FERASE( cTempNtx )
       USE (cTempDbf) ALIAS (cBase) //VIA 'DBFCDX'
       INDEX ON DTOS(DATE)+NDOC+CODE+STATIA TAG DATE TO (cTempNtx)
       USE
       aParamdbf := { cBase, cTempDbf, }
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       lUseExc := .T.
     CASE cBase == "TMP_GOLOVA"
       SELECT( 0 )
       cTempDbf := TEMPFILE( _TMP_DIR, )
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'CDX'
       cTempDbf += 'DBF'
       dbCreate( cTempDbf,{                      ;
                            {'ORDER',    'C',  3, 0},;
                            {'SCHET',    'C', 10, 0},;
                            {'KSCHET',   'C', 10, 0},;
                            {'DT_SUMMA', 'N', 19, 3},;
                            {'KT_SUMMA', 'N', 19, 3} ;
                          }) //,'DBFCDX')
       USE
       FERASE( cTempNtx )
       USE (cTempDbf) ALIAS (cBase) //VIA 'DBFCDX'
       INDEX ON ORDER+SCHET+KSCHET TAG DATE TO (cTempNtx)
       USE
       aParamdbf := { cBase, cTempDbf, }
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       lUseExc := .T.
     CASE cBase == "TMP1_ORDER"
       SELECT( 0 )
       cTempDbf := TEMPFILE( _TMP_DIR, )
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'CDX'
       cTempDbf += 'DBF'
       dbCreate( cTempDbf,{                      ;
                            {'SCHET',    'C', 10, 0},;
                            {'CODE',     'C',  6, 0},;
                            {'DATE',     'D',  8, 0},;
                            {'NDOC',     'C',  6, 0},;
                            {'KSCHET',   'C', 10, 0},;
                            {'DT_SUMMA', 'N', 19, 3},;
                            {'KT_SUMMA', 'N', 19, 3},;
                            {'ANALIT',   'C',  6, 0},;
                            {'NAMEOPER', 'C', 40, 0} ;
                          }) //,'DBFCDX')
       USE
       FERASE( cTempNtx )
       USE (cTempDbf) ALIAS (cBase) //VIA 'DBFCDX'
         INDEX ON SCHET+CODE+DTOS(DATE)+NDOC+KSCHET TAG SCHET TO (cTempNtx)
         INDEX ON SCHET+KSCHET TAG SCHETS TO (cTempNtx)
         INDEX ON SCHET+CODE+DTOS(DATE)+NDOC+KSCHET+ANALIT TAG SCHETA TO (cTempNtx)
         INDEX ON DTOS(DATE)+NDOC+KSCHET+ANALIT+SCHET+CODE TAG SCHETZ TO (cTempNtx)
         INDEX ON DTOS(DATE)+NDOC+SCHET+CODE+KSCHET+ANALIT TAG SCHETX TO (cTempNtx)
       USE
       aParamdbf := { cBase, cTempDbf, }
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       lUseExc := .T.
     CASE cBase == "TMP2_ORDER"
       SELECT( 0 )
       cTempDbf := TEMPFILE( _TMP_DIR, )
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'CDX'
       cTempDbf += 'DBF'
       dbCreate( cTempDbf,{                      ;
                            {'REC_TMP1', 'C',  6, 0},;
                            {'DT_SCHET', 'C', 10, 0},;
                            {'KT_SCHET', 'C', 10, 0},;
                            {'SUMMA',    'N', 19, 3} ;
                          }) //,'DBFCDX')
       USE
       FERASE( cTempNtx )
       USE (cTempDbf) ALIAS (cBase)// VIA 'DBFCDX'
       INDEX ON REC_TMP1+DT_SCHET+KT_SCHET TAG REC TO (cTempNtx)
       USE
       aParamdbf := { cBase, cTempDbf, }
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       lUseExc := .T.
     CASE cBase == "TMP3_ORDER"
       SELECT( 0 )
       cTempDbf := TEMPFILE( _TMP_DIR, )
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'CDX'
       cTempDbf += 'DBF'
       dbCreate( cTempDbf,{                      ;
                            {'REC_TMP1', 'C',  6, 0},;
                            {'DATE',     'D',  8, 0},;
                            {'NDOC',     'C',  6, 0},;
                            {'DT_SCHET', 'C', 10, 0},;
                            {'DT_CODE',  'C',  6, 0},;
                            {'KT_SCHET', 'C', 10, 0},;
                            {'KT_CODE',  'C',  6, 0},;
                            {'SUMMA',    'N', 19, 3} ;
                          }) //,'DBFCDX')
       USE
       FERASE( cTempNtx )
       USE (cTempDbf) ALIAS (cBase) //VIA 'DBFCDX'
       INDEX ON REC_TMP1+DTOS(DATE)+NDOC+DT_SCHET+DT_CODE+KT_SCHET+KT_CODE+' ' TAG REC TO (cTempNtx)
       INDEX ON DTOS(DATE)+NDOC+DT_SCHET+KT_SCHET+' ' TAG RECD TO (cTempNtx)
       INDEX ON DTOS(DATE)+NDOC+KT_SCHET+DT_SCHET+' ' TAG RECK TO (cTempNtx)
       USE
       aParamdbf := { cBase, cTempDbf, }
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       lUseExc := .T.
     CASE cBase == "TMP_BOOK"
       SELECT( 0 )
       cTempDbf := TEMPFILE( _TMP_DIR, )
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'CDX'
       cTempDbf += 'DBF'
       dbCreate( cTempDbf,{                      ;
                            {'DATE',       'D',  8, 0},;
                            {'NDOC',       'C',  6, 0},;
                            {'NAME',       'C', 50, 0},;
                            {'DT_K_SUMMA', 'N', 19, 3},;
                            {'KT_K_SUMMA', 'N', 19, 3},;
                            {'DT_R_SUMMA', 'N', 19, 3},;
                            {'KT_R_SUMMA', 'N', 19, 3},;
                            {'STATUS',     'C',  1, 0},;
                            {'STATIA',     'C',  6, 0} ;
                          }) // ,'DBFCDX')
       USE
       FERASE( cTempNtx )
       USE (cTempDbf) ALIAS (cBase) // VIA 'DBFCDX'
       INDEX ON STATUS+DTOS(DATE)+NDOC+STATIA TAG SCHET TO (cTempNtx)
       USE
       aParamdbf := { cBase, cTempDbf, }
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       lUseExc := .T.
     CASE cBase == "ERROR"
       SELECT( 0 )
       cTempDbf := TEMPFILE(_TMP_DIR,)
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'IDX'
       cTempDbf+= 'DBF'
       dbCreate( cTempDbf,{                      ;
                            {'CODE_ERR',  'C',  14, 0},;
                            {'NAME_ERR',  'C', 150, 0} ;
                          }) //,'DBFCDX')
       USE
       USE (cTempDbf) ALIAS Error // VIA 'DBFCDX'
       INDEX ON UPPER(CODE_ERR) TO (cTempNtx)
       USE
       aParamdbf := { "ERROR", cTempDbf, cTempNtx }
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       lUseExc := .T.
     CASE cBase == "TMPPERE"
       SELECT( 0 )
       cTempDbf := TEMPFILE(_TMP_DIR,)
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'IDX'
       cTempDbf+= 'DBF'
       dbCreate( cTempDbf,{                      ;
                            {'SCHET',   'C', 10, 0},;
                            {'CODE',    'C',  6, 0},;
                            {'Dt_SUMMA', 'N', 19, 3},;
                            {'Kt_SUMMA', 'N', 19, 3} ;
                           }) //,'DBFCDX')
       USE
       USE (cTempDbf) ALIAS Tmppere // VIA 'DBFCDX'
       INDEX ON SCHET+CODE TO (cTempNtx)
       USE
       aParamdbf := { "TMPpere", cTempDbf, cTempNtx }
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       lUseExc := .T.
     CASE cBase == "KORTMP"
       SELECT( 0 )
       cTempDbf := TEMPFILE(_TMP_DIR,)
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'IDX'
       cTempDbf+= 'DBF'
       dbCreate( cTempDbf,{                      ;
                            {'OS_SCHET',  'C', 10, 0},;
                            {'Kor_SChet', 'C', 10, 0},;
                            {'Dt_Ob',     'N', 19, 3},;
                            {'Kt_Ob',     'N', 19, 3} ;
                           }) //,'DBFCDX')
       USE
       USE (cTempDbf) ALIAS KorTmp // VIA 'DBFCDX'
       INDEX ON OS_SCHET+KOR_SCHET TO (cTempNtx)
       USE
       aParamdbf := { "KORTMP", cTempDbf, cTempNtx }
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       lUseExc := .T.
     CASE cBase == "KORDATE"
       SELECT( 0 )
       cTempDbf := TEMPFILE(_TMP_DIR,)
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'IDX'
       cTempDbf+= 'DBF'
       dbCreate( cTempDbf,{                      ;
                            {'DATE',      'D',  8, 0},;
                            {'OS_SCHET',  'C', 10, 0},;
                            {'Kor_SChet', 'C', 10, 0},;
                            {'Dt_Ob',     'N', 19, 3},;
                            {'Kt_Ob',     'N', 19, 3},;
                            {'OS_CODE',   'C',  6, 0},;
                            {'Kor_CODE',  'C',  6, 0} ;
                           }) //,'DBFCDX')
       USE
       USE (cTempDbf) ALIAS KorDate // VIA 'DBFCDX'
       INDEX ON Field->Os_Schet+DTOS(Field->DATE)+Field->Kor_Schet+' ' TO (cTempNtx)
       USE
       aParamdbf := { "KORDATE", cTempDbf, cTempNtx }
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       lUseExc := .T.
     CASE cBase == "VALUTATMP"
       SELECT( 0 )
       cTempDbf := TEMPFILE(_TMP_DIR,)
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'IDX'
       cTempDbf+= 'DBF'
       dbCreate( cTempDbf,{                      ;
                            {'DATE',      'D',  8, 0},;
                            {'DT_SUMMA',  'N', 19, 3},;
                            {'KT_SUMMA',  'N', 19, 3},;
                            {'DT_GLOBAL', 'N', 19, 3},;
                            {'KT_GLOBAL', 'N', 19, 3} ;
                           }) //,'DBFCDX')
       USE
       USE (cTempDbf) ALIAS ValutaTmp // VIA 'DBFCDX'
       INDEX ON DTOS(DATE) TO (cTempNtx)
       USE
       aParamdbf := { "VALUTATMP", cTempDbf, cTempNtx }
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       lUseExc := .T.
     CASE cBase == "TMP"
       SELECT( 0 )
       cTempDbf := TEMPFILE(_TMP_DIR,)
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'IDX'
       cTempDbf+= 'DBF'
       // V@
       while aScan(aFileTmp,cTempDbf) != 0
             cTempDbf := TEMPFILE(_TMP_DIR,)
             FERASE( cTempDbf )
             cTempNtx := cTempDbf+'IDX'
             cTempDbf+= 'DBF'
       end

       dbCreate(cTempDbf,{          ;
                           {'Valuta', 'C',  3, 0},;
                           {'SCHET',  'C', 10, 0},;
                           {'DtOb',   'N', 19, 3},;
                           {'KtOb',   'N', 19, 3},;
                           {'DtOst',  'N', 19, 3},;
                           {'KtOst',  'N', 19, 3},;
                           {'DtOb_n', 'N', 19, 3},;
                           {'KtOb_n', 'N', 19, 3} ;
                         }) // ,'DBFCDX')
       USE
       USE (cTempDbf) ALIAS Tmp //  VIA 'DBFCDX'
       INDEX ON VALUTA+SCHET TO (cTempNtx)
       USE
       aParamdbf := { "TMP", cTempDbf, cTempNtx }
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       lUseExc := .T.
     CASE cBase == "TMPANAL"
       SELECT( 0 )
       cTempDbf := TEMPFILE(_TMP_DIR,)
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'IDX'
       cTempDbf+= 'DBF'
       // V@
       while aScan(aFileTmp,cTempDbf) != 0
             cTempDbf := TEMPFILE(_TMP_DIR,)
             FERASE( cTempDbf )
             cTempNtx := cTempDbf+'IDX'
             cTempDbf+= 'DBF'
       end

       dbCreate(cTempDbf,{          ;
                   {'Valuta', 'C',  3, 0},;
                   {'SCHET',  'C', 10, 0},;
                   {'CODE',   'C',  6, 0},;
                   {'DtOb',   'N', 19, 3},;
                   {'KtOb',   'N', 19, 3},;
                   {'DtOst',  'N', 19, 3},;
                   {'KtOst',  'N', 19, 3},;
                   {'DtOb_n', 'N', 19, 3},;
                   {'KtOb_n', 'N', 19, 3} ;
                         }) // ,'DBFCDX')
       USE
       USE (cTempDbf)  ALIAS TmpAnal  // VIA 'DBFCDX'
       INDEX ON VALUTA+SCHET+CODE+' ' TO (cTempNtx)
       USE
       aParamdbf := { "TMPANAL", cTempDbf, cTempNtx }
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       lUseExc := .T.
     CASE cBase == "TMPSCHET"
       SELECT( 0 )
       cTempDbf := TEMPFILE(_TMP_DIR,)
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'IDX'
       cTempDbf+= 'DBF'
       // V@
       while aScan(aFileTmp,cTempDbf) != 0
             cTempDbf := TEMPFILE(_TMP_DIR,)
             FERASE( cTempDbf )
             cTempNtx := cTempDbf+'IDX'
             cTempDbf+= 'DBF'
       end

       dbCreate(cTempDbf,{          ;
                   {'Valuta', 'C',  3, 0},;
                   {'SCHET',  'C', 10, 0},;
                   {'DtOb',   'N', 19, 3},;
                   {'KtOb',   'N', 19, 3},;
                   {'DtOst',  'N', 19, 3},;
                   {'KtOst',  'N', 19, 3},;
                   {'DtOb_n', 'N', 19, 3},;
                   {'KtOb_n', 'N', 19, 3} ;
                         })  // ,'DBFCDX')
       USE
       USE (cTempDbf) ALIAS TmpSchet  // VIA 'DBFCDX'
       INDEX ON VALUTA+SCHET TO (cTempNtx)
       USE
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       aParamdbf := { "TMPSCHET", cTempDbf, cTempNtx }
       lUseExc := .T.
     CASE cBase == "TMPDATE"
       SELECT( 0 )
       cTempDbf := TEMPFILE(_TMP_DIR,)
       FERASE( cTempDbf )
       cTempNtx := cTempDbf+'IDX'
       cTempDbf+= 'DBF'
       dbCreate(cTempDbf,{          ;
                   {'Date',   'D',  8, 0},;
                   {'DtOst',  'N', 19, 3},;
                   {'KtOst',  'N', 19, 3} ;
                         })  // ,'DBFCDX')
       USE
       USE (cTempDbf) ALIAS TmpDATE  // VIA 'DBFCDX'
       INDEX ON DATE TO (cTempNtx)
       USE
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       aParamdbf := { "TMPDATE", cTempDbf, cTempNtx }
       lUseExc := .T.
     CASE cBase == "KORANALTMP"
       SELECT( 0 )
       WHILE FILE((cTempDbf := TEMPFILE(_TMP_DIR))+"DBF");ENDDO
//       cTempDbf := TEMPFILE(_TMP_DIR,)
       FERASE( cTempDbf )


       cTempNtx := cTempDbf+'IDX'
       cTempDbf+= 'DBF'
       CLOSE
       FERASE(cTempDbf)
       dbCreate(cTempDbf,{                      ;
                   {'OS_SCHET',  'C', 10, 0},;
                   {'OS_Anal',   'C',  6, 0},;
                   {'Kor_SChet', 'C', 10, 0},;
                   {'Kor_Anal',  'C',  6, 0},;
                   {'Dt_Ob',     'N', 19, 3},;
                   {'Kt_Ob',     'N', 19, 3} ;
                  })
       USE

       USE (cTempDbf) ALIAS KorAnalTmp  // VIA 'DBFCDX'
       INDEX ON OS_SCHET+OS_ANAL+KOR_SCHET+KOR_ANAL TO (cTempNtx)
       USE
       AADD( aFileTmp, cTempDbf )
       AADD( aFileTmp, cTempNtx )
       aParamdbf := { "KorAnalTmp", cTempDbf, cTempNtx }
       lUseExc := .T.
     OTHERWISE
       IF GlobalTask == '00' .AND. EMPTY( lNoAllPath )
         aParamdbf := { cBase, cPath+cBase,  }
       ELSE
         aParamdbf := { cBase, cBase,  }
       ENDIF
     ENDCASE
     uRdd := NIL

/****************
     IF IsAds().and.ValType( aParamDbf ) == "A"
        if aScan(aFileTmp,{|x| Upper(x) == Upper(aParamDbf[2]) }) > 0
           uRdd := NameRdd()
        endif
     endif
******************/

     IF ValType( aParamDbf ) == "A"
       IF lUseExc
         lRez := NetUseExc( aParamDbf[1], aParamDbf[2], aParamDbf[3],uRdd )
       ELSE
         lRez := NetUse( aParamDbf[1], aParamDbf[2], aParamDbf[3],,uRdd, lReadyOnly )
       ENDIF
     IF EMPTY(lNoProces)
       Proces_Update( nProces )
     ENDIF
     IF !lRez
       BREAK
     ENDIF
   ELSE
     BREAK
   ENDIF
   COMMIT
//   INKEY( 0.1 )
 NEXT
 lRez := .T.

 RECOVER
 Error_Use( cBase )

 END SEQUENCE
 IF EMPTY(lNoProces)
   PROCES END
 ENDIF
RETURN( lRez )
//
Static Function M_TempPath()
Local szTmp :=  GlobalTmpPath   // B4_GetTempPath() Nikita
      if Right(szTmp,1) != '\'
         szTmp += '\'
      endif
Return szTmp

