***************************************************************************************************************
****	Proceduri:
****		initializeaza_vanzare_din_stoc
****		listeaza_ofacturare_stoc
****		relisteaza_ofacturare_stoc
****	Functii:
****		oscrie_vanzare_din_stoc
***************************************************************************************************************
*!* 10.07.2009
*!* marius.mutu
*!* cast(nvl(id_valuta,0) as N(5)) IN LOC DE nvl(id_valuta,0) - apareau **** daca primul id_valuta/id_valutad era NULL


*!* 15.05.2018
*!* marius.mutu
*!* initializeaza_vanzare_din_stoc + id_set 271 vanzare produse pret achizitie

*!* 29.06.2018
*!* marius.mutu
*!* initializeaza_vanzare_din_stoc + id_set 272 vanzare produse valuta pret achizitie
*!* initializeaza_vanzare_din_stoc + parametru toActAnterior - pentru lansarea din modificare_articole_gestiune

*!* 12.11.2019
*!* marius.mutu
*!* initializeaza_vanzare_din_stoc + IdSet2TipFacturare

*!* 03.05.2022
*!* oscrie_vanzare_din_stoc - completeaza pack_facturare.adauga_articol_factura_stoc(taxcode)

**************************************** INCEPUT: initializeaza_vanzare_din_stoc ******************************
Procedure initializeaza_vanzare_din_stoc
Lparameters tnIdSet, toActAnterior
LOCAL lnTip
If glLunaInchisa
	amessagebox("Nu puteti emite documente, deoarece aceasta luna este închisa!",0+48,"Luna închisa")
	Return
Endif
Dimension taValori[5,4]
Private poDate	&&	,pnTipFacturare	*!*	modificare	v ROAFACTURARE 2.0.67
lnTip = IdSet2TipFacturare(m.tnIdSet)
poDate = CREATEOBJECT("oDateFactura",tnIdSet,lnTip)
*!*	modificare	v 2.0.67
*!*	pnTipFacturare = 0
*!*	modificare	v 2.0.67	^
If gcNumeProgram = [ROAFACTURARE]
	selecteaza_gestiuni()
Endif

taValori[1,1]="poAct.dataireg"
taValori[1,2]= Dtoc(poDate.dataireg)
taValori[1,3]= .T.

taValori[2,1]="poAct.dataact"
taValori[2,2]= Dtoc(poDate.dataact)
taValori[2,3]= .T.

taValori[3,1]="poAct.datascad"
taValori[3,2]= Dtoc(poDate.datascad)
taValori[3,4]= Iif(gnScadentaAutomata=0,.F.,.T.)

taValori[4,1]="poAct.id_fdoc"
taValori[4,2]=Alltrim(Str(Nvl(poDate.id_fdoc,0)))
taValori[4,4]= !Empty(Nvl(poDate.id_fdoc,0))

taValori[5,1]="poAct.fdoc"
taValori[5,2]= Alltrim(poDate.fdoc)
taValori[5,4]= !Empty(Nvl(poDate.fdoc,[]))

lnRaspuns = 6
Do While lnRaspuns = 6

*!*		taValori[6,1]="poAct.nract"
*!*		taValori[6,2]=Alltrim(Str(poDate.nract))
*!*		taValori[6,3]= !Empty(poDate.nract)

	If Inlist(tnIdSet,223,225,226,227,272)
		Dimension taValori[6,4]
		taValori[6,1]="poAct.v8"
		taValori[6,2]= Dtoc(poDate.zi_curs)
		taValori[6,4]= .F.

		poDate.in_valuta = 1
	Endif

	lnSucces=lans(tnIdSet,.F.,.T.,@taValori, .F., toActAnterior)
*!*		If lnSucces = 2
*!*			Do dezaloca_numar_fact In oserii_numere.prg
*!*		Endif

	lnRaspuns = amessagebox("Doriti sa continuati cu operatii de acest fel?",4+32,"Confirmare")
	poDate.Reset(7-lnRaspuns)
Enddo
*!*	modificare ROAGEST	v 2.0.6
*!*	If Used('nom_gestiuni')
*!*		Use In nom_gestiuni
*!*	Endif
*!*	modificare ROAGEST	v 2.0.6	^
Release poDate	&&	,pnTipFacturare	*!*	modificare	v 2.0.67
Endproc
**************************************** SFARSIT: initializeaza_vanzare_din_stoc ******************************
******************************************** INCEPUT: oscrie_vanzare_din_stoc *********************************
*!* - facturarea din gestiuni;
*!* - intrare din gestiune valorica mf la pv - aviz expeditie
Function oscrie_vanzare_din_stoc
Lparameters toSet
*!* v 2.0.18 roagest
*!* in vanzari_detalii scriu pretul cu tva daca am marfa la pret de vanzare, daca nu scriu pretul de vanzare fara tva
*!* tip = -6, id_set = 236 intrare din gestiune valorica marfa la pv - aviz expeditie
*!* tip = -6, id_set = 240 intrare din gestiune valorica (cantitativ) marfa la pv - aviz expeditie
Local lnPretCuTva, lnSucces, llSucces, lcSql
lnPretCuTva = Iif(INLIST(gnTipGest , 6,7), 1, 0)
*!* v 2.0.18 roagest ^
If Used('crsvanztemp')
	Use In crsvanztemp
Endif
If Used('crsfactura')
	Use In crsfactura
Endif

poDate.nract = poAct.nract
poDate.serie_act = poAct.serie_act

*!*	modificare	ROAFACTURARE v 2.0.68
*!*	Create Cursor crsfactura(id_temp N(15),um c(10), denumire c(100), explicatie c(240), 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),id_jtva_coloana N(10),;
*!*		valdiminuatftva N(20,4),valdiminuattva N(20,4),	valdiminuatctva N(20,4),proc_tvav N(20,4),serie c(100),;
*!*		codmat c(50), codmatf c(50), codbare c(50),cu_tva N(1),;
*!*		vpretftva N(20,4),vvalftva N(20,4),vvaltva N(20,4),vdiscountftva N(20,4),vvaldiscountftva N(20,4),vvaldiscounttva N(20,4),;
*!*		vvaldiminuatftva N(20,4),vvaldiminuattva N(20,4),vvaldiminuatctva N(20,4),gestionabil N(1))
creeaza_facturacrs([crsfactura])
*!*	modificare	ROAFACTURARE v 2.0.68	^

*!*	modificare	ROAFACTURARE v 2.0.56 : am adaugat pretd, id_valutad
*!*	modificare	ROAFACTURARE v 2.0.90 : am adaugat multiplicator
Create Cursor crsvanztemp(id_articol N(20),Pret N(20,max(gnPPretV,4)),proc_tvav N(7,3),id_jtva_coloana N(10),cantitate N(20,max(gnPCant,4)),discount_unitar N(20,max(gnPPretV,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,max(gnPCurs,6)),multiplicator N(10),pret_achizitie N(20,max(gnPPret,4)),;
	pretd N(20,max(gnPPretVal,4)),id_valuta_d N(10),id_rul_aux N(10) Null,taxcode N(6) null,lot C(20) null)
*!*	modificare	ROAGEST v 2.0.142
completeaza_facturacrs([crsfactura])
*!*	*!* v 2.0.18 roagest - am calculat total cu tva, total tva, total fara tva = diferenta, adaos
*!*	If !INLIST(gnTipGest,6,7)
*!*		Insert Into crsfactura (id_temp,denumire,serie,cantitate,cu_tva,pretftva,pretctva,;
*!*			valftva,valtva,valctva,discountftva,discountctva,valdiscountftva,;
*!*			valdiscounttva, valdiscountctva, valdiminuatftva, valdiminuattva, valdiminuatctva, proc_tvav,id_jtva_coloana,um,codmat,codbare,;
*!*			vpretftva,vvalftva,vvaltva,vdiscountftva,vvaldiscountftva,vvaldiscounttva,;
*!*			vvaldiminuatftva,vvaldiminuattva,vvaldiminuatctva,gestionabil) ;
*!*			Select Recno() As id_temp,denumire, Nvl(serie,Space(100)) As serie, cante As cantitate,m.lnPretCuTva As 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, Nvl(codmat,Space(50)) As codmat, Nvl(codbare,Space(50)) As codbare,;
*!*			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,;
*!*			1 As gestionabil From rul_temp Where cante <> 0
*!*	Else
*!*		Insert Into crsfactura (id_temp,denumire,serie,cantitate,cu_tva,pretftva,pretctva,;
*!*			valftva,valtva,valctva,discountftva,discountctva,valdiscountftva,;
*!*			valdiscounttva, valdiscountctva, valdiminuatftva, valdiminuattva, valdiminuatctva, proc_tvav,id_jtva_coloana,um,codmat,codbare,;
*!*			vpretftva,vvalftva,vvaltva,vdiscountftva,vvaldiscountftva,vvaldiscounttva,;
*!*			vvaldiminuatftva,vvaldiminuattva,vvaldiminuatctva,gestionabil) ;
*!*			Select Recno() As id_temp,denumire, Nvl(serie,Space(100)) As serie, cante As cantitate,m.lnPretCuTva As cu_tva,Round(pretv,gnPc) As pretftva, ;
*!*			Round(pretv+tvav,gnPc) As pretctva,;
*!*			Round(Round((pretv+tvav),gnPc)*cante,gnPc) - Round(Round((pretv+tvav)*cante,gnPc)*(proc_tvav-1)/proc_tvav,gnPc) As valftva, ;
*!*			Round(Round((pretv+tvav)*cante,gnPc)*(proc_tvav-1)/proc_tvav,gnPc) As valtva, ;
*!*			Round(Round((pretv+tvav),gnPc)*cante,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+tvav),gnPc)*cante,gnPc) - Round(Round((pretv+tvav)*cante,gnPc)*(proc_tvav-1)/proc_tvav,gnPc) As valdiminuatftva, ;
*!*			Round(Round((pretv+tvav)*cante,gnPc)*(proc_tvav-1)/proc_tvav,gnPc) As valdiminuattva, ;
*!*			Round(Round((pretv+tvav),gnPc)*cante,gnPc) As valdiminuatctva, ;
*!*			proc_tvav,id_jtva_coloana, Nvl(um,Space(50)) As um,Nvl(codmat,Space(50)) As codmat, Nvl(codbare,Space(50)) As codbare, 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,;
*!*			1 As gestionabil From rul_temp Where cante <> 0

