*!* 12.06.2014
*!* marius.mutu
*!* listeaza_bon_fiscal, listeaza_bon_fiscal_det - adaugat suma achitata prin CARD POS. suma achitata anterior se considera numerar

*!* 24.08.2015
*!* marius.mutu
*!*	normare_comanda - vizualizare doar comenzi active (nearhivate)

*!*	31.08.2015
*!*	marius.mutu
*!*	generare_com, factureaza_comanda - salvare id partener care a referit comanda

*!* 27.01.2016
*!* marius.mutu
*!* factureaza_deviz - stornare avans se preiau proc_tvav si id_jtva_coloana din avansurile anterioare, in loc de cele standard din luna curenta

*!* 29.01.2016
*!* marius.mutu
*!* factureaza_deviz - listare cumulata articol REPARATII AUTO in loc de MANOPERA si MATERIALE

*!* 23.11.2017
*!* marius.mutu
*!* factureaza_deviz - tratare factura cu valoare 0 materiale si 0 manopera. se inregistreaza in scopul listarii.

*!* 12.04.2021
*!* marius.mutu
*!* generare_com + numarul de zile termen de executie comanda service

*!*	08.07.2024
*!*	marius.mutu
*!*	actualizare listare factura + lot C(20)

*!* 18.10.2024
*!*	marius.mutu
*!*	factureaza_deviz > pack_facturare.initializeaza_date_Factura + poDate.tip_saft

*******************************************
* PROCEDURE generare_com(  )
* Data/ora : 01/05/05, 08:58:28
* autor : liana.macinic
* descriere:

****** PARAMETER BLOCK **************
* Parametri : 0
*
*******************************************
Procedure generare_com()
	Parameters tnTipFactura
	Private pnTipFactura, poGeneratorNumere
	poGeneratorNumere = Createobject('oGeneratorNumere')
	Local lcMesaj, lnTermenZile
	
	If Empty(tnTipFactura)
		pnTipFactura=0			&& 0 - daca vine din meniul de generare comenzi, 1 - ITP, 2 - spalare auto, 3 - diverse
		lcMesaj="Nu puteti genera comenzi,deoarece aceasta luna este inchisa!"
	Else
		pnTipFactura=tnTipFactura
		lcMesaj="Nu puteti emite facturi,deoarece aceasta luna este inchisa!"
	Endif

	If glLunaInchisa
		amessagebox(lcMesaj,0+48,"Luna inchisa")
		Return
	Endif

	Private pntipcom,pnNrCom
	pntipcom = 1

	If pnTipFactura=0
		ofrmtipcom = Createobject('frm_alegtipcom',@pntipcom)
		*!*	ofrmtipcom.ogtipcom.controlsource = "pntipcom"
		ofrmtipcom.Show(1)

		If buton = 2
			Return
		Endif
	Endif

	*!*	modificare	v 2.0.28
	*!*		lcSql = [select ] + gcS + [.getdev_comanda() as nrcom from dual]
	*!*		lcCursor = [crsNrCom]
	*!*		lnSucces = goExecutor.oExecute(lcSql,lcCursor)
	*!*		If lnSucces < 0
	*!*			amessagebox(goExecutor.cEroare,0+16,"Eroare")
	*!*			Return
	*!*		Endif
	*!*		Select crsNrCom
	*!*		*!*	modificare 31.10
	*!*		Scatter Name ocomlistare
	*!*		*!*
	*!*		pnNrCom = Round(crsNrCom.nrcom,0)
	Private poGeneratorNumere
	poGeneratorNumere = Createobject('oGeneratorNumere')
	ocomlistare = Createobject("Custom")
	lnRezultat = poGeneratorNumere.creeaza_cursor_serii(20)
	pnNrCom = poGeneratorNumere.aloca_numar(20,Null)
	*!*	modificare	v 2.0.28	^
	Do update_asigurator In update_devize.prg
	Do update_inspector In update_devize.prg

	Private ofrmGencom,pcNr,pnIdInsp,pnIdAsig,pnIdMC,pnIdClie,pnIdOrdl,pnid_masina,pnKmInt,pnOreFct,pcNrDosar,pcSirIDOperatiiClient,pcObservatii,pcDefectiuni,pnIdPartRef
	Store '' To pcNr,pcNrDosar,pcSirIDOperatiiClient, pcObservatii,pcDefectiuni
	Store 0 To pnIdInsp,pnIdAsig,pnIdMC,pnIdClie,pnIdOrdl,pnid_masina,pnKmInt,pnOreFct,pdTermen, pnIdPartRef

	lnTermenZile = IIF(TYPE('gnTermenZileService') = 'N', m.gnTermenZileService, 10) && termenul implicit, daca nu exista optiune este de 10 zile
	pdTermen = DATE() + m.lnTermenZile && termenul de pe comanda este data curenta + optiunea TermenZile
		
	pcNr = Alltrim(Str(pnNrCom))
	Do Case
		Case pntipcom = 2
			pcNr = 'G' + Alltrim(Str(pnNrCom))
		Case pntipcom = 3
			pcNr = 'R' + Alltrim(Str(pnNrCom))
		Case pntipcom = 4
			pcNr = 'P' + Alltrim(Str(pnNrCom))
		Case pntipcom = 6
			pcNr = 'PR' + Alltrim(Str(pnNrCom))
		CASE pntipcom = 7
			pcNr = 'C' + Alltrim(Str(pnNrCom))
	Endcase

	Private pniesire
	pniesire=0

	If pnTipFactura=0
		*!* modificare 31.10
		*!*	modificare	v 2.0.9
		=update_norme([1=2])			&&	1=2	> modificare v 2.0.18
		*!*	modificare	v 2.0.9	^
		ofrmGencom = Createobject('frm_gencom',1,@pcNr,@pnIdInsp,@pnIdAsig,@pnIdMC,@pnIdClie,@pnid_masina,@pnKmInt,@pnOreFct,@pdTermen,@pcNrDosar,,,,@pcObservatii,@pcDefectiuni)
		ofrmGencom.Show(1)
		If pniesire!=1
			*!*	modificare	v 2.0.28
			poGeneratorNumere.dezaloca_numar(20)
			Release poGeneratorNumere
			*!*	modificare	v 2.0.28	^
			Return
		Endif
		*!*	modificare	v 2.0.28
		poGeneratorNumere.verifica_numar(20,Val(Substr(pcNr,Iif(pntipcom=6,3,Iif(pntipcom=1,1,2)),At([/],pcNr,1)-Iif(pntipcom=6,3,Iif(pntipcom=1,1,2)))))
		Release poGeneratorNumere
		*!*	modificare	v 2.0.28	^

		pnIdOrdl = 0
		lcTermen = Iif(Empty(pdTermen) Or Isnull(pdTermen),'NULL',[']+Dtoc(pdTermen)+['])

		lcSql = [begin pack_auto.dev_adauga_lucrare(?gcS,?gnAn,?gnLuna,?gnIdUtil,?pcNr,?pnIdInsp,] + ;
			[?pnIdAsig,?pcNrDosar,?pnIdMC,?pnKmInt,?pnOreFct, to_date(]+lcTermen+[,'DD/MM/YYYY'),?pntipcom,?pcSirIDOperatiiClient, ?pcObservatii, ?pcDefectiuni, ?pnIdPartRef, ?@pnIdOrdl); end;]
			
		*!*		lcSql = [begin pack_devize.dev_adauga_lucrare('] + gcS +[',] + Alltrim(Str(gnAn)) + [,] + Alltrim(Str(gnLuna))+;
		*!*			[, ]+ Alltrim(Str(gnIdUtil)) + [,'] + Alltrim(pcNr) + [',]+ Alltrim(Str(pnIdInsp)) + [,];
		*!*			+Alltrim(Str(pnIdAsig))+[,]+Alltrim(Str(pnIdMC)) + [,] + Alltrim(Str(pnKmInt)) + [,to_date(];
		*!*			+lcTermen+[,'DD/MM/YYYY'),?pntipcom,?@pnIdOrdl); end;]
		lnSucces = goExecutor.oExecute(lcSql)

		If lnSucces < 0
			amessagebox(goExecutor.cEroare,0+16,'Eroare')
			Return
		Endif
		*!*

		* Do listare_comanda With pntipcom && 22.06.2021
		DO listare_precomanda WITH m.pnIdOrdl

	Else
		*!* modificare 31.10
		*!*	nu se fac verificari ptr. km la bord pentru facturile de itp,de spalare si diverse
		*!*	modificare	v 2.0.9
		=update_norme([1=2])
		*!*	modificare	v 2.0.9	^
		ofrmGencom = Createobject('frm_gencom',2,@pcNr,@pnIdInsp,@pnIdAsig,@pnIdMC,@pnIdClie,@pnid_masina,@pnKmInt,@pnOreFct,@pdTermen,@pcNrDosar,,,,@pcObservatii,@pcDefectiuni)
		With ofrmGencom
			.lverificari=.F.
			.clb_kmint.teXT_SIMPLU1.ReadOnly=.T.
			.clb_termen.teXT_SIMPLU1.ReadOnly=.T.
		Endwith
		ofrmGencom.Show(1)
		If pniesire!=1
			*!*	modificare	v 2.0.28
			poGeneratorNumere.dezaloca_numar(20)
			Release poGeneratorNumere
			*!*	modificare	v 2.0.28	^
			Return
		Endif
		*!*
		*!*	modificare	v 2.0.28
		poGeneratorNumere.verifica_numar(20,Val(Substr(pcNr,Iif(pntipcom=6,3,Iif(pntipcom=1,1,2)),At([/],pcNr,1)-Iif(pntipcom=6,3,Iif(pntipcom=1,1,2)))))
		Do factureaza_comanda With pnTipFactura
		Release poGeneratorNumere
		*!*			Do factureaza_comanda With pnTipFactura
		*!*	modificare	v 2.0.28	^
	Endif
	Release poGeneratorNumere

Endproc

**********************sfarsit procedura generare_com*******************

*******************************************
* PROCEDURE normare_comanda(  )
* Data/ora : 01/10/05, 11:50:13
* autor : liana.macinic
* descriere:

****** PARAMETER BLOCK **************
* Parametri : 0
*
*******************************************
Procedure normare_comanda(  )
	If glLunaInchisa
		amessagebox("Nu puteti norma comenzi,deoarece aceasta luna este inchisa!",0+48,"Luna inchisa")
		Return
	Endif

	Private pcValoare1,pcValoare2,pcIntre,pnCriteriu, pnCriteriu2, pcFiltruOra, pcFiltruVFP
	Private pcselect,pcschema,pcfiltru,pcorder,pocomenzi,llAfiseaza
	Store '' To pocomenzi
	pcValoare1 = ""
	pcValoare2 = ""
	pnCriteriu = 1
	pnCriteriu2 = 1
	pcIntre = ""
	pcFiltruOra = ""
	pcFiltruVFP = ""
	Do Form frm_filtru_text With "nrord","Nr. comanda",pnCriteriu,pnCriteriu2 To pcFiltruOra

	buton=2
	Private poordl,pcschema1,pcselect1
	Store '' To poordl
	*!*	pcschema1=['DATAI d,NRORD c(30),VALIDAT n(1),NUME c(50),NRINMAT c(10),ID_LUCRARE n(10),ID_ORDL n(10)']
	*!*	pcselect1=['select datai,nrord,validat,nume,nrinmat,id_lucrare,id_ordl from ] + gcS + [.dev_vordl where 1=2']
	pcschema1=['']
	pcselect1=['select * from ] + gcS + [.auto_normare_comenzi a where 1=2']
	pcorder1=[datai]
	If !Empty(pcFiltruOra)
		pcFiltru1 = gcCondLuna + [ and a.inchis_fortat = 0 and a.validat=0 ] + pcFiltruOra
	Else
		pcFiltru1 = [1=2]
	Endif
	llAfiseaza = .F.
	gencursor('poordl','cliord',pcselect1,pcFiltru1,pcschema1,pcorder1,llAfiseaza)
	poordl.ca_baza1.afisare()

	ovs=Createobject('FRM_NOM_COM')
	If !Empty(pcFiltruOra)
		ovs.gcliord.SetAll('DynamicFontItalic','IIF(validat=1,.T.,.F.)','Column')
		ovs.gcliord.SetAll('DynamicForeColor','IIF(validat=1,RGB(128,128,128),RGB(0,0,0))','Column')
		*!*	modificare	v 2.0.17
		With ovs.ck_nrord
			.cValoare1 = pcValoare1
			.cValoare2 = pcValoare2
			.criteriu = pnCriteriu
			.criteriu2 = pnCriteriu2
			.cIntre = pcIntre
			.filtru = pcFiltruOra
			.filtru_vfp = pcFiltruVFP
			.Value = 1
		Endwith
		*!*	modificare	v 2.0.17	^
	Endif
	ovs.Show(1)

