*!* 12.10.2015
*!* marius.mutu
*!* valori_mat_bon, bon_com_nefact - fara comenzile arhivate INCHIS_FORTAT = 0
*!* #4224

*******************************************
* PROCEDURE ver_valid_lun(  )
* Data/ora : 01/31/05, 09:19:02
* autor : liana.macinic
* descriere:

****** PARAMETER BLOCK **************
* Parametri : 0
*
*******************************************
Procedure ver_valid_lun(  )
*!*	Private poordl,pcschema1,pcselect1
*!*	Store '' To poordl

*!*	pcschema1=['']
*!*	pcselect1=['select a.nrord,a.datai,a.nume,b.manopera,a.util_valid,a.dataoravalid '+] + ;
*!*		['from ] + gcS + [.dev_vordl a '+] + ;
*!*		['left join ] + gcS + [.dev_vordl_man b on a.id_ordl=b.id_ordl '+] + ;
*!*		['where 1=2']
*!*	pcorder1= [a.nrord]
*!*	pcfiltru1 = [extract(month from a.dataoravalid) = ] + Alltrim(Str(gnLuna)) + [ and extract(year from a.dataoravalid) = ] + Alltrim(Str(gnAn)) + [ and a.validat = 1]
*!*	gencursor('poordl','crsordl',pcselect1,pcfiltru1,pcschema1,pcorder1)
*!*	poordl.ca_baza1.afisare()

*!*	If Reccount('crsordl')=0
*!*		Use In crsordl
*!*		amessagebox("Nu exista comenzi validate in luna "+Alltrim(Str(gnLuna))+"/"+Alltrim(Str(gnAn))+" !",0+64,"Info listare")
*!*		Return
*!*	Endif

*!*	Private pcTitlu,pcDataora
*!*	Store '' To pcTitlu,pcDataora
*!*	pcTitlu = 'LISTA COMENZILOR VALIDATE IN CURSUL LUNII '+Alltrim(Str(gnLuna))+' / '+Alltrim(Str(gnAn))
*!*	pcDataora = get_ora(2)
*!*	Select crsordl
*!*	gofundal.Visible=.F.
*!*	Keyboard "{ctrl+f10}"
*!*	Report Form comvalidnef To Printer Prompt Preview
*!*	gofundal.Visible=.T.
Endproc

**********************sfarsit procedura ver_valid_lun*******************
*******************************************
* PROCEDURE ver_valid(  )
* Data/ora : 01/31/05, 10:39:49
* autor : liana.macinic
* descriere:

****** PARAMETER BLOCK **************
* Parametri : 0
*
*******************************************
Procedure ver_valid(  )

*!*	Private poordl,pcschema1,pcselect1
*!*	Store '' To poordl

*!*	pcschema1=['']
*!*	pcselect1=['select a.nrord,a.datai,a.nume,a.asigurator,a.util_valid,a.dataoravalid '+] + ;
*!*		['from ] + gcS + [.dev_vordl a '+] + ;
*!*		['where 1=2']
*!*	pcorder1= [a.nrord]
*!*	pcfiltru1 = [a.validat = 1]
*!*	gencursor('poordl','crsordl',pcselect1,pcfiltru1,pcschema1,pcorder1)
*!*	poordl.ca_baza1.afisare()

*!*	If Reccount('crsordl')=0
*!*		Use In crsordl
*!*		amessagebox("Nu exista comenzi validate!",0+64,"Info listare")
*!*		Return
*!*	Endif

*!*	Private pcTitlu,pcDataora
*!*	Store '' To pcTitlu,pcDataora
*!*	pcTitlu = 'LISTA COMENZILOR VALIDATE - TOTAL '
*!*	pcDataora = get_ora(2)
*!*	gofundal.Visible=.F.
*!*	Keyboard "{ctrl+f10}"
*!*	Select crsordl
*!*	Report Form comvalid To Printer Prompt Preview
*!*	gofundal.Visible=.T.
Endproc

**********************sfarsit procedura ver_valid*******************

*******************************************
* PROCEDURE ver_nevalid(  )
* Data/ora : 01/31/05, 10:54:49
* autor : liana.macinic
* descriere:

****** PARAMETER BLOCK **************
* Parametri : 0
*
*******************************************
Procedure ver_nevalid(  )

*!*	Private poordl,pcschema1,pcselect1
*!*	Store '' To poordl

*!*	pcschema1=['']
*!*	pcselect1=['select a.nrord,a.datai,a.nume,a.asigurator,a.util_valid,a.dataoravalid '+] + ;
*!*		['from ] + gcS + [.dev_vordl a '+] + ;
*!*		['where 1=2']
*!*	pcorder1= [a.nrord]
*!*	pcfiltru1 = [a.validat = 0]
*!*	gencursor('poordl','crsordl',pcselect1,pcfiltru1,pcschema1,pcorder1)
*!*	poordl.ca_baza1.afisare()

*!*	If Reccount('crsordl')=0
*!*		Use In crsordl
*!*		amessagebox("Nu exista comenzi deschise si nevalidate in luna "+Alltrim(Str(gnLuna))+"/"+Alltrim(Str(gnAn))+" !",0+64,"Info listare")
*!*		Return
*!*	Endif

*!*	Private pcTitlu,pcDataora
*!*	Store '' To pcTitlu,pcDataora
*!*	pcTitlu = 'LISTA COMENZILOR NEVALIDATE - TOTAL '
*!*	pcDataora = get_ora(2)
*!*	Select crsordl

*!*	Public titlu
*!*	titlu='LISTA COMENZILOR DESCHISE SI NEVALIDATE IN LUNA '+Alltrim(Str(gnLuna))+' - '+Alltrim(Str(gnAn))
*!*	gofundal.Visible=.F.
*!*	Keyboard "{ctrl+f10}"
*!*	Report Form comvalid To Printer Prompt Preview
*!*	gofundal.Visible=.T.
*!*	*!*	sele clie
*!*	*!*	set order to tag codc
*!*	*!*	sele ordl
*!*	*!*	SET RELATION TO codc INTO Clie ADDITIVE

*!*	*!*	sele ordl
*!*	*!*	*set order to tag datai
*!*	*!*	set filter to !validat
*!*	*!*	report form comvalid to printer prompt preview
*!*	*!*	sele ordl
*!*	*!*	set filter to
*!*	*!*	sele ordl
*!*	*!*	SET RELATION off inTO Clie

Endproc

**********************sfarsit procedura ver_nevalid*******************
*******************************************
* PROCEDURE ver_nefact(  )
* Data/ora : 01/31/05, 11:00:23
* autor : liana.macinic
* descriere:

****** PARAMETER BLOCK **************
* Parametri : 0
*
*******************************************
Procedure ver_nefact(  )