*!*	*!* v 2.0.52
*!*	*!* nu am discount la vanzare - si era formula gresita - trebuia sa plece de la pretv+tvav
*!*	*!*			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,
*!*	*!* v 2.0.52 ^
*!*	Endif
*!*	*!* v 2.0.18 roagest ^
*!*	modificare	ROAGEST v 2.0.142	^
If poDate.in_valuta = 1
&&	se foloseste pretul in valuta
*!*	modificare	ROAFACTURARE v 2.0.56 : am adaugat pretd, id_valutad
*!* modificare	ROAFACTURARE v 2.0.90 : am adaugat multiplicator
	Insert Into crsvanztemp(id_articol,Pret,proc_tvav,id_jtva_coloana,cantitate,discount_unitar,id_gestiune,Cont,pret_cu_tva,;
		serie,codmat,id_valuta,Curs,multiplicator,pret_achizitie,pretd,id_valuta_d,id_rul_aux,taxcode) ;
		SELECT a.id_articol,Iif(!INLIST(gnTipGest,6,7), a.pretvval, Round(a.pretvval* proc_tva, gnPVal)),a.proc_tvav,;
		a.id_jtva_coloana,;
		a.cante As cantitate,a.discunitar As discount_unitar,a.id_gestiune,;
		a.Cont, m.lnPretCuTva As pret_cu_tva,Nvl(a.serie,Space(100)) As serie,Nvl(a.codmat,Space(50)) As codmat,;
		CAST(Nvl(a.id_valuta_vanz,0) as N(5)) As id_valuta, CAST(Nvl(b.Curs,0) as N(18,6)) As Curs,;
		CAST(NVL(b.multiplicator,1) as N(10)) as multiplicator,;
		a.Pret As pret_achizitie,a.pretd,CAST(Nvl(a.id_valuta,0) as N(5)) As id_valuta_d,a.id_rul_aux, a.taxcode ;
		From rul_temp a left join crscursuri b on NVL(a.id_valuta_vanz,0) = b.id_valuta
	Use In crscursuri

	Select crsvanztemp
	poDate.Curs = Curs
	poDate.multiplicator = multiplicator
	If !INLIST(gnTipGest,6,7)
		Calculate Sum(Round(Pret*cantitate,gnPVal)),Sum(Round(Round(Pret*cantitate,gnPVal)*(proc_tvav-1),gnPVal)) ;
			To poDate.totftvaconv,poDate.tottvaconv
		poDate.totftvaconv	=	Round(poDate.totftvaconv*poDate.Curs/poDate.multiplicator,gnPc)
		poDate.tottvaconv	=	Round(poDate.tottvaconv*poDate.Curs/poDate.multiplicator,gnPc)
		poDate.totctvaconv	=	poDate.totftvaconv+poDate.tottvaconv
	Else
		Calculate Sum(Round(Pret*cantitate,gnPVal)),Sum(Round(Round(Pret*cantitate,gnPVal)*(proc_tvav-1)/proc_tvav,gnPVal)) ;
			To poDate.totctvaconv,poDate.tottvaconv
		poDate.totctvaconv	=	Round(poDate.totctvaconv*poDate.Curs/poDate.multiplicator,gnPc)
		poDate.tottvaconv	=	Round(poDate.totcvaconv*poDate.Curs/poDate.multiplicator,gnPc)
		poDate.totftvaconv = poDate.totctvaconv	- poDate.tottvaconv
	Endif

Else
*!* poDate.tip = -6 retur
*!*	modificare	ROAFACTURARE v 2.0.56 : am adaugat pretd, id_valutad
	Insert Into crsvanztemp(id_articol,Pret,proc_tvav,id_jtva_coloana,cantitate,discount_unitar,id_gestiune,Cont,pret_cu_tva,;
		serie,codmat,id_valuta,Curs,multiplicator,pret_achizitie,pretd,id_valuta_d,id_rul_aux,taxcode) ;
		SELECT id_articol,Iif(!INLIST(gnTipGest,6,7), pretv, pretv+tvav) As Pret,proc_tvav,id_jtva_coloana,cante As cantitate,;
		discunitar As discount_unitar,Iif(poDate.tip <> -6, id_gestiune, id_gestiunec) As id_gestiune,;
		cont, m.lnPretCuTva 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,id_rul_aux,taxcode From rul_temp Where cante <> 0
Endif

Do Case
Case poDate.tip = -10
	Select Distinct dataireg,id_fdoc,dataact,datascad,nract,id_partc As id_part,nume_val,id_valuta,id_lucrare ;
		From ACTACTAN ;
		WHERE Alltrim(scd) = '6582' And Alltrim(scc) = '401' ;
		Into Cursor crstemp
Case poDate.tip = -9
	Select Distinct dataireg,id_fdoc,dataact,datascad,nract,id_partc As id_part,nume_val,id_valuta,id_lucrare ;
		From ACTACTAN ;
		WHERE Alltrim(scd) = '623' And Alltrim(scc) = '401' ;
		Into Cursor crstemp
Case poDate.tip = -6
	Select Distinct dataireg,id_fdoc,dataact,datascad,nract,id_gestin As id_part,nume_val,id_valuta,id_lucrare ;
		From ACTACTAN ;
		Where Alltrim(scc) = '371' ;
		Into Cursor crstemp
*!*	modificare ROAGEST v 2.0.46 : am inlocuit id_gestout cu id_gestin
*!*	modificare ROAGEST v 2.0.51
Case poDate.tip = -7
	Select Distinct dataireg,id_fdoc,dataact,datascad,nract,id_partd As id_part,nume_val,id_valuta,id_lucrare ;
		From ACTACTAN ;
		Where id_partd <> 0 And scd = '418' ;
		Into Cursor crstemp
*!*	modificare ROAGEST v 2.0.51	^
*!*	modificare	ROAFACTURARE v 2.0.96
CASE poDate.tip = -13
	Select Distinct dataireg,id_fdoc,dataact,datascad,nract,id_partd As id_part,nume_val,id_valuta,id_lucrare ;
		From ACTACTAN ;
		Where id_partd <> 0 And scd = '357' ;
		Into Cursor crstemp
*!*	modificare	ROAFACTURARE v 2.0.96	^
Otherwise
	Select Distinct dataireg,id_fdoc,dataact,datascad,nract,id_partd As id_part,nume_val,id_valuta,id_lucrare ;
		From ACTACTAN ;
		Where id_partd <> 0 And scd = '4111' ;
		Into Cursor crstemp
Endcase

Select crstemp
poDate.dataireg = dataireg
poDate.id_fdoc = id_fdoc
poDate.dataact = dataact
poDate.datascad = datascad
poDate.nract = nract
poDate.id_client = id_part
poDate.nume_valuta = nume_val
poDate.id_valuta = id_valuta
poDate.id_lucrare = id_lucrare
poDate.id_sectie = poAct.id_sectie
poDate.tva_incasare = poAct.tva_incasare		&&	modificare	ROAGEST v 2.2.0
Use In crstemp
*!*

Private ofrmdatesupl
*!*	modificare ROAFACTURARE v 2.0.80 : creeaza cursor
poDate.dataora_exp = Get_Ora()	&&	modificare ROAFACTURARE v 2.0.80
ofrmdatesupl = Createobject("frm_alte_date")
ofrmdatesupl.Show(1)
Release ofrmdatesupl
If gnButon = 2
	lnSucces = -1
Else
	lnSucces = SQLSetprop(gnhandle,"Transactions",2)
	If lnSucces >= 0
