*** AVIZ TRANSFER (apelat din ointroduceri.prg dupa scrierea NIR-ului pret de lista id_set 231, 247, 266)

*!* 30.03.2010
*!* marius.mutu
*!* completare parametrii V_SERIE_ACT_INCASARE, V_DATAORA_EXP la apelul pack_facturare.scrie_factura2

*!* 19.05.2010
*!* marius.mutu
*!* finalizeaza_scriere_verificare - apel parametru aditional


*!* 05.11.2010
*!* marius.mutu
*!*	adauga_articol_factura + parametru multiplicator_curs = 1

*!* 13.06.2017
*!* marius.mutu
*!* scatter name poArt memo - nu exporta campul "explicatia" MEMO

Private ptDataOra
Local lnIdSet,lnIdTipDoc,lcCursorVerificare,lcCursorFinal,pcSirDifAcont ,pcSirDifPart,lnSucces
lnSucces = 1
lcCursorVerificare = [crsactverif]
lcCursorFinal = [tmpactactan]
pcSirDifAcont = []
pcSirDifPart = []



lnIdSet = 25000 + 30 - 1 + gnScadereStoc * 10
*!*		 	lcObiect = [frm_date_aviz_lucrare]
lnIdTipDoc = 6
If Type('poDate') <> 'O'
	poDate=Createobject("oDateFactura",lnIdSet,30)
	Private poGeneratorNumere
	poGeneratorNumere = Createobject("oGeneratorNumere")
Else
	If Type('poGeneratorNumere') <> 'U'
		poGeneratorNumere.ResetNumere()
	Endif
Endif

poDate.rezultat_serii=poGeneratorNumere.creeaza_cursor_serii(lnIdTipDoc)

If Type('poDateGestiuneDest') <> 'O'
	poDateGestiuneDest = Createobject("oDateGestiune")
Endif
Select actactan
*!*	SCATTER NAME poclient FIELDS nract
*!*	ADDPROPERTY(poclient,'denumire','')
poDate.id_client = actactan.id_gestin
poDate.nume_client = actactan.GESTIN
poDate.DATAACT = actactan.DATAACT
poDate.tip = 30
*!*	poClient.denumire = poDate.descriere
pnButon=1
ofrmceredate=Createobject('frm_date_aviz')
ofrmceredate.Show(1)
Release ofrmceredate
If pnButon=2
	poGeneratorNumere.dezaloca_numar(lnIdTipDoc)
	Release poDate,poGeneratorNumere
	Return
Else
	poGeneratorNumere.verifica_numar(lnIdTipDoc,poDate.nract)
Endif

*!*	Select 0 As id_c,id_articol,serie,id_gestiune,id_valuta,discunitar As discount_unitar ,codmat,denumire,um,1 As gestionabil,;
*!*		cant As cantitate,proc_tvav,0 As preturi_cu_tva,Curs,Pret As preta,pretv As Pret,tvav,0 As pret_val,nume_val,;
*!*		0 As discount_unitar_val,0 As tip_valuta,Cont,acont From rul_temp ;
*!*		into Cursor crs_artTemp

*!*	modificare	v 2.0.77
*!*	Create Cursor crsfactura(id_c N(20),id_temp N(20),id_articol N(20),id_pol N(20) Null,id_gestiune N(20),Cont c(4),um c(10), ;
*!*		id_valuta N(10),gestionabil N(1),tip_valuta N(1),Curs N(20,4),id_jtva_coloana N(20) Null,codmat c(100),codbare c(50),codmatf c(100),;
*!*		pret_achizitie N(20,4),denumire c(100),pretftva N(20,4),pretctva N(20,4),valftva N(20,4), valtva N(20,4),valctva N(20,4),;
*!*		cantitate N(20,4),discountftva N(20,4), discountctva N(20,4), valdiscountftva N(20,4),valdiscounttva N(20,4),;
*!*		valdiscountctva N(20,4),valdiminuatftva N(20,4),valdiminuattva N(20,4),	valdiminuatctva N(20,4),proc_tvav N(20,4),cu_tva N(1),serie c(100),;
*!*		vpretftva N(20,4),vpretctva N(20,4),vvalftva N(20,4),vvaltva N(20,4),vvalctva N(20,4),;
*!*		vdiscountftva N(20,4),vdiscountctva N(20,4),vvaldiscountftva N(20,4),vvaldiscounttva N(20,4),;
*!*		vvaldiscountctva N(20,4),vvaldiminuatftva N(20,4),vvaldiminuattva N(20,4),vvaldiminuatctva N(20,4),id_set_fact N(20) Null,explicatie c(100),;
*!*		id_part_rez N(10) Null,id_lucrare_rez N(10) Null,pretv_orig N(20,4),pretd N(20,4),id_valuta_d N(20))
*!*	modificare	v 2.0.142
*!*	creeaza_crsfactura()
creeaza_facturacrs([crsfactura])
*!*	modificare	v 2.0.142	^
*!*	modificare	v 2.0.77	^
	
