//Журнал регистрации изменений //titov
// Copyright (c) 1993-2005 "Компания БЭСТ". Все права сохраняются.


#include "s_public.ch"
#include "inkey.ch"
#include "my.ch"
#include "assocarr.ch"

#DEFINE PAROL       "Crypt_A3"

#DEFINE P_PATH      1
#DEFINE P_TAG       2 
#DEFINE P_NNOPER    3
#DEFINE P_JRN       4
#DEFINE P_DOC       5
#DEFINE P_DATE      6
#DEFINE P_AGENTNAME 7
#DEFINE P_SUMMA     8



STATIC aKeys,aReestr
STATIC aOper:={;
{"1","Изменен ","Изм"},;
{"2","Создан  ","Соз"},;
{"3","Удален  ","Уд "};
}





PROCEDURE N_Jrn()

   LOCAL aSet := SaveSet()
   LOCAL aSetKey := SaveSetKey()
   LOCAL cBoxHead := 'Журнал регистрации изменений'+IF(!_JRN_YES," ВЫКЛЮЧЕН","")
   LOCAL cHead := ''
   LOCAL cColHead:=;
"Дата     Время Пользователь              Реестр   Документ        Дата док Оп "
*12345678 12345 1234567890123456789012345 12345678 123456789012345 12345678 123*
*012345678901234567890123456789012345678901234567890123456789012345678901234567
   LOCAL aBlockCols:= {;
                        {{|| DTOC(Date)}, 0 },;
                        {{|| TIME}, 9},;
                        {{|| Jrn_GetUserName()},15},;
                        {{|| Jrn_GetReestr()},41},;
                        {{|| Jrn_GetDoc()},50},;
                        {{|| Jrn_GetDate()},66},;
                        {{|| Jrn_GetOper(3)},75};
                      }
   LOCAL nTop:=3
   LOCAL nBottom:=19
   LOCAL cCurProc:={||CoProc(nBottom)}
   LOCAL aHeads :=  {;
                     {'Дата изменения.......:',"Date"},;
                     {'Операция изменения...:',"Oper"},;
                     {'Дата документа.......:',"MyDate","0","1","0","aIn[3,1]<=CTOD(Jrn_GetDate()).AND.aIn[3,2]>=CTOD(Jrn_GetDate())"};
                    }
   LOCAL bScrInit
   LOCAL bPost
   LOCAL bPreGet
   LOCAL bPostGet
   LOCAL bScrPost
   LOCAL aRef:= {,{|oGet|RotateAndReader(oGet,aOper)}}
   LOCAL aGetBlock := {,{|x|RotateBlock(x,aOper,'aIn[2]')}}
   LOCAL aPict := {'@D','@K',"@D"}
   LOCAL aWhen
   LOCAL aValid 
   LOCAL nUniMode
   LOCAL bDelInit
   LOCAL bColor
   LOCAL bDelPost
   LOCAL cFindMacro:='cFind$UPPER(TRIM(Jrn_GetUserName()))'
   LOCAL aSortSeek:={;
 {'- дате регистрации   ','Дата?:  ','Date','DTOS(aIn[1])','@D'},;
 {'- имени пользователя ','Имя?:','Jrn_GetUserName()','TRIM(UPPER(Jrn_GetUserName(aIn[1])))','@K',,,,,,,,.F.},;
 {'- ID документа       ','ID документа?:','NNOper','STR(aIn[1],17,0)'};
 }

   LOCAL aPHeads:={"Журнал регистрации изменений",;
   {'Дата',"DTOC(Date)","99/99/99"},;
   {'Время',"Time","XXXXX"},;
   {'Пользователь',"Jrn_GetUserName()","XXXXXXXXXXXXXXXXXXXXXXXXX"},;
   {"Операция","Jrn_GetOper()","XXXXXXXX"},;
   {"Реестр","Jrn_GetReestr()","XXXXXXXX"},;
   {"Документ","Jrn_GetDoc()+SPACE(1)+Jrn_GetDate()",REPLICATE("X",24)},;
   {"Сумма","Jrn_GetSumma()","99999999999.99"},;
   {"Партнер","Jrn_GetPartner()",REPLICATE("X",25)};
   }

   LOCAL cKey

   PRIVATE MyDate:=DATE()


   SETKEY(K_F4,{||1})
   SETKEY(K_RETURN,{||1})
   SETKEY(K_F8,{||Jrn_Clear()})

   ScrMain()
   ScrTitul(1,cBoxHead)
   ScrTitul(23,"F8:Очистка журнала полностью или за период")
   ScrTitul(24,;
   "F3:Сортировка F6/Alt-F6:Фильтр F7:Поиск F9:Печать")
   SETCOLOR( COL_BROWSE )
   
   ShadowBox("",02,0,22,79,,"┌─┐│┘─└│ ",,,"NoShadow")
   @ nBottom+1,1 SAY REPLICATE("─",78)
   @ nBottom+2,1 SAY "Партнер:                            Сумма:                 ID:                " COLOR "w/b"   

   @ nBottom+1,35 SAY "┬"
   @ nBottom+2,35 SAY "│"
   @ nBottom+3,35 SAY "┴"

   @ nBottom+1,58 SAY "┬"
   @ nBottom+2,58 SAY "│"
   @ nBottom+3,58 SAY "┴"


   SetKeys()