*!*	modificare	ROAFACTURARE	v 2.0.29
*!*				lcSql = [BEGIN ] + gcS + [.pack_facturare.initializeaza_date_factura(?poDate.dataireg,?poDate.id_fdoc,?poDate.dataact,] + ;
*!*					[?poDate.datascad,?poDate.serie_act,?poDate.nract,?poDate.id_client,?poDate.id_lucrare,NULL,NULL,NULL,?ALLTRIM(poDate.descriere),] + ;
*!*					[?poDate.Tip,?poDate.id_set,?poDate.zi_curs,?poDate.id_valuta,?poDate.in_valuta,?gnIdSucursala,?gnIdUtil); END;]
		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	ROAFACTURARE v 2.0.97
			[NULL,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	ROAGEST v 2.2.0
			Iif(Isnull(gnIdSucursala),[NULL],Alltrim(Str(gnIdSucursala))) + [,] + ;
			Alltrim(Str(gnIdUtil)) + [); end;]
*!*	modificare	ROAFACTURARE	v 2.0.29	^
		lnSucces = goExecutor.oexecute(lcSql)
		If lnSucces < 0
			amessagebox(goExecutor.oPrelucrareEroare(),16,"Eroare")
		ELSE

			Private poArticol
			Select crsvanztemp
			Scan
				Scatter Name poArticol Memo
*!*	modificare	ROAFACTURARE	v 2.0.29
*!*						lcSql = [BEGIN ] + gcS + [.pack_facturare.adauga_articol_factura_stoc(?poArticol.id_articol,?ALLTRIM(poArticol.serie),] + ;
*!*							[?poArticol.pret_achizitie,?poArticol.pret,] + ;
*!*							Iif(poDate.in_valuta=1,[?poArticol.id_valuta],[NULL]) + [,] + ;
*!*							[?poArticol.curs,?poArticol.proc_tvav,?poArticol.cantitate,?poArticol.discount_unitar,?poArticol.id_gestiune,] + ;
*!*							[?ALLTRIM(poArticol.Cont),?poArticol.pret_cu_tva); END;]
*!*	modificare	ROAFACTURARE	v 2.0.56 : am adaugat pretd, id_valuta
				lcSql = [begin ] + gcS + [.pack_facturare.adauga_articol_factura_stoc(] + ;
					Alltrim(Str(poArticol.id_articol)) + [,] + ;
					['] + Strtran(Alltrim(Nvl(poArticol.serie,[])),['],['']) + [',] + ;
					Alltrim(Str(poArticol.pret_achizitie,18,gnPPret)) + [,] + ;
					Alltrim(Str(poArticol.pretd,18,gnPPretVal)) + [,] + ;
					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,Iif(poDate.in_valuta = 1,gnPVal,gnPPretV))) + [,] + ;
					Alltrim(Str(poArticol.id_gestiune)) + [,] + ;
					['] + Alltrim(Nvl(poArticol.Cont,'')) + [',] + ;
					Alltrim(Str(poArticol.pret_cu_tva)) + [,null,]+ ;
					NVL(Alltrim(Str(poArticol.id_rul_aux)),[null])+ [,] + ;
					IIF(EMPTY(NVL(poArticol.taxcode, '')), [null], Alltrim(Str(poArticol.taxcode)))+ [,] + ;
					['] + Strtran(Alltrim(Nvl(poArticol.lot,[])),['],['']) + ['] + ;
					[); end;]
*!*	modificare	ROAFACTURARE	v 2.0.29	^
				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
*!*	modificare	ROAFACTURARE	v 2.0.44
			If lnSucces >= 0
*!*	modificare	ROAFACTURARE	v 2.0.44	^
				lnSucces = oscrie_in_fisiere(0,.F.,.T.)	&&	?
				If lnSucces >= 0
*!*	modificare	ROAFACTURARE	v 2.0.29
*!*						lcSql = [BEGIN ] + gcS + [.pack_facturare.scrie_in_vanzari(0,?poDate.id_delegat,?poDate.id_masina,] + ;
*!*							[?poDate.id_agent,?poDate.text_aditional); END;]
*!*	modificare	ROAFACTURARE	v 2.0.58 : am adaugat poDate.nid_vanzare
*!*	modificare	ROAFACTURARE	v 2.0.80 : am adaugat poDate.dataora_exp
					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); end;]
*!*	modificare	ROAFACTURARE	v 2.0.29	^
					lnSucces = goExecutor.oexecute(lcSql)
					If lnSucces < 0
						amessagebox(goExecutor.oPrelucrareEroare(),16,"Eroare")
					ELSE
						lcSql = [update vanzari set id_fact = pack_contafin.get_idFact() where id_vanzare = ?poDate.nid_vanzare]
						llSucces = goExecutor.oexecuta(lcSql)
						lnSucces = IIF(m.llSucces, 1, -1)
					ENDIF
					
				Endif
*!*	modificare	ROAFACTURARE	v 2.0.44
			Endif
*!*	modificare	ROAFACTURARE	v 2.0.44	^
		Endif
	Endif

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

	Do Case
	Case lnSucces2 < 0
		amessagebox(lcSql + Chr(13) + goExecutor.cEroare,0+16,"Eroare")
	Case lnSucces2 >=0 And lcSql = "COMMIT"
	SELECT crsvanztemp
		listeaza_ofacturare_stoc()
	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
Return lnSucces
Endfunc
******************************************** SFARSIT: oscrie_vanzare_din_stoc *********************************
******************************************* INCEPUT: relisteaza_ofacturare_stoc ********************************************
Procedure relisteaza_ofacturare_stoc
Lparameters tnNrAct, tcSerie, tnTip

Private pnCod, poDate, pnNrAct, pcSerie
*!*	modificare	v 2.0.67
*!*	PRIVATE pnTipFacturare
*!*	pnTipFacturare = 0
*!*	modificare	v 2.0.67	^

pnNrAct = tnNrAct
If !Inlist(tnTip ,-9,-10)
	pcSerie = Iif(Empty(Nvl(tcSerie,'')),[+_],Alltrim(tcSerie))
Else
	pcSerie = Nvl(tcSerie,[+_])
Endif
lcSql = [Select distinct cod,datascad,dataact from act ] + ;
	[where an = ?gnAn and luna = ?gnLuna and sters = 0 and nract = ?pnNrAct and Nvl(serie_act,'+_') LIKE '%]+Alltrim(pcSerie)+[%' ]
Do Case
Case tnTip = 1
	lcSql = lcSql + [ and scd = '418']
Case tnTip = -6 && aviz de retur de la o gestiune valorica
	lcSql = lcSql + [ and scc = '371']
Case tnTip = -10
	lcSql = lcSql + [ and scd = '6582' and scc = '401' ]
Case tnTip = -9
	lcSql = lcSql + [ and scd = '623' and scc = '401' ]
Otherwise
	lcSql = lcSql + [ and scd = '4111']
Endcase

lcSql = lcSql + [ and sters = 0] + gcCondSucursala + [ order by datascad desc]
lcCursor=[crsact]
lnSucces = goExecutor.oexecute(lcSql,lcCursor)
If lnSucces < 0
	amessagebox(goExecutor.cEroare,0+16,"Eroare")
	Return
Endif

If Reccount(lcCursor) > 0
	Select (lcCursor)
	pnCod = cod
	poDate=Createobject("oDateFactura",0,0)
	poDate.nract = pnNrAct
	poDate.serie_act = pcSerie
	poDate.dataact = Iif(Type('dataact')='T',Ttod(dataact),dataact)
	poDate.datascad = Iif(Type('datascad')='T',Ttod(datascad),datascad)
	Use In (lcCursor)

	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,tva_incasare from fact_vfacturi where cod = ] + ALLTRIM(STR(pnCod))
	lnSucces = goExecutor.oexecute(lcSql,[crsfacturi])
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,"Eroare")
		Return
	Endif

	Select crsfacturi
	poDate.nRelistare = 1		&&	modificare	ROAFACTURARE v 2.0.58
	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	&&	modificare ROAFACTURARE v 2.0.80
	poDate.afisare_scadenta = afisare_scadenta	&&	modificare	ROACONTRACTE v 2.0.38
*!*	modificare	ROAFACTURARE	v 2.0.68
*!*		poDate.listaid = Iif(poDate.tip = 2,Alltrim(Str(id_ctr)),Iif(poDate.tip = 3,Alltrim(Str(id_comanda)), [0]))
	poDate.listaid = Iif(poDate.tip = 3,Alltrim(Str(id_comanda)), [0])