Endproc
**********************sfarsit procedura normare_comanda*******************
*******************************************
* PROCEDURE dec2rgb(  )
* Data/ora : 02/11/05, 16:29:34
* autor : liana.macinic
* descriere:

****** PARAMETER BLOCK **************
* Parametri : 0
*
*******************************************
Procedure dec2rgb
	Lparameters lnValue

	lTalk=Iif(Set('TALK')='ON',.T.,.F.)
	Set Talk Off

	* Determine the hexadecimal equivalent of the decimal parameter passed
	lcHex = ""
	lnFactor = 24          && set up factor value one exponent greater than used

	For lnPos = 6 To 1 Step -1
		lnFactor = lnFactor - 4     && decrement factorial
		lnExp = 2 ^ lnFactor        && extrapolate next least power of two
		For lnOrd = 15 To 1 Step -1
			If lnValue < lnExp            && no value greater than current one,
				lcHex = lcHex + "0"    && so store a zero in this position
				Exit                   && go back for the next value
			Endif
			If lnValue >= lnExp * lnOrd  && is value greater than or equal to?
				* find the matching hex value from its ordinal position
				lcHex = lcHex + Substr('123456789ABCDEF', lnOrd, 1)
				Exit
			Endif
		Endfor
		lnValue = lnValue % lnExp     && leave remainder of exponential division
	Endfor

	* reverse the order of the individual color indicators
	lcHex = Right(lcHex, 2) + Substr(lcHex, 3, 2) + Left(lcHex, 2)

	* convert the pairs into decimal values
	lnPick = 2          && offset to determine which pair to convert
	lcRGB = ""     && start of string delineator

	* parse each color indicator and convert to decimal
	For lnColor = 1 To 3
		lcHue = Substr(lcHex, (lnPick * lnColor) - 1, 2) && pull out color
		lnMSB = Asc(Left(lcHue, 1))     && "Most Significant Bit"
		lnLSB = Asc(Right(lcHue, 1))     && "Least Significant Bit"

		* subtract appropriate value from each to get decimal equivalent
		lnMSB = lnMSB - Iif(lnMSB > 57, 55, 48)
		lnLSB = lnLSB - Iif(lnLSB > 57, 55, 48)

		* then add decimals together
		lcRGB = lcRGB + Transform( lnMSB * 16 + lnLSB, '999') + ", "
	Endfor
	lcRGB = Left(lcRGB, Len(lcRGB) - 2)
	Return Alltrim(lcRGB)

Endproc

**********************sfarsit procedura dec2rgb*******************


*------------------------------inceput procedura calc_analitic-----------------------------------------
* PROCEDURE calc_analitic( tcCont, pcAct,  )
* Data : 03/15/05, 14:52:49
* autor : liana.macinic
* descriere:

****** PARAMETER BLOCK **************
* Parameters : 3
* Parameter 1:
* Parameter 2: pcRul
* Parameter 3:
*
*******************************************
Procedure calc_analitic
	Parameters tcCont,pcAct,pcRul

	Private pcCont,pcAct,pcRul,pParamP,pParamS
	Store 0 To pParamP,pParamS

	lcAlias = Alias()

	pcCont = Alltrim(tcCont)

	lcSel = [SELECT * from ] + gcS + [.config_analitice WHERE cont = ?pcCont]
	lcCursor = 'crs_cfg_ana'
	lnSucces = goExecutor.oExecute(lcSel,lcCursor)
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,"Eroare")
	Endif

	If lnSucces > 0
		If Reccount('crs_cfg_ana')=0
			Use In crs_cfg_ana
			lnSucces = -1
		Endif
	Endif

	If lnSucces > 0
		Select crs_cfg_ana
		Scatter Name ocfg
		lcCampPrefix = Nvl(Alltrim(ocfg.camp_leg_prefix),'')
		lcCampSufix = Nvl(Alltrim(ocfg.camp_leg_sufix),'')


		If !Empty(lcCampPrefix)
			If Type('&pcRul..'+lcCampPrefix) # 'U'
				pParamP = &pcRul..&lcCampPrefix
			Else
				If Type('&pcAct..'+lcCampPrefix) # 'U'
					pParamP = &pcAct..&lcCampPrefix
				Endif
			Endif
		Endif


		If !Empty(lcCampSufix)
			If Type('&pcRul..'+lcCampSufix) # 'U'
				pParamS = &pcRul..&lcCampSufix
			Else
				If Type('&pcAct..'+lcCampSufix) # 'U'
					pParamS = &pcAct..&lcCampSufix
				Endif
			Endif
		Endif

		lcSel = [{call fconturi_analitice(?gcs,?pcCont,0,?pParamP,?pParamS)}]
		lcCursor = 'crs_analitice'
		lnSucces = goExecutor.oExecute(lcSel,lcCursor)

		If lnSucces < 0
			amessagebox(goExecutor.cEroare,0+16,"Eroare")
		Endif

	Endif

	&& iau Primul Simbol Analitic din Tabel - ordonat pt ca e selectat cu Distinct
	If lnSucces > 0
		Select crs_analitice
		Go Top
		lcAnalitic = Alltrim(Left(acont,4))
	Endif

	&& verificare analiticului cu Planul de Conturi
	If lnSucces > 0
		lcSel = [SELECT cont,acont from ] + gcS + [.vplcont_analitic WHERE cont = ?pcCont and acont = ?lcAnalitic and an = ?gnAn ]
		lcCursor = 'crs_verific'
		lnSucces = goExecutor.oExecute(lcSel,lcCursor)
		If lnSucces < 0
			amessagebox(goExecutor.cEroare,0+16,"Eroare")
		Endif
	Endif

	If lnSucces > 0
		If Reccount('crs_verific')=0
			lnSucces = -1
		Endif
	Endif

	If Used('crs_cfg_ana')
		Use In crs_cfg_ana
	Endif
	If Used('crs_verific')
		Use In crs_verific
	Endif
	If Used('crs_analitice')
		Use In crs_analitice
	Endif
	If Used('crs_verific')
		Use In crs_verific
	Endif

	If lnSucces < 0
		lcAnalitic = ''
	Endif

	Select (lcAlias)
	Return lcAnalitic



Endproc
*------------------------------sfarsit procedura calc_analitic-----------------------------------------

*------------------------------inceput procedura factureaza_deviz -----------------------------------------
* PROCEDURE factureaza_deviz(  )
* Data : 03/16/05, 14:07:08
* autor : liana.macinic
* descriere: facturare

