********
PROCEDURE sitan

pcNl=m.nl
pcAn=m.an

SELECT *, SPACE(4) AS an, SPACE(2) AS nl FROM mf WHERE 1=2 INTO CURSOR mfsel READWRITE

SELECT an,nl FROM calendar WHERE VAL(an)=VAL(pcAn) AND VAL(nl)<=VAL(pcNl) INTO CURSOR tcalendar

SELECT tcalendar
SCAN
	lcnl=nl
	lcAn=an
	lcdate='&calefirma\an'+lcAn+'\date'+lcnl+'\mf.dbf'
	IF FILE(lcdate)
		SELECT mfsel

		IF TYPE("&lcDate..inactiv")!="U"
			APPEND FROM (lcdate) FOR INLIST(UPPER(fel),&pcfelul) AND !casat AND !inactiv
		ELSE
			APPEND FROM (lcdate) FOR INLIST(UPPER(fel),&pcfelul) AND !casat
		ENDIF
		REPLACE ALL nl WITH lcnl FOR EMPTY(nl)
		REPLACE ALL an WITH lcAn FOR EMPTY(an)
	ENDIF
	SELECT tcalendar
ENDSCAN

lcCursor = [sitmf]
SELECT SUM(amortlun) AS amortlun, SUM(amorttot) AS amorttot, SUM(valoare) AS valoare, an, nl, ALLTRIM(scd) AS scd ;
	FROM mfsel ;
	INTO CURSOR (lcCursor) ;
	GROUP BY an, nl, scd


IF USED('mfsel')
	USE IN mfsel
ENDIF
IF USED('tcalendar')
	USE IN tcalendar
ENDIF

RETURN lcCursor

*---------------------------------------------------------------------------
PROCEDURE rulaje
PARAMETERS tcCamp, tcAlias

ancrt=m.an
luncrt=m.nl
firmcrt=nfscurt
lcRet = []
lcCamp = ALLTRIM(tcCamp)

IF EMPTY(tcAlias) OR TYPE('tcAlias') # 'C'
	lcAlias = [sitmf]
ELSE 
	lcAlias = ALLTRIM(tcAlias)
ENDIF 

SELECT DISTINCT scd FROM (lcAlias) INTO CURSOR conturi
SELECT DISTINCT an,nl FROM (lcAlias) INTO CURSOR luni

tt='create table &loc\&nfscurt\tempo\rulaje.DBF (an c(4),nl c(2)'
SELECT conturi
SCAN
	SCAT MEMV
	tt=tt+',c'+ALLTRIM(m.scd)+' n(14,gnZ)'
	SELECT conturi
ENDSCAN


tt=tt+')'
&tt
SELECT rulaje
APPEND FROM DBF('luni')
USE IN luni

*sume---
SELECT (lcAlias)
SCAN
	SCATTER MEMV
	SELECT rulaje
	LOCATE FOR nl=m.nl AND an=m.an
	tt='REPLACE c'+ALLTRIM(m.scd)+' with '+ lcCamp
	&tt
	SELECT (lcAlias)
ENDSCAN

*totaluri---
LOCAL m.c
m.c=0
SELECT rulaje
APPEND BLANK
REPLACE an WITH 'TOT'
SELECT conturi
SCAN
	SCATTER MEMV
	SELECT rulaje
	tt='sum c'+ALLTRIM(m.scd)+' to m.c FOR NL<=LUNCRT'
	&tt

	SELECT rulaje
	GO BOTT
	tt='REPLACE  c'+ALLTRIM(m.scd)+' with m.c'
	&tt
	SELECT conturi
ENDSCAN

m.an=ancrt
m.nl=luncrt
nfscurt=firmcrt

IF USED('conturi')
	USE IN conturi
ENDIF 
IF USED('rulaje')
	USE IN rulaje
	lcRet = [&loc\&nfscurt\tempo\rulaje.DBF]
ENDIF 
IF USED(lcAlias)
	USE IN (lcAlias)
ENDIF 

RETURN lcRet
