

*!*	*--------------------------

*!*	Procedure LIST_SCHIMBPRET
*!*	Parameters M.NRACT1
*!*	Sele act
*!*	Loca For Val(nnir)=m.NRACT1 And Left(scd,3)='371' And Left(scc,3)='378'
*!*	If !Found()
*!*		Do mesaj With 'Nu a fost inregistrat nici un NIR','in luna curenta, cu numarul '+Allt(Str(m.NRACT1))
*!*		Return
*!*	Endif

*!*	Scatter Fields cod,DATAACT Memvar

*!*	Select CODMAT,DENUMIRE,Iif(CANT=0,CANTE,CANT) As CANT,Sum(Iif(CANT#0,0,pretvTVA)) As pretv,Sum(Iif(CANT=0,0,pretvTVA)) As pretvnou;
*!*		FROM rull Where cod=M.cod ;
*!*		INTO Table &loc/&nfscurt/tempo/schimbp Group By DENUMIRE,CODMAT

*!*	Select schimbp
*!*	Report Form schimbpret To Printer Prompt Preview
*!*	Use In schimbp
*!*	Do STERGE
*!*	Return

*!*	*--------------------------

*!*	Procedure LIST_NIR
*!*	Parameters M.NNIR,DECARE
*!*	m.nnir=Allt(M.NNIR)
*!*	LOCAL M.SUM1,M.SUM2
*!*	STORE 0 TO M.SUM1,M.SUM2
*!*	SELECT ACT
*!*	SET ORDER TO TAG COD

*!*	Sele rull
*!*	Set Filter To
*!*	Go Top
*!*	Loca For Val(nnir)=Val(m.nnir) And CANT#0 And CANTE=0
*!*	If !Found()
*!*		Do mesaj With 'Nu a fost inregistrat nici un NIR','in luna curenta, cu numarul '+m.nnir
*!*		Return
*!*	Else
*!*		Sele rull
*!*		Scat Fiel cod Memv
*!*		Sele act
*!*		Set Filter To
*!*		SEEK m.cod
*!*		If Found()
*!*			Scat Memv
*!*		Endif
*!*		Loca For cod=m.cod And scc='767 '
*!*		If Found()
*!*			Do tva
*!*			Sele act
*!*			m.sum1=suma
*!*			m.sum2=m.sum1*(m.ctva-1)
*!*		Else
*!*			Store 0 To m.sum1,m.sum2
*!*		Endif

*!*		m.T='NIRURI'
*!*		Select Distinct act.nume,act.fdoc,act.nract,act.dataireg,act.DATAACT,ACT.COD From act;
*!*			WHERE cod=M.cod AND LEFT(ACT.SCC,2)='40' Into Cursor FF1
*!*			
*!*		SELECT * from ff1 WHERE RECNO() = 1 INTO CURSOR ff
*!*		USE IN ff1

*!*		Select RULL.*,FF.*,RULL.nnir+Str(RULL.gest) AS NGEST;
*!*			from FF,rull;
*!*			where FF.cod=rull.cod And Val(rull.nnir)=Val(m.nnir) And rull.CANTE=0 And rull.CANT#0;
*!*			into CURSOR ra ORDER BY NGEST

*!*	*!*			Select RULL.*,FF.*;
*!*	*!*			from FF,rull;
*!*	*!*			where FF.cod=rull.cod And Val(rull.nnir)=Val(m.nnir) And rull.CANTE=0 And rull.CANT#0;
*!*	*!*			into TABLE &loc\&nfscurt\tempo\ra 
*!*		*Sele ra
*!*		*Index On nnir+Str(gest) Tag ngest Of &loc\&nfscurt\tempo\ra
*!*		*Sele ra
*!*		*Set Order To Tag ngest

*!*	sele optiuni
*!*	loca for optiune='NIR STANDARD'
*!*	nir_standard = da


*!*	SELECT ra
*!*	DO CASE
*!*	CASE DECARE=1
*!*		If !NIR_STANDARD
*!*			Report Format NIRMATD.FRX To Printer Prompt Preview
*!*		Else
*!*			Report Format NIRTOT.FRX To Printer Prompt Preview
*!*		ENDIF
*!*	CASE DECARE=2
*!*		Report Format NIRMARFNIR.FRX To Printer Prompt Preview
*!*	ENDCASE

*!*		Use In ra
*!*		Use In FF
*!*	ENDIF

*!*	SELECT ACT
*!*	SET ORDER TO TAG DATAIREG
*!*	Do STERGE
*!*	Return





*!*	*--------------------------
*!*	Procedure LIST_BON_achi
*!*	Parameters M.NNIR


*!*	Sele rull
*!*	Loca For Val(rull.nnir)==VAL(m.NNIR) AND CANTE#0
*!*	If !Found()
*!*		Do mesaj With 'Nu a fost inregistrat nici un bon','cu numarul '+M.NNIR
*!*		Return
*!*	ENDIF 

*!*	M.COD=COD
*!*		m.T='BONURI'

*!*	SELECT DISTINCT NUME_2 As RESPONS,COD;
*!*	WHERE COD=M.COD;
*!*	FROM ACT INTO CURSOR FF


*!*		Select Distinct rull.*,FF.*;
*!*			from FF,rull;
*!*			where FF.cod=rull.cod And Val(rull.nnir)=VAL(m.NNIR) And rull.cante # 0 And rull.cant=0;
*!*			into Table &loc\&nfscurt\tempo\ra
*!*		Sele ra
*!*			Index On Str(gest,2)+nnir To &loc\&nfscurt\tempo\ra

*!*			Report Format BONCONS.FRX To Printer Prompt Preview

*!*	Use In ra
*!*	USE IN FF

*!*	DO STERGE
*!*	RETURN


*!*	*--------------------------
*!*	Procedure LIST_BON
*!*	Parameters M.NNIR

*!*	Sele act
*!*	Loca For Val(nnir)==VAL(m.NNIR) AND INLIST(ID_SET,0,56,61,78,80,88,90) &&NUMAI BONURI (NOI SAU VECHI)
*!*	If !Found()
*!*		Do mesaj With 'Nu a fost inregistrat nici un bon','cu numarul '+M.NNIR
*!*		Return
*!*	ENDIF 

*!*	M.COD=COD
*!*		m.T='BONURI'

*!*	SELECT DISTINCT NUME_2 As RESPONS,COD;
*!*	WHERE COD=M.COD;
*!*	FROM ACT INTO CURSOR FF


*!*		Select Distinct rull.*,FF.*;
*!*			from FF,rull;
*!*			where FF.cod=rull.cod And Val(rull.nnir)=VAL(m.NNIR) And rull.cante # 0 And rull.cant=0;
*!*			into Table &loc\&nfscurt\tempo\ra
*!*		Sele ra
*!*			Index On Str(gest,2)+nnir To &loc\&nfscurt\tempo\ra
*!*		If !BON_ACHI
*!*			Report Format BONLI.FRX To Printer Prompt Preview
*!*		Else
*!*			Report Format BONCONS.FRX To Printer Prompt Preview
*!*		Endif

*!*	Use In ra
*!*	USE IN FF

*!*	DO STERGE
*!*	RETURN

*!*	*-------------------------------------------------------------

*!*	PROCEDURE list_pvoi
*!*	PARAMETERS m.nnir
*!*	Sele act
*!*	Set Order To Tag cod
*!*	Loca For Val(nnir)=VAL(m.nnir) AND INLIST(ID_SET,82,55)
*!*	If Found()
*!*		Scatter Memvar
*!*		Sele rull
*!*		Set Filt To cod=m.cod AND LEFT(scd,1) = '3'
*!*		Report Format PVOI.FRX To Printer Prompt Preview

*!*		Sele act
*!*		Set Order To Tag dataireg
*!*	Else
*!*		Do mesaj With 'Numar inexistent!',''
*!*	Endif
*!*	Do STERGE
*!*	SELECT rull 
*!*	SET FILTER TO 
*!*	RETURN



*!*	*-------------------------------------------------------------
*!*	PROCEDURE list_fact
*!*	PARAMETERS m.nract1

*!*	SELE FIRMA
*!*	LOCA FOR NFSCURT=FSCURT
*!*	SCAT MEMV
*!*	FCOD_FISCAL=M.COD_FISCAL
*!*	SELE act
*!*	LOCA for nract=m.nract1 and LEFT(scd,3)='411'
*!*	IF found()
*!*		SCAT memv
*!*		SELE clienti
*!*		LOCA for nume=m.nume
*!*		IF found()
*!*			SCAT fiel COD_FISCAL memv
*!*		ELSE
*!*			m.COD_FISCAL=''
*!*		ENDIF
*!*		
*!*		DO FORM DATEFACT
*!*		
*!*		SELECT respon
*!*		LOCATE FOR ales
*!*		SCATTER MEMVAR 
*!*			
*!*		SELE RULl
*!*		
*!*		SET FILTER TO cod=m.cod AND CANTE#0 
*!*		
*!*		*and left(scd,3)='371'
*!*		sele optiuni
*!*		loca for optiune='FORMAT A4'
*!*		IF DA
*!*			SELE RULl
*!*			REPORT FORM FACTvanz TO PRINTER PROMPT PREVIEW
*!*		ELSE
*!*			SELE RULl
*!*			REPORT FORM FACTvanz_A5 TO PRINTER PROMPT PREVIEW
*!*		ENDIF 
*!*	ELSE
*!*		DO mesaj with 'Factura '+allt(str(m.nract1))+' nu este','inregistrata in aceasta luna!'
*!*	ENDIF
*!*	DO sterge

*!*	SELECT rul 
*!*	SET FILTER TO 

*!*	RETURN


*!*	*--------------------------
*!*	Procedure LIST_pv_prod
*!*	Parameters M.NNIR
*!*	m.nnir=Allt(M.NNIR)
*!*	LOCAL M.SUM1,M.SUM2
*!*	STORE 0 TO M.SUM1,M.SUM2
*!*	SELECT ACT
*!*	SET ORDER TO TAG COD

*!*	Sele rull
*!*	Set Filter To
*!*	Go Top
*!*	Loca For Val(nnir)=Val(m.nnir) And CANT#0 And CANTE=0
*!*	If !Found()
*!*		Do mesaj With 'Nu a fost inregistrat nici un PV','in luna curenta, cu numarul '+m.nnir
*!*		Return
*!*	Else
*!*		Sele rull
*!*		Scat Fiel cod Memv
*!*		Sele act
*!*		Set Filter To
*!*		SEEK m.cod
*!*		If Found()
*!*			Scat Memv
*!*		Endif
*!*		Loca For cod=m.cod 
*!*		If Found()
*!*			Do tva
*!*			Sele act
*!*			m.sum1=suma
*!*			m.sum2=m.sum1*(m.ctva-1)
*!*		Else
*!*			Store 0 To m.sum1,m.sum2
*!*		Endif

*!*		*m.T='NIRURI'
*!*		Select Distinct act.nume,act.fdoc,act.nract,act.dataireg,act.DATAACT,ACT.COD From act;
*!*			WHERE cod=M.cod AND ID_SET=81 Into Cursor FF 
*!*			
*!*		Select RULL.*,FF.*,RULL.nnir+Str(RULL.gest) AS NGEST;
*!*			from FF,rull;
*!*			where FF.cod=rull.cod And Val(rull.nnir)=Val(m.nnir) And rull.CANTE=0 And rull.CANT#0;
*!*			into CURSOR ra ORDER BY NGEST

*!*	*!*			Select RULL.*,FF.*;
*!*	*!*			from FF,rull;
*!*	*!*			where FF.cod=rull.cod And Val(rull.nnir)=Val(m.nnir) And rull.CANTE=0 And rull.CANT#0;
*!*	*!*			into TABLE &loc\&nfscurt\tempo\ra 
*!*		*Sele ra
*!*		*Index On nnir+Str(gest) Tag ngest Of &loc\&nfscurt\tempo\ra
*!*		*Sele ra
*!*		*Set Order To Tag ngest
*!*		
*!*		*sele optiuni
*!*		*loca for optiune='FORMAT A4'
*!*		*IF DA
*!*			Sele ra
*!*			Report Format PV_PROD.FRX To Printer Prompt Preview
*!*		*ELSE
*!*		*	Sele ra
*!*		*	Report Format PV_PROD_A5.FRX To Printer Prompt Preview
*!*		*ENDIF 


*!*		Use In ra
*!*		Use In FF
*!*	ENDIF

*!*	SELECT ACT
*!*	SET ORDER TO TAG DATAIREG
*!*	Do STERGE
*!*	RETURN

*!*	*-------------------------------------------------------------

*!*	PROCEDURE LIST_RETUR
*!*	PARAMETERS M.NRACT1,DECARE
*!*	sele act
*!*	loca for nract=m.nract1 
*!*	if found()
*!*		scat memv
*!*		m.numegest=m.explicatia
*!*		SELE RULL
*!*		*SET FILTER TO cod=m.cod 
*!*		sele rulL.* from rulL where cod=m.cod and LEFT(scd,1) = '3' into table &loc\&nfscurt\tempo\ra
*!*		sele ra
*!*		repl all cante with -cante

*!*		IF DECARE=5
*!*			REPORT FORMAT RETURMAT.FRX TO PRINTER PROMPT PREVIEW
*!*		ELSE
*!*			REPORT FORMAT RETUR.FRX TO PRINTER PROMPT PREVIEW
*!*		ENDIF
*!*	else
*!*		do mesaj with 'Nu a fost emisa nota cu nr.'+allt(str(m.nract1)),'in aceasta luna.'
*!*	endif

*!*	DO STERGE
*!*	RETURN



*!*	*-------------------------------
*!*	PROCEDURE LIST_TRANSFER
*!*	PARAMETERS M.NRACT1,DECARE


*!*	sele act
*!*	loca for nract=m.nract1 and INLIST(id_set,74,75,76,89)
*!*	if found()
*!*		scat memv
*!*		m.numegest=m.explicatia
*!*		SELE RULl
*!*		SET ORDER TO tag cod
*!*		*loca for cod=m.cod
*!*		SEEK m.cod
*!*		if !found()
*!*			DO MESAJ WITH 'Nu exista aceasta nota de transfer',''
*!*			return
*!*		ELSE
*!*			IF decare # 26
*!*				SET FILTER TO cod=m.cod and !empty(cante)
*!*				IF NR_GEST=6 OR DECARE=18
*!*					report form nirtransferl to printer prompt preview
*!*				ELSE
*!*					report form nirtransferMATl to printer prompt preview
*!*				ENDIF
*!*			ELSE 
*!*				LOCATE FOR cod=m.cod AND !EMPTY(cant)
*!*				m.nume_2 = nresp
*!*				SET FILTER TO cod=m.cod and !empty(cante)
*!*				LOCATE 
*!*				pcResp = nresp
*!*				report form transfer8039 to printer prompt preview
*!*			ENDIF 
*!*		endif
*!*	ELSE
*!*		DO MESAJ WITH 'Nu exista aceasta nota de transfer',''
*!*	ENDIF

*!*	sele act
*!*	set filter to
*!*	SELECT RULl
*!*	SET ORDER TO 
*!*	SET FILTER TO 
*!*	DO STERGE

*!*	RETURN

*!*	*-------------------------------------------------------


*!*	PROCEDURE FIFO
*!*	PARAMETERS TCOD,TMAT,TDATA,tpret,tcant
*!*	tmat=UPPER(ALLTRIM(tmat))
*!*	tcod=UPPER(ALLTRIM(tcod))

*!*	SELECT DISTINCT denumire,codmat,pret FROM fifo INTO CURSOR verif
*!*	SELECT verif
*!*	SCAN
*!*		SCATTER NAME ver 
*!*		SELECT iesiri
*!*		GO TOP 
*!*		LOCATE FOR UPPER(ALLTRIM(denumire))=UPPER(ALLTRIM(ver.denumire)) AND UPPER(ALLTRIM(codmat))=UPPER(ALLTRIM(ver.codmat)) AND pret=ver.pret
*!*		IF !FOUND()
*!*			SELECT fifo
*!*			REPLACE ALL dataout WITH {},cante WITH 0,incomplet WITH .f.;
*!*			FOR UPPER(ALLTRIM(denumire))=UPPER(ALLTRIM(ver.denumire)) AND UPPER(ALLTRIM(codmat))=UPPER(ALLTRIM(ver.codmat)) AND pret=ver.pret
*!*		ENDIF 
*!*		SELECT verif
*!*	ENDSCAN 
*!*	RELEASE ver
*!*	USE IN verif 

*!*	SELECT fifo
*!*	LOCATE FOR UPPER(ALLTRIM(denumire))=tmat AND UPPER(ALLTRIM(codmat))=tcod
*!*	IF !FOUND()
*!*		IF USED('cfifo')
*!*			USE IN cfifo
*!*		ENDIF 
*!*		
*!*		SELECT denumire,codmat,pret,cants+cant-cante as cant,cante,datain,dataout,curs as idf;
*!*		FROM stoc;
*!*		WHERE ALLTRIM(UPPER(denumire))==tmat AND ALLTRIM(UPPER(codmat))==tcod ;
*!*		AND cants+cant-cante>0 AND gest=m.gest;
*!*		INTO TABLE &loc\&nfscurt\tempo\cfifo ORDER BY datain

*!*		SELECT CFIFO 
*!*		REPLACE ALL cante WITH 0,dataout WITH {}
*!*		CALCULATE MIN(datain) TO mindata
*!*		IF tdata>mindata
*!*			DO mesaj WITH 'ATENTIE !','Nu se respecta metoda FIFO !'
*!*			MARCA=.T.
*!*			RETURN
*!*		ENDIF 
*!*		
*!*		SELECT fifo
*!*		APPEND FROM &loc\&nfscurt\tempo\cfifo 
*!*		LOCATE FOR UPPER(ALLTRIM(denumire))=tmat AND UPPER(ALLTRIM(codmat))=tcod AND pret=tpret
*!*		REPLACE dataout WITH DATE()&&,cante WITH tcant
*!*	*!*		IF cant-cante>0
*!*	*!*			REPLACE incomplet WITH .t.
*!*	*!*		ENDIF 
*!*	ELSE 
*!*		SELECT fifo
*!*		CALCULATE MIN(datain) TO mindata FOR UPPER(ALLTRIM(denumire))=tmat AND UPPER(ALLTRIM(codmat))=tcod AND (EMPTY(dataout) OR incomplet)
*!*		GO TOP 
*!*		LOCATE FOR UPPER(ALLTRIM(denumire))=tmat AND UPPER(ALLTRIM(codmat))=tcod AND pret=tpret &&AND (EMPTY(dataout) OR incomplet)
*!*		IF tdata>mindata
*!*			DO mesaj WITH 'ATENTIE !','Nu se respecta metoda FIFO'
*!*			MARCA=.T.
*!*			RETURN
*!*		ENDIF 
*!*		REPLACE dataout WITH DATE()&&,cante WITH tcant
*!*	*!*		IF cant-cante>0
*!*	*!*			REPLACE incomplet WITH .t.
*!*	*!*		ELSE 
*!*	*!*			REPLACE incomplet WITH .f.
*!*	*!*		ENDIF 
*!*	ENDIF 

*!*	ENDPROC 
*!*	*-------------------------------------------------------


*!*	PROCEDURE LIFO
*!*	PARAMETERS TCOD,TMAT,TDATA,tpret
*!*	tmat=UPPER(ALLTRIM(tmat))
*!*	tcod=UPPER(ALLTRIM(tcod))

*!*	SELECT DISTINCT denumire,codmat,pret FROM fifo INTO CURSOR verif
*!*	SELECT verif
*!*	SCAN
*!*		SCATTER NAME ver 
*!*		SELECT iesiri
*!*		GO TOP 
*!*		LOCATE FOR UPPER(ALLTRIM(denumire))=UPPER(ALLTRIM(ver.denumire)) AND UPPER(ALLTRIM(codmat))=UPPER(ALLTRIM(ver.codmat)) AND pret=ver.pret
*!*		IF !FOUND()
*!*			SELECT fifo
*!*			REPLACE ALL dataout WITH {},cante WITH 0,incomplet WITH .f.;
*!*			FOR UPPER(ALLTRIM(denumire))=UPPER(ALLTRIM(ver.denumire)) AND UPPER(ALLTRIM(codmat))=UPPER(ALLTRIM(ver.codmat)) AND pret=ver.pret
*!*		ENDIF 
*!*		SELECT verif
*!*	ENDSCAN 
*!*	RELEASE ver
*!*	USE IN verif 

*!*	SELECT fifo
*!*	LOCATE FOR UPPER(ALLTRIM(denumire))=tmat AND UPPER(ALLTRIM(codmat))=tcod
*!*	IF !FOUND()
*!*		IF USED('cfifo')
*!*			USE IN cfifo
*!*		ENDIF 
*!*		
*!*		SELECT denumire,codmat,pret,cants+cant-cante as cant,cante,datain,dataout,curs as idf;
*!*		FROM stoc;
*!*		WHERE ALLTRIM(UPPER(denumire))==tmat AND ALLTRIM(UPPER(codmat))==tcod ;
*!*		AND cants+cant-cante>0 AND gest=m.gest;
*!*		INTO TABLE &loc\&nfscurt\tempo\cfifo ORDER BY datain

*!*		SELECT CFIFO 
*!*		REPLACE ALL cante WITH 0,dataout WITH {}
*!*		CALCULATE Max(datain) TO maxdata
*!*		IF tdata<maxdata
*!*			DO mesaj WITH 'ATENTIE !','Nu se respecta metoda LIFO !'
*!*			MARCA=.T.
*!*			RETURN
*!*		ENDIF 

*!*		
*!*		SELECT fifo
*!*		APPEND FROM &loc\&nfscurt\tempo\cfifo 
*!*		LOCATE FOR UPPER(ALLTRIM(denumire))=tmat AND UPPER(ALLTRIM(codmat))=tcod AND pret=tpret
*!*		REPLACE dataout WITH DATE()
*!*	ELSE 
*!*		SELECT fifo
*!*		CALCULATE max(datain) TO maxdata FOR UPPER(ALLTRIM(denumire))=tmat AND UPPER(ALLTRIM(codmat))=tcod AND (EMPTY(dataout) OR incomplet)
*!*		GO TOP 
*!*		LOCATE FOR UPPER(ALLTRIM(denumire))=tmat AND UPPER(ALLTRIM(codmat))=tcod AND pret=tpret &&AND (EMPTY(dataout) OR incomplet)
*!*		IF tdata<maxdata
*!*			DO mesaj WITH 'ATENTIE !','Nu se respecta metoda LIFO'
*!*			MARCA=.T.
*!*			RETURN
*!*		ENDIF 
*!*		REPLACE dataout WITH DATE()
*!*	ENDIF 

*!*	ENDPROC 

*!*	*________________________________________________________________________

*!*	PROCEDURE fisa_magazie_FIFO
*!*	PARAMETERS tcod,tmat,tfis1,tfis2,tccond
*!*	SET DATE TO DMY 
*!*	tcod=UPPER(ALLTRIM(tcod))
*!*	tmat=UPPER(ALLTRIM(tmat))

*!*	CREATE TABLE &loc\&nfscurt\tempo\fisa_stoc (ldata d,nrdoc c(15),cantin n(12,3),pretin n(12,3),valin n(14,2),;
*!*				cantout n(12,3),pretout n(12,3),valout n(14,2),cantf n(12,3),pretf n(12,3),valf n(14,2),idf n(3))

*!*	&& -----------------------&tfis1  = stocul
*!*	buton=2
*!*	ON ERROR do mesaj with 'Reindexati fisierele din luna '+loLuna.NL+' '+loLuna.AN,''  && daca nu are campul datain

*!*	SELECT &tfis1..CANTS AS CANTF,&tfis1..PRET AS pretf,&tfis1..CANTS*&tfis1..PRET AS VALF,&tfis1..datain;
*!*	from &tfis1 WHERE UPPER(ALLTRIM(&tfis1..codmat))=tcod AND UPPER(ALLTRIM(&tfis1..denumire))=tmat;
*!*	into TABLE &loc\&nfscurt\tempo\cstoc ORDER BY &tfis1..datain

*!*	ON ERROR
*!*	IF buton=1
*!*		RETURN
*!*	ENDIF 
*!*	&& -----------------------

*!*	SELECT cstoc
*!*	DELETE ALL FOR cantf=0

*!*	SELECT FISA_StOC
*!*	APPEND FROM &loc\&nfscurt\tempo\CSTOC FOR !DELETED()
*!*	SELECT fisa_stoc

*!*	GO top
*!*	IF EOF()
*!*		APPEND BLANK 
*!*	ENDIF 

*!*	SUM CANTF TO lnCantf
*!*	SUM valf TO lnValf

*!*	GO TOP
*!*	REPLACE CANTIn WITH lnCantf, valin WITH lnValf,nrdoc WITH 'Stoc initial'
*!*	REPLACE ALL idf WITH 1
*!*	IF lncantf#0
*!*		REPLACE pretin WITH lnValf/lnCantf
*!*	ENDIF 
*!*	&&----------------------&tfis2 = rulajele
*!*	SELECT * from &tfis2 WHERE UPPER(ALLTRIM(&tfis2..codmat))=tcod AND UPPER(ALLTRIM(&tfis2..denumire))=tmat AND &TCCOND;
*!*	into TABLE &loc\&nfscurt\tempo\trulaj ORDER BY &tfis2..dataACT 

*!*	SELECT trulaj
*!*	SCAN
*!*	SCATTER NAME xrul

*!*		SELECT fisa_stoc
*!*		CALCULATE MAX(idf) TO lnMax
*!*		lnMaX=lnMax+1
*!*		APPEND FROM &loc\&nfscurt\tempo\cstoc FOR !DELETED()
*!*		REPLACE ALL idf WITH lnMax FOR EMPTY(idf)

*!*		DO CASE 
*!*		CASE  xrul.cant#0 &&AND !INLIST(xrul.pret,&lista)
*!*			LOCATE FOR pretf=xrul.pret AND idf=lnMaX
*!*			IF !FOUND()
*!*				SELECT fisa_stoc
*!*				APPEND BLANK
*!*				REPLACE cantin WITH xrul.cant,pretin WITH xrul.pret,valin WITH xrul.cant*xrul.pret
*!*				REPLACE cantf WITH xrul.cant,pretf WITH xrul.pret,valf WITH xrul.cant*xrul.pret
*!*				REPLACE idf WITH lnMax,ldata WITH xrul.datain,nrdoc WITH xrul.nnir
*!*						
*!*				SELECT cstoc
*!*				APPEND BLANK 
*!*				REPLACE cantf WITH xrul.cant,pretf WITH xrul.pret,valf WITH xrul.cant*xrul.pret
*!*			ELSE 
*!*				REPLACE cantin WITH xrul.cant,pretin WITH xrul.pret,valin WITH xrul.cant*xrul.pret
*!*				REPLACE cantf WITH cantf+cantin,valf WITH valf+valin
*!*				REPLACE ldata WITH xrul.datain,nrdoc WITH xrul.nnir
*!*				
*!*				SELECT cstoc
*!*				LOCATE FOR pretf=xrul.pret
*!*				REPLACE cantf WITH cantf+xrul.cant,valf WITH valf+xrul.cant*xrul.pret
*!*			ENDIF 
*!*		CASE xrul.cante#0
*!*			SELECT fisa_stoc
*!*			LOCATE FOR pretf=xrul.pret AND idf=lnMaX		
*!*			IF !FOUND()
*!*				*DO mesaj WITH 'Stoc negativ',''
*!*				APPEND BLANK 
*!*				REPLACE idf WITH lnMax
*!*			ENDIF 
*!*			
*!*			REPLACE cantout WITH xrul.cante,pretout WITH xrul.pret,valout WITH xrul.cante*xrul.pret
*!*			REPLACE cantf WITH cantf-cantout,pretf WITH xrul.pret,valf WITH valf-valout
*!*			REPLACE ldata WITH xrul.dataout,nrdoc WITH xrul.nnir
*!*			
*!*			SELECT cstoc
*!*			LOCATE FOR pretf=xrul.pret
*!*			IF !FOUND()
*!*				*DO mesaj WITH 'Stoc negativ',''
*!*				APPEND BLANK 
*!*			ENDIF 
*!*			REPLACE cantf WITH cantf-xrul.cante,pretf WITH xrul.pret,valf WITH valf-xrul.cante*xrul.pret
*!*			
*!*		ENDCASE 	
*!*		SELECT cstoc
*!*		DELETE ALL FOR cantf=0
*!*	RELEASE xrul 
*!*	SELECT trulaj		
*!*	ENDSCAN

*!*	SELECT fisa_stoc

*!*	ENDPROC   &&fisa_magazie_FIFO

*!*	*___________________________________________________________________________________________________________


*!*	PROCEDURE evidenta_comenzi

*!*	PRIVATE pncom1,pncom2
*!*	STORE 0 TO pncom1,pncom2

*!*	DO cereDATE WITH 'NR.COMENZII:','pncom1','pncom2','Nmarul initial','Numarul final'

*!*	CREATE TABLE &loc\&nfscurt\tempo\lista_comenzi.dbf (comanda c(12),val_mat n(14),val_marja n(14),val_prod n(14),val_fact n(14),;
*!*	val_tva n(14),totfact n(14),nract n(12),dataact d,nume c(30))

*!*	SELECT DISTINCT nrord as comanda FROM actan WHERE BETWEEN(VAL(nrord),pncom1,pncom2) INTO CURSOR comenzi

*!*	SELECT comenzi 
*!*	SCAN 
*!*		lccomanda=ALLTRIM(comanda)
*!*		SELECT actan 
*!*		LOCATE FOR scd='411 ' AND scc='701 ' AND ALLTRIM(nrord)=lccomanda
*!*		m.nract=actan.nract
*!*		m.dataact=actan.dataact
*!*		m.nume=actan.nume
*!*		CALCULATE sum(suma) TO m.val_mat FOR LEFT(scd,3)='601' AND LEFT(scc,3)='301' AND ALLTRIM(nrord)=lccomanda
*!*		CALCULATE sum(suma) TO m.val_prod FOR scd='345 ' AND scc='711 ' AND ALLTRIM(nrord)=lccomanda
*!*		CALCULATE sum(suma) TO m.val_fact FOR scd='411 ' AND scc='701 ' AND ALLTRIM(nrord)=lccomanda
*!*		CALCULATE sum(suma) TO m.val_tva FOR scd='411 ' AND scc='4427 ' AND ALLTRIM(nrord)=lccomanda
*!*		
*!*		SELECT lista_comenzi
*!*		APPEND BLANK 
*!*		GATHER MEMVAR 
*!*		SELECT lista_comenzi
*!*		REPLACE totfact WITH val_fact+val_tva
*!*		REPLACE comanda WITH lccomanda
*!*		REPLACE val_marja WITH val_prod-val_mat FOR !EMPTY(val_prod)
*!*	SELECT comenzi 
*!*	ENDSCAN 

*!*	SELECT lista_comenzi
*!*	REPORT FORM lista_comenzi TO PRINTER PROMPT PREVIEW 

*!*	USE IN comenzi
*!*	USE IN lista_comenzi 
*!*	ENDPROC  && evidenta_comenzi

*!*	*_____________________________________________________________________________________________________

*!*	PROCEDURE list_marf_furn_grupe
*!*	PARAMETERS numar_raport

*!*	SELECT cod,nume,nract from act WHERE scd='371 ' AND INLIST(scc,'401 ','408 ') INTO CURSOR tact

*!*	SELECT t.*, r.*, STR(r.id_articol) + t.nume as cod_nume_mat ;
*!*	from tact t JOIN rull r ON r.cod=t.cod WHERE r.cante=0 AND r.cant#0 AND !INLIST(r.id_set, 74, 75, 76) ;
*!*	INTO CURSOR trul ORDER BY cod_nume_mat

*!*	USE IN tact 

*!*	IF numar_raport=1
*!*		SELECT trul
*!*		TOTAL TO &loc\&nfscurt\tempo\list_marf ON cod_nume_mat FIELDS cant,pret 
*!*		USE &loc\&nfscurt\tempo\list_marf IN 0 SHARED 
*!*	ELSE 	
*!*		SELECT trul
*!*		lc_dbf=DBF('trul')
*!*		USE (lc_dbf) IN 0 shared AGAIN ALIAS list_marf
*!*	ENDIF 

*!*	SELECT l.id_articol,l.id_grupa,l.id_sbgrupa,a.dn_grupa,b.dn_sbgrupa ;
*!*	FROM ((listast l LEFT JOIN art_gr a ON l.id_grupa=a.id_grupa ) ;
*!*	LEFT JOIN art_sbgr b ON l.id_grupa=b.id_grupa AND l.id_sbgrupa=b.id_sbgrupa) ;
*!*	INTO CURSOR tlista

*!*	SELECT a.denumire,a.codmat,a.pret,a.um,a.cant,a.gest,a.nume,a.dataact,a.nract,b.* ;
*!*	FROM list_marf a JOIN tlista b ON a.id_articol=b.id_articol INTO CURSOR tfinal

*!*	IF numar_raport=1
*!*		titlu='APROVIZIONARE PRODUSE LUNA '+m.nl+' '+m.an
*!*		SELECT tfinal
*!*		INDEX ON nume + STR(id_grupa) + STR(id_sbgrupa) TO &loc\&nfscurt\tempo\index_art.idx 

*!*		SELECT tfinal 
*!*		REPORT FORM stoc_furniz TO PRINTER PROMPT PREVIEW 
*!*	ELSE 
*!*		titlu='CUMPARARI PRODUSE LUNA '+m.nl+' '+m.an
*!*		SELECT tfinal
*!*		INDEX ON DENUMIRE TO &loc\&nfscurt\tempo\index_art.idx 
*!*		*BROWSE 
*!*		SELECT tfinal 
*!*		REPORT FORM stoc_fact TO PRINTER PROMPT PREVIEW 
*!*	ENDIF 

*!*	USE IN list_marf
*!*	USE IN tlista
*!*	USE IN tfinal 

*!*	ENDPROC && list_marf_furn_grupe
*!*	*__________________________________________________________________________________________________

*!*	PROCEDURE list_articole_gr

*!*	lcCond = '.t.'
*!*	PRIVATE pddata1, pddata2
*!*	STORE DATE() TO pddata1, pddata2
*!*		DO cereDATE WITH 'Selectati perioada:','pddata1','pddata2','Data initiala','Data finala'
*!*		
*!*		SELECT DISTINCT * FROM art_gr INTO CURSOR tgrupa READWRITE ORDER BY dn_grupa

*!*		SELECT tgrupa
*!*		APPEND blan
*!*		REPLACE dn_grupa WITH ' <TOATE>'
*!*		SCATTER MEMVAR BLANK 
*!*		
*!*		DO CAUT_ALFa_cursor WITH "tgrupa","dn_grupa",'Alegeti grupa:',''
*!*		USE IN tgrupa
*!*		
*!*		IF buton = 2 
*!*			RETURN 
*!*		ENDIF 
*!*		IF ALLTRIM(m.dn_grupa)  # '<TOATE>'
*!*			lcCond = lcCond + [ and id_grupa = m.id_grupa]
*!*		ENDIF 
*!*		
*!*		SELECT DISTINCT dn_sbgrupa, id_sbgrupa FROM art_sbgr WHERE id_grupa = m.id_grupa INTO CURSOR tgrupa READWRITE ORDER BY dn_sbgrupa 

*!*		SELECT tgrupa
*!*		APPEND blan
*!*		REPLACE dn_sbgrupa WITH ' <TOATE>'
*!*		SCATTER MEMVAR BLANK 
*!*		
*!*		DO CAUT_ALFa_cursor WITH "tgrupa","dn_sbgrupa",'Alegeti subgrupa:',''
*!*		USE IN tgrupa
*!*		
*!*		IF buton = 2 
*!*			RETURN 
*!*		ENDIF 
*!*		IF ALLTRIM(m.dn_sbgrupa)  # '<TOATE>'
*!*			lcCond = lcCond + [ and id_sbgrupa = m.id_sbgrupa]
*!*		ENDIF
*!*		
*!*		SELECT DISTINCT id_articol, denumire, codmat, um, id_grupa, id_sbgrupa ;
*!*		FROM listast WHERE &lccond INTO CURSOR tlist READWRITE ORDER BY id_grupa, id_sbgrupa, denumire, codmat 
*!*		
*!*		SELECT t.*, g.dn_grupa, s.dn_sbgrupa ;
*!*		FROM ((tlist t LEFT JOIN art_gr g ON t.id_grupa = g.id_grupa ) ;
*!*		LEFT JOIN art_sbgr s ON t.id_sbgrupa = s.id_sbgrupa AND t.id_grupa = s.id_grupa ) ;
*!*		INTO CURSOR tlista
*!*		USE IN  tlist
*!*		
*!*		SELECT t.*, sum(r.pret*r.cant) as valoare, sum(r.cant) as intrari FROM  rul r JOIN  tlista t ON r.id_articol = t.id_articol ;
*!*		WHERE BETWEEN(r.dataact,pdData1, pdData2) AND r.cant#0 AND LEFT(ALLTRIM(r.scd),3) = '371' AND !INLIST(r.id_set, 74, 75, 76) ;
*!*		INTO CURSOR trez ; 
*!*		GROUP BY r.id_articol ;
*!*		ORDER BY t.dn_grupa, t.dn_sbgrupa, t.denumire, t.codmat 
*!*		
*!*		titlu = 'Intrari de la ' + DTOC(pdData1) + ' la ' + DTOC(pdData2)
*!*		
*!*		SELECT trez
*!*		REPORT FORM stoc_grupe TO PRINTER PROMPT PREVIEW 
*!*		
*!*		USE IN tlista
*!*		USE IN trez 
*!*	ENDPROC && list_articole_gr
*!*	*__________________________________________________________________________________________________
*!*	 
*!*	PROCEDURE list_stoc_articol

*!*	SELECT s.denumire,s.codmat,s.um,s.gest,ALLTRIM(STR(s.id_articol))+ALLTRIM(STR(s.gest))+ALLTRIM(s.denumire)+ALLTRIM(s.codmat) as articol,sum(s.cants+s.cant-s.cante) as cantitate,g.numegest;
*!*	from stoc s,numegest g ;
*!*	WHERE s.gest=g.gest; 
*!*	GROUP BY articol INTO CURSOR tstoc ORDER BY denumire 
*!*	SELECT tstoc
*!*	*BROWSE 
*!*	REPORT FORM stoc_articol TO PRINTER PROMPT PREVIEW 
*!*	USE IN tstoc

*!*	ENDPROC && list_stoc_articol

*!*	*__________________________________________________________________________________________________

*!*	PROCEDURE fisa_magazie_simpla

*!*	LOCAL ln_stoci
*!*	STORE 0 TO ln_stoci

*!*	SELECT rull
*!*	SCATTER NAME oru

*!*	SELECT DISTINCT r.nnir,r.cante,r.cant,r.dataact,a.nract,r.cant AS STOCI,r.cant AS STOCF ;
*!*	FROM rull r LEFT JOIN act a ON r.cod=a.cod ;
*!*	WHERE (denumire=oru.denumire AND codmat=oru.codmat AND gest=oru.gest) AND id_articol=oru.id_articol ;
*!*	INTO TABLE &loc\&nfscurt\tempo\fisa_stoc ORDER BY r.dataact
*!*	SELECT FISA_STOC
*!*	REPLACE ALL STOCI WITH 0,stocf WITH 0 

*!*	SELECT stoc
*!*	LOCATE FOR (denumire=oru.denumire AND codmat=oru.codmat AND gest=oru.gest) AND id_articol=oru.id_articol
*!*	IF FOUND()
*!*		ln_stoci=cants
*!*	ENDIF 

*!*	SELECT fisa_stoc
*!*	GO top
*!*	REPLACE stoci WITH ln_stoci &&,stocf WITH ln_stoci+cant-cante
*!*	SCAN
*!*		REPLACE stocf WITH ln_stoci+cant-cante
*!*		ln_stoci=stocf
*!*	ENDSCAN 

*!*	SELECT listast
*!*	LOCATE FOR id_articol=oru.id_articol
*!*	Lnid_grupa=id_grupa
*!*	Lnid_sbgrupa=id_sbgrupa
*!*	*WAIT WINDOW STR(oru.gest)

*!*	SELECT numegest.numegest,art_gr.dn_grupa,art_sbgr.dn_sbgrupa FROM numegest,art_gr ,art_sbgr;
*!*	where numegest.gest=oru.gest AND art_gr.id_grupa=Lnid_grupa AND art_sbgr.id_sbgrupa=Lnid_sbgrupa ;
*!*	INTO CURSOR tdate 

*!*	*BROWSE 
*!*	SELECT fisa_stoc
*!*	REPORT FORM fisa_magazie_simpla TO PRINTER PROMPT PREVIEW 

*!*	RELEASE oru
*!*	USE IN fisa_stoc 
*!*	USE IN tdate 
*!*	ENDPROC && fisa_magazie_simpla

*!*	*____________________________________________________________________________________________

*!*	PROCEDURE list_stoc_art
*!*	PARAMETERS tc_cond
*!*	tc_cond=ALLTRIM(tc_cond)

*!*	IF USED('tstoc')
*!*		USE IN tstoc
*!*	ENDIF 

*!*	SELECT *,sum(cants+cant-cante) as stocf,SUM((CANTs+cant-cante)*PRET) AS VALoare, ;
*!*	ALLTRIM(denumire)+ALLTRIM(codmat)+ALLTRIM(STR(id_articol)) as indexul ;
*!*	FROM stoc WHERE &tc_cond ;
*!*	GROUP BY indexul ;
*!*	INTO CURSOR tstoc 

*!*	SELECT tstoc 
*!*	ENDPROC && list_stoc_art

*!*	*____________________________________________________________________________________________

*!*	PROCEDURE raport_material_furnizor
*!*	PRIVATE poConditie, lddata1, lddata2

*!*	DO FORM frm_filtru_text WITH 'r.denumire','Denumirea materialului',1 TO pcConditie

*!*	*!*	IF .filtru = ""
*!*	*!*		.Value = 0
*!*	*!*	ENDIF 
*!*		
*!*	loLuna=ret_luna("Selectati luna de inceput")
*!*	lddata1=CTOD('01/'+loLuna.nl+'/'+loLuna.an) && 01/01/2003

*!*	loLuna=ret_luna("Selectati luna de sfarsit")
*!*	lddata2=CTOD('01/'+loLuna.nl+'/'+loLuna.an) && 01/01/2003
*!*	*lddata2=GOMONTH(CTOD('01/'+m.Nl+'/'+m.An),1)-1	&& 31/07/2003 

*!*	CREATE TABLE &loc\&nfscurt\tempo\tfis (an c(4), luna c(2), denumire c(100), codmat c(50), cod n(10),cant n(12), pret n(14), nnir c(10), nume c(30))


*!*	SELECT calendar
*!*	SCAN FOR BETWEEN(CTOD('01/'+nl+'/'+an), lddata1, lddata2)
*!*		
*!*		lcAn = an
*!*		lcLuna = nl
*!*		
*!*		lcDate = ADDBS(calefirma)+'AN' + an + '\DATE' + nl+'\'
*!*		lcFisRul = lcDate + "rull.dbf"
*!*		lcFisAct = lcDate + "act.dbf"
*!*		
*!*		IF !FILE(lcFisRul) OR !FILE(lcFisAct)
*!*			SELECT calendar
*!*			LOOP
*!*		ENDIF
*!*		
*!*		IF USED('rulaje')
*!*			USE IN rulaje
*!*		ENDIF
*!*		
*!*		IF USED('rj')
*!*			USE IN rj
*!*		ENDIF
*!*		
*!*		IF USED('tcrul')
*!*			USE IN tcrul
*!*		ENDIF 
*!*		
*!*		USE &lcFisRul AGAIN IN 0 shared ALIAS rulaje ORDER TAG "denumire"
*!*		USE &lcFisAct AGAIN IN 0 shared ALIAS rj ORDER TAG "nume"
*!*		SELECT DISTINCT r.denumire, r.codmat, r.cod, r.cant, r.pret, r.nnir, a.nume,ALLTRIM(r.denumire)+ALLTRIM(r.codmat)+ALLTRIM(STR(ROUND(pret,0))) as numecod ;
*!*		FROM rulaje r LEFT JOIN rj a ON r.cod = a.cod AND r.nnir = a.nnir ;
*!*		WHERE &pcConditie AND r.cant # 0 AND LEFT(a.scc,3) = '401';
*!*		INTO CURSOR tcrul ;
*!*		ORDER BY a.nume, numecod
*!*		
*!*		SELECT tcrul
*!*		TOTAL TO &loc\&nfscurt\tempo\xtotal ON numecod FIELDS cant 
*!*	*	GROUP BY r.denumire, r.codmat, r.pret, a.nume ;	

*!*		SELECT tfis
*!*	*	APPEND FROM DBF('tcrul')
*!*		APPEND FROM &loc\&nfscurt\tempo\xtotal
*!*		REPLACE ALL luna WITH lcLuna FOR EMPTY(luna)
*!*		REPLACE ALL an WITH lcAn FOR EMPTY(an)

*!*		SELECT calendar
*!*	ENDSCAN 

*!*	SELECT tfis
*!*	INDEX ON AN + ALLTRIM(NUME)+ LUNA TAG nume OF &loc\&nfscurt\tempo\xULEI ASCENDING 
*!*	SELECT tfis
*!*	REPORT FORM list_ulei TO PRINTER PROMPT PREVIEW 

*!*	IF USED('rulaje')
*!*		USE IN rulaje
*!*	ENDIF

*!*	IF USED('rj')
*!*		USE IN rj
*!*	ENDIF

*!*	IF USED('tcrul')
*!*		USE IN tcrul
*!*	ENDIF 
*!*	USE IN tfis 
*!*	ENDPROC  && raport_material_furnizor

*!*	*________________________________________

*!*	PROCEDURE raport_productie_postcalcul

*!*	SELECT DISTINCT NRORD FROM RULL into TABLE &LOC\&NFSCURT\tempo\raA.DBF 
*!*	SELECT RAA
*!*	*!*	APPEND BLANK
*!*	*!*	REPLACE NRORD WITH " <TOATE>"
*!*	Index ON NRORD TAG NRORD
*!*	do caut_alfa with "RAA","Nrord","NUMELE COMENZII","M.nrord"

*!*	PRIVATE pnCant
*!*	pnCant = 0
*!*	Ointre=CREATEOBJECT("CAUTintre")
*!*		WITH Ointre
*!*			.CAPTION="Dat in executie"
*!*			.label1.caption="Cantitatea :"
*!*			.label2.visible=.f.
*!*			.text1.controlsource="pnCant"
*!*			.text2.visible=.f.
*!*		endwith
*!*	ointre.show(1)
*!*		
*!*	SELECT denumire, um, sum(cante) as canttot, pret, gest, codmat, ;
*!*		sum(round(pret*cante, 0)) as valtot, sum(ROUND(cante/pnCant,3)) as cant_unit, sum(round(pret*cante/pnCant, 3)) as val_unit;
*!*		from rull ;
*!*		where nrord = m.nrord And cante # 0 And cant = 0 ;
*!*		into CURSOR rapostcalcul GROUP BY denumire, codmat, pret ORDER BY denumire

*!*	*!*	SELECT RApostcalcul
*!*	*!*	*Index On NRORD+STR(VAL(ALLTRIM(nnir)))+DTOC(dataact) TAG nnir &&To &LOC\&NFSCURT\tempo\FFD 
*!*	*!*	BROWSE 

*!*	SELECT RApostcalcul
*!*	*!*	SET FILTER TO NRORD=M.NRORD
*!*	REPORT FORM postcalcul TO PRINTER PROMPT PREVIEW 

*!*	USE IN rapostcalcul

*!*	ENDPROC  && raport_productie_postcalcul