****** PARAMETER BLOCK **************
* Parameters : 0
*
*******************************************
Procedure factureaza_comanda
	Lparameters tnTipFactura
	Local lcTip,lnIdSet,lnTipFactura,lnTipListare
	Local ofrmincasare As 'frm_incasare_avans'
	Local ofrmnormsect As 'frm_aleg_operatie'
	Local lcSql, lcTermen, lcTipJ, llTaxareInversa, lnLungime, lnProcTVA, lnSucces, loJtva
	*:Global oCautare, oactan, ocomanda, oincasare, otva, pnid_norme, pnore, pntimpn, poactan
	*:Global taValori[1], x

	Private pnid_norma,pnid_sectie,pcsectie,pcdenop,pnProcTva,pnTipIncasare,pnIdJtvaColoana,pnIdTva
	Private pniesire,pnid_mecanic,pcnume,pocomenzi
	Private pcselect,pcschema,pcfiltru,pcorder,llAfiseaza
	Private pnIdOrdl
	Store "" To oCautare,pocomenzi
	Store 1 To pnTipIncasare
	lnTipFactura=tnTipFactura
	pnProcTva = 0
	pnIdTva = 0
	pnIdJtvaColoana = 0
	optiuni_firma()									&&	reinitializare optiuni firma
	Do Case
		Case lnTipFactura = 1
			lcTip = 'ITP'
			lnIdSet = 31003
			pnid_sectie=Nvl(gnid_sectie_itp,0)
			If Empty(gnid_norme_itp) Or Isnull(gnid_norme_itp)
				pnid_norme=0
				=ccnorme()
			Else
				pnid_norme=gnid_norme_itp
				=ccnorme('NORMA',pnid_norme)
			Endif
		Case lnTipFactura = 2
			lcTip = 'SPALARE AUTO'
			lnIdSet = 31004
			pnid_sectie=Nvl(gnid_sectie_spalare,0)
			If Empty(gnid_norme_spalare) Or Isnull(gnid_norme_spalare)
				pnid_norme=0
				=ccnorme()
			Else
				pnid_norme=gnid_norme_spalare
				=ccnorme('NORMA',pnid_norme)
			Endif
		Case lnTipFactura = 3
			lcTip = 'DIVERSE'
			lnIdSet = 31005
			pnid_sectie=0
			pnid_norme=0
			=ccnorme()
	Endcase
	pcdenop=""
	pnid_mecanic=0
	pcsectie=""
	pntimpn=1
	pnore=1
	Do ccsectii In update_devize.prg
	=ccmecanici()
	*!*		If lnTipFactura = 1
	*!*			pnid_norma = gnId_itp
	*!*			ofrmnormsect=Createobject('frm_aleg_sectie')
	*!*			ofrmnormsect.Show(1)
	*!*		Else
	******************************************
	&&	alegere denumire operatie + sectie + mecanic + timpn + ore
	pniesire=0
	ofrmnormsect=Createobject('frm_aleg_operatie')
	ofrmnormsect.Show(1)
	*!*				pnid_norma = gnid_spalare
	*!*				ofrmnormsect=Createobject('frm_aleg_sectie')
	*!*				ofrmnormsect.Show(1)
	*!*			Else

	*!*			Endif
	If pniesire !=1
		Return
	Endif
	******************************************
	******************************************
	*!* 27.07.2007
	*!* marius.mutu
	*!*	lnNumarFactura = aloca_numar_fact()

	&&	adaugare lucrare
	SQLSetprop(gnHandle,"Transactions",2)
	pnIdOrdl = 0
	*!*	modificare	v 2.0.14
	*!*	lcSql = [begin pack_devize.dev_adauga_lucrare(?gcS,?gnAn,?gnLuna,?gnIdUtil,?pcNr,?pnIdInsp,] + ;
	*!*		[?pnIdAsig,?pcNrDosar,?pnIdMC,?pnKmInt,to_date(NULL,'DD/MM/YYYY'),?pntipcom,?@pnIdOrdl); end;]
	lcTermen = Iif(Empty(pdTermen) Or Isnull(pdTermen),'NULL',[']+Dtoc(pdTermen)+['])
	lcSql = [begin pack_auto.dev_adauga_lucrare(?gcS,?gnAn,?gnLuna,?gnIdUtil,?pcNr,?pnIdInsp,] + ;
		[?pnIdAsig,?pcNrDosar,?pnIdMC,?pnKmInt,?pnOreFct,to_date(]+lcTermen+[,'DD/MM/YYYY'),?pntipcom,?pcSirIDOperatiiClient, ?pcObservatii, ?pcDefectiuni, ?pnIdPartRef, ?@pnIdOrdl); end;]
	*!*	modificare	v 2.0.14	^
	lnSucces = goExecutor.oExecute(lcSql)

	If lnSucces < 0
		Sqlrollback(gnHandle)
		SQLSetprop(gnHandle,"Transactions",1)
		amessagebox(goExecutor.cEroare,0+16,'Eroare')
		Return
	Endif

	******************************************

	******************************************
	If Used('crscomenzi')
		Use In crsComenzi
	Endif
	pcschema=[''] 
	pcselect=['select * from ] + gcS + [.auto_ordl_facturare where 1=2']
	pcfiltru = [ id_ordl = ] + Alltrim(Str(pnIdOrdl))
	pcorder=[datai,nrord]
	llAfiseaza=.F.
	gencursor('pocomenzi','crscomenzi',pcselect,pcfiltru,pcschema,pcorder,llAfiseaza)
	pocomenzi.ca_baza1.afisare()
	Select crsComenzi
	Scatter Name ocomanda
	Use In crsComenzi
	******************************************

	******************************************
	&&	date factura
	lnLungime=4
	Dimension taValori[lnLungime,3]
	taValori[1,1]="poAct.v4111"
	taValori[1,2]=Alltrim(ocomanda.nume)
	taValori[1,3]=.T.
	taValori[2,1]="poAct.nrord"
	taValori[2,2]=Alltrim(ocomanda.nrord)
	taValori[2,3]=.T.
	taValori[3,1]="poAct.id_lucrare"
	taValori[3,2]=Alltrim(Str(ocomanda.id_lucrare))
	taValori[3,3]=.T.
	taValori[4,1]="poAct.id_vv4111"
	taValori[4,2]=Alltrim(Str(ocomanda.id_partener))
	taValori[4,3]=.T.

	*!*	taValori[5,1]="poAct.nract"
	*!*	taValori[5,2]=Alltrim(Str(lnNumarFactura))
	*!*	taValori[5,3]=.F.

	If !Empty(pnid_sectie)
		Dimension taValori[lnLungime+2,3]
		taValori[lnLungime+1,1]="poAct.id_sectie"
		taValori[lnLungime+1,2]=Alltrim(Str(pnid_sectie))
		taValori[lnLungime+1,3]=.T.
		taValori[lnLungime+2,1]="poAct.sectie"
		taValori[lnLungime+2,2]=Alltrim(pcsectie)
		taValori[lnLungime+2,3]=.T.
		lnLungime = lnLungime+2
	Endif

	Dimension taValori[lnLungime+2,3]
	taValori[lnLungime+1,1]="poAct.id_fdoc"
	*!*	modificare	v 2.0.28
	*!*	taValori[lnLungime+1,2]=Alltrim(Str(gnid_fdoc_factura))
	taValori[lnLungime+1,2] = Iif(Empty(Nvl(pnIdAsig,0)),Alltrim(Str(gnid_fdoc_fact)),Alltrim(Str(gnid_fdoc_factasig)))
	*!*	modificare	v 2.0.28	^
	taValori[lnLungime+1,3]=.T.
	taValori[lnLungime+2,1]="poAct.fdoc"
	taValori[lnLungime+2,2]='FACTURA'
	taValori[lnLungime+2,3]=.T.
	lnLungime=lnLungime+2

	lans(lnIdSet,.F.,.T.,@taValori)

	If buton=2
		Do deschid_actc
		Sqlrollback(gnHandle)
		SQLSetprop(gnHandle,"Transactions",1)
		*!*		Do dezaloca_numar_fact In oserii_numere.prg
		poGeneratorNumere.dezaloca_numere()
		Return
	Endif

	*!*	SELECT actactan
	*!*	GO TOP
	*!*	lnNumarFacturaAct = nract
	*!*	IF lnNumarFacturaAct <> lnNumarFactura
	*!*		DO dezaloca_numar_fact In oserii_numere.prg
	*!*	ENDIF
	******************************************


	******************************************
	&&	introducere suma factura + incasare
	Use In (SELECT('v_nom_casa'))
	lcSql=[select id_part,nume from vcoresp_tip_part where tip_partener IN ('BANCA LEI', 'CASA LEI')]
	lnSucces=goExecutor.oExecute(lcSql,'v_nom_casa')
	If lnSucces < 0
		Sqlrollback(gnHandle)
		SQLSetprop(gnHandle,"Transactions",1)
		*!*		Do dezaloca_numar_fact In oserii_numere.prg
		poGeneratorNumere.dezaloca_numere()
		amessagebox(goExecutor.cEroare,0+16,'Eroare')
		Return
	Endif
	
	local lnTvaIncasare, lcContTVA
	Select actactan
	Calculate Max(tva_incasare) To lnTvaIncasare && 0/1

	lnProcTVA = GetProcTvaStandard() && 21
	lcTipJ = "JV"
	llTaxareInversa = .F.
		
	pnIdJtvaColoana = ProcentTva2IdJtva(m.lnProcTVA, m.lcTipJ, m.llTaxareInversa, m.lnTvaIncasare)
	loJtva = GeJtvaColoana(m.pnIdJtvaColoana, m.lnTVAIncasare, m.lcTipJ)
	pnIdTva = loJtva.id_tva
	pnProcTva = 1 + m.lnProcTVA / 100
		
	lcContTVA = IIF(lnTvaIncasare = 1, [4428], [4427])

	Private pnTotalfTva,pnTotalTva,pnTotalcTva,pnNrChit,pnIdCasa,pcCasa, pcSerieChit,pnPretCuTva, pnPOS
	Store 0 To pnTotalfTva,pnTotalTva,pnTotalcTva,pnIdCasa,pnNrChit,pnPretCuTva, pnPOS
	Store [] To pcSerieChit, pcCasa		&&	modificare	v 2.0.28
	pniesire=1
	*!*	modificare	v 2.0.42	:	IIF(lnTipFactura=3,1,2) in loc de 1
	ofrmincasare=Createobject('frm_incasare_avans',lnTvaIncasare,IIF(lnTipFactura=3,1,2))
	ofrmincasare.lb_titlu_alb_b121.Caption=Upper(Alltrim("FACTURA "+lcTip))
	ofrmincasare.Show(1)
	If pniesire!=1
		Sqlrollback(gnHandle)
		SQLSetprop(gnHandle,"Transactions",1)
		*!*		Do dezaloca_numar_fact In oserii_numere.prg
		poGeneratorNumere.dezaloca_numere()
		Return
	Endif
	Use In v_nom_casa
	******************************************

	Select actactan
	Replace suma With pnTotalfTva,explicatia With "MANOPERA "+lcTip,id_jtva_coloana With pnIdJtvaColoana,proc_tva With pnProcTva For Alltrim(scc)='704' Or Alltrim(scc)='419'
	Replace suma With pnTotalTva,explicatia With "TVA MANOPERA "+lcTip,id_sectie With pnid_sectie,sectie With pcsectie,id_jtva_coloana With pnIdTva,proc_tva With pnProcTva For scc=lcContTVA
	*!*	Replace proc_tva With m.ctvam,explicatia With "MANOPERA "+lcTip For Alltrim(scd)='411'
	*!*	modificare	v 2.1.0 : am adaugat Alltrim(scd) = lcContTva
	Replace proc_tva With pnProcTva For Alltrim(scd)='4111' or alltrim(scd) = lcContTva

	If pnTipIncasare>1
		*!*	If !Empty(pnNrChit)
		*!* incasare = 5311
		Select actactan
		Go Top
		Scatter Name oactan
		Append Blank
		Gather Name oactan Fields Except id_jtva_coloana,proc_tva	&& Fields Except suma, ascc, scc, id_partc
		Replace nr_nota With Recno(),partc With partd, id_partc With id_partd, suma With pnTotalcTva
		Replace scc With Alltrim(scd), ascc With ascd, scd With '5311', ascd With '', perecheC With nract,nract With pnNrChit
		Replace id_partd With pnIdCasa,partd With m.pcCasa,neimpozab With 0, explicatia With 'INCASARE '+lcTip, id_factd With id_fact, datascad With {}
		Do Case
			Case pnTipIncasare=2
				Replace id_fdoc With gnid_fdoc_bonfiscal,fdoc With 'BON FISCAL'
			Case pnTipIncasare=3
				Replace id_fdoc With gnid_fdoc_chitanta,fdoc With 'CHITANTA'	&&	modificare v 2.0.29 : am inlocuit gnid_fdoc_incasare
		Endcase
		*!*	modificare	v 2.1.0
		If lnTvaIncasare = 1
			local lnTotalTvaNeex
			Select actactan
			calculate sum(suma) for scc = lcContTva to lnTotalTvaNeex
			Locate For scc = lcContTVA
			If Found()
				Scatter Name otva
				Locate For scd = '5311'
				If Found()
					Scatter Name oincasare
					Append Blank
					Gather Name oincasare Fields Except id_partc,id_partd,partc,partd,scc,scd,id_fact,pereched,perechec,id_jtva_coloana,suma
					Replace suma with lnTotalTvaNeex,scd With '4428',scc With '4427',id_fact With -5,;
						perechec With otva.nract,id_jtva_coloana With getIdTva(pnIdTva,0),proc_tva with otva.proc_tva
				Endif
			Endif
			release lnTotalTvaNeex
		Endif
		*!*	modificare	v 2.1.0	^	

		IF m.pnTipIncasare = 2 AND m.pnPOS = 1 
			SELECT actactan
			Locate For scd = '5311'
			If Found()		
				REPLACE explicatia4 WITH partd && numele bancii
				REPLACE scd WITH '5125', id_partd WITH id_partc, partd WITH partc
			ENDIF 
		ENDIF 		
	Endif

	Select actactan
	Scan
		Scatter Name poactan
		If Type('poActan.cont') = 'U'
			x = AddProperty(poactan,'cont',poactan.scc)
		Endif
		poactan.ascc = calc_analitic(poactan.scc,'poActan','poActan')
		Select actactan
		Replace ascc With poactan.ascc

		Release poactan
		Select actactan
		Scatter Name poactan
		If Type('poActan.cont') = 'U'
			x = AddProperty(poactan,'cont',poactan.scd)
		Endif
		poactan.ascd = calc_analitic(poactan.scd,'poActan','poActan')
		Select actactan
		Replace ascd With poactan.ascd
	Endscan

	******************************************
	*!*	modificare 09.07
	*!*	AddProperty(ocomanda,'delegat','')
	*!*	AddProperty(ocomanda,'eliberatde','')
	*!*	AddProperty(ocomanda,'bi','')
	*!*	AddProperty(ocomanda,'nrinmat_exp',ocomanda.nrinmat)
	*!*	ofrmdelegat=Createobject("frm_delegat_factura")
	*!*	ofrmdelegat.nidpartener=ocomanda.id_partener
	*!*	ofrmdelegat.cclient=ocomanda.nume
	*!*	ofrmdelegat.cnrinmat_exp=ocomanda.nrinmat_exp
	*!*	ofrmdelegat.Show(1)
	******************************************

	Private buton
	buton=1
	Select actactan
	Replace all tva_incasare with lnTvaIncasare	&&	modificare	v 2.1.0
	Go Top
	*!*	modificare v 2.0.17
	*!*	Do Form verificare With .T.
	If !verificare_note_contabile('actactan', .T.,.T., .F.)
		Do Form verificare With .T.
	Endif
	*!*	modificare v 2.0.17	^
	If buton=2
		Sqlrollback(gnHandle)
		SQLSetprop(gnHandle,"Transactions",1)
		*!*		Do dezaloca_numar_fact In oserii_numere.prg
		poGeneratorNumere.dezaloca_numere()
		Return
	Endif

	lcSql = [begin pack_auto.dev_adauga_oper_fact(?gcS,?pnIdOrdl,?pnid_sectie,?pnid_norme,?pnTotalFTva,?pntimpn,?pnore,]+;
		[?gnIdUtil,?pnid_mecanic); end;]
	lnSucces = goExecutor.oExecute(lcSql)
	If lnSucces < 0
		Sqlrollback(gnHandle)
		SQLSetprop(gnHandle,"Transactions",1)
		*!*		Do dezaloca_numar_fact In oserii_numere.prg
		poGeneratorNumere.dezaloca_numere()
		amessagebox(goExecutor.cEroare,0+16,'Eroare')
		Return
	Endif

	*!*	modificare	v 2.0.28
	*!*		Select actactan
	*!*		Do oscrie_in_fisiere
	*!*		*!*	Sqlrollback(gnHandle)
	*!*		Sqlcommit(gnHandle)
	*!*		SQLSetprop(gnHandle,"Transactions",1)
	*!*		amessagebox("Factura a fost inregistrata!",0+64,"Confirmare facturare")
	*!*	modificare	v 2.0.28	^
	******************************************
	&&	listari
	*!*	DO listare_precomanda WITH pnIdOrdl
	*!*	modificare	v 2.0.28
	*!*		Do listare_FACTURA With ocomanda.id_partener,'actactan',ocomanda.nrord,ocomanda.nrinmat,Iif(lnTipFactura=2,lnTipFactura,3),0,0,0,0,0,0,pcdenop,lnTipFactura In oproceduri_listari
*!*	modificare	v 2.0.35
*!*		If factureaza_deviz(ocomanda.id_lucrare,ocomanda.nrord,ocomanda.nrinmat,pcdenop)
	*!*	modificare	v 2.0.41	:	am adaugat Alltrim(Str(ocomanda.id_lucrare))
	If factureaza_deviz(ocomanda.id_lucrare,ocomanda.nrord,ocomanda.nrinmat,pcdenop,,,,,,,ALLTRIM(STR(pnIdOrdl)),Alltrim(Str(ocomanda.id_lucrare)))
*!*	modificare	v 2.0.35	^
		Sqlcommit(gnHandle)
	Else
		poGeneratorNumere.dezaloca_numere()
		Sqlrollback(gnHandle)
	Endif
	SQLSetprop(gnHandle,"Transactions",1)
	*!*	modificare	v 2.0.28	^
	Release ocomanda
	*!*	toClient : id-ul de client
	*!*	tcCursor : Alias'ul cursorului
	*!*	tnTipfact : 1 - finala, 2 - spalare , 3 - restul
	*!*	tnProcDiscM,tnProcDiscN,tnProcDiscM,tnDiscountN,tnDiscountM,tnDiscountTvaM,tnDiscountTvaN,tcdenop