*!*	Private pcselect,pcschema,pcfiltru,pcorder,pofacturi,llAfiseaza
*!*	Store '' To pofacturi
*!*	pcschema=['']
*!*	pcorder=[a.nume]
*!*	pcselect=['select a.nrord,a.datai,a.nume,a.asigurator,a.validat,a.dataoravalid,a.util_valid from ] + gcS + [.dev_vvalid_comenzi a ]+;
*!*		[where 1=2']
*!*	*!*	pcfiltru=[b.luna=]+ALLTRIM(STR(gnLuna))+[ and b.an=]+ALLTRIM(STR(gnAn))
*!*	pcfiltru=[a.facturat = 0]

*!*	llAfiseaza=.F.
*!*	gencursor('pofacturi','crsfacturi',pcselect,pcfiltru,pcschema,pcorder,llAfiseaza)
*!*	pofacturi.ca_baza1.afisare()

*!*	If Reccount('crsfacturi')=0
*!*		Use In crsfacturi
*!*		amessagebox("Nu exista comenzi nefacturate in luna "+Alltrim(Str(gnLuna))+"/"+Alltrim(Str(gnAn))+" !",0+64,"Info listare")
*!*		Return
*!*	Endif

*!*	Private pcTitlu,pcDataora
*!*	Store '' To pcTitlu,pcDataora
*!*	pcTitlu = 'LISTA COMENZILOR NEFACTURATE - LUNA '+Alltrim(Str(gnLuna))+' / '+ Alltrim(Str(gnAn))
*!*	pcDataora = get_ora(2)
*!*	Select crsfacturi
*!*	gofundal.Visible=.F.
*!*	Keyboard "{ctrl+f10}"
*!*	Report Form comfact To Printer Prompt Preview
*!*	gofundal.Visible=.T.
Endproc

**********************sfarsit procedura ver_nefact*******************
*******************************************
* PROCEDURE ver_valid_nefact(  )
* Data/ora : 01/31/05, 12:05:27
* autor : liana.macinic
* descriere:

****** PARAMETER BLOCK **************
* Parametri : 0
*
*******************************************
Procedure ver_valid_nefact(  )

*!*	Private pcselect,pcschema,pcfiltru,pcorder,pofacturi,llAfiseaza
*!*	Store '' To pofacturi
*!*	pcschema=['']
*!*	pcorder=[a.nume]
*!*	pcselect=['select a.nrord,a.datai,a.nume,a.asigurator,a.validat,a.dataoravalid,a.util_valid from ] + gcS + [.dev_vvalid_comenzi a ]+;
*!*		[where 1=2']
*!*	*!*	pcfiltru=[b.luna=]+ALLTRIM(STR(gnLuna))+[ and b.an=]+ALLTRIM(STR(gnAn))
*!*	pcfiltru=[a.facturat = 0 and a.validat = 1 and extract(month from a.dataoravalid) = ]+Alltrim(Str(gnLuna))+ [ and extract(year from a.dataoravalid) = ]+Alltrim(Str(gnAn))

*!*	llAfiseaza=.F.
*!*	gencursor('pofacturi','crsfacturi',pcselect,pcfiltru,pcschema,pcorder,llAfiseaza)
*!*	pofacturi.ca_baza1.afisare()

*!*	If Reccount('crsfacturi')=0
*!*		Use In crsfacturi
*!*		amessagebox("Nu exista comenzi validate si nefacturate in luna "+Alltrim(Str(gnLuna))+"/"+Alltrim(Str(gnAn))+" !",0+64,"Info listare")
*!*		Return
*!*	Endif

*!*	Private pcTitlu,pcDataora
*!*	Store '' To pcTitlu,pcDataora
*!*	pcTitlu = 'LISTA COMENZILOR VALIDATE SI NEFACTURATE IN LUNA '+Alltrim(Str(gnLuna))+' / '+ Alltrim(Str(gnAn))
*!*	pcDataora = get_ora(2)

*!*	gofundal.Visible=.F.
*!*	Keyboard "{ctrl+f10}"
*!*	Select crsfacturi
*!*	Report Form comfact To Printer Prompt Preview
*!*	gofundal.Visible=.T.
*!*	Use In crsfacturi

Endproc
**********************sfarsit procedura ver_valid_nefact*******************

*******************************************
* PROCEDURE ver_com_rep(  )
* Data/ora : 01/31/05, 12:45:31
* autor : liana.macinic
* descriere:

****** PARAMETER BLOCK **************
* Parametri : 0
*
*******************************************
Procedure ver_com_rep(  )

*!*	Private pcselect,pcschema,pcfiltru,pcorder,pofacturi,llAfiseaza
*!*	Store '' To pofacturi
*!*	pcschema=['']
*!*	pcorder=[nume]
*!*	pcselect=['select nrord,datai,nume,asigurator,validat,facturat,datafact,dataoravalid,util_valid from ] + gcS + [.dev_vvalid_comenzi ]+;
*!*		[where 1=2']
*!*	*!*	pcfiltru=[b.luna=]+ALLTRIM(STR(gnLuna))+[ and b.an=]+ALLTRIM(STR(gnAn))
*!*	pcfiltru=[facturat = 0 and validat = 1 and extract(month from dataoravalid) = ]+Alltrim(Str(gnLuna))+ [ and extract(year from dataoravalid) = ]+Alltrim(Str(gnAn))
*!*	pcfiltru = [trunc(datai) < to_date('01/]+Alltrim(Str(gnLuna)) + [/]+Alltrim(Str(gnAn))+;
*!*		[','dd/mm/yyyy') and ((trunc(datafact)<to_date('01/]+Alltrim(Str(gnLuna)) + [/]+Alltrim(Str(gnAn))+;
*!*		[','dd/mm/yyyy')) or facturat = 0)]
*!*	llAfiseaza=.F.
*!*	gencursor('pofacturi','crsfacturi',pcselect,pcfiltru,pcschema,pcorder,llAfiseaza)
*!*	pofacturi.ca_baza1.afisare()

*!*	If Reccount('crsfacturi')=0
*!*		Use In crsfacturi
*!*		amessagebox("Nu exista comenzi reportate in luna "+Alltrim(Str(gnLuna))+"/"+Alltrim(Str(gnAn))+" !",0+64,"Info listare")
*!*		Return
*!*	Endif

*!*	Private pcTitlu,pcDataora
*!*	Store '' To pcTitlu,pcDataora
*!*	pcTitlu = 'COMENZI REPORTATE IN LUNA '+Alltrim(Str(gnLuna))+' / '+ Alltrim(Str(gnAn))
*!*	pcDataora = get_ora(2)
*!*	gofundal.Visible=.F.
*!*	Keyboard "{ctrl+f10}"
*!*	Select crsfacturi
*!*	Report Form verordl To Printer Prompt Preview
*!*	gofundal.Visible=.T.
*!*	Use In crsfacturi
*!*	*!*	LOCAL cond
*!*	*!*	buton=1
*!*	*!*	*do danu with 'Inclusiv Garantii,Pregatiri,Regie?'
*!*	*!*	IF buton=2
*!*	*!*		cond="!INLIST(left(allt(ordl.nrord),1),'G','R','P')"
*!*	*!*	ELSE
*!*	*!*		cond='.t.'
*!*	*!*	ENDIF

*!*	*!*	dirfirm=loc+'\'+nfscurt
*!*	*!*	SELE calendar
*!*	*!*	LOCA FOR nl=m.nl AND an=m.an
*!*	*!*	IF BOF()
*!*	*!*		DO mesaj WITH 'Aceasta este prima luna',''
*!*	*!*		RETURN
*!*	*!*	ENDIF
*!*	*!*	SKIP -1
*!*	*!*	LOCAL d
*!*	*!*	d=calefirma+'\an'+an+'\date'+nl
*!*	*!*	SELE 0
*!*	*!*	USE &d\ordl ALIAS ordlprec

*!*	*!*	SET EXCL ON
*!*	*!*	SELE DISTINCT ordlprec.datai,ordlprec.facturat AS _fact,ordlprec.VALIDAT AS _validat,ordl.facturat,ordl.VALIDAT,ordl.nrord;
*!*	*!*		FROM ordlprec,ordl;
*!*	*!*		WHERE ordl.nrord=ordlprec.nrord AND &cond;
*!*	*!*		INTO TABLE &dirfirm\tempo\verordl
*!*	*!*	SELE verordl
*!*	*!*	INDEX ON nrord TAG nrord OF &dirfirm\tempo\verordl
*!*	*!*	SET ORDER TO TAG nrord
*!*	*!*	*/brow
*!*	*!*	TITLU='COMENZI REPORTATE'
*!*	*!*	REPORT FORM verordl TO PRINTER PROMPT PREVIEW
*!*	*!*	USE IN verordl
*!*	*!*	USE IN ordlprec

*!*	*!*	SET EXCL OFF

*!*	* and !INLIST(left(allt(ordl.nrord),1),'G','R','P');


Endproc

**********************sfarsit procedura ver_com_rep*******************
**********************inceput procedura verificare_venituri*******************
Procedure verificare_venituri
Local tlOptiune
Private pnTotalManOrdl,pnTotalManAct,pnTotalMatOrdl,pnTotalMatAct,pnTotalMatDisc,pnTotalManDisc,pcDataora

loTherm = Newobject("_thermometer","_therm","","Verificare venituri...")
lcTask = "Verificare sume"
_Screen.MousePointer= 11
*!*	tlOptiune=gofundal.AlwaysOnTop
*!*	gofundal.AlwaysOnTop=.F.
With loTherm
	.AlwaysOnTop=.T.
	.Show()

	lnPercent = 0
	lcTask="Verificari cont 704..."
	.Update(lnPercent, lcTask)

	If Used('crstotalman')
		Use In crstotalman
	Endif
*!*	inlocuire dev_vvalid_comenzi
	lcSql=[select '1' as tabel,NVL(round(sum(manopera),?gnPc),0) as manopera from ]+gcS+[.auto_validare_comenzi where ]+;
		[extract(month from datafact)=?gnLuna and extract(year from datafact)=?gnAn and facturat=1 ]+;
		[union all ]+;
		[select '2' as tabel,NVL(round(sum(d.suma),?gnPc),0) as manopera from ]+gcS+[.act d where d.scc='704' and ]+;
		[d.luna+d.an*12=?gnLuna+?gnAn*12 and d.sters=0 ]+;
		[union all ]+;
		[select '3' as tabel,NVL(round(sum(d.suma),?gnPc),0) as manopera from ]+gcS+[.act d where d.scc='704' and ]+;
		[d.luna+d.an*12=?gnLuna+?gnAn*12 and d.sters=0 and NVL(d.explicatia,'X') like '%DISCOUNT%']

*!*	modificare 27.01
*!*			[d.luna+d.an*12=?gnLuna+?gnAn*12 and d.sters=0]
	lnSucces = goExecutor.oExecute(lcSql,'crstotalman')
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,'Eroare')
	Endif
	Select crstotalman
	Scan
		Do Case
		Case crstotalman.tabel=[1]
			pnTotalManOrdl=crstotalman.manopera
		Case crstotalman.tabel=[2]
			pnTotalManAct=crstotalman.manopera
		Case crstotalman.tabel=[3]
			pnTotalManDisc=Abs(crstotalman.manopera)
		Endcase
	Endscan

	lnPercent = 5
	lcTask="Verificari cont 704 - registrul jurnal..."
	.Update(lnPercent, lcTask)
	If Used('crsverman')
		Use In crsverman
	Endif
	If Used('crsverman1_1')
		Use In crsverman1_1
	Endif
	lcSql=[select dataact,fdoc,dataireg,nract,partc,partd,explicatia,NVL(nrord,'*') as nrord,scd,NVL(ROUND(suma,?gnPc),0) as suma,0 as grup]+;
		[ from ]+gcS+[.vact where scc='704' and an=?gnAn and luna=?gnLuna ]+;
		[and id_set not between 31001 and 31012]
	lnSucces = goExecutor.oExecute(lcSql,'crsverman1_1')
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,'Eroare')
	Endif
	If Reccount('crsverman1_1')=0
		Select * From crsverman1_1 Into Cursor crsverman1 Readwrite
		Use In crsverman1_1
		Select crsverman1
		Append Blank
		Replace grup With 0
	Else
		Select * From crsverman1_1 Into Cursor crsverman1
		Use In crsverman1_1
	Endif

	lnPercent = 25
	lcTask="Verificari cont 704 - comenzi..."
	.Update(lnPercent, lcTask)
	If Used('crsverman2')
		Use In crsverman2
	Endif
*!*	inlocuire dev_vvalid_comenzi
	lcSql=[select NVL(a.nrord,'*') as nrord,a.datai,a.nume,a.tip_comanda,ROUND(a.manopera,?gnPc) as suma1,]+;
		[NVL(round(sum(b.suma) over (partition by b.id_lucrare),?gnPc),0) as suma2,0 as grup ] + ;
		[from ]+gcS+[.auto_validare_comenzi a left join ]+gcS+[.act b on a.id_lucrare=b.id_lucrare and b.scc='704' and ]+;
		[b.luna+b.an*12=?gnLuna+?gnAn*12 and b.sters=0 ] +;
		[where a.id_lucrare in (select id_lucrare from ]+;
		[(select id_lucrare,NVL(round(manopera,?gnPc),0) as manopera ]+;
		[from ]+gcS+[.auto_validare_comenzi where extract(month from datafact)=?gnLuna and extract(year from datafact)=?gnAn ]+;
		[and facturat=1 minus ]+;
		[select id_lucrare,NVL(round(sum(d.suma) over (partition by d.id_lucrare),?gnPc),0) as manopera ] + ;
		[from ]+gcS+[.act d where d.scc='704' and d.luna+d.an*12=?gnLuna+?gnAn*12 and d.sters=0 and NVL(d.explicatia,'X') not like '%DISCOUNT%')) ] + ;
		[and NVL(ROUND(manopera,?gnPc),0)!=0]
*!*	modificare 27.01
*!*		[from ]+gcS+[.act d where d.scc='704' and d.luna+d.an*12=?gnLuna+?gnAn*12 and d.sters=0 and NVL(d.explicatia,'X') not like '%DISCOUNT%'))]


*!*		lcSql=[select nrord,datai,nume,tip_comanda,ROUND(manopera,?gnPa) as suma,0 as grup ] + ;
*!*		[from ]+gcS+[.dev_vvalid_comenzi where id_lucrare in (select id_lucrare from ]+;
*!*		[(select id_lucrare,NVL(round(manopera,?gnPa),0) as manopera ]+;
*!*		[from ]+gcS+[.dev_vvalid_comenzi where extract(month from datafact)=?gnLuna and extract(year from datafact)=?gnAn ]+;
*!*		[and facturat=1 minus ]+;
*!*		[select id_lucrare,NVL(round(sum(d.suma) over (partition by d.id_lucrare),?gnPa),0) as manopera ] + ;
*!*		[from ]+gcS+[.act d where d.scc='704' and d.luna+d.an*12=?gnLuna+?gnAn*12 and d.sters=0)) ] + ;
*!*		[and NVL(ROUND(manopera,?gnPa),0)!=0]
	lnSucces = goExecutor.oExecute(lcSql,'crsverman2')
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,'Eroare')
	Endif

	lnPercent = 45
	lcTask="Verificari cont 707..."
	.Update(lnPercent, lcTask)
	If Used('crstotalmat')
		Use In crstotalmat
	Endif
*!*	inlocuire dev_vvalid_comenzi
	lcSql=[select '1' as tabel,NVL(round(sum(materiale),?gnPc),0) as materiale from ]+gcS+[.auto_validare_comenzi where ]+;
		[extract(month from datafact)=?gnLuna and extract(year from datafact)=?gnAn and facturat=1 ]+;
		[union all ]+;
		[select '2' as tabel,NVL(round(sum(d.suma),?gnPc),0) as materiale from ]+gcS+[.act d where d.scc='707' and ]+;
		[d.luna+d.an*12=?gnLuna+?gnAn*12 and d.sters=0 ]+;
		[union all ]+;
		[select '3' as tabel,NVL(round(sum(d.suma),?gnPc),0) as materiale from ]+gcS+[.act d where d.scc='707' and ]+;
		[d.luna+d.an*12=?gnLuna+?gnAn*12 and d.sters=0 and NVL(d.explicatia,'X') like '%DISCOUNT%']
*!*	modificare 27.01
*!*		[d.luna+d.an*12=?gnLuna+?gnAn*12 and d.sters=0]
	lnSucces = goExecutor.oExecute(lcSql,'crstotalmat')
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,'Eroare')
	Endif
	Select crstotalmat
	Scan
		Do Case
		Case crstotalmat.tabel=[1]
			pnTotalMatOrdl=crstotalmat.materiale
		Case crstotalmat.tabel=[2]
			pnTotalMatAct=crstotalmat.materiale
		Case crstotalmat.tabel=[3]
			pnTotalMatDisc=Abs(crstotalmat.materiale)
		Endcase
	Endscan
	lnPercent = 50
	lcTask="Verificari cont 707 - registrul jurnal..."
	.Update(lnPercent, lcTask)
	If Used('crsvermat')
		Use In crsvermat
	Endif
	If Used('crsvermat1_1')
		Use In crsvermat1_1
	Endif
	lcSql=[select dataact,fdoc,dataireg,nract,partc,partd,explicatia,NVL(nrord,'*') as nrord,scd,NVL(ROUND(suma,?gnPc),0) as suma,1 as grup from ]+;
		gcS+[.vact where scc='707' and an=?gnAn and luna=?gnLuna and id_set not between 31001 and 31012]
	lnSucces = goExecutor.oExecute(lcSql,'crsvermat1_1')
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,'Eroare')
	Endif
	If Reccount('crsvermat1_1')=0
		Select * From crsvermat1_1 Into Cursor crsvermat1 Readwrite
		Use In crsvermat1_1
		Select crsvermat1
		Append Blank
		Replace grup With 1
	Else
		Select * From crsvermat1_1 Into Cursor crsvermat1
		Use In crsvermat1_1
	Endif

	lnPercent = 70
	lcTask="Verificari cont 707 - comenzi..."
	.Update(lnPercent, lcTask)
	If Used('crsvermat2')
		Use In crsvermat2
	Endif
*!*	inlocuire dev_vvalid_comenzi
	lcSql=[select NVL(a.nrord,'*') as nrord,a.datai,a.nume,a.tip_comanda,ROUND(a.materiale,?gnPc) as suma1,]+;
		[NVL(round(sum(b.suma) over (partition by b.id_lucrare),?gnPc),0) as suma2,1 as grup ] + ;
		[from ]+gcS+[.auto_validare_comenzi a left join ]+gcS+[.act b on a.id_lucrare=b.id_lucrare and b.scc='707' and ]+;
		[b.luna+b.an*12=?gnLuna+?gnAn*12 and b.sters=0 ] +;
		[where a.id_lucrare in (select id_lucrare from ]+;
		[(select id_lucrare,NVL(round(materiale,?gnPc),0) as materiale ]+;
		[from ]+gcS+[.auto_validare_comenzi where extract(month from datafact)=?gnLuna and extract(year from datafact)=?gnAn ]+;
		[and facturat=1 minus ]+;
		[select id_lucrare, NVL(round(sum(d.suma) over (partition by d.id_lucrare),?gnPc),0) as materiale ]+;
		[from ]+gcS+[.act d where d.scc='707' and d.luna+d.an*12=?gnLuna+?gnAn*12 and d.sters=0 and NVL(d.explicatia,'X') not like '%DISCOUNT%')) ] + ;
		[and NVL(ROUND(materiale,?gnPc),0)!=0]
*!*	modificare 27.01
*!*	[from ]+gcS+[.act d where d.scc='707' and d.luna+d.an*12=?gnLuna+?gnAn*12 and d.sters=0)) ] + ;