*!* modificare roagest2.0.46
*!*	Local lcIdJtva
*!*	Select crs_artTemp
*!*	Local lni
*!*	Store 0 To lni
*!*	Scan
*!*		Scatter Name loArticole
*!*		lni = lni +1
*!*		Select crsfactura
*!*		update_jtva_coloane([JV],'CrsCotaTva',0)
*!*		Select CrsCotaTva
*!*		Locate For cota_tva = (loArticole.proc_tvav*100-100)
*!*		If Found()
*!*			lcIdJtva = id_jtva_coloana
*!*		Else
*!*			lcIdJtva = Null
*!*		Endif
*!*		Use In CrsCotaTva
*!*		Insert Into crsfactura ;
*!*			(id_c,id_temp,id_articol,id_gestiune,Cont,um,;
*!*			id_valuta,gestionabil ,tip_valuta ,Curs ,id_jtva_coloana ,codmat ,;
*!*			pret_achizitie,denumire ,pretftva ,pretctva ,valftva , valtva ,valctva ,;
*!*			cantitate ,discountftva , discountctva , valdiscountftva ,valdiscounttva ,;
*!*			valdiscountctva ,valdiminuatftva ,valdiminuattva ,	valdiminuatctva ,proc_tvav ,cu_tva ,serie ,;
*!*			id_set_fact ,explicatie,id_pol ) ;
*!*			values (;
*!*			lni,loArticole.id_c,loArticole.id_articol,loArticole.id_gestiune,loArticole.Cont,loArticole.um,;
*!*			loArticole.id_valuta,loArticole.gestionabil,loArticole.tip_valuta,loArticole.Curs,lcIdJtva ,loArticole.codmat,;
*!*			loArticole.preta,loArticole.denumire,loArticole.Pret,loArticole.Pret+loArticole.tvav,Round(loArticole.cantitate*loArticole.Pret,gnpa),Round(loArticole.cantitate*loArticole.tvav,gnpa),Round((loArticole.cantitate*loArticole.Pret)+(loArticole.cantitate*loArticole.tvav),gnpa),;
*!*			loArticole.cantitate,0,0,0,0,;
*!*			0,Round(loArticole.cantitate*loArticole.Pret,gnpa),Round(loArticole.cantitate*loArticole.tvav,gnpa),Round((loArticole.cantitate*loArticole.Pret)+(loArticole.cantitate*loArticole.tvav),gnpa),loArticole.proc_tvav,loArticole.preturi_cu_tva,'',;
*!*			null,'',Null)
*!*	&&25039

*!*		Select crs_artTemp
*!*	Endscan