Endproc
*------------------------------sfarsit procedura factureaza-----------------------------------------
******************************************************************************************************************************
Procedure factureaza_deviz
	Lparameters tnIdComanda,tcNrOrd,tcNrInmat,tcDenop,tnMultiple,tnDiscountM,tnDiscountN,tnProcDiscM,tnProcDiscN,tnIdOrdl,tcSirIdOrdl,tcSirIdLucrare,tnPretCuTva
	*!*	Parameters tnIdClient,tcCursor,tcSirNrord,tcNrInmat,tnTipfact,tnProcDiscM,tnProcDiscN,tnDiscountM,tnDiscountN,tnDiscountTvaM,tnDiscountTvaN,tcdenop,tnTipFactura
	Local lnProcTvav,lnIdJTvaColoana,lnIdSet,llScris,ltDataOra,lnPretCuTva
	LOCAL llArticolCumulat, llFacturaZero, lnTaxCode
	lnProcTvav = 0
	lnIdJTvaColoana = Null
	lnTaxCode = NULL
	lnIdSet = 0
	lnDiscountM = Iif(Empty(tnDiscountM),0,tnDiscountM)
	lnDiscountN = Iif(Empty(tnDiscountN),0,tnDiscountN)
	lnProcDiscM = Iif(Empty(tnProcDiscM),0,tnProcDiscM)
	lnProcDiscN = Iif(Empty(tnProcDiscN),0,tnProcDiscN)
	lnMultiple = Iif(Empty(tnMultiple),0,tnMultiple)
	lcDenop = Iif(Empty(tcDenop),[],Alltrim(Upper(tcDenop)))
	lnPretCuTva = IIF(EMPTY(tnPretCuTva),0,tnPretCuTva)			&&	modificare	v 2.0.41
	lcCursorDeviz = [crsdeviz]										&&	modificare	v 2.0.41
	llFacturaZero = .F.
	
	If Used('crsvanztemp')
		Use In crsvanztemp
	Endif
	If Used('crsfactura')
		Use In crsfactura
	Endif
	If Used(lcCursorDeviz)
		Use In (lcCursorDeviz)
	Endif

	creeaza_facturacrs([crsfactura])
*!*	modificare	v 2.0.41
*!*		Create Cursor (lcCursorDeviz)(denumire c(100),explicatie c(240),cante N(20,4),pretv N(20,4),proc_tvav N(7,3),discunitar N(20,4),id_jtva_coloana N(10),;
*!*			pretvval N(20,4),id_articol N(10),um c(10) Null,serie c(10) Null Default Null,codmat c(50) Null Default Null,Pret N(7,3),pretd N(7,3),;
*!*			id_valuta N(10) Null Default Null)
	CREATE CURSOR (lcCursorDeviz)(id_vanzare_det n(10) DEFAULT RECNO(),id_articol N(10),explicatie c(240),denumire c(100),;
		lot C(20) NULL DEFAULT null, serie c(10) NULL DEFAULT null,codmatf c(50) NULL DEFAULT null,codmat c(50) NULL DEFAULT null,;
		codbare c(50) NULL DEFAULT null,id_jtva_coloana N(10),ID_JTVA_COLOANA_EX N(10) null,taxcode N(6) null, pret_achizitie N(20,4) DEFAULT 0,cantitate N(20,4),;
		proc_Tvav N(7,3),um c(10) null,pret_cu_tva N(1) DEFAULT 0,pret N(20,4),;
		pret_val N(20,4) DEFAULT 0,discount_unitar N(20,4),discount_unitar_val N(20,4) DEFAULT 0,;
		id_vanzare_set N(10) NULL DEFAULT null,id_gestiune N(10) NULL DEFAULT null,id_ctr N(20) NULL DEFAULT null,;
		numar_contract c(10) NULL DEFAULT null,id_valuta N(10) DEFAULT 0,tip_valuta N(1) DEFAULT 0,;
		CURS N(10,4) DEFAULT 0,multiplicator n(1) DEFAULT 1,nume_val c(50) DEFAULT " ")
*!*	modificare	v 2.0.41	^

	Select actactan
	Locate For proc_tva <> 0
	If Found()
		lnProcTvav = proc_tva
		lnIdJTvaColoana = id_jtva_coloana
		lnTaxCode = taxcode
	ENDIF

	* Verific daca factura are toate sumele 0. Daca are toate sumele 0, inregistrez totusi factura in vanzari, in scopul listarii.
	Select actactan	
	LOCATE FOR suma <> 0
	llFacturaZero = !FOUND()

	Sum suma For Alltrim(scd) = '4111' And Alltrim(scc) = '707' And Left(Alltrim(explicatia),3) = "MAT" To lnMaterialeFTva
	Sum suma For Alltrim(scd) = '4111' And Alltrim(scc) = '704' And Left(Alltrim(explicatia),3) = "MAN" To lnManoperaFTva
	Sum suma For Alltrim(explicatia)='STORNARE AVANS' And !Inlist(Alltrim(scc),'4427','4428') To lnStornareAvansFTva
	Sum suma For Alltrim(scd) = '4111' And Alltrim(scc) = Iif(gnAvans419=1,[419],[707]) And Like([AVANS*],Upper(Alltrim(explicatia))) To lnAvansFTva
	*!*	modificare	v 2.0.41
	Sum suma For Alltrim(scd) = '4111' And Like([AVANS*],Upper(Alltrim(explicatia))) To lnAvansCTva
	Sum suma For Alltrim(scd) = '4111' AND (Left(Alltrim(explicatia),3) = "MAT" OR Left(Alltrim(explicatia),7) = "TVA MAT") To lnMaterialeCTva
	*!*	modificare	v 2.1.12 : am pus (-1)*SIGN(...)*ABS(suma) in loc de suma
	SUM (-1)*SIGN(lnMaterialeFTVA)*ABS(suma) FOR LEFT(ALLTRIM(explicatia),12) = "DISCOUNT MAT" TO lnDiscountNCTva
	SUM (-1)*SIGN(lnManoperaFTva)*ABS(suma) FOR LEFT(ALLTRIM(explicatia),12) = "DISCOUNT MAN" TO lnDiscountMCTva	
	*!*	modificare	v 2.0.41	^
	*!*	modificare	v 2.0.42
	Sum suma For Alltrim(scd) = '4111' And (Left(Alltrim(explicatia),3) = "MAN" OR Left(Alltrim(explicatia),7) = "TVA MAN") To lnManoperaCTva
	*!*	modificare	v 2.0.42	^
	Locate For id_set <> 0
	If Found()
		lnIdSet = id_set
	Endif
	Private poDate
	poDate = Createobject("oDateFactura",lnIdSet,-12)
	*!*	modificare	ROAAUTO v 2.1.0 : tva_incasare
	Select Distinct dataireg,id_fdoc,dataact,datascad,serie_act,nract,id_partd As id_part,nume_val,id_valuta,id_lucrare,tva_incasare ;
		From actactan ;
		WHERE Alltrim(scd) = '4111' ;
		Into Cursor crstemp

*!*	modificare	v 2.0.41
*!*		If lnAvansFTva <> 0
*!*			Insert Into crsdeviz(denumire,cante,pretv,proc_tvav,discunitar,id_jtva_coloana,pretvval,id_articol,Pret,pretd) ;
*!*				values("AVANS",1,lnAvansFTva,lnProcTvav,0,lnIdJTvaColoana,0,-10002,0,0)
	IF (lnAvansFTva<>0 AND lnPretCuTva = 0) OR (lnAvansCTva<>0 AND lnPretCuTva = 1)
*!*			Insert Into (lcCursorDeviz)(denumire,cante,pretv,proc_tvav,discunitar,id_jtva_coloana,pretvval,id_articol,Pret,pretd,cu_tva) ;
*!*				values("AVANS",1,IIF(lnAvansPretCTva=1,lnAvansCTva,lnAvansFTva),lnProcTvav,0,lnIdJTvaColoana,0,-10002,0,0,lnAvansPretCTva)
		Insert Into (lcCursorDeviz)(id_articol,denumire,explicatie,cantitate,um,id_jtva_coloana,proc_Tvav,taxcode,pret,discount_unitar,pret_cu_tva) ;
			values(-100005,"AVANS","",1,"",lnIdJTvaColoana,lnProcTvav,lnTaxCode,IIF(lnPretCuTva=1,lnAvansCTva,lnAvansFTva),0,lnPretCuTva)
*!*	modificare	v 2.0.41	^
	Endif

*!*	modificare	v 2.0.41
*!*		If lnMaterialeFTva <> 0
*!*			Insert Into (lcCursorDeviz)(denumire,cante,pretv,proc_tvav,discunitar,id_jtva_coloana,pretvval,id_articol,Pret,pretd) ;
*!*				values ("MATERIALE",1,lnMaterialeFTva,lnProcTvav,ABS(lnDiscountN),lnIdJTvaColoana,0,-10001,0,0)
	IF (lnMaterialeFTva<>0 AND !glAutoBonDet) OR (lnMaterialeCTva <> 0 AND glAutoBonDet) OR m.llFacturaZero
		*!*	modificare	v 2.1.12 : am pus SIGN(lnMaterialeFTVA) pentru ca discountul trebuie sa aiba acelasi semn ca totalul de la materiale
		Insert Into (lcCursorDeviz)(id_articol,denumire,explicatie,cantitate,um,id_jtva_coloana,proc_Tvav,taxcode,pret,discount_unitar,pret_cu_tva) ;
			values (-100003,"MATERIALE","",1,"",lnIdJTvaColoana,lnProcTvav,lnTaxCode,IIF(glAutoBonDet,lnMaterialeCTva,lnMaterialeFTva),;
				SIGN(lnMaterialeFTva)*IIF(glAutoBonDet,ABS(lnDiscountNCTva),ABS(lnDiscountN)),IIF(glAutoBonDet,1,0))
*!*	modificare	v 2.0.41	^
	Endif

*!*	modificare	v 2.0.42
*!*		If lnManoperaFTva <> 0
*!*	*!*	modificare	v 2.0.41
*!*	*!*			Insert Into (lcCursorDeviz)(denumire,cante,pretv,proc_tvav,discunitar,id_jtva_coloana,pretvval,id_articol,Pret,pretd,explicatie) ;
*!*	*!*				values(Iif(lnIdSet=31003,"INSPECTIE TEHNICA PERIODICA",Iif(lnIdSet=31004,"SPALARE AUTO","MANOPERA")),1,lnManoperaFTva,lnProcTvav,ABS(lnDiscountM),lnIdJTvaColoana,0,Iif(lnIdSet=31003,-10004,Iif(lnIdSet=31004,-10005,-10000)),0,0,Iif(lnIdSet=31005,lcDenop,[]))
*!*			Insert Into (lcCursorDeviz)(id_articol,denumire,explicatie,cantitate,um,id_jtva_coloana,proc_Tvav,pret,discount_unitar) ;
*!*				values(Iif(lnIdSet=31003,-100007,Iif(lnIdSet=31004,-100008,-100000)),;
*!*					Iif(lnIdSet=31003,"INSPECTIE TEHNICA PERIODICA",Iif(lnIdSet=31004,"SPALARE AUTO","MANOPERA")),;
*!*					Iif(lnIdSet=31005,lcDenop,[]),1,"",;
*!*					lnIdJTvaColoana,lnProcTvav,lnManoperaFTva,IIF(glAutoBonDet,0,ABS(lnDiscountM)))
	IF (lnManoperaFTva <> 0 AND !INLIST(lnIdSet,31003,31004)) OR m.llFacturaZero
		*!*	modificare	v 2.1.12 : am pus SIGN(lnManoperaFTva) pentru ca discountul trebuie sa aiba acelasi semn ca totalul de la manopera
		Insert Into (lcCursorDeviz)(id_articol,denumire,explicatie,cantitate,um,id_jtva_coloana,proc_Tvav,taxcode,pret,discount_unitar) ;
			values(-100000,"MANOPERA",Iif(lnIdSet=31005,lcDenop,[]),1,"",;
				lnIdJTvaColoana,lnProcTvav,lnTaxCode,lnManoperaFTva,IIF(glAutoBonDet,0,SIGN(lnManoperaFTva)*ABS(lnDiscountM)))