*!*		lcSql=[select nrord,datai,nume,tip_comanda,ROUND(materiale,?gnPa) as suma,1 as grup ]+;
*!*		[from ]+gcS+[.dev_vvalid_comenzi where id_lucrare in (select id_lucrare from ]+;
*!*		[(select id_lucrare,NVL(round(materiale,?gnPa),0) as materiale ]+;
*!*		[from ]+gcS+[.dev_vvalid_comenzi where extract(month from datafact)=?gnLuna and extract(year from datafact)=?gnAn ]+;
*!*		[and facturat=1 minus ]+;
*!*		[select id_lucrare, NVL(round(sum(d.suma) over (partition by d.id_lucrare),?gnPa),0) as materiale ]+;
*!*		[from ]+gcS+[.act d where d.scc='707' and d.luna+d.an*12=?gnLuna+?gnAn*12 and d.sters=0)) ] + ;
*!*		[and NVL(ROUND(materiale,?gnPa),0)!=0]
	lnSucces = goExecutor.oExecute(lcSql,'crsvermat2')
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,'Eroare')
	Endif

	lnPercent = 90
	lcTask="Finalizare verificari..."
	.Update(lnPercent, lcTask)
	pcDataora=get_ora(2)
	If Used('crstotal')
		Use In crstotal
	Endif

	lnPercent = 95
	lcTask="Generare raport..."
	.Update(lnPercent, lcTask)

	Select 1 As tabel,dataact,fdoc,dataireg,nract,partc,partd,explicatia,nrord,scd,0 As suma1,0 As suma2,suma,grup From crsverman1 ;
		union ;
		select 2 As tabel,datai As dataact,'' As fdoc,{} As dataireg,0 As nract,nume As partc,'' As partd,'' As explicatia,nrord,'' As scd,suma1,suma2,suma1-suma2 As suma,0 As grup From crsverman2 ;
		UNION ;
		Select 3 As tabel,dataact,fdoc,dataireg,nract,partc,partd,explicatia,nrord,scd,0 As suma1,0 As suma2,suma,grup From crsvermat1 ;
		union ;
		select 4 As tabel,datai As dataact,'' As fdoc,{} As dataireg,0 As nract,nume As partc,'' As partd,'' As explicatia,nrord,'' As scd,suma1,suma2,suma1-suma2 As suma,1 As grup From crsvermat2 ;
		INTO Cursor crstotal
	.Complete()
	.AlwaysOnTop=.F.