*!*	ar trebui comasat if-ul de mai jos cu completeaza_facturacrs din ofacturare_stoc.prg
Local lnPretCuTva
lnPretCuTva = Iif(INLIST(gnTipGest,6,7), 1, 0)
If !INLIST(gnTipGest,6,7)
	Insert Into crsfactura (id_gestiune,id_articol,Cont,gestionabil,denumire,serie,cantitate,cu_tva,pretftva,pretctva,;
		valftva,valtva,valctva,discountftva,discountctva,valdiscountftva,;
		valdiscounttva, valdiscountctva, valdiminuatftva, valdiminuattva, valdiminuatctva, proc_tvav,um,codmat,codbare,codmatf,;
		vpretftva,vvalftva,vvaltva,vdiscountftva,vvaldiscountftva,vvaldiscounttva,;
		vvaldiminuatftva,vvaldiminuattva,vvaldiminuatctva,pretd,id_valuta_d,pret_achizitie) ;		
		Select id_gestiune,id_articol,Cont,;
		1 as gestionabil,denumire, Nvl(serie,' ') As serie, cant As cantitate,m.lnPretCuTva As cu_tva,;
		Round(pretv,gnPPretV) As pretftva,;
		Round(pretv,gnPPretV) + Round(Round(pretv,gnPPretV) * (proc_tvav-1),gnPPretV) As pretctva,;
		Round(Round(pretv,gnPPretV)*cant,gnPc) As valftva,;
		ROUND(Round(pretv*cant,gnPc)*(proc_tvav-1),gnPc) As valtva, ;
		Round(Round(pretv,gnPPretV)*cant,gnPc) + Round(Round(pretv*cant,gnPc)*(proc_tvav-1),gnPc) As valctva, ;
		ROUND(discunitar,gnPPretV) As discountftva,;
		ROUND(discunitar,gnPPretV)+Round(Round(discunitar,gnPPretV)*(proc_tvav-1),gnPPretV) As discountctva,;
		Round(Round(discunitar,gnPPretV)*cant,gnPc) As valdiscountftva, ;
		ROUND(Round(discunitar*cant,gnPc)*(proc_tvav-1),gnPc) As valdiscounttva, ;
		Round(Round(discunitar,gnPPretV)*cant,gnPc) + Round(Round(discunitar*cant,gnPc)*(proc_tvav-1),gnPc) As valdiscountctva,;
		Round(Round(pretv-discunitar,gnPPretV)*cant,gnPc) As valdiminuatftva,;
		ROUND(Round((pretv-discunitar)*cant,gnPc)*(proc_tvav-1),gnPc) As valdiminuattva,;
		ROUND(Round(Round(pretv-discunitar,gnPPretV)*cant,gnPc)*proc_tvav,gnPc) As valdiminuatctva,;
		proc_tvav, Nvl(um,Space(50)) As um, Nvl(codmat,Space(50)) As codmat, Nvl(codbare,Space(50)) As codbare,Nvl(codmatf,Space(50)) As codmatf,;
		Round(pretvval,gnPVal) As vpretftva,;
		ROUND(Round(pretvval,gnPVal)*cant,gnPVal) As vvalftva,;
		ROUND(Round(Round(pretvval,gnPVal)*cant,gnPVal)*(proc_tvav-1),gnPVal) As vvaltva,;
		0 As vdiscountftva,0 As vvaldiscountftva,0 As vvaldiscounttva,;
		Round(Round(pretvval-0,gnPVal)*cant,gnPVal) As vvaldiminuatftva,;
		ROUND(Round((pretvval-0)*cant,gnPVal)*(proc_tvav-1),gnPVal) As vvaldiminuattva,;
		ROUND(Round(Round(pretvval-0,gnPVal)*cant,gnPVal)*proc_tvav,gnPVal) As vvaldiminuatctva,;
		pretd,id_valuta,pret From rul_temp
		*!*	modificare	 v 2.0.77 : am adaugat pretd,id_valuta
		*!*	modificare	v 2.0.142 : am completat vvaldiminuatftva, vvaldiminuattva, vvaldiminuatctva