*!*	modificare	v 2.0.42	^
		If glAutoBonDet AND lnDiscountMCTva <> 0
		*!*	modificare	v 2.1.12 : am pus SIGN(lnManoperaFTva) pentru ca discountul trebuie sa aiba acelasi semn ca totalul de la manopera
			Insert Into (lcCursorDeviz)(id_articol,denumire,explicatie,cantitate,um,id_jtva_coloana,proc_Tvav,taxcode,Pret,pret_cu_tva) ;
				values(-100001,"DISCOUNT MANOPERA","Discount "+ALLTRIM(STR(lnProcDiscM,5,2))+" %",1,"",lnIdJTvaColoana,lnProcTvav,lnTaxCode,(-1)*SIGN(lnManoperaFTva)*Abs(lnDiscountMCTva),1)
		Endif
*!*	modificare	v 2.0.41	^
	Endif

*!*	modificare	v 2.0.42
	If (m.lnManoperaCTva <> 0 And Inlist(lnIdSet,31003,31004))
		Insert Into (lcCursorDeviz)(id_articol,denumire,cantitate,um,id_jtva_coloana,proc_Tvav,taxcode,Pret,pret_cu_tva) ;
			values(Iif(lnIdSet=31003,-100007,-100008),;
			Iif(lnIdSet=31003,"INSPECTIE TEHNICA PERIODICA","SPALARE AUTO"),1,"",;
			lnIdJTvaColoana,lnProcTvav,lnTaxcode,lnManoperaCTva,1)
	Endif
*!*	modificare	v 2.0.42	^

	*** Cumulez MATERIALE + MANOPERA pentru optiunea REPARATII AUTO (in loc de materiale + manopera)
	*** doar in cazul in care nu doresc detaliat materialele pe bonul fiscal si pe factura, fara facturi ITP, spalare auto
	llArticolCumulat = .F.
	IF !m.glAutoBonDet AND !Inlist(lnIdSet,31003,31004) AND TYPE('gnAUTOIdArticolReparatii') = 'N' AND !EMPTY(NVL(m.gnAUTOIdArticolReparatii, 0))
		PRIVATE pcArticolReparatii 
		pcArticolReparatii = ''
		lnSucces = goExecutor.oSelect2Value('select denumire from nom_articole where id_articol = ?gnAUTOIdArticolReparatii',@pcArticolReparatii)
		IF lnSucces < 0
			aMESSAGEBOX(goExecutor.cEroare, 0+48,_screen.Caption)
		ENDIF 
		IF EMPTY(m.pcArticolReparatii)
			pcArticolReparatii = 'REPARATII AUTO'
		ENDIF 			
		SELECT m.gnAUTOIdArticolReparatii as id_articol, m.pcArticolReparatii as denumire, MAX(explicatie) as explicatie, ;
			1 as cantitate, '' as um, id_jtva_coloana, proc_Tvav, taxcode, SUM(pret) as pret, SUM(discount_unitar) as discount_unitar, pret_cu_tva ;
			FROM (lcCursorDeviz) ;
			WHERE INLIST(id_articol,-100003, -100000, -100002, -100001) ;
			GROUP BY id_jtva_coloana, proc_Tvav, taxcode, pret_cu_tva ;
			INTO CURSOR crsArtCumulat
			
		DELETE FROM (lcCursorDeviz) WHERE INLIST(id_articol,-100003, -100000, -100002, -100001)

		Insert Into (lcCursorDeviz)(id_articol,denumire,explicatie,cantitate,um,id_jtva_coloana,proc_Tvav,taxcode, pret,discount_unitar,pret_cu_tva) ;
			SELECT id_articol,denumire,explicatie,cantitate,um,id_jtva_coloana,proc_Tvav,taxcode,pret,discount_unitar,pret_cu_tva ;
				FROM crsArtCumulat
		llArticolCumulat = .T.
		USE IN (SELECT('crsArtCumulat'))		
	ENDIF 
	
	IF lnStornareAvansFTva <> 0
*!*	modificare	v 2.0.41
*!*			Insert Into (lcCursorDeviz)(denumire,cante,pretv,proc_tvav,discunitar,id_jtva_coloana,pretvval,id_articol,Pret,pretd) ;
*!*				values("STORNARE AVANS",1,lnStornareAvansFTva,lnProcTvav,0,lnIdJTvaColoana,0,-10003,0,0)
		Local loStornare
		lcSql = [{call pack_auto.citeste_sume_stornare(']+tcSirIdLucrare+[',',')}]
		lcCursorStornare = [crsstornari]
		If goExecutor.oExecuta(lcSql,lcCursorStornare)
			Select (lcCursorStornare)
			Scan
				Scatter Name loStornare
				Insert Into (lcCursorDeviz)(id_articol,denumire,explicatie,cantitate,um,id_jtva_coloana,proc_Tvav,taxcode,Pret,discount_unitar,pret_cu_tva) ;
					values(-100006,"STORNARE AVANS","",1,"",loStornare.id_jtva_coloana, loStornare.proc_tvav,loStornare.taxcode,loStornare.Pret,0,loStornare.pret_cu_tva)
				Select (lcCursorStornare)
			Endscan
		Endif
		Use In (lcCursorStornare)
		Release loStornare
*!*	modificare	v 2.0.41	^
	Endif

	If Used('crsalteserv')
*!*	modificare	v 2.0.41
*!*			Insert Into (lcCursorDeviz)(denumire,um,cante,pretv,proc_tvav,discunitar,id_jtva_coloana,pretvval,id_articol,Pret,pretd) ;
*!*				Select denumire,um,cantitate,pretftva,lnProcTvav,0,lnIdJTvaColoana,0,id_articol,0,0 From crsalteserv Where !Deleted()
		Insert Into (lcCursorDeviz)(id_articol,denumire,explicatie,cantitate,um,id_jtva_coloana,proc_Tvav,taxcode,pret,discount_unitar) ;
			Select id_articol,denumire,"",cantitate,um,CAST(lnIdJTvaColoana as N(6) null) as id_jtva_coloana,CAST(lnProcTvav as N(7,2) null) as proc_tvav,CAST(lnTaxCode as N(6) null) as taxcode,pretftva,0 From crsalteserv Where !Deleted()
*!*	modificare	v 2.0.41	^
	Endif

	* In xml eFactura nu este permis pret unitar negativ. Cantitate negativa si pret pozitiv
	SELECT (m.lcCursorDeviz)
	SCAN FOR pret < 0
		REPLACE cantitate WITH -cantitate, pret WITH -pret, discount_unitar WITH discount_unitar
	ENDSCAN 
	
	Select crstemp
	poDate.dataireg = dataireg
	poDate.id_fdoc = id_fdoc
	poDate.dataact = dataact
	poDate.datascad = datascad
	poDate.nract = nract
	poDate.serie_act = Alltrim(serie_act)
	poDate.id_client = id_part
	poDate.nume_valuta = nume_val
	poDate.id_valuta = id_valuta
	poDate.id_lucrare = id_lucrare
	poDate.zi_curs = dataact
	poDate.id_ordl = IIF(EMPTY(NVL(tnIdOrdl,0)),NULL,tnIdOrdl)		&&	modificare	v 2.0.33
	poDate.tva_incasare = tva_incasare								&&	modificare	v 2.1.0
	*!*		poDate.id_sectie = id_sectie
	Use In crstemp

	*!*		ofrmdelegat=Createobject("frm_delegat_factura")
	*!*		ofrmdelegat.nidpartener = poDate.id_client
	*!*		ofrmdelegat.cclient = poDate.nume_client
	*!*		ofrmdelegat.cnrinmat_exp = tcNrInmat	&&	poDate.nrinmat_del
	*!*		ofrmdelegat.Show(1)
	*!*		Release ofrmdelegat
	Private ofrmdatesupl
	ltDataOra = Get_Ora()
	
	* Daca initializez vanzari.tip_saft cu cod 751 (factura in scop informativ) in loc de 380 (factura initiala)
	* pentru facturile incasate cu bon fiscal, initializez cu tip 751 ca sa nu apara duplicate in decontul TVA precompletat
	IF TYPE('gnEFactura_tip_saft_bf') = 'N' AND !EMPTY(NVL(m.gnEFactura_tip_saft_bf, 0))
		IF pnTipIncasare = 2 && incasare bon fiscal
			poDate.tip_saft = m.gnEFactura_tip_saft_bf && 751/380
		ENDIF 	
	ENDIF 
	
	poDate.dataora_exp = ltDataOra
	ofrmdatesupl = Createobject("frm_alte_date")
	ofrmdatesupl.Show(1)
	Release ofrmdatesupl
	If gnButon = 2
		lnSucces = -1
		llScris = .F.
	Else
		Select actactan
		Locate For Alltrim(scd) = '5311'
		Do Case
			Case Found() And pnTipIncasare=2 && bon fiscal
				poDate.ntip_incasare = 2
				poDate.nr_incasare = actactan.nract
				poDate.incasat = actactan.suma
			Case Found() And pnTipIncasare=3 && chitanta
				poDate.ntip_incasare = 11
				poDate.nr_incasare = actactan.nract
				poDate.serie_chit = actactan.serie_act
				poDate.incasat = actactan.suma
			Otherwise
				poDate.ntip_incasare = 0
		ENDCASE
		
		SELECT actactan
		LOCATE For Alltrim(scd) = '5125' && efecte de incasat
		IF Found() And m.pnTipIncasare=2 AND m.pnPos = 1 && bon fiscal incasat prin CARD POS
			poDate.ntip_incasare = 2
			poDate.nr_incasare = actactan.nract
			poDate.incasatCARD = actactan.suma
		ENDIF 
		
		*!*	modificare	v 2.0.35 : am adaugat STRTRAN(tcNrOrd,[,],[, ]) in loc de tcNrOrd
		Do Case
*!*	modificare	v 2.0.43
			Case (lnAvansFTva<>0 And lnPretCuTva = 0) Or (lnAvansCTva<>0 And lnPretCuTva = 1) ; 
				OR (lnStornareAvansFTva <> 0 And lnManoperaFTva = 0 And lnMaterialeFTva = 0)
					poDate.text_aditional = [LA ]+Iif(lnMultiple=0,[COMANDA ],[COMENZILE ])+STRTRAN(tcNrOrd,[,],[, ]) + ;
						IIF(!Empty(poDate.text_aditional),Chr(13)+Chr(10)+poDate.text_aditional,[])
*!*	*!*	modificare	v 2.0.41
*!*	*!*				Case lnAvansFTva <> 0
*!*				Case (lnAvansFTva<>0 And lnPretCuTva = 0) Or (lnAvansCTva<>0 And lnPretCuTva = 1)
*!*					Update (lcCursorDeviz) Set explicatie = [LA ]+Iif(lnMultiple=0,[COMANDA ],[COMENZILE ])+STRTRAN(tcNrOrd,[,],[, ]) Where id_articol = -100005
*!*	*!*	modificare	v 2.0.41	^
*!*				Case lnStornareAvansFTva <> 0 And lnManoperaFTva = 0 And lnMaterialeFTva = 0
*!*					Update (lcCursorDeviz) Set explicatie = [LA ]+Iif(lnMultiple=0,[COMANDA ],[COMENZILE ])+STRTRAN(tcNrOrd,[,],[, ]) Where id_articol = -100006
*!*	modificare	v 2.0.43	^
			Otherwise
				Do Case
					Case (!Between(lnIdSet,31003,31005) And lnManoperaFTva <> 0 And lnMaterialeFTva <> 0) OR m.llFacturaZero
						lcExplicatie = [MANOPERA SI MATERIALE ]
					Case !Between(lnIdSet,31003,31005) And lnManoperaFTva <> 0
						lcExplicatie = [MANOPERA ]
					Case !Between(lnIdSet,31003,31005) And lnMaterialeFTva <> 0
						lcExplicatie = [MATERIALE ]
					Otherwise
						lcExplicatie = []
				Endcase
		
				IF m.llArticolCumulat && REPARATII AUTO in loc DE MANOPERA + MATERIALE
					poDate.text_aditional = Iif(lnMultiple=0,[COMANDA/DEVIZ ],[COMENZI/DEVIZE ])+STRTRAN(tcNrOrd,[,],[, ]) + ;
							IIF(!Empty(poDate.text_aditional),Chr(13)+Chr(10)+poDate.text_aditional,[])
				ELSE 
					*!*	modificare	v 2.0.41 : am adaugat Between(lnIdSet,31003,31005)
					If !Empty(lcExplicatie) OR Between(lnIdSet,31003,31005)
						poDate.text_aditional = lcExplicatie + [CF. ]+Iif(lnMultiple=0,[COMENZII/DEVIZULUI ],[COMENZILOR/DEVIZELOR ])+STRTRAN(tcNrOrd,[,],[, ]) + ;
							IIF(!Empty(poDate.text_aditional),Chr(13)+Chr(10)+poDate.text_aditional,[])
					ENDIF						
				ENDIF 		

		Endcase