Endwith
Release loTherm
_Screen.MousePointer= 0

gofundal.Visible=.F.
Keyboard "{ctrl+f10}"
Select crstotal
Report Form rap_verifvenit To Printer Prompt Preview
gofundal.Visible=.T.
Use In (SELECT('crstotal'))
Use In (SELECT('crstotalman'))
Use In (SELECT('crsverman1'))
Use In (SELECT('crsverman2'))
Use In (SELECT('crstotalmat'))
Use In (SELECT('crsvermat1'))
Use In (SELECT('crsvermat2'))

*!*	gofundal.AlwaysOnTop=&tlOptiune
Endproc
**********************sfarsit procedura verificare_venituri*******************
**********************inceput procedura valori_mat_bon ******************Proc matnefact
*!*	Sele ordl.*,clie.nume From ordl,clie ;
*!*		where !ordl.facturat And !Empty(ordl.materiale) And ordl.codc=clie.codc;
*!*		and !Empty(ordl.nrord) And &cond;
*!*		into Cursor cliord1 Order By nrord
*********************
Procedure valori_mat_bon
Local lcOrder,lcSql,lcFiltru,lnSucces
If amessagebox("Inclusiv comenzile inchise prin validare?",4+32,"Bonuri pe comenzi nefacturate - pe sectii")==7
	lcFiltru = [EXTRACT(MONTH FROM DATAI)+EXTRACT(YEAR FROM DATAI)*12<=?gnLuna+?gnAn*12 AND ] + ;
		[(FACTURAT=0 OR (FACTURAT=1 AND EXTRACT(MONTH FROM DATAFACT)+EXTRACT(YEAR FROM DATAFACT)*12>?gnLuna+?gnAn*12)) ]+;
		[AND INCH_VALIDARE = 0]