*!*	modificare	ROAFACTURARE	v 2.0.68	^
	poDate.ntip_incasare = tip_incasare			&&	modificare ROAFACTURARE v 2.0.84
 	poDate.serie_chit = NVL(serie_chit,[])		&&	modificare ROAFACTURARE v 2.0.80
	poDate.nr_incasare = nr_incasare
	poDate.incasat = incasat
	poDate.tva_incasare = tva_incasare			&&	modificare	ROAGEST v 2.2.0
	IF tnTip = -6 && aviz de retur de la o gestiune valorica
		IF tnTip <> poDate.tip	
			amessagebox("Nu exista " + Iif(tnTip = 1,[avizul],[factura]) + " cu acest numar in luna curenta!",48,"Atentie")
			USE IN crsFacturi
			RELEASE podate
			RETURN
		ENDIF 
		poDate.id_client = id_gestiune
	ELSE 
		poDate.id_client = id_part
	ENDIF 
	poDate.nume_client = client
	poDate.in_valuta = in_valuta
	If poDate.in_valuta = 1
		poDate.nume_valuta = nume_val
		poDate.Curs = Curs
		poDate.multiplicator = multiplicator
		poDate.totftvaconv = total_fara_tva
		poDate.tottvaconv = total_tva
		poDate.totctvaconv = poDate.totftvaconv + poDate.tottvaconv
		lnDiscountVal = discount
		lnDiscount = Round(lnDiscountVal * poDate.Curs / poDate.multiplicator,gnPPretV)
	Else
		lnDiscount = discount
		lnDiscountVal = 0
	Endif
	Use In crsfacturi

*!*	modificare	ROAFACTURARE v 2.0.46
*!*	*!* v 2.0.18 roagest (codmat)
*!*		lcSql = [select explicatie,codmat,denumire,cantitate,proc_tvav,um,pret_cu_tva,pret,discount_unitar,serie,pret_val,nume_val,] + ;
*!*			[discount_unitar_val,curs,codbare from fact_vfacturi_detalii where id_vanzare = ?pnIdVanzare]
*!*	*!* v 2.0.18 roagest ^
*!*	modificare ROAFACTURARE v 2.0.56 : am adaugat id_temp
*!*	modificare ROAFACTURARE v 2.0.68 : am adaugat id_ctr,numar_contract,id_valuta,tip_valuta,curs,nume_val
	lcSql = [select * from fact_vfacturi_detalii where id_vanzare = ] + ALLTRIM(STR(poDate.nid_vanzare))
*!*	modificare	ROAFACTURARE v 2.0.46	^
	lnSucces = goExecutor.oexecute(lcSql,[crsdetalii])
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,"Eroare")
		Return
	Endif

*!* v 2.0.18 roagest (codmat, total cu tva, total tva, total fara tva = diferenta)
	Select crsdetalii
	Calculate Max(proc_tvav) To lnProcTvav
*!*		Select explicatie,codmat,denumire,Nvl(serie,'') As serie,Nvl(cantitate,1) As cantitate,proc_tvav,Nvl(um,'') As um, ;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Pret,gnPc),;
*!*			Round(Round(Pret,gnPc)/proc_tvav,gnPc)) As pretftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Round(Pret,gnPc)*Nvl(cantitate,1),gnPc),;
*!*			ROUND(Round(Round(Pret,gnPc)/proc_tvav,gnPc)*Nvl(cantitate,1),gnPc)) As valftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Round(Round(Pret,gnPc)*Nvl(cantitate,1),gnPc)*(proc_tvav-1),gnPc),;
*!*			ROUND(Round(Pret,gnPc)*Nvl(cantitate,1),gnPc)-;
*!*			Round(Round(Round(Pret,gnPc)/proc_tvav,gnPc)*Nvl(cantitate,1),gnPc)) As valtva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(discount_unitar,gnPc),;
*!*			Round(Round(discount_unitar,gnPc)/proc_tvav,gnPc)) As discountftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Round(discount_unitar,gnPc)*Nvl(cantitate,1),gnPc),;
*!*			ROUND(Round(Round(discount_unitar,gnPc)/proc_tvav,gnPc)*Nvl(cantitate,1),gnPc)) As valdiscountftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			ROUND(Round(Round(discount_unitar,gnPc)*Nvl(cantitate,1),gnPc)*(proc_tvav-1),gnPc),;
*!*			ROUND(Round(discount_unitar,gnPc)*Nvl(cantitate,1),gnPc)-;
*!*			Round(Round(Round(discount_unitar,gnPc)/proc_tvav,gnPc)*Nvl(cantitate,1),gnPc)) As valdiscounttva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round((Round(Pret,gnPc)-Round(discount_unitar,gnPc))*Nvl(cantitate,1),gnPc),;
*!*			ROUND(Round((Round(Pret,gnPc)-Round(discount_unitar,gnPc))/proc_tvav,gnPc)*Nvl(cantitate,1),gnPc)) As valdiminuatftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Round((Round(Pret,gnPc)-Round(discount_unitar,gnPc))*Nvl(cantitate,1),gnPc)*(proc_tvav-1),gnPc),;
*!*			ROUND((Round(Pret,gnPc)-Round(discount_unitar,gnPc))*Nvl(cantitate,1),gnPc)-;
*!*			Round(Round((Round(Pret,gnPc)-Round(discount_unitar,gnPc))/proc_tvav,gnPc)*Nvl(cantitate,1),gnPc)) As valdiminuattva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(pret_val,gnPVal),;
*!*			Round(Round(pret_val,gnPVal)/proc_tvav,gnPVal)) As vpretftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Round(pret_val,gnPVal)*Nvl(cantitate,1),gnPVal),;
*!*			ROUND(Round(Round(pret_val,gnPVal)/proc_tvav,gnPVal)*Nvl(cantitate,1),gnPVal)) As vvalftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Round(Round(pret_val,gnPVal)*Nvl(cantitate,1),gnPVal)*(proc_tvav-1),gnPVal),;
*!*			ROUND(Round(pret_val,gnPVal)*Nvl(cantitate,1),gnPVal)-;
*!*			Round(Round(Round(pret_val,gnPVal)/proc_tvav,gnPVal)*Nvl(cantitate,1),gnPVal)) As vvaltva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(discount_unitar_val,gnPc),;
*!*			Round(Round(discount_unitar_val,gnPc)/proc_tvav,gnPc)) As vdiscountftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Round(discount_unitar_val,gnPc)*Nvl(cantitate,1),gnPc),;
*!*			ROUND(Round(Round(discount_unitar_val,gnPc)/proc_tvav,gnPc)*Nvl(cantitate,1),gnPc)) As vvaldiscountftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			ROUND(Round(Round(discount_unitar_val,gnPc)*Nvl(cantitate,1),gnPc)*(proc_tvav-1),gnPc),;
*!*			ROUND(Round(discount_unitar_val,gnPc)*Nvl(cantitate,1),gnPc)-;
*!*			Round(Round(Round(discount_unitar_val,gnPc)/proc_tvav,gnPc)*Nvl(cantitate,1),gnPc)) As vvaldiscounttva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round((Round(Pret_val,gnPc)-Round(discount_unitar_val,gnPc))*Nvl(cantitate,1),gnPc),;
*!*			ROUND(Round((Round(Pret_val,gnPc)-Round(discount_unitar_val,gnPc))/proc_tvav,gnPc)*Nvl(cantitate,1),gnPc)) As vvaldiminuatftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Round((Round(Pret_val,gnPc)-Round(discount_unitar_val,gnPc))*Nvl(cantitate,1),gnPc)*(proc_tvav-1),gnPc),;
*!*			ROUND((Round(Pret_val,gnPc)-Round(discount_unitar_val,gnPc))*Nvl(cantitate,1),gnPc)-;
*!*			Round(Round((Round(Pret_val,gnPc)-Round(discount_unitar_val,gnPc))/proc_tvav,gnPc)*Nvl(cantitate,1),gnPc)) As vvaldiminuattva ;
*!*			From crsdetalii Into Cursor crsfactura Readwrite