/*******
   FOR EACH cKey IN aKeys:Keys
   NetUse("Tmp"+cKey,LoadPath()+EVAL(aKeys[cKey][P_PATH]))
   ORDSETFOCUS(aKeys[cKey][P_TAG])
   NEXT
***********/
   NetUse("Jrn",LoadPath()+"Jrn")
/************
   FOR EACH cKey IN aKeys:Keys
   SET RELATION TO NNOPER INTO ("Tmp"+cKey) ADDITIVE
   NEXT
***************/
   
   InitList(nTop,nBottom,cColHead,aBlockCols,cCurProc,aHeads,aRef,;
         aPict,aWhen,aValid,nUniMode,bDelInit,bScrInit,aSortSeek,aPHeads,bPost,bDelPost,aGetBlock,bColor,,,bScrPost,cFindMacro,,,bPreGet,bPostGet)

//   ClearRefer()
   CLOSE
/************
   FOR EACH cKey IN aKeys:Keys
   ("Tmp"+cKey)->(DbCloseArea())
   NEXT
*************/
   RestSet(aSet)
   RestSetKey(aSetKey)
RETURN


STATIC FUNCTION CoProc(nBottom)

@ nBottom+2,9 SAY Jrn_GetPartner()   
@ nBottom+2,43 SAY Jrn_GetSumma()   
@ nBottom+2,63 SAY Jrn_GetID()   
RETURN 1


STATIC FUNCTION Jrn_Clear()
LOCAL aDates
LOCAL cMessage:={;
"Операция завершена!",;
"Соответствующие записи помечены как удаленные,",;  
"после первой индексации записи физически удалятся из журнала"}
LOCAL lYes:=YesOrNo("Очистить журнал",.F.,' Полностью ',' За период ')
IF LASTKEY()!=K_ESC
   IF lYes
      IF YesOrNo("Очистить архив полностью?")
         IF LASTKEY()!=K_ESC
            Busy(.T., "Очистка архива документов")
            xDBEVAL({|| dbDelete() },,,.T.)
            Busy(.F.)
            SayAndWait(cMessage)
         ENDIF
      ENDIF
   ELSE
      aDates:=GetDates(13,22,CTOD("01/01/05"),date())
      IF LASTKEY()!=K_ESC
         Busy(.T., "Очистка архива документов")
         xDBEVAL({|| dbDelete() },{|| FIELD->Date >= aDates[1].AND.FIELD->Date <= aDates[2] },,.T.)
         Busy(.F.)
         SayAndWait(cMessage)
      ENDIF
   ENDIF
ENDIF
RETURN 2


FUNCTION Jrn_Reestr()
LOCAL cRet:="",i,cPath:=SUBSTR(UPPER(LoadPath()),3),c
SetKeys()
altd()
IF _JRN_YES
   c:=UPPER(dbinfo(10))
   i:=AT(cPath,c)+LEN(cPath)
   TRY
     cRet:=aReestr[SUBSTR(c,i)]
   CATCH
     cRet:=""
   END
ENDIF
RETURN cRet



FUNCTION Jrn_Write(nAdd)
STATIC sPre:="!" 
LOCAL nArea:=SELECT(),cReestr:=Jrn_Reestr(),aRee
LOCAL cUserName:=PADR(IF(EMPTY(_USER_NAME),SUBSTR(IDENT_USER,COUNTLEFT(IDENT_USER,"0")+1),_USER_NAME),25)
LOCAL cPre