Else
	lcFiltru = [EXTRACT(MONTH FROM DATAI)+EXTRACT(YEAR FROM DATAI)*12<=?gnLuna+?gnAn*12 AND ] + ;
		[(((FACTURAT=0 OR (FACTURAT=1 AND EXTRACT(MONTH FROM DATAFACT)+EXTRACT(YEAR FROM DATAFACT)*12>?gnLuna+?gnAn*12)) ]+;
		[AND INCH_VALIDARE = 0) OR ((VALIDAT=0 OR (VALIDAT=1 AND EXTRACT(MONTH FROM DATAORAVALID)+EXTRACT(YEAR FROM DATAORAVALID)*12>]+;
		[?gnLuna+?gnAn*12)) AND INCH_VALIDARE = 1))]
Endif

loTherm = Newobject("_thermometer","_therm","","Valori materiale bonate pe comenzi nefacturate...")
lcTask = "Generare raport..."
_Screen.MousePointer= 11
With loTherm
	.AlwaysOnTop=.T.
	.Show()

	lnPercent = 5
	.Update(lnPercent, lcTask)
	pcDataora=get_ora(2)

	lnPercent = 10
	.Update(lnPercent, lcTask)
*!* inlocuire dev_vvalid_comenzi
	lcSql = [SELECT NUME,NRORD,DATAI,MATERIALE,ASIGURATOR FROM auto_VALIDARE_COMENZI WHERE ] + ;
		[MATERIALE!=0 AND INCHIS_FORTAT = 0 and ] + lcFiltru + [ ORDER BY 2]
	lnSucces = goExecutor.oExecute(lcSql,'crsmatnefact')
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,'Eroare')
	Endif
	.Complete()
	.AlwaysOnTop=.F.
Endwith
Release loTherm
_Screen.MousePointer= 0

If Reccount('crsmatnefact')=0
	amessagebox("Nu exista valori materiale bonate pe comenzi nefacturate!",0+48,"Info analiza")
	Return
Endif

gofundal.Visible=.F.
Keyboard "{ctrl+f10}"
Select crsmatnefact
*!*	Report Form matnefact To Printer Prompt Preview
goExport.export2frx('crsmatnefact','matnefact ',.F., , , , , .T.)	
gofundal.Visible=.T.
Use In (SELECT('crsmatnefact'))

Endproc
**********************sfarsit procedura valori_mat_bon *******************
**********************inceput procedura bon_com_nefact_sectii *******************
*!*	Sele ordl.*,clie.nume From ordl,clie ;
*!*		where !ordl.facturat And ordl.codc=clie.codc;
*!*		and !Empty(ordl.nrord) And &cond;
*!*		into Table &loc\&nfscurt\tempo\matnefact Order By nrord
*!*	cond='((MONTH(DATAACT)<=VAL(M.NL) AND YEAR(DATAACT)=VAL(M.AN)) OR YEAR(DATAACT)<VAL(M.AN))'
*!*	Sele matnefact.*,actan.nract,actan.dataact,actan.suma,actan.nresp,actan.sectie;
*!*		from matnefact,actan Where Allt(actan.nrord)=Allt(matnefact.nrord);
*!*		and Inlist(actan.scd,'332 ','331 ') And actan.scc='711 ' And &cond;
*!*		into Cursor mat1 Order By actan.sectie,matnefact.nrord
*************************************
Procedure bon_com_nefact
Lparameters tlCuSectie
Private pcDataora
Local lcOrder,lcSql,lcFiltru,lnSucces
If amessagebox("Inclusiv comenzile care se inchid prin validare?",4+32,"Bonuri pe comenzi nefacturate - pe sectii")==7
*!*		lcFiltru = [A.ID_LUCRARE NOT IN (SELECT ID_LUCRARE FROM ] + gcS + [.DEV_VORDL_FACTURI WHERE FACTURAT=1 ]+;
*!*		[AND EXTRACT(MONTH FROM DATAACT)+EXTRACT(YEAR FROM DATAACT)*12<=?gnLuna+?gnAn*12) AND ] + ;
*!*		[EXTRACT(MONTH FROM A.DATAI)+EXTRACT(YEAR FROM A.DATAI)*12<=?gnLuna+?gnAn*12 AND A.ID_TIP=1]
	lcFiltru = [(A.FACTURAT=0 OR ]+;
		[(A.FACTURAT=1 AND EXTRACT(MONTH FROM A.DATAFACT)+EXTRACT(YEAR FROM A.DATAFACT)*12>?gnLuna+?gnAn*12)) ]+;
		[AND A.INCH_VALIDARE=0]
Else
*!*		lcFiltru = [EXTRACT(MONTH FROM A.DATAI)+EXTRACT(YEAR FROM A.DATAI)*12<=?gnLuna+?gnAn*12 AND ] + ;
*!*		[((A.ID_LUCRARE NOT IN (SELECT ID_LUCRARE FROM ] + gcS + [.DEV_VORDL_FACTURI WHERE FACTURAT=1 ] + ;
*!*		[AND EXTRACT(MONTH FROM DATAACT)+EXTRACT(YEAR FROM DATAACT)*12<=?gnLuna+?gnAn*12) AND A.ID_TIP=1)] + ;
*!*		[OR ((A.VALIDAT=0 OR (A.VALIDAT=1 AND EXTRACT(MONTH FROM A.DATAORAVALID)+EXTRACT(YEAR FROM A.DATAORAVALID)*12>]+;
*!*		[?gnLuna+?gnAn*12)) AND A.ID_TIP IN (2,3,4)))]
	lcFiltru = [(((A.FACTURAT=0 OR ]+;
		[(A.FACTURAT=1 AND EXTRACT(MONTH FROM A.DATAFACT)+EXTRACT(YEAR FROM A.DATAFACT)*12>?gnLuna+?gnAn*12)) ]+;
		[AND A.INCH_VALIDARE=0) ]+;
		[OR ((A.VALIDAT=0 OR ]+;
		[(A.VALIDAT=1 AND EXTRACT(MONTH FROM A.DATAORAVALID)+EXTRACT(YEAR FROM A.DATAORAVALID)*12>?gnLuna+?gnAn*12)) ]+;
		[AND A.INCH_VALIDARE=1))]
Endif

If tlCuSectie
	lcOrder = [ORDER BY 9,4]
	lcExplicatie = [ - pe sectii]
Else
	lcOrder = [ORDER BY 4]
	lcExplicatie = []