*!*	modificare	v 2.0.41
*!*			Insert Into ([crsfactura]) (id_temp,id_articol,denumire,explicatie,cantitate,cu_tva,pretftva,pretctva,;
*!*				valftva,valtva,valctva,discountftva,discountctva,valdiscountftva,;
*!*				valdiscounttva, valdiscountctva, valdiminuatftva, valdiminuattva, valdiminuatctva, proc_tvav,id_jtva_coloana,um,;
*!*				vpretftva,vvalftva,vvaltva,vdiscountftva,vvaldiscountftva,vvaldiscounttva,;
*!*				vvaldiminuatftva,vvaldiminuattva,vvaldiminuatctva,gestionabil) ;
*!*				Select Recno() As id_temp,id_articol,denumire,explicatie, 1 As cantitate,cu_tva,;
*!*				Round(pretv,gnPc) As pretftva,;
*!*				Round(pretv,gnPc) + Round(Round(pretv,gnPc) * (proc_tvav-1),gnPc) As pretctva,;
*!*				Round(Round(pretv,gnPc)*cante,gnPc) As valftva,;
*!*				ROUND(Round(pretv*cante,gnPc)*(proc_tvav-1),gnPc) As valtva, ;
*!*				Round(Round(pretv,gnPc)*cante,gnPc) + Round(Round(pretv*cante,gnPc)*(proc_tvav-1),gnPc) As valctva, ;
*!*				ROUND(discunitar,gnPc) As discountftva,;
*!*				ROUND(discunitar,gnPc)+Round(Round(discunitar,gnPc)*(proc_tvav-1),gnPc) As discountctva,;
*!*				Round(Round(discunitar,gnPc)*cante,gnPc) As valdiscountftva, ;
*!*				ROUND(Round(discunitar*cante,gnPc)*(proc_tvav-1),gnPc) As valdiscounttva, ;
*!*				Round(Round(discunitar,gnPc)*cante,gnPc) + Round(Round(discunitar*cante,gnPc)*(proc_tvav-1),gnPc) As valdiscountctva,;
*!*				Round(Round(pretv-discunitar,gnPc)*cante,gnPc) As valdiminuatftva,;
*!*				ROUND(Round((pretv-discunitar)*cante,gnPc)*(proc_tvav-1),gnPc) As valdiminuattva,;
*!*				ROUND(Round(Round(pretv-discunitar,gnPc)*cante,gnPc)*proc_tvav,gnPc) As valdiminuatctva,;
*!*				proc_tvav,id_jtva_coloana, Nvl(um,Space(50)) As um, ;
*!*				Round(pretvval,gnPVal) As vpretftva,;
*!*				ROUND(Round(pretvval,gnPVal)*cante,gnPVal) As vvalftva,;
*!*				ROUND(Round(Round(pretvval,gnPVal)*cante,gnPVal)*(proc_tvav-1),gnPVal) As vvaltva,;
*!*				0 As vdiscountftva,0 As vvaldiscountftva,0 As vvaldiscounttva,;
*!*				Round(Round(pretvval-0,gnPc)*cante,gnPc) As vvaldiminuatftva,;
*!*				ROUND(Round((pretvval-0)*cante,gnPc)*(proc_tvav-1),gnPc) As vvaldiminuattva,;
*!*				ROUND(Round(Round(pretvval-0,gnPc)*cante,gnPc)*proc_tvav,gnPc) As vvaldiminuatctva,;
*!*				0 As gestionabil From (lcCursorDeviz) Where cante <> 0

		prelucreaza_facturacrs(lcCursorDeviz,[crsfactura],lnProcTvav,0,0)
*!*	modificare	v 2.0.41	^

		Create Cursor crsvanztemp(id_articol N(20),explicatie c(240),Pret N(20,4),proc_tvav N(7,3),id_jtva_coloana N(10),taxcode N(6) NULL,cantitate N(20,4),discount_unitar N(20,4),;
			id_gestiune N(20),Cont c(4),pret_cu_tva N(1),serie c(100),id_valuta N(10),codmat c(50),Curs N(20,6),multiplicator N(10),pret_achizitie N(20,4),;
			pretd N(20,4),id_valuta_d N(10))

*!*	modificare	v 2.0.41
*!*			Insert Into crsvanztemp(id_articol,explicatie,Pret,proc_tvav,id_jtva_coloana,cantitate,discount_unitar,pret_cu_tva,;
*!*				serie,codmat,id_valuta,Curs,multiplicator,pret_achizitie,pretd,id_valuta_d) ;
*!*				SELECT id_articol,explicatie,pretv As Pret,proc_tvav,id_jtva_coloana,cante As cantitate,;
*!*				discunitar As discount_unitar,cu_tva As pret_cu_tva,Nvl(serie,Space(100)) As serie,Nvl(codmat,Space(50)) As codmat,;
*!*				0 As id_valuta,0 As Curs,1 As multiplicator,Pret,pretd,Cast(Nvl(id_valuta,0) As N(5)) As id_valuta_d From (lcCursorDeviz) Where cante <> 0

		Insert Into crsvanztemp(id_articol,explicatie,Pret,proc_tvav,id_jtva_coloana,taxcode,cantitate,discount_unitar,pret_cu_tva,;
			serie,codmat,id_valuta,Curs,multiplicator,pret_achizitie,pretd,id_valuta_d) ;
			SELECT id_articol,explicatie,Pret,proc_tvav,id_jtva_coloana,taxcode,cantitate,;
				discount_unitar,pret_cu_tva,Nvl(serie,Space(100)) As serie,Nvl(codmat,Space(50)) As codmat,;
				id_valuta,Curs,multiplicator,pret_achizitie,0 as pretd,Cast(Nvl(id_valuta,0) As N(5)) As id_valuta_d ;
				From (lcCursorDeviz) Where cantitate <> 0 OR m.llFacturaZero