IF EMPTY(cReestr).OR.;
   UPPER(sPre)==(cPre:=UPPER(DTOS(Date())+LEFT(Time(),5)+cReestr+cUserName+;
   STR(EVAL(aKeys[cReestr,P_NNOPER]),17,0)+STR(nAdd,1,0)))
   RETURN .T.
ENDIF

NetUse("Jrn_Sys",LoadPath()+"Jrn")
AddRec()
REPLACE Date WITH Date(),Time WITH LEFT(Time(),5),Reestr WITH cReestr,;
UserName WITH cUserName,;
NNOper WITH (nArea)->(EVAL(aKeys[cReestr,P_NNOPER])),Oper WITH STR(nAdd,1,0)
sPre:=DTOS(Date)+TIME+Reestr+UserName+STR(NNOPER,17,0)+Oper
REPLACE UserName WITH Crypt(UserName,PAROL)
//IF nAdd==3//пишем всегда, иначе при уалении теряются концы в предыдущих записях
   aRee:=aKeys[cReestr]
   REPLACE Comment WITH ;
   (nArea)->(;
   EVAL1(aRee[P_JRN])+";"+EVAL1(aRee[P_DOC])+;
   ";"+DTOC(EVAL(aRee[P_DATE]))+";"+;
   EVAL1(aRee[P_AGENTNAME])+";"+;
   STR(EVAL(aRee[P_SUMMA]),14,2);
   )
//ENDIF

UNLOCK
CLOSE
SELECT(nArea)
RETURN .T.



FUNCTION Jrn_Say(cReestr)
LOCAL aSet := SaveSet()
LOCAL aSetKey := SaveSetKey()
LOCAL aRee:=aKeys[cReestr]
LOCAL cBoxHead := ' Протокол изменений док-та '+;
ALLTRIM(EVAL(aRee[P_DOC]))+;
" "+DTOC(EVAL(aRee[P_DATE]))+" "
LOCAL cHead := ''
LOCAL cColHead:=;
"Дата     Время Пользователь              Операция"
*12345678 12345 1234567890123456789012345 12345678*
*012345678901234567890123456789012345678901234567890123456789012345678901234567
 LOCAL aBlockCols:= {;
                        {{|| DTOC(Date)}, 0 },;
                        {{|| TIME}, 9},;
                        {{|| Jrn_GetUserName()},15},;
                        {{|| Jrn_GetOper()},41};
                      }
LOCAL nTop:=4
LOCAL nBottom:=20
LOCAL nLeft:=15
LOCAL cCurProc
LOCAL aHeads :=  {;
                     {'Дата.................:',"Date"};
                     }
LOCAL bScrInit
LOCAL bPost
LOCAL bPreGet
LOCAL bPostGet
LOCAL bScrPost
LOCAL aRef:={,,,,,}
LOCAL aGetBlock
LOCAL aPict := {'@D','@K 99:99'}
LOCAL aWhen
LOCAL aValid 
LOCAL nUniMode
LOCAL bDelInit
LOCAL bColor
LOCAL bDelPost
LOCAL aSortSeek
LOCAL cFindMacro:='cFind$UPPER(TRIM(Jrn_GetUserName()))'

LOCAL aPHeads:={;
TRIM(EVAL(aRee[P_JRN]))+" "+ALLTRIM(EVAL(aRee[P_DOC]))+;
" "+DTOC(EVAL(aRee[P_DATE]))+" "+ALLTRIM(STR(EVAL(aRee[P_SUMMA]),15,2))+" "+LOWER(GlobalValuta),;
{'Дата',"DTOC(Date)","99/99/99"},;
{'Время',"Time","XXXXX"},;
{'Пользователь',"Jrn_GetUserName()","XXXXXXXXXXXXXXXXXXXXXXXXX"},;
{"Операция","Jrn_GetOper()","XXXXXXXX"};
}
LOCAL cHelp:="Alt-F6:Фильтр F9:Печать"
LOCAL cNNOper:=STR(EVAL(aKeys[cReestr,P_NNOPER]),17,0)
LOCAL cColor:=SETCOLOR(COL_HEADR)


ShadowBox(cBoxHead,nTop-1,nLeft-2,nBottom+1,nLeft+LEN(cColHead)+1,,"┌─┐│┘─└│ ",,,"NoShadow")
ScrTitul(23,"")
ScrTitul(24,cHelp)