Endif

loTherm = Newobject("_thermometer","_therm","","Bonuri pe comenzi nefacturate"+lcExplicatie+"...")
lcTask = "Generare raport..."
_Screen.MousePointer= 11
With loTherm
	.AlwaysOnTop=.T.
	.Show()

	lnPercent = 5
	.Update(lnPercent, lcTask)
	pcDataora=get_ora(2)

	lnPercent = 10
	.Update(lnPercent, lcTask)


	lcSql=[SELECT A.ID_LUCRARE,A.NUME,A.DATAI,A.NRORD,B.ID_SECTIE,B.DATAACT,B.NRACT,]+;
		[(case ]+;
		[when b.luna+b.an*12<]+;
		[pack_sesiune.GET_LUNARON()+pack_sesiune.GET_ANRON()*12]+;
		[ and ]+;
		[pack_sesiune.getAn()*12+pack_sesiune.getLuna()>=]+;
		[pack_sesiune.GET_ANRON()*12+pack_sesiune.GET_LUNARON() ]+;
		[then nvl(b.suma,0)/10000]+;
		[ else ]+;
		[nvl(b.suma,0) end ) ]+;
		[as SUMA,C.SECTIE,D.NUME AS NRESP ]+;
		[FROM auto_NORMARE_COMENZI A ]+;
		[LEFT JOIN ACT B ON A.ID_LUCRARE=B.ID_LUCRARE ]+;
		[LEFT JOIN VNOM_SECTII C ON B.ID_SECTIE=C.ID_SECTIE ]+;
		[LEFT JOIN VNOM_RESPONSABILI D ON B.ID_RESPONSABIL=D.ID_RESPONSABIL ]+;
		[WHERE EXTRACT(MONTH FROM A.DATAI)+EXTRACT(YEAR FROM A.DATAI)*12<=?gnLuna+?gnAn*12 AND A.INCHIS_FORTAT = 0 AND ]+;
		lcFiltru +;
		[AND B.STERS=0 AND B.SCD IN ('332','331') AND B.SCC='711' ]+;
		[AND EXTRACT(MONTH FROM B.DATAACT)+EXTRACT(YEAR FROM B.DATAACT)*12<=?gnLuna+?gnAn*12 ] + ;
		lcOrder


	lnSucces = goExecutor.oExecute(lcSql,'crsmatnefact')
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,'Eroare')
	Endif
	.Complete()
	.AlwaysOnTop=.F.
Endwith
Release loTherm
_Screen.MousePointer= 0
*!*	SELECT crsmatnefact
*!*	BROWSE
If Reccount('crsmatnefact')=0
	amessagebox("Nu exista bonuri pe comenzi nefacturate!",0+48,"Info analiza")
	Return
Endif

gofundal.Visible=.F.
Keyboard "{ctrl+f10}"
Select crsmatnefact
If tlCuSectie
*!*		Report Form matbon_sec To Printer Prompt Preview
	goExport.export2frx('crsmatnefact','matbon_sec',.F., , , , , .T.)
Else
*!*		Report Form matbon To Printer Prompt Preview
	goExport.export2frx('crsmatnefact','matbon',.F., , , , , .T.)	
ENDIF


gofundal.Visible=.T.
Use In (SELECT('crsmatnefact'))

Endproc
**********************sfarsit procedura bon_com_nefact_sectii *******************

**********************inceput procedura raport_salarizare *******************
Procedure raport_salarizare
Private pcDataora,plPerioada,pcondper,pcPerioada,pnLunaI,pnAnI,pnLunaF,pnAnF
Local lcOrder,lcSql,lcFiltru,lnSucces

pcondper=""
ofrmperioada=Createobject('frm_perioada_luni')
ofrmperioada.Show(1)
If gnButon=2
	Return
Endif

plPerioada=.F.
lnPoz=At('_',pcondper)
If lnPoz>0
	plPerioada=.T.
Endif

If plPerioada
	pnLunaI=Val(Substr(pcondper,1,2))
	pnAnI=Val(Substr(pcondper,3,4))
	pnLunaF=Val(Substr(pcondper,8,2))
	pnAnF=Val(Substr(pcondper,10,4))
	pcPerioada = [Perioada ]+ ;
		SUBSTR(pcondper,1,2)+'/'+Substr(pcondper,3,4) + ' - ' + ;
		SUBSTR(pcondper,8,2)+'/'+Substr(pcondper,10,4)
Else
	pnLunaI=Val(Substr(pcondper,1,2))
	pnAnI=Val(Substr(pcondper,3,4))
	pnLunaF=pnLunaI
	pnAnF=pnAnI
	pcPerioada = [Luna ] + Substr(pcondper,1,2)+'/'+Substr(pcondper,3,4)
Endif

loTherm = Newobject("_thermometer","_therm","","Raport de salarizare...")
lcTask = "Generare raport..."
_Screen.MousePointer= 11
With loTherm
	.AlwaysOnTop=.T.
	.Show()

	lnPercent = 5
	.Update(lnPercent, lcTask)
	pcDataora=get_ora(2)

	lnPercent = 10
	.Update(lnPercent, lcTask)
	distribuire_timp_normat()

	lnPercent = 70
	.Update(lnPercent, lcTask)
	lcSql = [begin pack_auto.set_perioada_raport(?pnLunaI,?pnAnI,?pnLunaF,?pnAnF); end;]
	lnSucces = goExecutor.oExecute(lcSql,)
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,'Eroare')
	Endif

	lnPercent = 80
	.Update(lnPercent, lcTask)
	lcSql=[SELECT * FROM ]+gcS+[.AUTO_ANALIZA_SALARII_REG ORDER BY NUME]

	lnSucces = goExecutor.oExecute(lcSql,'crssalarii')
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,'Eroare')
	Endif
	.Complete()
	.AlwaysOnTop=.F.
Endwith
Release loTherm
_Screen.MousePointer= 0