*!*	modificare ROAFACTURARE	v 2.0.77
*!*	*!*	modificare ROAFACTURARE v 2.0.56 : am adaugat id_temp
*!*		Select id_temp,explicatie,Nvl(codmat,Space(50)) As codmat,Nvl(codmatf,Space(50)) As codmatf,Nvl(codbare,Space(50)) As codbare,;
*!*			Iif(Nvl(id_gestiune,0)<>0,1,0) As gestionabil,denumire,Nvl(serie,Space(100)) As serie,Nvl(cantitate,1) As cantitate,;
*!*			proc_tvav,id_jtva_coloana,Nvl(um,Space(10)) As um,pret_cu_tva As cu_tva,;
*!*			Iif(pret_cu_tva = 1,Round(Pret,gnPc),Round(Pret,gnPc)+Round(Round(Pret,gnPc)*(proc_tvav-1),gnPc)) As pretctva,;
*!*			Iif(pret_cu_tva = 1,Round(discount_unitar,gnPc),0) As discountctva,;
*!*			Iif(pret_cu_tva = 1,Round(Round(Pret,gnPc)*Nvl(cantitate,1),gnPc),Round(Round(Pret,gnPc)*Nvl(cantitate,1),gnPc)+;
*!*			Round(Round(Round(Pret,gnPc)*Nvl(cantitate,1),gnPc)*(proc_tvav-1),gnPc)) As valctva,;
*!*			Iif(pret_cu_tva = 1,Round(Round(discount_unitar,gnPc)*Nvl(cantitate,1),gnPc),;
*!*			ROUND((Round(discount_unitar,gnPc)-Round(Round(discount_unitar,gnPc)*(proc_tvav-1),gnPc))*Nvl(cantitate,1),gnPc)) As valdiscountctva,;
*!*			IIF(pret_cu_tva = 1,;
*!*			ROUND((Round(Pret,gnPc)-Round(discount_unitar,gnPc))*Nvl(cantitate,1),gnPc),;
*!*			ROUND((Round(Pret,gnPc)+Round(Round(Pret,gnPc)*(proc_tvav-1),gnPc)-Round(discount_unitar,gnPc)-Round(Round(discount_unitar,gnPc)*(proc_tvav-1),gnPc))*Nvl(cantitate,1),gnPc)) As valdiminuatctva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Pret,gnPc),;
*!*			Round(Round(Pret,gnPc)/proc_tvav,gnPc)) As pretftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Round(Pret,gnPc)*Nvl(cantitate,1),gnPc),;
*!*			ROUND(Round(Pret,gnPc)*Nvl(cantitate,1),gnPc) - ;
*!*			Round(Round(Round(Pret,gnPc)*Nvl(cantitate,1),gnPc)*(proc_tvav-1)/proc_tvav, gnPc)) As valftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Round(Round(Pret,gnPc)*Nvl(cantitate,1),gnPc)*(proc_tvav-1),gnPc),;
*!*			Round(Round(Round(Pret,gnPc)*Nvl(cantitate,1),gnPc)*(proc_tvav-1)/proc_tvav, gnPc)) As valtva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(discount_unitar,gnPc),;
*!*			Round(Round(discount_unitar,gnPc)/proc_tvav,gnPc)) As discountftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Round(discount_unitar,gnPc)*Nvl(cantitate,1),gnPc),;
*!*			ROUND(Round(discount_unitar,gnPc)*Nvl(cantitate,1),gnPc) - ;
*!*			Round(Round(Round(discount_unitar,gnPc)*Nvl(cantitate,1),gnPc)*(proc_tvav-1)/proc_tvav, gnPc)) As valdiscountftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			ROUND(Round(Round(discount_unitar,gnPc)*Nvl(cantitate,1),gnPc)*(proc_tvav-1),gnPc),;
*!*			Round(Round(Round(discount_unitar,gnPc)*Nvl(cantitate,1),gnPc)*(proc_tvav-1)/proc_tvav, gnPc)) As valdiscounttva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round((Round(Pret,gnPc)-Round(discount_unitar,gnPc))*Nvl(cantitate,1),gnPc),;
*!*			ROUND((Round(Pret,gnPc)-Round(discount_unitar,gnPc))*Nvl(cantitate,1),gnPc) - ;
*!*			Round(Round((Round(Pret,gnPc)-Round(discount_unitar,gnPc))*Nvl(cantitate,1),gnPc)*(proc_tvav-1)/proc_tvav, gnPc)) As valdiminuatftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Round((Round(Pret,gnPc)-Round(discount_unitar,gnPc))*Nvl(cantitate,1),gnPc)*(proc_tvav-1),gnPc),;
*!*			Round(Round((Round(Pret,gnPc)-Round(discount_unitar,gnPc))*Nvl(cantitate,1),gnPc)*(proc_tvav-1)/proc_tvav, gnPc)) As valdiminuattva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(pret_val,gnPVal),;
*!*			Round(Round(pret_val,gnPVal)/proc_tvav,gnPVal)) As vpretftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Round(pret_val,gnPVal)*Nvl(cantitate,1),gnPVal),;
*!*			ROUND(Round(pret_val,gnPVal)*Nvl(cantitate,1),gnPVal) - ;
*!*			Round(Round(Round(pret_val,gnPVal)*Nvl(cantitate,1),gnPVal)*(proc_tvav-1)/proc_tvav, gnPVal)) As vvalftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Round(Round(pret_val,gnPVal)*Nvl(cantitate,1),gnPVal)*(proc_tvav-1),gnPVal),;
*!*			Round(Round(Round(pret_val,gnPVal)*Nvl(cantitate,1),gnPVal)*(proc_tvav-1)/proc_tvav, gnPVal)) As vvaltva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(discount_unitar_val,gnPVal),;
*!*			Round(Round(discount_unitar_val,gnPVal)/proc_tvav,gnPVal)) As vdiscountftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Round(discount_unitar_val,gnPVal)*Nvl(cantitate,1),gnPVal),;
*!*			ROUND(Round(discount_unitar_val,gnPVal)*Nvl(cantitate,1),gnPVal) - ;
*!*			Round(Round(Round(discount_unitar_val,gnPVal)*Nvl(cantitate,1),gnPVal)*(proc_tvav-1)/proc_tvav, gnPVal)) As vvaldiscountftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			ROUND(Round(Round(discount_unitar_val,gnPVal)*Nvl(cantitate,1),gnPVal)*(proc_tvav-1),gnPVal),;
*!*			Round(Round(Round(discount_unitar_val,gnPVal)*Nvl(cantitate,1),gnPVal)*(proc_tvav-1)/proc_tvav, gnPVal)) As vvaldiscounttva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round((Round(pret_val,gnPVal)-Round(discount_unitar_val,gnPVal))*Nvl(cantitate,1),gnPVal),;
*!*			ROUND((Round(pret_val,gnPVal)-Round(discount_unitar_val,gnPVal))*Nvl(cantitate,1),gnPVal) - ;
*!*			Round(Round((Round(pret_val,gnPVal)-Round(discount_unitar_val,gnPVal))*Nvl(cantitate,1), gnPVal)*(proc_tvav-1)/proc_tvav, gnPVal)) As vvaldiminuatftva,;
*!*			IIF(pret_cu_tva = 0,;
*!*			Round(Round((Round(pret_val,gnPVal)-Round(discount_unitar_val,gnPVal))*Nvl(cantitate,1),gnPVal)*(proc_tvav-1),gnPVal),;
*!*			Round(Round((Round(pret_val,gnPVal)-Round(discount_unitar_val,gnPVal))*Nvl(cantitate,1), gnPVal)*(proc_tvav-1)/proc_tvav, gnPVal)) As vvaldiminuattva, ;
*!*			id_ctr,numar_contract,id_valuta,tip_valuta,NVL(curs,1.000) as curs,nume_val	;		&&	modificare ROAFACTURARE v 2.0.68
*!*			From crsdetalii Into Cursor crsfactura Readwrite
*!*	*!* v 2.0.18 roagest ^
*!*		If lnDiscount<> 0
*!*			Select crsfactura
*!*	*!*	modificare ROAFACTURARE v 2.0.56
*!*	*!*			Calculate Sum(valdiminuatftva),Sum(vvaldiminuatftva) To lnTotalBaza,lnTotalBazaVal
*!*			Calculate Sum(valdiminuatftva),Sum(vvaldiminuatftva),Max(id_temp) To lnTotalBaza,lnTotalBazaVal,lnIdTemp
*!*	*!*	modificare ROAFACTURARE v 2.0.56	^
*!*			Select crsfactura
*!*			Append Blank
*!*	*!*	modificare ROAFACTURARE v 2.0.56 : am adaugat id_temp
*!*			Replace denumire With Replicate('Z',20),cantitate With 1,;
*!*				pretftva With lnTotalBaza,discountftva With lnDiscount,valdiscountftva With lnDiscount,;
*!*				valdiscounttva With Round(lnDiscount * (lnProcTvav - 1),gnPc),;
*!*				vpretftva With lnTotalBazaVal,vdiscountftva With lnDiscountVal,vvaldiscountftva With lnDiscountVal,;
*!*				vvaldiscounttva With Round(lnDiscountVal * (lnProcTvav - 1),gnPc),;
*!*				proc_tvav With lnProcTvav,id_temp With lnIdTemp + 1
*!*		Endif
	creeaza_facturacrs([crsfactura])
	prelucreaza_facturacrs([crsdetalii],[crsfactura],lnProcTvav,lnDiscount,lnDiscountVal)
	Use In crsdetalii
*!*	modificare	ROAFACTURARE v 2.0.77	^
	listeaza_ofacturare_stoc()

	If Used('crsfactura')
		Use In crsfactura
	Endif

	Release poDate
Else
	amessagebox("Nu exista " + Iif(tnTip = 1,[avizul],[factura]) + " cu acest numar in luna curenta!",48,"Atentie")
Endif

Endproc	&&	relisteaza_ofacturare_stoc
******************************************* SFARSIT: relisteaza_ofacturare_stoc ********************************************
******************************************** INCEPUT: listeaza_ofacturare_stoc *********************************************
Procedure listeaza_ofacturare_stoc
*!*	modificare	ROAFACTURARE	v 2.0.77
*!*	Local loArticol
*!*	Private poClient,ptDataOra,pcExplicatieContract,pnTotalPozitii