Else
	Insert Into crsfactura (id_gestiune,id_articol,Cont,gestionabil,denumire,serie,cantitate,cu_tva,pretftva,pretctva,;
		valftva,valtva,valctva,discountftva,discountctva,valdiscountftva,;
		valdiscounttva, valdiscountctva, valdiminuatftva, valdiminuattva, valdiminuatctva, proc_tvav,um,codmat,codbare,codmatf,;
		vpretftva,vvalftva,vvaltva,vdiscountftva,vvaldiscountftva,vvaldiscounttva,;
		vvaldiminuatftva,vvaldiminuattva,vvaldiminuatctva,pretd,id_valuta_d,pret_achizitie) ;
		Select id_gestiune,id_articol,Cont,;
		1 as gestionabil,denumire, Nvl(serie,' ') As serie, cant As cantitate,m.lnPretCuTva As cu_tva,Round(pretv,gnPPretV) As pretftva, ;
		Round(pretv+tvav,gnPPretV) As pretctva,;
		Round(Round((pretv+tvav),gnPPretV)*cant,gnPc) - Round(Round((pretv+tvav)*cant,gnPc)*(proc_tvav-1)/proc_tvav,gnPc) As valftva, ;
		Round(Round((pretv+tvav)*cant,gnPc)*(proc_tvav-1)/proc_tvav,gnPc) As valtva, ;
		Round(Round((pretv+tvav),gnPPretV)*cant,gnPc) As valctva, ;
		ROUND(discunitar,gnPPretV) As discountftva, ;
		ROUND(discunitar,gnPPretV)+Round(Round(discunitar,gnPPretV)*(proc_tvav-1),gnPPretV) As discountctva,;
		Round(Round(discunitar,gnPPretV)*cant,gnPc) As valdiscountftva, ;
		Round(Round(discunitar*cant,gnPc)*(proc_tvav-1),gnPc) As valdiscounttva, ;
		Round(Round(discunitar,gnPPretV)*cant,gnPc) + Round(Round(discunitar*cant,gnPc)*(proc_tvav-1),gnPc) As valdiscountctva, ;
		Round(Round(pretv-discunitar,gnPPretV)*cant,gnPc) As valdiminuatftva,;
		ROUND(Round((pretv-discunitar)*cant,gnPc)*(proc_tvav-1),gnPc) As valdiminuattva,;
		ROUND(Round(Round(pretv-discunitar,gnPPretV)*cant,gnPc)*proc_tvav,gnPc) As valdiminuatctva,;
		proc_tvav, Nvl(um,Space(50)) As um,Nvl(codmat,Space(50)) As codmat, Nvl(codbare,Space(50)) As codbare,Nvl(codmatf,Space(50)) As codmatf,;
		Round(pretvval,gnPVal) As vpretftva,;
		ROUND(Round(pretvval,gnPVal)*cant,gnPVal) As vvalftva,;
		ROUND(Round(Round(pretvval,gnPVal)*cant,gnPVal)*(proc_tvav-1),gnPVal) As vvaltva,;
		0 As vdiscountftva,0 As vvaldiscountftva,0 As vvaldiscounttva,;
		Round(Round(pretvval-0,gnPVal)*cant,gnPVal) As vvaldiminuatftva,;
		ROUND(Round((pretvval-0)*cant,gnPVal)*(proc_tvav-1),gnPVal) As vvaldiminuattva,;
		ROUND(Round(Round(pretvval-0,gnPVal)*cant,gnPVal)*proc_tvav,gnPVal) As vvaldiminuatctva,;
		pretd,id_valuta,pret From rul_temp
		*!*	modificare	 v 2.0.77 : am adaugat pretd,id_valuta
		*!*	modificare	v 2.0.142 : am completat vvaldiminuatftva, vvaldiminuattva, vvaldiminuatctva				
Endif

update_jtva_coloane([JV],'CrsCotaTva',0)
Select crsFactura
Scan
	Scatter Name loArticole
	Select CrsCotaTva
	Locate For cota_tva = (loArticole.proc_tvav*100-100)
	If Found()
		lcIdJtva = id_jtva_coloana
	Else
		lcIdJtva = Null
	Endif
	Select crsFactura
	Replace id_jtva_coloana With lcIdJtva
Endscan


Use In CrsCotaTva
*!*\ modificare roagest2.0.46
*!*	DEBUG
*!*	SUSPEND
lnSucces = SQLSetprop(gnHandle,"Transactions", 2)
If lnSucces < 0
	aMESSAGEBOX('Programul nu a reusit trecerea pe tranzactie manuala',0+16,'Eroare')