ofrmsalarii=Createobject("frm_raport_salarizare")
ofrmsalarii.Show(1)
Release ofrmsalarii,pcDataora,plPerioada,pcondper,pcPerioada,pnLunaI,pnAnI,pnLunaF,pnAnF
Endproc
**********************sfarsit procedura raport_salarizare *******************
**********************inceput procedura raport_salarizare_val *******************
Procedure raport_salarizare_val
	Private pcDataora,pcTitlu,pcondper,pcPerioada,pnLunaI,pnAnI,pnLunaF,pnAnF
	Local lcSql,lcCursor
	lcCursor = [crssalarii]
	pcondper=""
	ofrmperioada=Createobject('frm_perioada_luni')
	ofrmperioada.Show(1)
	If gnButon=2
		Return
	Endif

	If At('_',pcondper)>0
		pnLunaI=Val(Substr(pcondper,1,2))
		pnAnI=Val(Substr(pcondper,3,4))
		pnLunaF=Val(Substr(pcondper,8,2))
		pnAnF=Val(Substr(pcondper,10,4))
		pcPerioada = [Perioada ]+ ;
			SUBSTR(pcondper,1,2)+'/'+Substr(pcondper,3,4) + ' - ' + ;
			SUBSTR(pcondper,8,2)+'/'+Substr(pcondper,10,4)
	Else
		pnLunaI=Val(Substr(pcondper,1,2))
		pnAnI=Val(Substr(pcondper,3,4))
		pnLunaF=pnLunaI
		pnAnF=pnAnI
		pcPerioada = [Luna ] + Substr(pcondper,1,2)+'/'+Substr(pcondper,3,4)
	Endif

	loTherm = Newobject("_thermometer","_therm","","Raport de salarizare - comenzi validate ...")
	lcTask = "Generare raport..."
	_Screen.MousePointer= 11
	With loTherm
		.AlwaysOnTop=.T.
		.Show()

		lnPercent = 5
		.Update(lnPercent, lcTask)
		distribuire_timp_normat()

		lnPercent = 70
		.Update(lnPercent, lcTask)
		lcSql = [begin pack_auto.set_perioada_raport(?pnLunaI,?pnAnI,?pnLunaF,?pnAnF); end;]
		If goExecutor.oExecuta(lcSql)
			lnPercent = 80
			.Update(lnPercent, lcTask)
			lcSql=[SELECT * FROM ]+gcS+[.AUTO_ANALIZA_SALARII_VAL ORDER BY NUME]
			goExecutor.oExecuta(lcSql,lcCursor)
		Endif
		.Complete()
		.AlwaysOnTop=.F.
	Endwith
	Release loTherm
	_Screen.MousePointer= 0

	If Used(lcCursor)
		If Reccount(lcCursor)>0
			pcDataora=Ttoc(get_ora())
			pcTitlu = [RAPORT DE SALARIZARE - COMENZI VALIDATE ÎN ]
			goExport.export2frx([crssalarii],[salarii],.F., , , , , .T.)	&&	modificare v 2.1.9
		Else
			amessagebox("Nu exista inregistrari pentru listare!",0+48,"Atentie")
		Endif
		Use In (lcCursor)
	Endif
	Release pcDataora,pcTitlu,pcondper,pcPerioada,pnLunaI,pnAnI,pnLunaF,pnAnF
Endproc
**********************sfarsit procedura raport_salarizare_val *******************
**********************inceput procedura manopera_asig *******************
Procedure manopera_asig
Lparameters tlCuSectie
Private pcDataora,plPerioada,pcondper,pcPerioada
Local lcOrder,lcSql,lcFiltru,lnSucces

pcondper=""
ofrmperioada=Createobject('frm_perioada_luni')
ofrmperioada.Show(1)
If gnButon=2
	Return
Endif

plPerioada=.F.
lnPoz=At('_',pcondper)
If lnPoz>0
	plPerioada=.T.
Endif

lcFiltru = [extract(month from (decode(e.inch_validare,0,last_day(trunc(c.dataact)),last_day(trunc(a.dataoravalid))))) + ] + ;
		[extract(year from (decode(e.inch_validare,0,last_day(trunc(c.dataact)),last_day(trunc(a.dataoravalid))))) * 12 ]

If plPerioada
	lnInit=Val(Substr(pcondper,1,2))+Val(Substr(pcondper,3,4))*12
	lnFinal=Val(Substr(pcondper,8,2))+Val(Substr(pcondper,10,4))*12
	lcFiltru = lcFiltru + [ between ]+;
		ALLTRIM(Str(lnInit))+[ and ]+Alltrim(Str(lnFinal))
	pcPerioada = [Perioada ]+ ;
		SUBSTR(pcondper,1,2)+'/'+Substr(pcondper,3,4) + ' - ' + ;
		SUBSTR(pcondper,8,2)+'/'+Substr(pcondper,10,4)
Else
	lnInit = Val(Substr(pcondper,1,2))+Val(Substr(pcondper,3,4))*12
	lcFiltru = lcFiltru + [ = ]+;
		ALLTRIM(Str(lnInit))
	pcPerioada = [Luna ] + Substr(pcondper,1,2)+'/'+Substr(pcondper,3,4)
Endif

loTherm = Newobject("_thermometer","_therm","","Ore de manopera pe asiguratori...")
lcTask = "Generare raport..."
_Screen.MousePointer= 11
With loTherm
	.AlwaysOnTop=.T.
	.Show()

	lnPercent = 5
	.Update(lnPercent, lcTask)
	pcDataora=get_ora(2)

	lnPercent = 10
	.Update(lnPercent, lcTask)

*!*		lcSql=[SELECT TIP,LUNA,ASIG,TIMP_N FROM ]+gcS+[.DEV_ANALIZA_MANASIG ]+lcFiltru+;
*!*			[ ORDER BY LUNA,TIP]
	lcSql = [Select decode(a.id_tip, 1, 'POST GARANTIE', 2, 'GARANTIE', 'REGIE') As tip,] + ;
		[NVL(d1.denumire, '<FARA ASIGURATOR>') as asig,] + ;
		[decode(e.inch_validare,0,last_day(trunc(c.dataact)),last_day(trunc(a.dataoravalid))) as luna,] + ;
		[Nvl(Sum(round(b.timpn, 3)), 0) As timp_n ] + ;
		[From ] + ;
			[(select a.id_ordl, a.id_lucrare, a.id_asigurator, a.id_tip, ] + ;
			[(case when extract(month from a.dataoravalid) + extract(year from a.dataoravalid) * 12 ] + ;
				[<= pack_sesiune.getluna() + pack_sesiune.getan() * 12 then 1 else 0 end) as validat,] + ;
			[(case when extract(month from a.dataoravalid) + extract(year from a.dataoravalid) * 12 ] + ;
				[<= pack_sesiune.getluna() + pack_sesiune.getan() * 12 then a.dataoravalid else null end) as dataoravalid ] + ;
			[from ] + gcS + [.dev_ordl a where a.sters = 0) a ] + ;
		[Left Join ] + gcS + [.dev_oper b on a.id_ordl = b.id_ordl ] + ;
		[left join ] + gcS + [.auto_vordl_facturi c on a.id_lucrare = c.id_lucrare ] + ;
		[left join ] + gcS + [.dev_nom_asiguratori d on a.id_asigurator = d.id_asigurator ] + ;
		[left join ] + gcS + [.nom_parteneri d1 on d.id_part = d1.id_part ] + ;
		[left join ] + gcS + [.dev_tip_deviz e on a.id_tip = e.id_tip ] +  ;
		[Where ((a.validat = 1 and e.inch_validare = 1) or (nvl(c.facturat, 0) = 1 and e.inch_validare = 0)) ] + ;
		[and ] + lcFiltru + [ and b.sters = 0 ] + ;
		[Group By d1.denumire, a.id_tip, decode(e.inch_validare,0,last_day(trunc(c.dataact)),last_day(trunc(a.dataoravalid))) ] + ;
		[order by 3,1,2]

	lnSucces = goExecutor.oExecute(lcSql,'manopera_asig')
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,'Eroare')
	Endif
	.Complete()
	.AlwaysOnTop=.F.
Endwith
Release loTherm
_Screen.MousePointer= 0

If Reccount('manopera_asig')=0
	amessagebox("Nu exista inregistrari pentru acest raport!",0+64,"Raport manopera pe asiguratori")
	Return
Endif

Select manopera_asig
gofundal.Visible=.F.
Keyboard "{ctrl+f10}"
Report Form rap_manasig To Printer Prompt Preview
gofundal.Visible=.T.
Use In manopera_asig