*!*	************************************************
*!*	**	Date client, responsabil facturare si firma
*!*	************************************************
*!*	Do Case
*!*	Case poDate.tip = 30
*!*		lcSql = [select 1 as tip,Nvl(c.denumire,a.nume_gestiune) as denumire,a.cgest as cod_fiscal,] + ;
*!*			[Nvl(c.adresa,'') as adresa,'' as telefon,'' as fax,] + ;
*!*			['' as reg_comert,'' as banca,'' as cont_banca,] + ;
*!*			['' as banca2,'' as cont_banca2,'' as banca3,'' as cont_banca3,] + ;
*!*			[sysdate as dataora,1 as tip_persoana,0 as capital_soc_var,] + ;
*!*			[0 as capital_soc_sub from ] + gcS + [.nom_gestiuni a ] + ;
*!*			[left join ] + gcS + [.asociere_parteneri_gestiuni b on a.id_gestiune = b.id_gestiune ] + ;
*!*			[left join ] + gcS + [.nom_parteneri c on b.id_part = c.id_part ] + ;
*!*			[where a.id_gestiune = ?poDateGestiuneDest.id_gestiune ] + ;
*!*			[union all ] + ;
*!*			[select 2 as tip,denumire,cod_fiscal,'' as adresa,'' as telefon,'' as fax,'' as reg_comert,'' as banca,] + ;
*!*			['' as cont_banca,] + ;
*!*			['' as banca2,'' as cont_banca2,'' as banca3,'' as cont_banca3,] + ;
*!*			[null as dataora,tip_persoana,0 as capital_soc_var,0 as capital_soc_sub ] + ;
*!*			[from ] + gcS + [.nom_parteneri where sters = 0 and inactiv = 0 and id_part in ] + ;
*!*			[(select id_partener from ] + gcS + [.utilizatori_rol_intern where sters = 0 and id_util = ?gnIdUtil)] + ;
*!*			[union all ] + ;
*!*			[select 3 as tip,antet as denumire,cod_fiscal,adresa,telefon,fax,reg_comert,] + ;
*!*			[banca1 as banca,cont_banca1 as cont_banca,] + ;
*!*			[banca2,cont_banca2,banca3,cont_banca3,] + ;
*!*			[null as dataora,0 as tip_persoana,capital_soc_var,capital_soc_sub ] + ;
*!*			[from syn_nom_firme where id_firma = ?gnIdFirma]
*!*	Case Inlist(poDate.tip , -6) && RETUR AVIZ DIN GESTIUNE VALORICA (ROAGEST)
*!*		lcSql = [select 1 as tip,Nvl(c.denumire,a.nume_gestiune) as denumire,a.cgest as cod_fiscal,] + ;
*!*			[Nvl(c.adresa,'') as adresa,'' as telefon,'' as fax,] + ;
*!*			['' as reg_comert,'' as banca,'' as cont_banca,] + ;
*!*			['' as banca2,'' as cont_banca2,'' as banca3,'' as cont_banca3,] + ;
*!*			[sysdate as dataora,1 as tip_persoana,0 as capital_soc_var,] + ;
*!*			[0 as capital_soc_sub from ] + gcS + [.nom_gestiuni a ] + ;
*!*			[left join ] + gcS + [.asociere_parteneri_gestiuni b on a.id_gestiune = b.id_gestiune ] + ;
*!*			[left join ] + gcS + [.nom_parteneri c on b.id_part = c.id_part ] + ;
*!*			[where a.id_gestiune = ?poDate.id_client ] + ;
*!*			[union all ] + ;
*!*			[select 2 as tip,denumire,cod_fiscal,'' as adresa,'' as telefon,'' as fax,'' as reg_comert,'' as banca,] + ;
*!*			['' as cont_banca,] + ;
*!*			['' as banca2,'' as cont_banca2,'' as banca3,'' as cont_banca3,] + ;
*!*			[null as dataora,tip_persoana,0 as capital_soc_var,0 as capital_soc_sub ] + ;
*!*			[from ] + gcS + [.nom_parteneri where sters = 0 and inactiv = 0 and id_part in ] + ;
*!*			[(select id_partener from ] + gcS + [.utilizatori_rol_intern where sters = 0 and id_util = ?gnIdUtil)] + ;
*!*			[union all ] + ;
*!*			[select 3 as tip,antet as denumire,cod_fiscal,adresa,telefon,fax,reg_comert,] + ;
*!*			[banca1 as banca,cont_banca1 as cont_banca,] + ;
*!*			[banca2,cont_banca2,banca3,cont_banca3,] + ;
*!*			[null as dataora,0 as tip_persoana,capital_soc_var,capital_soc_sub ] + ;
*!*			[from syn_nom_firme where id_firma = ?gnIdFirma]
*!*	Otherwise
*!*		lcSql = [select 1 as tip,(case when tip_persoana = 1 then prefix||' '||denumire||' '||sufix else denumire end) as denumire,]+;
*!*			[cod_fiscal,adresa,telefon,'' as fax,reg_comert,banca,cont_banca,] + ;
*!*			['' as banca2,'' as cont_banca2,'' as banca3,'' as cont_banca3,] + ;
*!*			[sysdate as dataora,tip_persoana,0 as capital_soc_var,] + ;
*!*			[0 as capital_soc_sub from ] + gcS + [.vnom_parteneri where id_part = ?poDate.id_client ] + ;
*!*			[union all ] + ;
*!*			[select 2 as tip,denumire,cod_fiscal,'' as adresa,'' as telefon,'' as fax,reg_comert,'' as banca,'' as cont_banca,] + ;
*!*			['' as banca2,'' as cont_banca2,'' as banca3,'' as cont_banca3,] + ;
*!*			[null as dataora,tip_persoana,0 as capital_soc_var,0 as capital_soc_sub from ] + gcS + [.nom_parteneri ] + ;
*!*			[where sters = 0 and inactiv = 0 and id_part in ] + ;
*!*			[(select id_partener from ] + gcS + [.utilizatori_rol_intern where sters = 0 and id_util = ?gnIdUtil)] + ;
*!*			[union all ] + ;
*!*			[select 3 as tip,antet as denumire,cod_fiscal,adresa,telefon,fax,reg_comert,banca1 as banca,] + ;
*!*			[cont_banca1 as cont_banca,] + ;
*!*			[banca2,cont_banca2,banca3,cont_banca3,] + ;
*!*			[null as dataora,0 as tip_persoana,capital_soc_var,capital_soc_sub ] + ;
*!*			[from syn_nom_firme where id_firma = ?gnIdFirma ]
*!*	Endcase

*!*	If Used('crsdatefacturare')
*!*		Use In crsdatefacturare
*!*	Endif
*!*	lcCursor = [crsdatefacturare]
*!*	lnSucces = goExecutor.oexecute(lcSql,lcCursor)
*!*	If lnSucces<0
*!*		amessagebox(goExecutor.oPrelucrareEroare(),16,"Eroare")
*!*		Return
*!*	Endif

*!*	Select crsdatefacturare
*!*	Scan
*!*		Do Case
*!*		Case tip= 1
*!*			Scatter Name poClient Memo
*!*			ptDataOra = poClient.dataora
*!*		Case tip = 2
*!*			With poDate
*!*				.nume_responsabil	=	denumire
*!*				.BIresp				=	reg_comert
*!*				.CNPresp			=	cod_fiscal
*!*			Endwith
*!*		Otherwise
*!*			Scatter Name poFirma Memo
*!*		Endcase
*!*	Endscan
*!*	Use In crsdatefacturare
*!*	************************************************
*!*	*!*	modificare	ROAFACTURARE	v 2.0.46
*!*	*!*	pcExplicatieContract = []
*!*	************************************************
*!*	AddProperty(poClient,'denumireClient',[])
*!*	*!*	AddProperty(poClient,'gestiune',[])
*!*	AddProperty(poFirma,'b_swift',[])
*!*	AddProperty(poFirma,'b_adresa',[])
*!*	AddProperty(poFirma,'b_swift2',[])
*!*	AddProperty(poFirma,'b_adresa2',[])
*!*	AddProperty(poFirma,'b_swift3',[])
*!*	AddProperty(poFirma,'b_adresa3',[])
*!*	************************************************
*!*	pcExplicatieContract = []
*!*	*!*	modificare	ROAFACTURARE v 2.0.58
*!*	If poDate.nRelistare = 0
*!*		poDate.nSalveazaAtasamente = Nvl(citeste_optiune_firma([ATASAMENTEFACT]),0)
*!*	Endif
*!*	*!*	modificare	ROAFACTURARE v 2.0.58	^

*!*	alege_optiuni_listare_facturare()
*!*	If glAlegeBanca
*!*		alege_banci_facturare()
*!*	Endif
*!*	*!*	modificare	ROAFACTURARE	v 2.0.46	^

*!*	Select crsfactura
*!*	Calculate Max(Round(Nvl(proc_tvav,1),2)) To poDate.proc_tva
*!*	poDate.proc_tva = poDate.proc_tva*100-100

*!*	*!*	modificare	v 2.0.67	^
*!*	*!*	prelucreaza_factura(poDate.discount_evidentiat,pnTipFacturare,poDate.in_valuta,gnPretListSubunitati)		&&	ofacturare_comun.prg
*!*	prelucreaza_factura([crsfactura],[crsfacturaset],[crsfacturafinala],poDate.discount_evidentiat,poDate.in_valuta,gnPretListSubunitati)
*!*	*!*	modificare	v 2.0.67	^

