LOCAL cond,c

lnValRez = m.valrez
IF VAL(m.an) >= 2004
	m.valrez = 0     && din 2004 trece ca si valoare amortizata
ENDIF 

cond='month(m.datapif)=val(m.nl) and year(m.datapif)=val(m.an) and m.uzuraprec=0'
m.normaan=ROUND(m.normat/12,3)

IF m.valramasa = 0 AND m.dataeval = m.datapif
	m.valramasa = m.valin - m.valrez
ENDIF

IF m.normat2=0
	m.normat2=m.normaan
ENDIF

IF m.normat2lun=0
	m.normat2lun=m.normat
ENDIF

DO CASE
	CASE UPPER(LEFT(m.tipamort,1))='L'   &&LINIARA
		DO amortlin
		m.amortan=ROUND(m.amortlun*12,gnZ)
	CASE UPPER(LEFT(m.tipamort,1))='A'  &&ACCELERATA
		IF (m.P>0 AND m.P<=0.5) AND m.UZURA<=12
			m.amortlun = IIF(m.UZURA>m.normat OR &cond ,0,IIF(M.UZURA=M.normat,M.valin-m.valrez-M.AMORTprec,ROUND((m.valin-m.valrez)*m.P/12,gnZ)))
		ELSE
			m.amortlun = IIF(m.UZURA>m.normat OR &cond ,0,IIF(M.UZURA=M.normat,M.valin-m.valrez-M.AMORTprec,ROUND(((m.valin-m.valrez)*(1-m.P))/(m.normat-12),gnZ)))
		ENDIF
		m.amortan=ROUND(m.amortlun*12,gnZ)
	CASE UPPER(LEFT(m.tipamort,1))='D'  &&DEGRESIVA
		IF MOD(m.UZURA,12)=1
			c=12*m.k/m.normat
			m.amortan = IIF(m.UZURA>m.normat,0,ROUND((m.valin-m.valrez-m.AMORTprec)*c,gnZ))
			IF m.amortan<ROUND(12*(m.valin-m.valrez)/m.normat,gnZ)
				m.amortan = ROUND((m.valin-m.valrez-m.AMORTprec)/(ROUND(m.normat2lun/12,3)-ROUND(m.UZURA/12,3)),gnZ)
			ENDIF
		ENDIF
		m.amortlun = IIF(m.UZURA>m.normat OR &cond ,0,IIF(m.UZURA=m.normat,M.valin-m.valrez-M.AMORTprec,ROUND(m.amortan/12,gnZ)))
ENDCASE

m.amorttot=m.amortlun+m.AMORTprec
m.valrez = lnValRez

RETURN
***------------------------------------------------------------------------------------------

PROCEDURE amortlin
LOCAL cond,c,cond2
cond='(month(m.datapif)=val(m.nl) and year(m.datapif)=val(m.an) and m.uzuraprec=0)' && in luna punerii in functiune

IF ROUND(12*VAL(m.an)+VAL(m.nl),0)>12*YEAR(m.dataeval)+MONTH(m.dataeval)+m.normat2lun
	cond2='(M.AMORTPREC>=M.valin-m.valrez)' && total amortizare din luna precedenta a ajuns la valoare-valoarea reziduala
ELSE
	cond2 = '.f.'
ENDIF

IF &cond OR &cond2
	m.amortlun =0
ELSE
	IF ROUND(12*VAL(m.an)+VAL(m.nl),0)=12*YEAR(m.dataeval)+MONTH(m.dataeval)+m.normat2lun AND m.cota <> 0
		m.amortlun = M.valin - m.valrez - M.AMORTprec
		IF m.amortlun<0
			m.amortlun=0
		ENDIF
	ELSE
		m.amortlun = ROUND(m.valramasa*m.cota/12/100,gnZ)
	ENDIF
ENDIF

IF M.AMORTprec+M.amortlun>m.valin-m.valrez AND m.valin = m.valoare  && cele care nu au fost reevaluate
	m.amortlun=M.valin-m.valrez-M.AMORTprec
	IF M.amortlun<0
		m.amortlun=0
	ENDIF
ENDIF

***------------------------------------------------------------------------------------------------