SETKEY(K_F4,{||1})
SETKEY(K_RETURN,{||1})
SETKEY(K_F8,{||1})

NetUse("Jrn_Sys",LoadPath()+"Jrn")
ORDSETFOCUS("REESTR")

SetScope("UPPER(cReestr)+STR(NNOPER,17,0)",cReestr+cNNOper)
GO TOP
InitList(nTop,nBottom,cColHead,aBlockCols,cCurProc,aHeads,aRef,;
     aPict,aWhen,aValid,nUniMode,bDelInit,bScrInit,aSortSeek,aPHeads,bPost,bDelPost,aGetBlock,bColor,,nLeft,bScrPost,cFindMacro,COL_HEADR,,bPreGet,bPostGet)
CLOSE
RestSet(aSet)
RestSetKey(aSetKey)
SETCOLOR(cColor)
RETURN 1



FUNCTION Jrn_GetUserName(cUserName)
IF EMPTY(cUserName)
   RETURN IF(EMPTY(FIELD->UserName),FIELD->UserName,Crypt(FIELD->UserName,PAROL))
ENDIF
RETURN Crypt(cUserName,PAROL)




FUNCTION Jrn_GetReestr()
RETURN TOKEN(Comment,";",1)


FUNCTION Jrn_GetDoc()
RETURN PADR(TOKEN(Comment,";",2),15)

FUNCTION Jrn_GetDate()
RETURN TOKEN(Comment,";",3)


FUNCTION Jrn_GetPartner()
RETURN PADR(TOKEN(Comment,";",4),25)


FUNCTION Jrn_GetSumma()
RETURN STR(VAL(TOKEN(Comment,";",5)),14,2)

FUNCTION Jrn_GetID()
RETURN STR(NNOPER,16,0)


FUNCTION Jrn_GetOper(n)
LOCAL nOper:=VAL(FIELD->Oper)
LOCAL cOper
IF n==NIL
   n:=2
ENDIF

cOper:=SPACE(LEN(aOper[1,n]))
IF !EMPTY(nOper)
   cOper:=aOper[nOper,n]
ENDIF
RETURN cOper



STATIC PROCEDURE SetKeys()
IF VALTYPE(aKeys)=="A"
   RETURN 
ENDIF
aReestr:=TAssociativeArray() 
aReestr["BANK\DOC51.DBF"]       :="0101"
aReestr["CASH\K_ORDER.DBF"]     :="0201"
aReestr["CASH\AVANS.DBF"]       :="0202"
aReestr["CASH\PLAT_VED.DBF"]    :="0203"
aReestr["CASH\DEPON.DBF"]       :="0204"

aReestr["SCLAD\MDOC.DBF"]       :="0301"
aReestr["ZAPAS\MDOC.DBF"]       :="0901"

aReestr["TOVAR\ACT.DBF"]        :="TV01"
aReestr["TOVAR\SH_FACT.DBF"]    :="TV02"
aReestr["TOVAR\S_KREDIT.DBF"]   :="TV03"
aReestr["TOVAR\BOOK.DBF"]       :="TV04"

aReestr["CONTRACT\CONTRACT.DBF"]:="SCN1"

aReestr["REAL\ACT.DBF"]         :="0501"
aReestr["REAL\SH_FACT.DBF"]     :="0502"
aReestr["REAL\RBOOK.DBF"]       :="0503"
aReestr["REAL\BOOK.DBF"]        :="0504"



aKeys:=TAssociativeArray() 

aKeys["0101"]:={;
{||"BANK\DOC51.DBF"},;
"TAG_MAIN",;
{||NNOper},;
{||PADR(IF(FIELD->OBOROT="1","-","+")+"ВЫПИСКА",8)},;
{||VDoc+SPACE(1)+NDoc},;
{||DOper},;
{||Agent_N},;
{||Summa}}

aKeys["0201"]:={;
{||"CASH\K_ORDER.DBF"},;
"TAG_MAIN",;
{||NNProvod},;
{||PADR(IF(UPPER(FIELD->TYPE)="Р/О","-","+")+"КАССА",8)},;
{||VType+SPACE(1)+NNDoc},;
{||DataOper},;
{||IF(EMPTY(An_Name),SUBSTR(Contragent,1,25),An_Name)},;
{||Summa}}


aKeys["0202"]:={;
{||"CASH\AVANS.DBF"},;
"TAG_SVOPER",;
{||NNOper},;
{||PADR("АВ_ОТЧЕТ",8)},;
{||NNDoc},;
{||Data},;
{||EVAL(m->bFio)},;
{||RUBLI_ITOG}}