*!*	modificare	v 2.0.41	^

		lnSucces = SQLSetprop(gnHandle,"Transactions",2)
		If lnSucces >= 0
			lcSql = [begin ] + 	gcS +[.pack_facturare.initializeaza_date_factura(] + ;
				[to_date('] + Alltrim(Dtoc(poDate.dataireg,2)) + [','YYYYMMDD'),] + ;
				Nvl(Alltrim(Str(poDate.id_fdoc)),[NULL]) + [,to_date('] + Alltrim(Dtoc(poDate.dataact,2)) + [','YYYYMMDD'),] + ;
				[to_date('] + Alltrim(Dtoc(poDate.datascad,2)) + [','YYYYMMDD'),'] + Nvl(poDate.serie_act,[]) + [',] + ;
				Alltrim(Str(poDate.nract,14,0)) + [,] + ;
				Iif(Isnull(poDate.id_client),[NULL],Alltrim(Str(poDate.id_client))) + [,] + ;
				Iif(Isnull(poDate.id_lucrare),[NULL],Alltrim(Str(poDate.id_lucrare))) + [,] + ;
				Iif(Isnull(poDate.id_sectie),[NULL],Alltrim(Str(poDate.id_sectie))) + [,] + ;
				Iif(Isnull(poDate.id_venchelt),[NULL],Alltrim(Str(poDate.id_venchelt))) + [,] + ;
				Iif(Isnull(poDate.id_responsabil),[NULL],Alltrim(Str(poDate.id_responsabil))) + [,] + ;
				IIF(EMPTY(nvl(poDate.explicatia4,[])),[NULL],['] + STRTRAN(ALLTRIM(poDate.explicatia4),['],['']) + [']) + [,] + ;		&&	modificare v 2.0.33
				IIF(EMPTY(NVL(poDate.id_ordl,0)),[NULL],ALLTRIM(STR(poDate.id_ordl))) + [,NULL,] + ;
				['] + Strtran(Alltrim(Nvl(poDate.descriere,[])),['],['']) + [',] + ;
				Alltrim(Str(poDate.tip)) + [,] + Alltrim(Str(poDate.id_set)) + [,] + ;
				[to_date('] + Dtoc(poDate.zi_curs,2) + [','YYYYMMDD'),] + Alltrim(Str(poDate.id_valuta)) + [,] + ;
				Alltrim(Str(poDate.in_valuta)) + [,] + ;
				alltrim(str(poDate.tva_incasare)) + [,] + ;	&&	modificare ROAAUTO v 2.1.0
				Iif(Isnull(gnIdSucursala),[NULL],Alltrim(Str(gnIdSucursala))) + [,] + ;
				Alltrim(Str(gnIdUtil)) + [,NULL,NULL,] + ;
				IIF(EMPTY(NVL(poDate.tip_saft,0)), [NULL], ALLTRIM(STR(poDate.tip_saft))) + [); end;]
			lnSucces = goExecutor.oExecute(lcSql)
			If lnSucces < 0
				amessagebox(goExecutor.oPrelucrareEroare(),16,"Eroare")
			ELSE

				Private poArticol
				Select crsvanztemp
				Scan
					Scatter Name poArticol
					lcSql = [begin ] + gcS + [.pack_facturare.adauga_articol_factura_deviz(] + ;
						Alltrim(Str(poArticol.id_articol)) + [,] + ;
						['] + Strtran(Alltrim(Nvl(poArticol.explicatie,[])),['],['']) + [',] + ;
						['] + Strtran(Alltrim(Nvl(poArticol.serie,[])),['],['']) + [',] + ;
						Alltrim(Str(poArticol.pret_achizitie,18,gnPPret)) + [,] + ;
						Alltrim(Str(poArticol.pretd,18,gnPVal)) + [,] + ;
						Alltrim(Str(poArticol.id_valuta_d)) + [,] + ;
						Alltrim(Str(poArticol.Pret,18,Iif(poDate.in_valuta = 1,gnPVal,gnPPretV))) + [,] + ;
						Iif(poDate.in_valuta=1,Alltrim(Str(poArticol.id_valuta)),[NULL]) + [,] + ;
						Alltrim(Str(poArticol.Curs,18,6)) + [,] + ;
						Alltrim(Str(poArticol.multiplicator)) + [,] + ;
						Alltrim(Str(poArticol.proc_tvav,18,2)) + [,] + ;
						Alltrim(Str(poArticol.id_jtva_coloana)) + [,] + ;
						Alltrim(Str(poArticol.cantitate,18,gnPCant)) + [,] + ;
						Alltrim(Str(poArticol.discount_unitar,18,gnPPretV)) + [,] + ;
						Alltrim(Str(poArticol.id_gestiune)) + [,] + ;
						['] + Alltrim(Nvl(poArticol.Cont,'')) + [',] + ;
						Alltrim(Str(poArticol.pret_cu_tva)) + [,NULL,NULL,] + IIF(ISNULL(poArticol.taxcode), [NULL], ALLTRIM(TRANSFORM(poArticol.taxcode))) + [); end;]
					lnSucces = goExecutor.oExecute(lcSql)
					If lnSucces < 0
						amessagebox(goExecutor.oPrelucrareEroare(),16,"Eroare")
						Exit
					Endif
				Endscan
				If !Used('INFISIERE')
					lcCaleDateMenu = gcAppPath+[\COMUN\DATEMENU\]
					Use &lcCaleDateMenu.INFISIERE In 0 Alias INFISIERE
				Endif
				If lnSucces >= 0
					lnSucces = oscrie_in_fisiere(0,.F.,.T.)	&&	?
					If lnSucces >= 0
*!*	modificare	v 2.0.47 : am adaugat lnIdSet la pack_devize.actualizeaza_deviz
						lcSql = [begin ] + gcS + [.pack_facturare.scrie_in_vanzari(0,] + ;
							IIF(Isnull(poDate.id_delegat),[NULL],Alltrim(Str(poDate.id_delegat))) + [,] + ;
							IIF(Isnull(poDate.id_masina),[NULL],Alltrim(Str(poDate.id_masina))) + [,] + ;
							IIF(Isnull(poDate.id_facturare),[NULL],Alltrim(Str(poDate.id_facturare))) + [,] + ;
							IIF(Isnull(poDate.nListareDetaliata),[0],Alltrim(Str(poDate.nListareDetaliata))) + [,] + ;																	
							[?poDate.dataora_exp,] + ;
							IIF(Isnull(poDate.id_agent),[NULL],Alltrim(Str(poDate.id_agent))) + [,] + ;
							['] + Strtran(Alltrim(Nvl(poDate.text_aditional,[])),['],['']) + [',?@poDate.nid_vanzare); ] + ;
							[pack_auto.actualizeaza_deviz(] + ALLTRIM(STR(lnProcTvav,10,4)) + [,'] + ALLTRIM(tcSirIdOrdl) + [',] + ALLTRIM(STR(lnIdSet)) + [); end;]
*!*	modificare	v 2.0.35	: am scos apelul catre pack_devize.dev_completeaza_rul; e inclus in actualizeaza_deviz
						lnSucces = goExecutor.oExecute(lcSql)
						If lnSucces < 0
							amessagebox(goExecutor.oPrelucrareEroare(),16,"Eroare")
						ELSE 
							* Completare vanzari.id_fact cu act.id_fact
								TEXT TO lcSql TEXTMERGE NOSHOW 
merge into vanzari a using
	(SELECT v.cod, (select min(id_fact) from act where cod = v.cod and scd = '4111') as id_fact from vanzari v where v.id_vanzare=?poDate.nid_vanzare) b on (a.cod = b.cod)
	when matched then 
	  update set id_fact = b.id_fact;
								endtext	  
							llSucces = goExecutor.oExecuta(m.lcSql)	
						Endif
					Endif
				Endif
			Endif
		Endif

		If lnSucces < 0
			amessagebox(goExecutor.oPrelucrareEroare(),16,"Eroare")
			lcSql = "ROLLBACK"
			llScris = .F.
		Else
			lcSql = "COMMIT"
			llScris = .T.
		Endif
		lnSucces2 = goExecutor.oExecute(lcSql)

		Do Case
			Case lnSucces2 < 0
				amessagebox(lcSql + Chr(13) + goExecutor.cEroare,0+16,"Eroare")
				llScris = .F.
			Case lnSucces2 >=0 And lcSql = "COMMIT"
				listeaza_ofacturare()
				If poDate.ntip_incasare = 2 && bon fiscal
					If glAutoBonDet And !Inlist(lnIdSet,31001,31002)
						listeaza_bon_fiscal_det(ltDataOra,poDate.nr_incasare,poDate.incasat,poDate.incasatCARD,poDate.proc_tva,lnProcDiscN,lnProcDiscM)
					Else
						listeaza_bon_fiscal(ltDataOra,poDate.nr_incasare,poDate.incasat,poDate.incasatCARD,poDate.proc_tva,poDate.nract)
					Endif
				Endif
		Endcase

		lnSucces2 = SQLSetprop(gnHandle,"Transactions",1)
		If lnSucces2 < 0
			amessagebox('Programul nu a reusit sa treaca pe tranzactie automata. Iesiti din program si intrati din nou!',48,'Atentie!')
		Endif
	Endif

	If Used('crsvanztemp')
		Use In crsvanztemp
	Endif
	If Used('crsfactura')
		Use In crsfactura
	Endif
	Release poDate
	Return llScris
Endproc
*******************************************************************************************************************
Procedure listeaza_bon_fiscal_det
	Lparameters ttDataOra,tnNrBon,tnSumaAchitNumerar,tnSumaAchitCARD,tnProcentTva,tnProcDiscMat,tnProcDiscMan
	Local lcCursor
	lcCursor = [crsDateBon]
	Create Cursor (lcCursor) (denumire c(100), um c(10), CANT N(10,4), Pret N(18,4), DEPARTAMENT N(2), proc_tvav N(5,2),PROCENT N(5,2),DISCOUNT N(2) Default 0)
	If Used('crsBonDetaliat')
		Insert Into (lcCursor) (denumire,um,CANT,Pret,DEPARTAMENT,proc_tvav) ;
			Select denumire, Nvl(um,'BUC') As um, CANT, Pret, 1, 1+(tnProcentTva/100) From crsBonDetaliat
	Endif
	If tnProcDiscMat <> 0
		Select (lcCursor)
		Append Blank
		Replace denumire With 'DISCOUNT MATERIALE',um With 'BUC',CANT With 1,PROCENT With tnProcDiscMat,;
			DEPARTAMENT With 1,proc_tvav With 1+(tnProcentTva/100),DISCOUNT With 2
	Endif
	Select crsfactura
	Locate For id_articol = -100000	&&	Manopera
	If Found()
		lnSumaManopera = valctva
		Select (lcCursor)
		Append Blank
		Replace denumire With 'MANOPERA',um With 'BUC',CANT With 1,Pret With lnSumaManopera,;
			DEPARTAMENT With 1,proc_tvav With 1+(tnProcentTva/100)
	Endif
	If tnProcDiscMan <> 0
		Select (lcCursor)
		Append Blank
		Replace denumire With 'DISCOUNT MANOPERA',um With 'BUC',CANT With 1,PROCENT With tnProcDiscMan,;
			DEPARTAMENT With 1,proc_tvav With 1+(tnProcentTva/100),DISCOUNT With 1
	Endif
	Select crsfactura
	Scan For !Inlist(id_articol,-100000,-100001,-100003)	&&	fara manopera, discount manopera, materiale
		lcDenumire = denumire
		lcUM = Nvl(um,'BUC')
		lnCantitate = cantitate
		lnPret = pretctva
		Select (lcCursor)
		Append Blank
		Replace denumire With lcDenumire,um With lcUM,CANT With lnCantitate,Pret With lnPret,;
			DEPARTAMENT With 1,proc_tvav With 1+(tnProcentTva/100)
		Select crsfactura
	Endscan
	loHash = GetHash()
	loHash.SetValue("cTip", "1;")
	loHash.SetValue("nNumarBon", tnNrBon)
	loHash.SetValue("nValoareNumerar", m.tnSumaAchitNumerar)
	loHash.SetValue("nValoareCARD", m.tnSumaAchitCard)	
	loHash.SetValue("nValoareTotal", m.tnSumaAchitNumerar + m.tnSumaAchitCard)
	loHash.SetValue("cCursor",lcCursor)
	loHash.SetValue("tDataOra",ttDataOra)
	goControllerEcr.imprima(loHash)
	Use In (lcCursor)
	Release loHash
Endproc	&&	listeaza_bon_fiscal_det
*******************************************************************************************************************
Procedure listeaza_bon_fiscal
	Lparameters ttDataOra,tnNrBon,tnSumaAchitNumerar,tnSumaAchitCARD,tnProcentTva,tnNrFact
	*!*	lcSir=[1;Fact.]+Alltrim(Str(tnNrFact))+[;1;1;1;]+Alltrim(Str(tnSumaAchit*100))+[;1000;0\n]+CRLF
	*!*	lcSir=lcSir+[5;]+Alltrim(Str(tnSumaAchit*100))+[;0;0;0\n]+Chr(13)+Chr(10)+Chr(13)+Chr(10)
	*!*	imprimare_bon_fiscal(lcSir,tdDataOra,tnNrBon)
	Local lcCursor
	lcCursor = [crsDateBon]
	Create Cursor (lcCursor) (denumire c(100), um c(10), CANT N(10,4), Pret N(18,4), DEPARTAMENT N(2), proc_tvav N(5,2))
	Append Blank
	Replace denumire With [Fact.]+Alltrim(Str(tnNrFact)),CANT With 1,Pret With m.tnSumaAchitNumerar + m.tnSumaAchitCARD,proc_tvav With 1+(tnProcentTva/100),DEPARTAMENT With 1

	loHash = GetHash()
	loHash.SetValue("cTip", "1;")
	loHash.SetValue("nNumarBon", tnNrBon)
	loHash.SetValue("nValoareNumerar", m.tnSumaAchitNumerar)
	loHash.SetValue("nValoareCARD", m.tnSumaAchitCard)	
	loHash.SetValue("nValoareTotal", m.tnSumaAchitNumerar + m.tnSumaAchitCard)
	loHash.SetValue("cCursor",lcCursor)
	loHash.SetValue("tDataOra",ttDataOra)
	goControllerEcr.imprima(loHash)
	Use In (lcCursor)
	Release loHash
Endproc	&&	listeaza_bon_fiscal
*******************************************************************************************************************
Procedure alege_facturi_relistare
	LPARAMETERS tcCursorComenzi
	* tcCursorComenzi cursor cu comenzile selectate pentru listare
	* trebuie sa aiba coloanele: ales N(1), id_lucrare I, nrord C
	
	Local lnRaspuns,lcFisier,lcSql,lnSucces,lnIdLucrare,ldDataAct,lnNrAct,lcSelect,lcFiltru,lcSchema,lcOrder,llAfisare,lnnr,lnExp,lncounta,lncountb,lncountcod, lcFieldAles
	Select (m.tcCursorComenzi)
	lnRecno = Recno()

	If Reccount(m.tcCursorComenzi)>0
		lcFieldAles = tcCursorComenzi + '.ales'
		IF TYPE(m.lcFieldAles) = 'U'
			lnAlese = 0
		ELSE 	
			Calculate Sum(ales) To lnAlese
		ENDIF 	
		If lnAlese = 0
			Select * From (tcCursorComenzi) Where Recno() = lnRecno Into Cursor crsRelistare
		Else
			Select * From (tcCursorComenzi) With (Buffering = .T.) Where ales = 1 Into Cursor crsRelistare
		ENDIF
			
		Select crsRelistare
		Scan
			Scatter Name ocomanda
			lnIdLucrare=crsrelistare.id_lucrare
			If Used('crsexport')
				Use In crsexport
			Endif
			lcSql = [Select distinct 0 as ales,cod,serie_act,nract,MAX(datascad) as datascad,dataact from act ] + ;
				[where id_set between 31000 and 31020 ] + ;
				[and id_lucrare = ] + Alltrim(Str(lnIdLucrare)) + [ and SUBSTR(scd,1,3) not in ('711','531') ] + ;
				[and sters = 0] + gcCondSucursala + [ and cod in (select cod from vanzari where sters = 0) ] + ;
				[group by cod,serie_act,nract,dataact ] + ;
				[order by dataact,nract]
			lnSucces = goExecutor.oExecute(lcSql,[crsexport])
			If lnSucces < 0
				amessagebox(goExecutor.cEroare,48,"Atentie")
			Else
				Do Case
					Case Reccount([crsexport]) = 0
						amessagebox("Nu exista documente pentru comanda " + Alltrim(crsrelistare.nrord)+ " !",0+48,"Atentie")
					Case Reccount([crsexport]) = 1
						Select ([crsexport])
						relisteaza_factura_deviz(cod,serie_act,nract,dataact,datascad)
					Otherwise
						loFrmDocLuc=Createobject('frm_documente_lucrare',crsrelistare.nrord)
						loFrmDocLuc.Show(1)
						Select ([crsexport])
						Scan For ales = 1
							relisteaza_factura_deviz(cod,serie_act,nract,dataact,datascad)
							Select ([crsexport])
						Endscan
				Endcase
			Endif
		Endscan
		Use In (Select('crsrelistare'))
		Use In (Select('crsexport'))

		SELECT (m.tcCursorComenzi)
		Go Max(Min(lnRecno,Reccount(tcCursorComenzi)),1)
	Else
		amessagebox("Nu ati selectat nici o comanda!",0+48,"Atentie")
	Endif
Endproc
*******************************************************************************************************************
Procedure relisteaza_factura_deviz
	Lparameters tnCod,tcSerie,tnNrAct,tdDataAct,tdDataScad
	pnCod = tnCod
	poDate=Createobject("oDateFactura",0,0)
	poDate.serie_act = tcSerie
	poDate.nract = tnNrAct
	poDate.dataact = Iif(Type('tdDataAct')='T',Ttod(tdDataAct),tdDataAct)
	poDate.datascad = Iif(Type('tdDataScad')='T',Ttod(tdDataScad),tdDataScad)

	*!*	modificare	v 2.1.0	:	am adaugat tva_incasare
	lcSql = [select id_vanzare,id_comanda,dataora,dataora_exp,data_act,sters,dataoras,numar_act,serie_act,]+;
		[tip,id_part,discount,disc_fara_tva,discount_evidentiat,text_aditional,facturat,data_facturat,]+;
		[explicatie,altele,client,cod,utilizator,utils,utilfact,delegat,bidelegat,cnpdelegat,]+;
		[nume_agent,nrinmat,total_fara_tva,total_tva,total_cu_tva,id_gestiune,serie_chit,nr_incasare,incasat,]+;
		[in_valuta,sucursala,id_ruta,ruta,curs,multiplicator,nume_val,id_delegat,id_agent,id_masina,valoarea,]+;
		[nume_gestiune,id_sectie,sectie,id_lucrare,lucrare,tip_incasare,afisare_scadenta,id_ordl,tva_incasare from fact_vfacturi where cod = ] + ALLTRIM(STR(m.pnCod))
	lnSucces = goExecutor.oExecute(lcSql,[crsfacturiTemp])
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,"Eroare")
		Return
	Endif

	Select crsfacturiTemp
	poDate.nRelistare = 1
	poDate.nid_vanzare = id_vanzare
	poDate.tip = tip
	poDate.discount_evidentiat = discount_evidentiat
	poDate.text_aditional = Nvl(text_aditional,[])
	poDate.nrinmat = nrinmat
	poDate.nume_delegat = delegat
	poDate.bidelegat = bidelegat
	poDate.cnpdelegat = cnpdelegat
	poDate.dataora_exp = dataora_exp
	poDate.afisare_scadenta = afisare_scadenta
	poDate.listaid = Iif(poDate.tip = 3,Alltrim(Str(id_comanda)), [0])
	poDate.ntip_incasare = tip_incasare
	poDate.serie_chit = Nvl(serie_chit,[])
	poDate.nr_incasare = nr_incasare
	poDate.incasat = incasat
	poDate.id_client = id_part
	poDate.nume_client = client
	poDate.in_valuta = in_valuta
	poDate.id_ordl = id_ordl
	poDate.tva_incasare = tva_incasare	&&	modificare	v 2.1.0
	lnDiscount = DISCOUNT
	lnDiscountVal = 0
	Use In (SELECT('crsfacturiTemp'))

	lcSql = [select * from fact_vfacturi_detalii where id_vanzare = ] + ALLTRIM(STR(poDate.nid_vanzare))
	lnSucces = goExecutor.oExecute(lcSql,[crsdetalii])
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,"Eroare")
		Return
	Endif

	Select crsdetalii
	Calculate Max(proc_tvav) To lnProcTvav
	creeaza_facturacrs([crsfactura])
	prelucreaza_facturacrs([crsdetalii],[crsfactura],lnProcTvav,lnDiscount,lnDiscountVal)
	Use In crsdetalii
	listeaza_ofacturare()

	If Used('crsfactura')
		Use In crsfactura
	Endif

	Release poDate