Endproc
**********************sfarsit procedura manopera_asig *******************
*******************************************************************************************
Procedure verificare_articole
Private pcTitlu
Local lcCursorRaport, lcConditie, lcTitlu
lcConditie = []
lcConditie2 = []
lcCompletareTitlu = []
pnOptiune=1
pnButon=1
lnRaspuns = 1
Do While lnRaspuns = 1
	lcTitlu = [ARTICOLE PE COMENZI]
	lcIntrebare="Doriti ca raportul sa contina :"
	lnNrOptiuni=4
	ofrmopt=Createobject("frm_optiune",lcTitlu,lcIntrebare,lnNrOptiuni)
	ofrmopt.ogOptiuni.option1.Caption="Ptr. un articol (cu intrari in luna)"
	ofrmopt.ogOptiuni.option2.Caption="Ptr. un articol din stocul lunii"
	ofrmopt.ogOptiuni.option3.Caption="Doar articolele cu intrari in luna"
	ofrmopt.ogOptiuni.option4.Caption="Toate articolele din stocul lunii"
	ofrmopt.Show(1)

	Release ofrmopt
	If pnButon=1
		If Inlist(pnOptiune,1,3)
			lcConditie = [and x.cant <> 0]
			lcCompletareTitlu = [ CU INTRĂRI ÎN LUNĂ]
		Endif

		If Inlist(pnOptiune,1,2)
			loCauta = caut_articol()
			If !Empty(Nvl(loCauta.id_articol,0))
				lcConditie2 = [and x.id_articol = ] + Alltrim(Str(loCauta.id_articol))
				lcTip = [ARTICOL]
			Else
				Return
			Endif
		Else
			lcTip = [ARTICOLE]
		Endif

		pcTitlu = [VERIFICĂRI ] + lcTip + lcCompletareTitlu + [ PE COMENZI]

		lcCursorRaport = [crsArticoleVerif]
		Use In (Select(lcCursorRaport))
		lcSql = [select a.id_articol,d.denumire,d.codmat,d.um,a.pret,a.cants,a.cant,a.id_gestiune,] + ;
			[b.nume_gestiune, b.cante, b.id_lucrare, e.nrord, NVL(c.facturat, 0) as facturat,a.nr_pag ] + ;
			[from (select x.id_articol, x.id_gestiune, x.cont, x.acont, x.cants, x.cant,] + ;
			[decode(q.nr_pag, 6, x.pretv, x.pret) as pret,q.nr_pag ] + ;
			[from stoc x ] + ;
			[left join nom_gestiuni q on x.id_gestiune = q.id_gestiune ] + ;
			[where x.an = ?gnAn and x.luna = ?gnLuna ] + lcConditie + lcConditie2 + [) a ] + ;
			[left join (select x.id_articol,decode(y.nr_pag, 6, x.pretv, x.pret) as pret,x.id_gestiune,] + ;
			[x.cont,x.acont,x.id_lucrare,sum(nvl(x.cante, 0)) as cante,y.nume_gestiune ] + ;
			[from rul x ] + ;
			[left join nom_gestiuni y on x.id_gestiune = y.id_gestiune ] + ;
			[where x.sters = 0 and x.cante <> 0 and x.an = ?gnAn and x.luna = ?gnLuna and x.id_tip_rulaj = 0 ] + lcConditie2 + ;
			[group by x.id_gestiune, y.nume_gestiune, x.id_articol, decode(y.nr_pag, 6, x.pretv, x.pret),] + ;
			[x.cont, x.acont, x.id_lucrare) b ] + ;
			[on a.id_articol = b.id_articol and a.pret = b.pret and a.id_gestiune = b.id_gestiune ] + ;
			[and NVL(a.cont, 'XXXX') = NVL(b.cont, 'XXXX') and NVL(a.acont, 'XXXX') = NVL(b.acont, 'XXXX') ] + ;
			[left join auto_vordl_facturate c on b.id_lucrare = c.id_lucrare ] + ;
			[left join nom_articole d on a.id_articol = d.id_articol ] + ;
			[left join vnom_lucrari e on b.id_lucrare = e.id_lucrare ] + ;
			[order by b.nume_gestiune, d.denumire, d.codmat, d.um, a.pret]
		lnSucces = goExecutor.oExecute(lcSql,lcCursorRaport)
		If lnSucces < 0
			amessagebox(goExecutor.cEroare,0+16,'Eroare')
		Endif
		If Used(lcCursorRaport)
			If Reccount(lcCursorRaport) > 0
				Private pcDataora,pcPerioada
				pnButon=1
				Do While pnButon=1
					pnOptiune=1
					ofrmaleg=Createobject('frm_aleg_vizualizare')
					ofrmaleg.Show(1)
					Do Case
					Case pnButon<>1
						Loop
					Case pnOptiune=1
						pcDataora = get_ora(2)
						pcPerioada = [LUNA ] + Padl(Alltrim(Str(gnLuna)),2,[0]) + [/] + Alltrim(Str(gnAn))
						Select (lcCursorRaport)
						Keyboard '{CTRL+F10}'
						Report Form rap_articole_comenzi To Printer Prompt Preview
					Case pnOptiune=2
						lcSirColoane=[nume_gestiune,denumire,codmat,um,nrord,facturat,cante,cant,cants]
						lcSirNume=[Gestiune,Nume_articol,Cod_material,UM,Nr_comanda,Facturat,Iesiri,Intrari_in_luna,Stoc_precedent]
						exportare(lcCursorRaport,lcSirColoane,lcSirNume)
					Endcase
					Release ofrmaleg
				Enddo
			Else
				amessagebox("Nu exista inregistrari pentru listare!",0+48,"Atentie")
			Endif
			Use In (lcCursorRaport)
		Endif
	Else
		lnRaspuns = 2
	Endif
Enddo
Endproc	&&	verificare_articole
*******************************************************************************************


PROCEDURE viz_date_comenzi
PRIVATE poDateComenzi
poDateComenzi = ''

TEXT TO lcSelect NOSHOW 
select nrord,
       id_part,
       nume,
       cod_fiscal,
       datai,
       asigurator,
       inspector,
       banca,
       cont_banca,
       adresa,
       email,
       telefon1,
       telefon2,
       nr_dosar,
       validat,
       id_masiniclient,
       nrinmat,
       series,
       seriem,
       culoare,
       kmint,
       id_masina,
       id_marca,
       marca,
       masina,
       semn,
       id_lucrare,
       codmat,
       denumire,
       cante,
       pret,
       data,
       id
  from auto_analiza_comenzi
ENDTEXT 

lcSchema = [nrord C(50),id_part N(12),nume  C(70),cod_fiscal C(30),datai T,asigurator  C(70),inspector   C(24),banca C(40),] + ;
[cont_banca C(30),adresa  C(250),email C(100),telefon1 C(30),telefon2 C(30),nr_dosar C(40),validat N(3),id_masiniclient (12),nrinmat C(40),] + ;
[series  C(17),seriem C(18),culoare C(30),kmint N(12),id_masina   N(7),id_marca N(7),marca C(24),masina  C(20),semn  C(1),] + ;
[id_lucrare  N(20),codmat C(50),denumire C(100),cante N(20,4),pret N(20,4),data T,id N(20)]

	lcFiltru=[1=2]
	lcOrder=[datai,nrord]
	llAfiseaza=.F.
	lcSchema = []
	llAfiseaza = .F.
	lcgroup = []
	llModParam = .T.
	lcFiltruOriginal = []

	gencursor('poDateComenzi','crsDateComenzi', lcSelect, lcFiltru, lcSchema, lcOrder, llAfiseaza, lcgroup, llModParam, lcFiltruOriginal)
	poDateComenzi.ca_baza1.afisare()

			
	loFrmDate = CREATEOBJECT("frm_viz_date_comenzi")
	loFrmDate.show(1)
	
	USE IN (SELECT('crsDateComenzi'))
	USE IN (SELECT('commandes'))
ENDPROC && viz_date_comenzi