aKeys["0203"]:={;
{||"CASH\PLAT_VED.DBF"},;
"TAG_NNOPER",;
{||NNOper},;
{||PADR("ПЛАТ_ВЕД",8)},;
{||NNDoc},;
{||Data},;
{||Name},;
{||Summa}}


aKeys["0204"]:={;
{||"CASH\DEPON.DBF"},;
"TAG_NNOPER",;
{||NNOper},;
{||PADR("ВЕД_ДЕП",8)},;
{||NNDoc},;
{||Data},;
{||Name_Depon},;
{||Summa}}






aKeys["0301"]:={;
{||"SCLAD\MDOC.DBF"},;
"TAG_REAL",;
{||PRO},;
{||PADR(IF(FIELD->VID="2","-","+")+"ТОВАР",8)},;
{||CodeDoc+SPACE(1)+NumDoc},;
{||Date},;
{||AgentName},;
{||SumOutR}}


aKeys["0901"]:={;
{||"ZAPAS\MDOC.DBF"},;
"TAG_REAL",;
{||PRO},;
{||PADR(IF(FIELD->VID="2","-","+")+"ЗАПАС",8)},;
{||CodeDoc+SPACE(1)+NumDoc},;
{||Date},;
{||AgentName},;
{||SumOutR}}




aKeys["TV01"]:={;
{||"TOVAR\ACT.DBF"},;
"TAG_OPER",;
{||NNOPER},;
{||PADR("+АКТ_УСЛ",8)},;
{||Type_P+SPACE(1)+Tek_Nomer},;
{||Tek_Data},;
{||Name_Ag},;
{||Summa}}



aKeys["TV02"]:={;
{||"TOVAR\SH_FACT.DBF"},;
"TAG_OPER",;
{||NNOPER},;
{||PADR("+СЧ_ФАКТ",8)},;
{||Tek_Nomer},;
{||Tek_Data},;
{||S_KREDIT->AG_NAME},;
{||Summa_Fact}}



aKeys["TV03"]:={;
{||"TOVAR\S_KREDIT.DBF"},;
"TAG_OPER",;
{||NNOPER},;
{||PADR("+СЧ_КРЕД",8)},;
{||Reg_Nomer+SPACE(1)+Tek_Nomer},;
{||Reg_Data},;
{||Ag_Name},;
{||Summa}}


aKeys["TV04"]:={;
{||"TOVAR\BOOK.DBF"},;
"TAG_OPER",;
{||NNOPER},;
{||PADR("+КНИГА",8)},;
{||Tek_Nomer},;
{||Tek_Data},;
{||PARTNER->ShortName},;
{||Summa_Fact}}


aKeys["0501"]:={;
{||"REAL\ACT.DBF"},;
"TAG_OPER",;
{||NNOPER},;
{||PADR("-АКТ_УСЛ",8)},;
{||Type_P+SPACE(1)+Tek_Nomer},;
{||Tek_Data},;
{||Name_Ag},;
{||Summa}}


aKeys["0502"]:={;
{||"TOVAR\SH_FACT.DBF"},;
"TAG_OPER",;
{||NNOPER},;
{||PADR("-СЧ_ФАКТ",8)},;
{||Tek_Nomer},;
{||Tek_Data},;
{||AG_NAME},;
{||Summa_Fact}}


aKeys["0503"]:={;
{||"REAL\RBOOK.DBF"},;
"TAG_OPER",;
{||NNOper},;
{||PADR(IF(STATUS="3","-ЗАЯВKA","-ЗАКАЗ"),8)},;
{||DopCode},;
{||Date},;
{||AgentName},;
{||SumOut}}

aKeys["0504"]:={;
{||"REAL\BOOK.DBF"},;
"TAG_OPER",;
{||NNOPER},;
{||PADR("-КНИГА",8)},;
{||Tek_Nomer},;
{||Tek_Data},;
{||PARTNER->ShortName},;
{||Summa_Fact}}


aKeys["SCN1"]:={;
{||"CONTRACT\CONTRACT.DBF"},;
"TAG_OPER",;
{||ID_CONTR},;
{||PADR("ДОГОВОР",8)},;
{||Vid+SPACE(1)+NumReg},;
{||Date},;
{||NameAgent},;
{||PLAN_OUT}}
RETURN