Else

	Select actactan
	Locate For Alltrim(scd) = '371' And INLIST(Alltrim(scc), '401', '408')
	Select actactan
	ptDataOra = dataora
	poDate.DATAACT = DATAACT
	lcSql = [pack_facturare.initializeaza_date_factura(] + ;
		[to_date('] + Dtoc(actactan.dataireg,2) + [','YYYYMMDD'),] + ;
		Nvl(Alltrim(Str(poDate.id_fdoc)),[NULL]) + [,to_date('] + Dtoc(actactan.DATAACT,2) + [','YYYYMMDD'),] + ;
		[to_date('] + Alltrim(Dtoc(actactan.datascad,2)) + [','YYYYMMDD'),'] + Nvl(poDate.serie_act,[]) + [',] + ;
		Alltrim(Str(poDate.nract)) + [,] + ;
		Iif(Isnull(actactan.id_gestin),[NULL],Alltrim(Str(actactan.id_gestin))) + [,] + ;
		Iif(Isnull(actactan.id_lucrare),[NULL],Alltrim(Str(actactan.id_lucrare))) + [,] + ;
		Iif(Isnull(actactan.id_sectie),[NULL],Alltrim(Str(actactan.id_sectie))) + [,] + ;
		Iif(IsNull(poDate.id_venchelt),[NULL],Alltrim(Str(poDate.id_venchelt))) + [,] + ;		
		Iif(Isnull(actactan.id_responsabil),[NULL],Alltrim(Str(actactan.id_responsabil))) + [,] + ;
		IIF(EMPTY(nvl(poDate.explicatia4,[])),[NULL],['] + STRTRAN(ALLTRIM(poDate.explicatia4),['],['']) + [']) + [,] + ;		&&	modificare	ROAGEST v 2.1.11
		Iif(Isnull(poDate.listaid),[NULL],['] + Alltrim(Iif(Type('podate.listaid')='C',poDate.listaid,Str(poDate.listaid))) + [']) + [,] + ;
		['] + Alltrim(Nvl('',[])) + [',] + ;
		Alltrim(Str(30)) + [,] + Alltrim(Str(actactan.id_set)) + [,] + ;
		[to_date('] + Dtoc(actactan.DATAACT,2) + [','YYYYMMDD'),] + Alltrim(Str(actactan.id_valuta)) + [,] + ;
		Alltrim(Str(0)) + [,] + ;
		alltrim(str(actactan.tva_incasare)) + [,] + ;	&&	modificare	ROAGEST v 2.2.0
		Iif(Isnull(gnIdSucursala),[NULL],Alltrim(Str(gnIdSucursala))) + [,] + ;
		Alltrim(Str(gnIdUtil)) + [);]

	lcSql = lcSql + [ pack_facturare.initializeaza_date_gestiune(] + Alltrim(Str(poDateGestiuneDest.id_gestiune)) + [,] + ;
		Alltrim(Str(poDateGestiuneDest.id_tipgest)) + [,'] + Alltrim(poDateGestiuneDest.Cont) +[',] + ;
		['] + Alltrim(Nvl(poDateGestiuneDest.acont,[])) + [');]

	lcSql = [begin ] + lcSql + [ end;]

	lnSucces = goExecutor.oExecute(lcSql)
	If lnSucces < 0
		aMESSAGEBOX(goExecutor.oPrelucrareEroare(),0+16,"Eroare")
		llReturn = .F.
	Else
		lcSql = []
		Private poArt
		lcSql = []
		Select crsfactura
		Scan
			Scatter Name poArt MEMO 
			*!*	modificare	v 2.0.77 : am adaugat pretd,id_valuta_d
			*!*	modificare 	v 2.0.121 : am adaugat NULL pentru id_ctr ( in id_set_fact )
			*!* 05.11.2010
			lcSql = lcSql + [pack_facturare.adauga_articol_factura(] + Alltrim(Str(poArt.id_temp)) + [,] + ;
				Alltrim(Str(poArt.id_articol)) + [,'] + Alltrim(Nvl(poArt.serie,[])) + [',] + ;
				['] + Alltrim(Nvl(poArt.explicatie,'')) + [',] + Nvl(Alltrim(Str(poact.id_pol)),[NULL]) + [,] + ;
				Nvl(Alltrim(Str(poArt.id_gestiune)),[NULL]) + [,] + Alltrim(Str(poArt.pret_achizitie,18,gnPPret)) + [,] + ;
				Alltrim(Str(poArt.pretd,18,gnPPretVal)) + [,] + ;
				Iif(IsNull(poArt.id_valuta_d),[NULL],Alltrim(Str(poArt.id_valuta_d))) + [,] + ;				
				IIF(poArt.cu_tva=0,;
				IIF(poArt.tip_valuta = 0,Alltrim(Str(poArt.pretftva,18,gnPPretV)),Alltrim(Str(poArt.vpretftva,18,gnPVal))),;
				IIF(poArt.tip_valuta = 0,Alltrim(Str(poArt.pretctva,18,gnPPretV)),Alltrim(Str(poArt.vpretctva,18,gnPVal)))) + [,] + ;
				Alltrim(Str(poArt.id_valuta)) + [,] + Alltrim(Str(poArt.cu_tva)) + [,] + Alltrim(Str(poArt.gestionabil)) + [,] + ;
				Alltrim(Str(poArt.cantitate,18,gnPCant)) + [,] + ;
				IIF(poArt.cu_tva = 0,;
				Iif(poArt.tip_valuta = 0,Alltrim(Str(poArt.discountftva,18,gnPPretV)),Alltrim(Str(poArt.vdiscountftva,18,gnPVal))), ;
				IIF(poArt.tip_valuta = 0,Alltrim(Str(poArt.discountctva,18,gnPPretV)),Alltrim(Str(poArt.vdiscountctva,18,gnPVal)))) + [,] + ;
				['] + Alltrim(Nvl(poArt.Cont,'')) + [',] + Alltrim(Str(poArt.Curs,18,4)) + [,1,] + Alltrim(Str(poArt.id_jtva_coloana)) + [,] + ;
				Nvl(Alltrim(Str(poArt.id_part_rez)),[NULL]) + [,] + Nvl(Alltrim(Str(poArt.id_lucrare_rez)),[NULL]) + [,] + ;
				Alltrim(Str(poArt.pretv_orig,18,gnPPretV)) + [,] + ;
				Nvl(Alltrim(Str(poArt.id_set_fact)),[NULL]) + [,NULL,] + Alltrim(Str(gnIdUtil)) + [);]
			*!* 05.11.2010 ^				
			lcSql = [begin ] + lcSql + [ end;]
			lnSucces = goExecutor.oExecute(lcSql)
			If lnSucces < 0
				aMESSAGEBOX(goExecutor.oPrelucrareEroare(),0+16,"Eroare")
				llReturn = .F.
				Exit
			Else
				lcSql = []
			Endif
		Endscan
	Endif

	If lnSucces > 0
		*!*	modificare v 2.0.79 : am adaugat poDate.nid_vanzare
*!*	modificare	v 2.0.142
*!*			lcSql = [{call pack_facturare.scrie_factura(0,0,] + ;
*!*				ALLTRIM(Str(0,18,gnPc)) + [,0,] + ;
*!*				[NULL,] + ;
*!*				[0,] + ;
*!*				[NULL,] + ;
*!*				[NULL,] + ;
*!*				[NULL,] + ;
*!*				[null,0,0,?poDate.nid_vanzare)}]
*!* 30.03.2010
		lcSql = [{call pack_facturare.scrie_factura2(0,0,] + ;
			ALLTRIM(Str(0,18,gnPc)) + [,'',0,] + ;
			[NULL,] + ;
			[NULL,] + ;
			[NULL,] + ;
			[NULL,] + ;
			[0,] + ;			
			[SYSDATE,] + ;
			[NULL,] + ;
			[null,0,0,?poDate.nid_vanzare)}]
*!* 30.03.2010 ^			
*!*	modificare	v 2.0.142	^
		lnSucces = goExecutor.oExecute(lcSql,lcCursorVerificare)
		If lnSucces < 0
			aMESSAGEBOX(goExecutor.oPrelucrareEroare(),0+16,"Eroare")
			llReturn = .F.
		Endif
	Endif
	If lnSucces > 0
		If Reccount(lcCursorVerificare)>0
			gnButon = 1
			Select a.*,a.suma As totftva, a.suma As tottva, Ttod(a.dataactt) As DATAACT, ;
				Ttod(a.datairegt) As dataireg, Ttod(a.datascadt) As datascad, ;
				0 As pozitie_1, 0 As pozitie_2 From (lcCursorVerificare) a Into Cursor (lcCursorFinal) Readwrite
			Use In (lcCursorVerificare)
			Select (lcCursorFinal)
			Do Form verificare With .T.,.T.
			If gnButon = 1
				Select (lcCursorFinal)
				Scan For Nvl(ascd,'') <> Nvl(ascd1,'') Or Nvl(ascc,'') <> Nvl(ascc1,'') Or ;
						NVL(id_partd,0) <> Nvl(id_partd1,0) Or Nvl(id_partc,0) <> Nvl(id_partc1,0)
					If Nvl(ascd,'') <> Nvl(ascd1,'') Or Nvl(ascc,'') <> Nvl(ascc1,'')
						pcSirDifAcont = pcSirDifAcont + Alltrim(Str(id_act)) + [|] + Alltrim(Nvl(ascd,'')) + [|] + Alltrim(Nvl(ascc,'')) + [;]
					Endif
					If Nvl(id_partd,0) <> Nvl(id_partd1,0) Or Nvl(id_partc,0) <> Nvl(id_partc1,0)
						If (Like([41*],scd) And Nvl(id_partd,0) <> Nvl(id_partd1,0)) ;
								Or (Like([41*],scc) And Nvl(id_partc,0) <> Nvl(id_partc1,0))
							aMESSAGEBOX("Nu puteti modifica clientul!",48,"Atentie")
							Return .F.
						Else
							pcSirDifPart = pcSirDifPart + Alltrim(Str(id_act)) + [|] + Alltrim(Str(Nvl(id_partd,0))) + [|] + Alltrim(Str(Nvl(id_partc,0))) + [;]
						Endif
					Endif
				Endscan
				lnReturn = 1
				gnButon = 2
				llReturn = .F.
				*!*	modificare v 2.0.79 : am adaugat poDate.nid_vanzare
				*!* 19.05.2010
				lcSql = [begin pack_facturare.finalizeaza_scriere_verificare(0,] + ;
					[NULL]+ [,] + ;
					[NULL]+ [,] + ;
					[NULL]+ [,] + ;
					[0]+ [,] + ;										
					[SYSDATE]+ [,] + ;					
					[NULL]+ [,] + ;
					[null,'] + Alltrim(Nvl(pcSirDifAcont,[])) + [','] + ;
					ALLTRIM(Nvl(pcSirDifPart,[])) + [',0,?poDate.nid_vanzare); end;]
				lnSucces = goExecutor.oExecute(lcSql)
			Endif
			If lnSucces<0
				aMESSAGEBOX(goExecutor.oPrelucrareEroare(),16,"Eroare")
				gnButon = 2
				llReturn = .F.
			Endif
			Use In (lcCursorFinal)
		Endif
	Endif
	Use In (Select(lcCursorVerificare))

	If lnSucces > 0
		Private PNTIPFACTURARE
		Store 0 To PNTIPFACTURARE
		listeaza_ofacturare_stoc()
	Endif
Endif  &&SQLSETPROP

USE IN crsfactura

IF lnSucces > 0
	lnSucces = goexecutor.oexecute('COMMIT')
ELSE
	poGeneratorNumere.dezaloca_numar(lnIdTipDoc)
	Release poDate,poGeneratorNumere
	lnSucces = goexecutor.oexecute('ROLLBACK')	
ENDIF 
If lnSucces < 0
	aMESSAGEBOX(goexecutor.ceroare,0+16,'Eroare')
ENDIF 

lnSucces = SQLSetprop(gnHandle,"Transactions", 1)
If lnSucces < 0
	aMESSAGEBOX('Programul nu a reusit trecerea pe tranzactie automata',0+16,'Eroare')
ENDIF 
*!*	DEBUG
*!*	SUSPEND
*!*		prelucreaza_factura(0,0,0,;
*!*		Iif(InList(poDate.tip,23,25,27,28,29,30,41) and Nvl(gnPretListSubunitati,2)=1,1,2))		&&	ofacturare_comun.prg

*!*	lcRaport = [AVIZ_TRANSFER]
*!*	lnVizualizare = Iif(Type('gnVizualAviz')='N',gnVizualAviz,1)
*!*	lcSetare = [AVIZ]
*!*	Local loExport
*!*	loExport = Createobject("oExportConfig")
*!*	loExport.listareUserReport('crsfacturafinala','FRX',lcRaport,lnVizualizare,lcSetare)

