Local valan,a,b,datea,dateb,nfrm
DIRFIRM=loc+'\'+NFSCURT

Set Safety Off
Set Exclusive On

b=Iif(M.NNLMAX<10,'0'+Str(M.NNLMAX,1),Str(M.NNLMAX,2))
dateb='an'+m.an+'\'+'DATE'+b
m.NNLMAX=M.NNLMAX+1
a=Iif(M.NNLMAX<10,'0'+Str(M.NNLMAX,1),Str(M.NNLMAX,2))
m.nl=a

If m.NNLMAX=13
	m.NNLMAX=1
	a='01'
	valan=m.anmax+1
	m.an=Alltrim(Str(valan))
	m.anmax=m.an
	m.nl=a
Endif
datea='an'+m.an+'\'+'DATE'+a
Date=datea

Set Defa To &calefirma
If !Directory('&datea')
	Md &datea
Endif
Close Database
*DO DES WITH 'CALENDAR'

*Do DESCHID.PRG
**************

Set Defa To ..
Set Defa To ..
Set Defa To ..
Set Defa To ..

m.anmax=m.an
m.nlmax=m.nl
m.NNL=M.NNLMAX
Show Gets
Set Exclusive Off

Do totv.PRG
Sele CALENDAR
*loca for SCONT=.f.
*
*if eof() then
Appe Blank
*endif
*
Repl nl With a
Repl an With m.an
*REPL SCONT WITH .T.
Goto Recno()-1
Scatter Fiel CTVAI,CTVAM,plafoncasa,plafonplat Memvar
Goto Recno()+1
*repl ctvai with m.ctvai
*repl ctvam with m.ctvam
Gath Fiel CTVAI,CTVAM,plafoncasa,plafonplat Memvar

Return
**********************************
* sfarsit procedura deschid luna *
**********************************