STATIC FUNCTION GetDates(nRow,nCol,dDayBeg,dDayEnd)
LOCAL aSetKey:=SaveSetKey()
LOCAL cLastColor := SetColor(COL_INPUT)
LOCAL GetList:={}
LOCAL sRest:=SAVESCREEN(nRow,nCol,nRow+4,nCol+30)
LOCAL lConfirm:=SET(_SET_CONFIRM,.T.)

ShadowBox('',nRow,nCol,nRow+3,nCol+27)
@ nRow+1,nCol+3 SAY 'Период с....:' GET dDayBeg PICTURE "@D" 
@ nRow+2,nCol+3 SAY '       по...:' GET dDayEnd VALID (dDayEnd>=dDayBeg.OR.SayError('Дата конца периода меньше даты начала')) PICTURE "@D"
SET CURSOR ON
READ
IF dDayEnd<dDayBeg
   dDayEnd:=dDayBeg
ENDIF
SETCOLOR(cLastColor)
SET CURSOR OFF
RESTSCREEN(nRow,nCol,nRow+4,nCol+30,sRest)
RestSetKey(aSetKey)
SET(_SET_CONFIRM,lConfirm)
RETURN IF(LASTKEY()=27,{},{dDayBeg,dDayEnd})



STATIC FUNCTION Eval1(b)
LOCAL c:=EVAL(b)
IF c==""
   c:=" "
ENDIF
RETURN c











/********************* Предыдущий вариант*******************
FUNCTION Jrn_GetReestr()
LOCAL cRet:="",nArea:=SELECT(),cReestr:=Reestr

IF !EMPTY(cReestr)
   IF ("Tmp"+cReestr)->(EOF())
      cRet:=TOKEN(Comment,";",1)
   ELSE
      TRY
        cRet:=("Tmp"+cReestr)->(EVAL(aKeys[cReestr][P_JRN]))
      CATCH
        cRet:=""
      END
   ENDIF
   SELECT(nArea)
ENDIF
RETURN PADR(cRet,8)


FUNCTION Jrn_GetDoc()
LOCAL cRet:="",nArea:=SELECT(),cReestr:=Reestr
IF !EMPTY(cReestr)
   IF ("Tmp"+cReestr)->(EOF())
      cRet:=TOKEN(Comment,";",2)
   ELSE
      TRY
        cRet:=("Tmp"+cReestr)->(EVAL(aKeys[cReestr][P_DOC]))
      CATCH
         cRet:=""
      END
   ENDIF
   SELECT(nArea)
ENDIF
RETURN PADR(cRet,15)


FUNCTION Jrn_GetDate()
LOCAL cRet:="",nArea:=SELECT(),cReestr:=Reestr
IF !EMPTY(cReestr)
   IF ("Tmp"+cReestr)->(EOF())
      cRet:=TOKEN(Comment,";",3)
   ELSE
      TRY
        cRet:=("Tmp"+cReestr)->(DTOC(EVAL(aKeys[cReestr][P_DATE])))
      CATCH
        cRet:=SPACE(8)
      END
   ENDIF
   SELECT(nArea)
ENDIF
RETURN PADR(cRet,8)


FUNCTION Jrn_GetPartner()
LOCAL cRet:="",nArea:=SELECT(),cReestr:=Reestr
IF !EMPTY(cReestr)
   IF ("Tmp"+cReestr)->(EOF())
      cRet:=TOKEN(Comment,";",4)
   ELSE
      TRY
        cRet:=("Tmp"+cReestr)->(EVAL(aKeys[cReestr][P_AGENTNAME]))
      CATCH
        cRet:=TOKEN(Comment,";",4)
      END
   ENDIF
   SELECT(nArea)
ENDIF
RETURN PADR(cRet,25)


FUNCTION Jrn_GetSumma()
LOCAL cRet:="",nArea:=SELECT(),cReestr:=Reestr
IF !EMPTY(cReestr)
   IF ("Tmp"+cReestr)->(EOF())
      cRet:=STR(VAL(TOKEN(Comment,";",5)),14,2)
   ELSE
      TRY
        cRet:=("Tmp"+cReestr)->(STR(EVAL(aKeys[cReestr][P_SUMMA]),14,2))
      CATCH
        cRet:=""
      END
   ENDIF
   SELECT(nArea)
ENDIF
RETURN PADR(cRet,14)



**********************************/