*!*	*!*	modificare ROAFACTURARE	v 2.0.46
*!*	*!*	Local loExport
*!*	*!*	loExport = Createobject("oExportConfig")
*!*	*!*	lnVizualizare = Iif(Type('gnVizualFact')='N',gnVizualFact,1)
*!*	*!*	modificare ROAFACTURARE	v 2.0.46	^
*!*	lcSetare = [FACTURA]
*!*	lnVizualizare = Iif(Type('gnVizualFact')='N',gnVizualFact,1)
*!*	*!* 30 transfer catre subunitati pe baza de NIR
*!*	*!* -6 intrare din gestiune valorica mf la pv - aviz expeditie
*!*	Do Case
*!*	Case Inlist(poDate.tip, 30, -6,-9)
*!*		If Nvl(gnPretListSubunitati,2)=2
*!*			lcRaport = [AVIZ_TRANSFER]
*!*		Else
*!*			lcRaport = [AVIZ_TRANSFER_CTVA]
*!*		Endif
*!*		lcSetare = [AVIZ]
*!*		lcExplicatieRaport = [avizul de transfer]
*!*	*!*	modificare ROAFACTURARE	v 2.0.46
*!*	*!*		lnVizualizare = Iif(Type('gnVizualAviz')='N',gnVizualAviz,1)
*!*		lcSetareVizualizare = [PREVIZAVIZ]
*!*	*!*	modificare ROAFACTURARE	v 2.0.46	^
*!*	Case Inlist(poDate.tip,-10)

*!*		Select crsfacturafinala
*!*	*!*		REPLACE ALL pretctva WITH pretftva,valctva WITH valftva
*!*		If Nvl(gnPretListSubunitati,2)=2
*!*			lcRaport = [AVIZ_TRANSFER]
*!*		Else
*!*			lcRaport = [AVIZ_TRANSFER_CTVA]
*!*		Endif
*!*		lcSetare = [AVIZ_TRANSFER]
*!*		lcExplicatieRaport = [avizul de transfer]
*!*	*!*	modificare ROAFACTURARE	v 2.0.46
*!*	*!*		lnVizualizare = Iif(Type('gnVizualAviz')='N',gnVizualAviz,1)
*!*		lcSetareVizualizare = [PREVIZAVIZ]
*!*	*!*	modificare ROAFACTURARE	v 2.0.46	^
*!*	Case poDate.tip = -7
*!*		lcRaport = [AVIZ]
*!*		lcSetare = [AVIZ]
*!*		lcExplicatieRaport = [avizul]
*!*		lnVizualizare = Iif(Type('gnVizualAviz')='N',gnVizualAviz,1)
*!*		lcSetareVizualizare = [PREVIZAVIZ]
*!*	Otherwise
*!*		lcExplicatieRaport = [factura]
*!*		Do Case
*!*		Case gnFormatFactura = 1	&&  format A4
*!*			lcRaport = [FACTURA]
*!*		Case gnFormatFactura = 2	&&	format A5
*!*			lcRaport = [FACTURA_A5]
*!*		Case gnFormatFactura = 3
*!*			If optiuni_format_listare(0) = 2
*!*				lcRaport = [FACTURA_A5]
*!*			Else
*!*				lcRaport = [FACTURA]
*!*			Endif
*!*		Endcase
*!*	*!*	modificare ROAFACTURARE	v 2.0.46
*!*		lcSetareVizualizare = [PREVIZFACT]
*!*	*!*	modificare ROAFACTURARE	v 2.0.46	^
*!*	Endcase


*!*	If poDate.in_valuta = 1
*!*	*!*	modificare	ROAFACTURARE v 2.0.46
*!*		poDate.text_aditional_invoice = poDate.text_aditional
*!*	*!*	modificare	ROAFACTURARE v 2.0.46	^
*!*		poDate.text_aditional = Iif(!Empty(Nvl(poDate.text_aditional,[])),poDate.text_aditional+Chr(13)+Chr(10),[])+;
*!*			[Curs valutar = ]+Alltrim(Str(poDate.Curs,14,4))+[ RON / ] + Alltrim(poDate.nume_valuta)
*!*	Endif

*!*	If poDate.incasat <> 0
*!*		poDate.text_aditional = Iif(!Empty(Nvl(poDate.text_aditional,[])),poDate.text_aditional+Chr(13)+Chr(10),[])+;
*!*			[ Achitat cu numerar cu chitanta nr. ] + Alltrim(Str(poDate.nr_incasare)) + [ din ] + Dtoc(poDate.dataact)
*!*	Endif

*!*	Select crsfacturafinala
*!*	Calculate Cnt() To pnTotalPozitii For cantitate <> 0
*!*	Go Top
*!*	*!*	modificare	ROAFACTURARE	v 2.0.58
*!*	If	poDate.nRelistare =	0 And poDate.eProforma = 0 And poDate.nSalveazaAtasamente = 1
*!*		goExport.export2pdf('crsfacturafinala', lcRaport,.F.,poDate.cDocAtasate)
*!*	Endif
*!*	*!*	modificare	ROAFACTURARE	v 2.0.58	^
*!*	lnRaspuns=6
*!*	Do While lnRaspuns=6
*!*	*!*	modificare ROAFACTURARE	v 2.0.46
*!*		goExport.export2frx('crsfacturafinala',lcRaport,.F.,lcSetareVizualizare,lcSetare)
*!*	*!*		loExport.listareUserReport('crsfacturafinala','FRX',lcRaport,lnVizualizare,lcSetare)
*!*	*!*	modificare ROAFACTURARE	v 2.0.46
*!*		lnRaspuns=amessagebox("Doriti sa mai listati "+lcExplicatieRaport+"?",4+32+256,"Confirmare repetare listare")
*!*	Enddo

*!*	If poDate.in_valuta = 1
*!*	*!*	modificare ROAFACTURARE v 2.0.56
*!*	*!*		lcRaportVal = lcRaport + [_VAL]
*!*	*!*		poDate.text_aditional = Strtran(poDate.text_aditional,[Curs valutar =],[Exchange rate =])
*!*		lcRaportVal = Strtran(lcRaport,[FACTURA],[INVOICE])
*!*	*!*	modificare ROAFACTURARE v 2.0.56	^
*!*		Select crsfacturafinalaval
*!*		Calculate Cnt() To pnTotalPozitii For cantitate <> 0
*!*		Go Top
*!*	*!*	modificare	ROAFACTURARE	v 2.0.58
*!*		If	poDate.nRelistare =	0 And poDate.eProforma = 0 And poDate.nSalveazaAtasamente = 1
*!*			goExport.export2pdf('crsfacturafinalaval', lcRaportVal,.F.,poDate.cDocAtasate)
*!*		Endif
*!*	*!*	modificare	ROAFACTURARE	v 2.0.58	^

*!*		lnRaspuns=6
*!*		Do While lnRaspuns=6
*!*	*!*	modificare ROAFACTURARE	v 2.0.46
*!*			goExport.export2frx('crsfacturafinalaval',lcRaportVal,.F.,lcSetareVizualizare,lcSetare)
*!*	*!*			loExport.listareUserReport('crsfacturafinalaval','FRX',lcRaportVal,lnVizualizare,lcSetare)
*!*	*!*	modificare ROAFACTURARE	v 2.0.46	^
*!*			lnRaspuns=amessagebox("Doriti sa mai listati factura in valuta?",4+32+256,"Confirmare repetare listare")
*!*		Enddo
*!*		Use In crsfacturafinalaval
*!*	Endif

*!*	*!*	modificare	ROAFACTURARE v 2.0.46
*!*	If poDate.listare_lista_livrare = 1
*!*	*!*	modificare	v 2.0.67
*!*	*!*		prelucreaza_lista_livrare(pnTipFacturare)
*!*		prelucreaza_lista_livrare()
*!*	*!*	modificare	v 2.0.67	^
*!*		If Reccount('crslistalivrare') > 0
*!*			goExport.export2frx('crslistalivrare','lista_livrare')
*!*		Else
*!*			amessagebox("Nu exista inregistrari pentru lista de livrare!",48,"Atentie")
*!*		Endif
*!*		Use In crslistalivrare
*!*	Endif
*!*	*!*	Release loExport
*!*	*!*	modificare	ROAFACTURARE v 2.0.46	^
*!*	*!*	modificare	ROAFACTURARE v 2.0.58
listeaza_ofacturare()
If poDate.nRelistare = 0 And poDate.eProforma = 0 And poDate.nSalveazaAtasamente = 1
*!*		poDate.scrieAtasamente()
	lnSucces2 = goExecutor.oexecute([COMMIT])