Endproc
*!*	******************************************************************************************************************************
*!*	Procedure listeaza_ofacturare_deviz
*!*		listeaza_ofacturare()
*!*	If poDate.nRelistare = 0 And poDate.eProforma = 0 And poDate.nSalveazaAtasamente = 1
*!*		lnSucces2 = goExecutor.oexecute([COMMIT])
*!*	Endif
*!*	Endproc
*!*	******************************************************************************************************************************

*******************************************
* PROCEDURE export_comanda_xml(  )
* Data/ora : 08/03/13, 08:58:28
* autor : liana.neagu
* descriere:

****** PARAMETER BLOCK **************
* Parametri : 0
*
*******************************************
PROCEDURE export_comanda_xml
	tlCautPlus = .t.
	Store "" To loCauta
	*!* tlCautPlus - daca se foloseste formularul caut_alfa_form_plus cu butonul but_start_criterii
	*!* 24.07.2009
	*!*	29.01.2013 : am adaugat um2 in selectie
	Local lcStringCriterii,lcCursor,lcXML,lcDateStyle,lcMark
	LOCAL lcFisierXml,lcCursor ,lcCaleFisier

	PRIVATE pcCodTehnician

	lcStringCriterii = ""
	
	
	lcStringCriterii="Lucrare\nrord\T\none\" + crlf + ;
		"Client\nume\T\none"+ crlf + ;
		"Nr. inmatriculare\nrinmat\T\none"+ crlf+;
		"Serie sasiu\series\T\none"+ crlf+;
		"Data\datai\D\none"+ crlf

	lcTitluColoane = [Nr lucrare,Data,Client,Nr. inmatriculare,Serie sasiu]
	lccoloane = [nrord,TTOD(datai),nume,nrinmat,series]


	lcFiltru = [2=2]
	lcSchema = []
	lcOrder = [datai]
	lcNumeProc = []
	lcTitlu = [Alege_i comenzile (mouse-click pe denumire sau apasa_i SPACE)]
	lcSelect = [select nrord,datai,nume,nrinmat,series,validat,id_ordl from auto_normare_comenzi a]
	lcFiltruOriginal = gcCondLuna + [ and a.validat=0 ]
	pcschema1=['']
	

	llToateIreg = .t.
	lcPrimaColoana = [nrord]
	lnPornire = 1
	lnTipReturn = 1
	lcIdColumn = "id_ordl"

	loHash = GetHash()
	loHash.SetValue("cSelect", lcSelect)
	loHash.SetValue("cFiltru", lcFiltru)
	loHash.SetValue("cSchema", lcSchema)
	loHash.SetValue("cOrder", lcOrder)
	loHash.SetValue("cColoana", lccoloane)
	loHash.SetValue("cTitlu", lcTitlu)
	loHash.SetValue("cTitluColoana", lcTitluColoane)
	loHash.SetValue("cNumeProc", lcNumeProc)
	loHash.SetValue("lToateIreg", llToateIreg)
	loHash.SetValue("cFiltruOriginal", lcFiltruOriginal)
	loHash.SetValue("cPrimaColoana", lcPrimaColoana)
	loHash.SetValue("nPornire", lnPornire)
	loHash.SetValue("nTipReturn", lnTipReturn)
	loHash.SetValue("cIdColumn", lcIdColumn)
	loHash.SetValue("cStringCriterii", lcStringCriterii)
	loCauta = cauta_alfa_hash(loHash)
*---------------------export in xml----------------------------------------
IF gnButon = 2 OR empty(NVL(loCauta,[]))
	RETURN
ENDIF 
lcCursor = [crsDateSelect]
XMLTOCURSOR(loCauta,lcCursor )


lcFisierXml = m.gcFISIERXMLCOMENZI

lcCaleFisier = JUSTPATH(lcFisierXml)
	If !Directory(m.lcCaleFisier)
		Md (m.lcCaleFisier)
	Endif

	lcSql = [select * from DEV_UTILIZATORI_CODURI where id_util = ?gnIdutil]
	lnSucces = goExecutor.oExecute(lcSql,[crscodUtil])
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,"Eroare")
		Return
	Endif


SELECT crsCodUtil
pcCodTehnician = ALLTRIM(cod)
USE IN crsCodUtil

IF  empty(NVL(pcCodTehnician,[]))
	oadaugcod = CREATEOBJECT('frm_codutilizator')
*!*		oadaugcod.Clb_tx_simplu1.text_simplu1.controlsource= 'pcCodTehnician'
	oadaugcod.show(1)
	IF gnbuton = 2
		RETURN
	ENDIF 
	
		lcSql = [merge into DEV_UTILIZATORI_CODURI a using (select ']+ALLTRIM(pcCodTehnician)+;
		[' as cod,?gnIdutil as id_util from dual) b ON (a.id_util = b.id_util) WHEN NOT MATCHED THEN insert (id_util,cod) values (?gnIdutil,']+ALLTRIM(pcCodTehnician)+;
		[') WHEN MATCHED THEN UPDATE SET cod = ']+ALLTRIM(pcCodTehnician)+[' where id_util = ?gnIdutil]
	lnSucces = goExecutor.oExecute(lcSql)
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,"Eroare")
		Return
	Endif
ENDIF 
lcDateStyle = Set("Date")
lcMark = Set("Mark")

Set Date To Dmy
Set Mark To '.'


Set Textmerge On To Memvar lcXML NOSHOW 
\<?xml version="1.0" encoding="iso-8859-1" ?> 
SELECT (lcCursor)
*!*	modificare	30.07.2012
\<Jobs>
SCAN 
	\<Job>
		\<Jobnumber><<SUBSTR(XmlSpecialCharacters(ALLTRIM(nrord)),1,20)>></Jobnumber>
		\<Customer><<SUBSTR(XmlSpecialCharacters(ALLTRIM(nume)),1,40)>></Customer>
		\<License><<SUBSTR(ALLTRIM(nrinmat),1,10)>></License>
		\<VINnumber><<SUBSTR(ALLTRIM(series),1,30)>></VINnumber>
		\<TechnicianCode><<SUBSTR(ALLTRIM(m.pcCodTehnician),1,3)>></TechnicianCode>
		\<CreatedDate><<TTOD(datai)>></CreatedDate>
		\<JobStatus>1</JobStatus>
	\</Job>
ENDSCAN 
\</Jobs>
Set Textmerge To

Strtofile(lcXML, m.lcFisierXml )
Set Date To &lcDateStyle
Set Mark To &lcMark

 

aMESSAGEBOX('S-a creat fisierul '+m.lcFisierXml ,0+64,_screen.Caption)



ENDPROC 
**********************sfarsit procedura export_comanda_xml*******************

*****************************************************************************
*  citeste procentele de discount pe contractul tip CLIENT AUTO
*  pentru completarea procentelor de discount la facturare
*****************************************************************************  
PROCEDURE citeste_discount_contract
	LPARAMETERS tnIdPart, tnIdCtr, tnProcDiscountManopera, tnProcDiscountMateriale
	* tnIdPart IN - id client
	* tnProcDiscountManopera, tnProcDiscountMateriale OUT

	Local lcSql, llSucces
	PRIVATE pnDiscountManopera, pnDiscountMateriale, pnIdCtr, pnIdPart
	pnIdPart = tnIdPart
	pnIdCtr = 0
	pnDiscountManopera = 0.00
	pnDiscountMateriale = 0.00

	lcSql = [begin pack_auto.citeste_discount_contract(?pnIdPart, ?gnIdSucursala, ?@pnIdCtr, ?@pnDiscountManopera, ?@pnDiscountMateriale); end;]
	llSucces = goExecutor.oExecuta(m.lcSql)
	IF !m.llSucces
		pnDiscountManopera = 0.00
		pnDiscountMateriale = 0.00
	ENDIF 
	tnIdCtr = pnIdCtr
	tnProcDiscountManopera = NVL(m.pnDiscountManopera, 0.00) 
	tnProcDiscountMateriale = NVL(pnDiscountMateriale, 0.00)
ENDPROC && citeste_discount_contract


*****************************************************************************
*  salveaza procentele de discount pe contractul tip CLIENT AUTO (il creeaza daca nu exista)
*  in formularul onom_devize.vcx:frm_dev_clienti
*****************************************************************************  
PROCEDURE salveaza_discount_contract
	LPARAMETERS tnIdPart, tnIdCtr, tnProcDiscountManopera, tnProcDiscountMateriale
	* tnIdPart IN - id client
	* tnIdCtr  IN - id contract SERVICE AUTO
	* tnProcDiscountManopera, tnProcDiscountMateriale IN

	Local lcSql, llSucces
	PRIVATE pnDiscountManopera, pnDiscountMateriale, pnIdCtr, pnIdPart
	pnIdPart = tnIdPart
	pnIdCtr = tnIdCtr
	pnDiscountManopera = tnProcDiscountManopera
	pnDiscountMateriale = tnProcDiscountMateriale
	lcSql = [begin pack_auto.salveaza_discount_contract(?pnIdPart, ?gnIdSucursala, ?pnIdCtr, ?pnDiscountManopera, ?pnDiscountMateriale); end;]
	llSucces = goExecutor.oExecuta(m.lcSql)
	RETURN m.llSucces
ENDPROC && salveaza_discount_contract 

* -----------------------------------
* Intoarce .T. daca un tip de comanda se inchide prin validare sau .F. daca se inchide in alt mod ( nota inchidere, factura)
* -----------------------------------
FUNCTION getOptiuneInchidereValidare
	LPARAMETERS tnTipComanda
	* tnTipComanda: 1 = garantie, 2 = postgarantie ...(DEV_TIP_DEVIZ)
	
	LOCAL lnReturnValue, llReturn, llSucces
	PRIVATE pnTipComanda
	
	pnTipComanda = m.tnTipComanda
	lnReturnValue  = 0
	llSucces = goExecutor.oSelecteaza2Value("Select getOptiuneInchidere(?pnTipComanda) from dual", @lnReturnValue)
	llReturn = (m.lnReturnValue = 1)

	RETURN m.llReturn
ENDFUNC && getOptiuneInchidereValidare

* -----------------------------------
* Salveaza optiunea de inchidere prin validare pe un tip de comanda
* -----------------------------------
FUNCTION setOptiuneInchidereValidare
	LPARAMETERS tnTipComanda, tlInchidereValidare
	
	LOCAL lnReturnValue
	PRIVATE pnTipComanda, pnInchidereValidare
	
	pnTipComanda = m.tnTipComanda
	pnInchidereValidare = IIF(m.tlInchidereValidare,1, 0)

	llSucces = goExecutor.oExecuta("begin setOptiuneInchidere(?pnTipComanda, ?pnInchidereValidare); end;")

	RETURN m.llSucces
ENDFUNC && setOptiuneInchidereValidare 