Endif
*!*	*!*	modificare	ROAFACTURARE v 2.0.58	^
*!*	modificare	ROAFACTURARE	v 2.0.77	^
Endproc
******************************************** SFARSIT: listeaza_ofacturare_stoc **********************************************
Procedure completeaza_facturacrs
	Lparameters tcCursor
	Local lnPretCuTva
	lnPretCuTva = Iif(Inlist(gnTipGest , 6,7), 1, 0)
	If !Inlist(gnTipGest,6,7)
		Insert Into (tcCursor) (id_temp,denumire,serie,cantitate,cu_tva,pretftva,pretctva,;
			valftva,valtva,valctva,discountftva,discountctva,valdiscountftva,;
			valdiscounttva, valdiscountctva, valdiminuatftva, valdiminuattva, valdiminuatctva, proc_tvav,id_jtva_coloana,um,codmat,codbare,;
			vpretftva,vvalftva,vvaltva,vdiscountftva,vvaldiscountftva,vvaldiscounttva,;
			vvaldiminuatftva,vvaldiminuattva,vvaldiminuatctva,gestionabil,id_rul_aux,explicatie,lot) ;
			Select Recno() As id_temp,denumire, Nvl(serie,Space(100)) As serie, cante 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)*cante,gnPc) As valftva,;
			ROUND(Round(pretv*cante,gnPc)*(proc_tvav-1),gnPc) As valtva, ;
			Round(Round(pretv,gnPPretV)*cante,gnPc) + Round(Round(pretv*cante,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)*cante,gnPc) As valdiscountftva, ;
			ROUND(Round(discunitar*cante,gnPc)*(proc_tvav-1),gnPc) As valdiscounttva, ;
			Round(Round(discunitar,gnPPretV)*cante,gnPc) + Round(Round(discunitar*cante,gnPc)*(proc_tvav-1),gnPc) As valdiscountctva,;
			Round(Round(pretv-discunitar,gnPPretV)*cante,gnPc) As valdiminuatftva,;
			ROUND(Round((pretv-discunitar)*cante,gnPc)*(proc_tvav-1),gnPc) As valdiminuattva,;
			ROUND(Round(Round(pretv-discunitar,gnPPretV)*cante,gnPc)*proc_tvav,gnPc) As valdiminuatctva,;
			proc_tvav,id_jtva_coloana, Nvl(um,Space(50)) As um, Nvl(codmat,Space(50)) As codmat, Nvl(codbare,Space(50)) As codbare,;
			Round(pretvval,gnPVal) As vpretftva,;
			ROUND(Round(pretvval,gnPVal)*cante,gnPVal) As vvalftva,;
			ROUND(Round(Round(pretvval,gnPVal)*cante,gnPc)*(proc_tvav-1),gnPVal) As vvaltva,;
			0 As vdiscountftva,0 As vvaldiscountftva,0 As vvaldiscounttva,;
			Round(Round(pretvval-0,gnPVal)*cante,gnPVal) As vvaldiminuatftva,;
			ROUND(Round((pretvval-0)*cante,gnPVal)*(proc_tvav-1),gnPVal) As vvaldiminuattva,;
			ROUND(Round(Round(pretvval-0,gnPVal)*cante,gnPVal)*proc_tvav,gnPVal) As vvaldiminuatctva,;
			1 As gestionabil,id_rul_aux,IIF(EMPTY(NVL(FIELD('explicatie',"rul_temp"),'')),'',explicatie), Nvl(lot,Space(20)) As lot From rul_temp Where cante <> 0
	Else
		Insert Into (tcCursor) (id_temp,denumire,serie,cantitate,cu_tva,pretftva,pretctva,;
			valftva,valtva,valctva,discountftva,discountctva,valdiscountftva,;
			valdiscounttva, valdiscountctva, valdiminuatftva, valdiminuattva, valdiminuatctva, proc_tvav,id_jtva_coloana,um,codmat,codbare,;
			vpretftva,vvalftva,vvaltva,vdiscountftva,vvaldiscountftva,vvaldiscounttva,;
			vvaldiminuatftva,vvaldiminuattva,vvaldiminuatctva,gestionabil,id_rul_aux,explicatie,lot) ;
			Select Recno() As id_temp,denumire, Nvl(serie,Space(100)) As serie, cante As cantitate,m.lnPretCuTva As cu_tva,;
			Round(pretv,gnPPretV) As pretftva,;
			Round(pretv+tvav,gnPPretV) As pretctva,;
			Round(Round((pretv+tvav),gnPPretV)*cante,gnPc) - Round(Round((pretv+tvav)*cante,gnPc)*(proc_tvav-1)/proc_tvav,gnPc) As valftva, ;
			Round(Round((pretv+tvav)*cante,gnPc)*(proc_tvav-1)/proc_tvav,gnPc) As valtva, ;
			Round(Round((pretv+tvav),gnPPretV)*cante,gnPc) As valctva, ;
			Round(Round(discunitar,gnPPretV)/proc_tvav,gnPPretV) As discountftva,;
			ROUND(discunitar,gnPPretV) As discountctva, ;
			ROUND(Round(discunitar,gnPPretV)*Nvl(cante,1),gnPc) - Round(Round(Round(discunitar,gnPPretV)*Nvl(cante,1),gnPc)*(proc_tvav-1)/proc_tvav, gnPc) As valdiscountftva,;
			Round(Round(Round(discunitar,gnPPretV)*Nvl(cante,1),gnPc)*(proc_tvav-1)/proc_tvav, gnPc) As valdiscounttva,;
			Round(Round(discunitar,gnPPretV)*cante,gnPc) As valdiscountctva, ;
			ROUND((Round((pretv+tvav),gnPPretV)-Round(discunitar,gnPPretV))*Nvl(cante,1),gnPc) - ;
			Round(Round((Round((pretv+tvav),gnPPretV)-Round(discunitar,gnPPretV))*Nvl(cante,1),gnPc)*(proc_tvav-1)/proc_tvav, gnPc) As valdiminuatftva,;
			Round(Round((Round((pretv+tvav),gnPPretV)-Round(discunitar,gnPPretV))*Nvl(cante,1),gnPc)*(proc_tvav-1)/proc_tvav, gnPc) As valdiminuattva, ;
			Round((Round((pretv+tvav),gnPPretV)-Round(discunitar,gnPPretV))*Nvl(cante,1),gnPc) As valdiminuatctva, ;
			proc_tvav,id_jtva_coloana, Nvl(um,Space(50)) As um,Nvl(codmat,Space(50)) As codmat, Nvl(codbare,Space(50)) As codbare, 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,gnPVal)*cante,gnPVal) As vvaldiminuatftva,;
			ROUND(Round((pretvval-0)*cante,gnPVal)*(proc_tvav-1),gnPVal) As vvaldiminuattva,;
			ROUND(Round(Round(pretvval-0,gnPVal)*cante,gnPVal)*proc_tvav,gnPVal) As vvaldiminuatctva,;
			1 As gestionabil,id_rul_aux,IIF(EMPTY(NVL(FIELD('explicatie',"rul_temp"),'')),'',explicatie), Nvl(lot,Space(20)) As lot From rul_temp Where cante <> 0
		*!* v 2.0.52
		*!* nu am discount la vanzare - si era formula gresita - trebuia sa plece de la pretv+tvav
		*!*			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,
		*!* v 2.0.52 ^
	Endif
Endproc
*******************************************************************************************************************************
PROCEDURE recalculeaza_cursuri
	LPARAMETERS tcCursorCursuri
	SELECT (tcCursorCursuri)
	SCAN
			
	ENDSCAN
ENDPROC
*******************************************************************************************************************************

FUNCTION IdSet2TipFacturare
	LPARAMETERS tnIdSet 
	LOCAL lnTip
	lnTip = -1
	
	Do Case
		Case Inlist(tnIdSet,73,222,223,224)
			lnTip = -1
		Case Inlist(tnIdSet,79,83,206,225,271,272)
			lnTip = -2
		Case Inlist(tnIdSet,61,62,63,102,103,226,227)
			lnTip = -3
		Case Inlist(tnIdSet,64,65)
			lnTip = -4
		Case Inlist(tnIdSet,236,240,241,242,255,256)
		&& 236 intrare din gestiune valorica - aviz expeditie, 240 + inregistrare cantitativ in chiosc
		&& 241 = 236, 242 = 240 pe pagina marfa la pret de achizitie
			lnTip = -6
		Case INLIST(tnIdSet, 238,260)		&&	aviz de retur - valoric
			lnTip = -7
		Case INLIST(tnIdSet , 239,259)		&&	factura de retur - valorica
			lnTip = -8
		Case INLIST(tnIdSet, 243,261,233, 270)  	&&	Protocol cu TVA; 270 protocol marfa la pret de vanzare
			lnTip = -9
		Case INLIST(tnIdSet, 244,262)  	&&	Sponsorizare
			lnTip = -10
		Case InList(tnIdSet,252,258)			&&	Marfa la pret de achizitie *
			lnTip = -11
		CASE tnIdSet = 267					&&	aviz de retur - marfa in custodie
			lnTip = -13
		Otherwise
			lnTip = -5
	ENDCASE
	RETURN m.lnTip
ENDFUNC && IdSet2TipFacturare