*!* 11.01.2012
*!* marius.mutu
*!* salvare proces verbal temporar in caz ca se da renunt sau programul iese cu eroare
*!* schimba_pret - proces verbal simplu (se repeta lans(52) + se face backup doar la cursorul crsschimb final)
*!* schimba_pret_grupa_gestiuni - proces verbal grupa de gestiuni cu/fara stoc actualizat (nu se repeta lans. se face backup la actactan, schimbpretstoc, crsschimb)

*!* 12.01.2012
*!* marius.mutu
*!* schimba_pret_grupa_gestiuni - proces verbal grupa de gestiuni cu/fara stoc actualizat 
*!* pretvtva_orig = pretvtva din stoc
*!* pretvtva = pretul precedent introdus in formularul precedent schimbpret_grupa
*!* se facea comparatie intre pretvtva si pretvtva_orig pentru a se recalcula pretv si tvav

*!*	12.07.2013
*!*	marius.mutu
*!*	arata_stoc_schimbare - am repus selectia cumulata pentru gestiuni cu stoc neactualizat

*!*	17.07.2013
*!*	marius.mutu
*!*	relisteaza_schimbare_pret
*!* adaugat id_set 269 (pv schimbare pret pe baza de lista preturi)
*!*	schimba_pret_grupa_gestiuni
*!*	adaugat TIP = 4 instiintare de schimbare de pret * ( gestiuni cu stoc neactualizat )

*!*	10.06.2015
*!*	marius mutu
*!*	relisteaza_schimbare_pret
*!*	adaugat id_set 999 pv schimbare pret cu schimbare cota tva
*!*	am grupat liniile sa nu mai apara separat iesirea si intrarea
*!*	am pus listare cu plaja de numere in loc de un singur numar

*!* 26.08.2015
*!* marius.mutu
*!* listeaza_schimbare_pret
*!* corectie eroare - nu exista nract in unele cursoare
*!* #4201

*!*	04.08.2025
*!*	marius.mutu
*!* schimbare pret vanzare pe baza de lista de preturi
*!*	arata_stoc_schimbare = se ia contul din stoc in loc de nom_articole

PROCEDURE schimba_pret
	lans(52)
	*** sterg salvarea backupset-ului daca operatia se incheie cu Terminat 
	LOCAL loBackupXML
	loBackupXML = CREATEOBJECT("BackupXML", "schimba_pret") && oproceduri_comune.prg	
	IF gnButon = 1
		loBackupXML.DeleteBackupSet()
	ENDIF 
ENDPROC && schimba_pret	

Procedure schimba_pret_grupa_gestiuni
	Lparameters tnTip
	*!*	1	-	lista de preturi
	*!*	2	-	lista de preturi * ( gestiuni cu stoc neactualizat )
	*!* 3	-   instiintare de schimbare de pret
	*!* 4   -   instiintare de schimbare de pret * ( gestiuni cu stoc neactualizat )
	
	Local loIm, llPoliticaPreturi
	LOCAL loBackupXML, lnReturn
	Private poGeneratorNumere
	poGeneratorNumere = Createobject('oGeneratorNumere')
	llPoliticaPreturi = inlist(m.tnTip, 1, 2)
	
	*** REINCARCARE STARE PROCES VERBAL SCHIMBARE PRET SALVAT ANTERIOR IN FORMAT XML SI NETERMINAT (FATAL ERROR)
	loBackupXML = CREATEOBJECT("BackupXML", "schimba_pret_grupa_gestiuni" + ALLTRIM(STR(tnTip))) && oproceduri_comune.prg
	*** daca exista deja un backupset
	IF loBackupXML.ExistsBackupSet() AND AMESSAGEBOX('Exista un proces verbal de schimbare de pret nesalvat. Doriti sa il continuati?', 4+32, _screen.Caption) = 6
		lnReturn = arata_stoc_schimbare(m.tnTip,.T.)
		If m.lnReturn = 2
			poGeneratorNumere.dezaloca_numere()
		Endif			
	ELSE  
		lnIdSet = iif(m.llPoliticaPreturi, 245, 269) && 245 = lista de preturi; 269 = instiintare schimbare pret
		If lans(m.lnIdSet) = 1
			
			if m.llPoliticaPreturi
				*** Politica de preturi  
				Select actactan
				Go Top
				lnIdPol = id_pol

				*!*	modificare	ROAGEST v 2.0.105 : am adaugat 9999999 as ordine
				text to lcSql textmerge noshow
					select row_number() over(order by a.nume_articol) as nrcrt,
					       a.id_articol,
					       a.nume_articol,
					       a.codmat,
					       a.pret,
					       a.proc_tvav,
					       a.pret as pretnou,
					       0 as schimb,
					       a.preturi_cu_tva,
					       a.id_pol,
					       a.id_pol_art,
					       a.id_venchelt,
					       9999999 as ordine
					  from vcrm_politici_pret_art a
					 where a.id_pol = <<m.lnIdPol>>
				endtext
			else
				*** Instiintare schimbare pret
				Select actactan
				Go Top
				lnIdInstiintare = id_instiintare

				text to lcSql textmerge noshow
					select row_number() over(order by a.denumire) as nrcrt,
					       id.id_articol,
					       a.denumire as nume_articol,
					       a.codmat,
					       id.pret_vechi as pret,
					       id.proc_tvav,
					       id.pret_nou as pretnou,
					       1 as schimb,
					       ppa.preturi_cu_tva,
					       ppa.id_pol,
					       ppa.id_pol_art,
					       ppa.id_venchelt,
					       9999999 as ordine
					  from instiintaripret_detalii id
					  join instiintaripret i on id.id_instiintare = i.id
					  join nom_articole a on id.id_articol = a.id_articol
					  join vcrm_politici_pret_art ppa on id.ID_ARTICOL = ppa.id_articol and i.id_pold = ppa.id_pol
					 where id.id_instiintare  = <<m.lnIdInstiintare>>				
				endtext
			
			endif 	

			Use In (Select("schimbPret"))			
			lcCursor = [schimbpret]
			lnSucces = goExecutor.oExecute(lcSql,lcCursor)
			If lnSucces < 0
				AMESSAGEBOX(goExecutor.cEroare,0+16, 'Eroare')
			endif

			loIm = Createobject('schimbpret_grupa',tnTip)
			loIm.Show(1)
			If gnButon = 2
				poGeneratorNumere.dezaloca_numere()
			Endif
			
		ENDIF
	ENDIF 
		
	Use In (Select("rul_temp"))
	Use In (Select("actactan"))
	Use In (Select("schimbpret"))
	Release loIm	
	Release poGeneratorNumere
Endproc
*****************************************************************************************************************************************************
Function arata_stoc_schimbare
Lparameters tnTip, tlLoadBackup

PRIVATE pnIdGrupa
Local lnReturn, lcSirIdArticol, loFrm
LOCAL loBackupXML
Local lcCursor, lcSql, lnIdGestiune, lnIdTipDoc, lnNnir, lnSucces, loCauta, llStocActualizat, llPoliticaPreturi, llInstiintare

lcSirIdArticol = []
Use In (Select("crsschimb"))
Use In (Select("schimbpretstoc"))
Use In (Select("schimbpretstoctemp"))

llStocActualizat =  INLIST(m.tnTip, 1, 3) && 1,3 stoc actualizat; 2,4 stoc neactualizat
llPoliticaPreturi = INLIST(m.tnTip, 1, 2) && 1,2 politica preturi
llInstiintare = INLIST(m.tnTip, 3, 4) && 3,4 instiintare schimbare pret

loBackupXML = CREATEOBJECT("BackupXML", "schimba_pret_grupa_gestiuni" + ALLTRIM(STR(tnTip))) && oproceduri_comune.prg
IF m.tlLoadBackup
	IF loBackupXML.ExistsBackupSet()
		loBackupXML.RestoreBackupSet()
		*** aloc un numar nou de bon
		lnIdGestiune = actactan.id_gestin
		lnIdTipDoc = 2 && bon consum
		poGeneratorNumere.creeaza_cursor_serii(m.lnIdTipDoc)
		lnNnir = poGeneratorNumere.aloca_numar(m.lnIdTipDoc, m.lnIdGestiune)
		Select actactan
		Replace All nnir With lnNnir, nract WITH lnNnir
		Select schimbpretstoc
		Go Top
		loFrm = Createobject('schimbpret_stoc_gest', tnTip)
		loFrm.oBackupXML = m.loBackupXML
		loFrm.Show(1)
		lnReturn = gnButon
		IF lnReturn = 1
			loBackupXML.DeleteBackupSet()
		ELSE 
			loBackupXML.SaveBackupSet()	
		ENDIF 
		lnReturn = gnButon
	ELSE 
		MESSAGEBOX('Nu exista nici un proces verbal de schimbare de pret nesalvat',0+48, _screen.Caption)
		lnReturn = 2	
	ENDIF 	
ELSE 
	*!*	modificare ROAGEST v 2.0.105 : ordine
	Select id_pol,id_pol_art,id_articol,pret,pretnou,preturi_cu_tva,proc_tvav,id_venchelt,ordine From schimbpret With (Buffering = .T.) Where schimb = 1 Into Cursor crsschimb
	Select crsschimb
	Scan
		lcSirIdArticol = lcSirIdArticol + [,] + Alltrim(Str(id_articol,14,0))
	Endscan
	lcSirIdArticol = Substr(lcSirIdArticol,2)

	loCauta = caut_grupa_gestiune()
	If gnButon = 1
		pnIdGrupa = loCauta.id_grupe
		
	*!*		modificare v 2.0.99
	If m.llStocActualizat && stoc actualizat
		TEXT TO lcSql TEXTMERGE NOSHOW 
select row_number() over(order by s.nume_gestiune, s.serie, nvl(s.pretv, 0)) as nrcrt,
       s.*,
       NVL(s.pretv + s.tvav, 0) as pretvtva,
       cast(0 as number(20, 4)) AS stoc,
       s.cants + s.cant - s.cante AS stoc_original,
       0 as schimb
  FROM (select c.id_stoc,
               a.id_articol,
               ?gnAn as an,
               ?gnLuna as luna,
               nvl(c.pret, 0.0000) AS pret,
               nvl(c.pretv, 0.0000) AS pretv,
               a.denumire,
               a.codmat,
               a.um,
               a.dnf,
               a.um2,
               a.cant_bax,
               b.id_gestiune,
               b.nume_gestiune,
               b.cgest,
               b.nr_pag,
               NVL(c.tva, 0.0000) as tva,
               NVL(c.tvav, 0.0000) as tvav,
               NVL(c.cants, 0.0000) AS cants,
               NVL(c.cant, 0.0000) AS cant,
               NVL(c.cante, 0.0000) AS cante,
               c.cont,
               c.acont,
               nvl(c.pretd, 0.0000) as pretd,
               NVL(c.dataora, SYSDATE) AS dataora,
               c.datain,
               c.dataout,
               nvl(c.proc_tvav, 0.0000) AS proc_tvav,
               c.serie,
               c.id_rul_aux,
               c.id_valuta,
               c.lot,
               c.adata_expirare,
               ?gnIdSucursala as id_sucursala,
               c.id_lucrare_rez,
               c.id_part_rez
          FROM (SELECT id_articol,
                       denumire,
                       codmat,
                       um,
                       dnf,
                       um2,
                       cant_bax,
                       cont
                  FROM nom_articole
                 WHERE id_articol in (<<m.lcSirIdArticol>>)) a
          JOIN (SELECT id_gestiune, nume_gestiune, cgest, nr_pag, acont
                 FROM nom_gestiuni
                WHERE sters = 0
                  AND inactiv = 0
                  AND id_gestiune in
                      (SELECT A1.ID_GESTIUNE
                         FROM GEST_CORESP_GRUPE_GESTIUNI A1
                        WHERE A1.STERS = 0
                          AND A1.ID_GRUPE IN
                              (SELECT ID_GRUPE
                                 FROM GEST_NOM_GRUPE
                                WHERE STERS = 0
                                START WITH ID_GRUPE = ?pnIdGrupa
                               CONNECT BY PRIOR ID_GRUPE = PARENT_ID))) b
            ON 1 = 1
          LEFT JOIN (SELECT id_articol,
                           id_gestiune,
                           id_stoc,
                           cont,
                           acont,
                           pret,
                           pretv,
                           tva,
                           tvav,
                           cants,
                           cant,
                           cante,
                           pretd,
                           dataora,
                           datain,
                           dataout,
                           proc_tvav,
                           serie,
                           id_rul_aux,
                           id_valuta,
                           lot,
                           adata_expirare,
                           id_lucrare_rez,
                           id_part_rez
                      FROM stoc
                     WHERE an = ?gnAn
                       AND luna = ?gnLuna
                       AND cants + cant - cante <> 0
                       and id_gestiune in
                           (SELECT A1.ID_GESTIUNE
                              FROM GEST_CORESP_GRUPE_GESTIUNI A1
                             WHERE A1.STERS = 0
                               AND A1.ID_GRUPE IN
                                   (SELECT ID_GRUPE
                                      FROM GEST_NOM_GRUPE
                                     WHERE STERS = 0
                                     START WITH ID_GRUPE = ?pnIdGrupa
                                    CONNECT BY PRIOR ID_GRUPE = PARENT_ID))
                     <<m.gcCondSucursala>>) c
            ON a.id_articol = c.id_articol
           AND b.id_gestiune = c.id_gestiune
         where a.id_articol in (<<m.lcSirIdArticol>>)) s
		ENDTEXT 
	ELSE && stoc neactualizat
		lcSql=[select row_number() over(order by s.nume_gestiune,s.serie,nvl(s.pretv,0)) as nrcrt,] +;
			[ s.*, NVL(s.pretv + s.tvav,0) as pretvtva, cast(0 as number(20,4)) AS stoc, s.cants + s.cant - s.cante AS stoc_original, 0 as schimb] +;
			[ FROM (select c.id_stoc, a.id_articol, ?gnAn as an, ?gnLuna as luna, nvl(c.pret,0) AS pret, nvl(c.pretv,0) AS pretv,] +;
			[ a.denumire, a.codmat, a.um, a.dnf, a.um2, a.cant_bax, b.id_gestiune, b.nume_gestiune, b.cgest, b.nr_pag, NVL(c.tva,0) as tva, NVL(c.tvav,0) as tvav,] +;
			[ NVL(c.cants, 0) AS cants, NVL(c.cant, 0) AS cant, NVL(c.cante, 0) AS cante, a.cont, nvl(c.pretd,0) as pretd,] +;
			[ NVL(c.dataora, SYSDATE) AS dataora, b.acont, c.datain, c.dataout, nvl(c.proc_tvav,0) AS proc_tvav, c.serie,] +;
			[ c.id_rul_aux, c.id_valuta, c.lot, c.adata_expirare, ?gnIdSucursala as id_sucursala, c.id_lucrare_rez, c.id_part_rez] +;
			[ FROM (SELECT id_articol, denumire, codmat, um, dnf, um2, cant_bax, cont FROM ] + gcS + [.nom_articole WHERE id_articol in (] + lcSirIdArticol + [)) a] +;
			[ JOIN (SELECT id_gestiune, nume_gestiune, cgest, nr_pag, acont FROM ] + gcS + [.nom_gestiuni WHERE sters = 0 AND inactiv = 0 AND id_gestiune in (SELECT A1.ID_GESTIUNE ] + ;
			[FROM ] +gcS + [.GEST_CORESP_GRUPE_GESTIUNI A1 WHERE A1.STERS = 0 AND A1.ID_GRUPE IN (SELECT ID_GRUPE FROM ] + gcS + [.GEST_NOM_GRUPE WHERE STERS = 0 ] + ;
			[START WITH ID_GRUPE = ] + Alltrim(Str(pnIdGrupa,14,0)) + [ CONNECT BY PRIOR ID_GRUPE = PARENT_ID))) b ON 1 = 1] +;
			[ LEFT JOIN (select id_stoc,id_articol,id_gestiune,pret,pretv,tva,tvav,cants,cant,cante,pretd,dataora,datain,dataout,proc_tvav,] + ;
			[serie,id_rul_aux,id_valuta,lot,adata_expirare,id_lucrare_rez,id_part_rez from (SELECT id_stoc,id_articol,id_gestiune,pretv,tvav,] + ;
			[sum(cants) over(partition by id_gestiune, id_articol) as cants,sum(cant) over(partition by id_gestiune, id_articol) as cant,] + ;
			[sum(cante) over(partition by id_gestiune, id_articol) as cante,row_number() over(partition by id_gestiune, id_articol order by pretv desc) as ales,] + ;
			[pret,tva,pretd,dataora,datain,dataout,proc_tvav,serie,id_rul_aux,id_valuta,lot,adata_expirare,id_lucrare_rez,id_part_rez from ] + gcS + [.stoc ] + ;
			[where an =] + Alltrim(Str(gnAn)) + [ AND luna =] + Alltrim(Str(gnLuna)) + [ AND cants + cant - cante > 0] + gcCondSucursala + [ and id_gestiune in (SELECT A1.ID_GESTIUNE ] + ;
			[FROM ] +gcS + [.GEST_CORESP_GRUPE_GESTIUNI A1 WHERE A1.STERS = 0 AND A1.ID_GRUPE IN (SELECT ID_GRUPE FROM ] + gcS + [.GEST_NOM_GRUPE WHERE STERS = 0 ] + ;
			[START WITH ID_GRUPE = ] + Alltrim(Str(pnIdGrupa,14,0)) + [ CONNECT BY PRIOR ID_GRUPE = PARENT_ID))) where ales = 1) c] +;
			[ ON a.id_articol =c.id_articol AND b.id_gestiune =c.id_gestiune where a.id_articol in (] + lcSirIdArticol + [)) s]	
	ENDIF 
	*!*	modificare ROAGEST v 2.0.105	^
		lcCursor = [schimbpretstoctemp]
		lnSucces = goExecutor.oExecute(lcSql,lcCursor)
		If lnSucces < 0
			AMESSAGEBOX(goExecutor.cEroare,0+16, 'Eroare')
			lnReturn = 2
		Else
	*!*	modificare ROAGEST v 2.0.105 : am modificat ordinea si am adaugat pretvtva_orig
	*!*				Select a.*,Iif(b.preturi_cu_tva=0,b.pretnou+Round(b.pretnou*(b.proc_tvav-1),gnPc),b.pretnou) As pretvtvanou,b.proc_tvav As proc_tva From schimbpretstoctemp a Left Join crsschimb b On a.id_articol = b.id_articol ;
	*!*					WHERE a.pretvtva<>Iif(b.preturi_cu_tva=0,b.pretnou+Round(b.pretnou*(b.proc_tvav-1),gnPc),b.pretnou) ;
	*!*					Order By a.nrcrt ;
	*!*					Into Cursor schimbpretstoc Readwrite
	*!*	modificare	v 2.0.111
			If !m.llStocActualizat
				Select a.*,b.ordine,Iif(b.preturi_cu_tva=0,b.pretnou+Round(b.pretnou*(b.proc_tvav-1),gnPPretV),b.pretnou) As pretvtvanou,b.proc_tvav As proc_tva,;
					a.pretvtva As pretvtva_orig, ;
					Iif(b.preturi_cu_tva=0,b.pret+Round(b.pret*(b.proc_tvav-1),gnPPretV),b.pret) As pretvtva_prec From schimbpretstoctemp a ;
					Left Join crsschimb b On a.id_articol = b.id_articol ;
					Order By b.ordine,a.nrcrt ;
					Into Cursor schimbpretstoc Readwrite
					*** completez pretvtva precedent cu cel completat in formularul precedent

					*!* 12.01.2012
					*!* pretvtva = pretul de vanzare precedent se completeaza cu pretul precedent introdus in formularul schimbpret_grupa (crsschimb.pret)
					UPDATE schimbpretstoc SET pretvtva = pretvtva_prec
					*!* 12.01.2012 ^					
			ELSE && stoc actualizat
	*!*	modificare	v 2.0.111	^
				Select a.*,b.ordine,Iif(b.preturi_cu_tva=0,b.pretnou+Round(b.pretnou*(b.proc_tvav-1),gnPPretV),b.pretnou) As pretvtvanou,b.proc_tvav As proc_tva,;
					a.pretvtva As pretvtva_orig From schimbpretstoctemp a ;
					Left Join crsschimb b On a.id_articol = b.id_articol ;
					WHERE a.pretvtva<>Iif(b.preturi_cu_tva=0,b.pretnou+Round(b.pretnou*(b.proc_tvav-1),gnPPretV),b.pretnou) ;
					Order By b.ordine,a.nrcrt ;
					Into Cursor schimbpretstoc Readwrite
				Select schimbpretstoc
				Replace nrcrt With Recno() All

				if m.llInstiintare && instiintare schimbare pret : stoc = stoc_original
					delete from schimbpretstoc where stoc_original = 0
					update schimbpretstoc set stoc = stoc_original
				endif 				
	*!*	modificare	v 2.0.111
			Endif
	*!*	modificare	v 2.0.111	^
	*!*	modificare ROAGEST v 2.0.105 ^
	*!*	   modificare v 2.0.99 ^

			loBackupXML.SaveBackupSet("crsschimb")
			loBackupXML.SaveBackupSet("schimbpretstoc")
			loBackupXML.SaveBackupSet("actactan")			
			Select schimbpretstoc
			Go Top

			loFrm = Createobject('schimbpret_stoc_gest', tnTip)
			loFrm.oBackupXML = m.loBackupXML
			loFrm.Show(1)
			lnReturn = gnButon
			IF lnReturn = 1
				loBackupXML.DeleteBackupSet()
			ELSE 
				loBackupXML.SaveBackupSet()	
			ENDIF 
		Endif
	Else
		lnReturn = 2
	ENDIF
ENDIF && m.tlLoadBackup	

Use In (Select("crsschimb"))
Use In (Select("schimbpretstoc"))
Use In (Select("schimbpretstoctemp"))
Release lcSirIdArticol, loFrm, pnIdGrupa
Return lnReturn
Endfunc	&&	arata_stoc_schimbare
*****************************************************************************************************************************************************
Function creeaza_note_schimbare_pret
Local lnReturn,lcCursorSchimb,lnNrDoc,lnIdTipDoc,lnTipBuffer
*!*	modificare ROAGEST v 2.0.105
lnIdTipDoc = 2		&&	bon de consum
lnTipBuffer = 2		&&	se dezaloca toate numerele in afara de primul
Select * From actactan Into Cursor crsaatemp
*!*	modificare ROAGEST v 2.0.105	^

lnReturn = 2
lcCursorSchimb = [schimbpretstoc]
If Used('rul_temp')
	Use In rul_temp
Endif

lcSql = [select v.*, v.id_gestiune as id_gestin, v.nume_gestiune as gestin, v.id_gestiune as id_gestout, v.nume_gestiune as gestout,] + ;
	[0 as nuInConturiX from ] + gcS + [.vrul v where 1=2]
lcCursor = [rul_temp]
lnSucces = goExecutor.oExecute(lcSql,lcCursor)
If lnSucces < 0
	AMESSAGEBOX(goExecutor.cEroare,0+16, 'Eroare')
	lnReturn = 2
Else
	Select actactan
	Locate For Alltrim(Upper(SCD))='X' And Alltrim(SCC)='378'
	If Found()
		Scatter Name loAct
		Delete
	Endif

	Select actactan
	Locate For Alltrim(Upper(SCD))='X' And Alltrim(SCC)='4428'
	If Found()
		Scatter Name loActTva
		Delete
	Endif

	lnIdSet = loAct.id_set

	Select (lcCursorSchimb)
*!*		Scan For stoc <> 0	&& modificare v 2.0.99 : stoc <> 0
	Scan For stoc <> 0	AND pretvtva <> pretvtvanou  && modificare v 2.0.111 : pretvtva <> pretvtvanou 
*!*	modificare ROAGEST v 2.0.105
		If pretvtva_orig <> pretvtva
			Replace pretv With Round(pretvtva/Iif(Nvl(proc_tva,1) = 0, 1, Nvl(proc_tva,1)),gnPPretV),;
				tvav With pretvtva - Round(pretvtva/Iif(Nvl(proc_tva,1) = 0, 1, Nvl(proc_tva,1)),gnPPretV),;
				proc_tvav With Iif(Nvl(proc_tvav,1) = 0,Iif(Nvl(proc_tva,1) = 0, 1, Nvl(proc_tva,1)),Nvl(proc_tvav,1))
*!*	completez proc_tvav ( daca pretvtva_original este 0, atunci proc_tvav este 0 si trebuie sa-l completez )
		Endif
*!*	modificare ROAGEST v 2.0.105	^
		Scatter Name poSchimb
		lnPretvtva = pretvtva
		lnStocOriginal=stoc_original
		lnPretvtvanou = Round(pretvtvanou, gnPPretV)
		lnCant = stoc
*!*			modificare v 2.0.99
		lnProcTvav = Iif(Nvl(proc_tva,1) = 0, 1, Nvl(proc_tva,1))
*!*			modificare v 2.0.99 ^
		If Type(lcCursorSchimb+'.pretvnou') = 'N'
			lnPretvNou = pretvnou
		ELSE
			lnPretvNou = Round(lnPretvtvanou / lnProcTvav, gnPPretV)
		Endif
		If Type(lcCursorSchimb+'.tvavnou') = 'N'
			lntvav = tvavnou
		Else
			lntvav = lnPretvtvanou - lnPretvNou
		Endif

		Select rul_temp
&& iesiri
*!*		modificare	v 2.0.105
*!*		modificare v 2.0.99
*!*				If lnStocOriginal>0
*!*		modificare v 2.0.99	^
		If lnStocOriginal > 0 Or poSchimb.pretvtva <> 0
*!*		modificare	v 2.0.105	^
			Append Blank
			Gather Name poSchimb
			Replace cant With 0, cante With lnCant, id_tip_rulaj With 3,id_set With lnIdSet
*!*		modificare v 2.0.99
		Endif
*!*		modificare v 2.0.99 ^
&& intrari
		Append Blank
		Gather Name poSchimb
		Replace pretv With lnPretvNou, pretvtva With lnPretvtvanou, tvav With lntvav, proc_tvav With lnProcTvav,;
			cant With lnCant, cante With 0, id_tip_rulaj With 3,id_set With lnIdSet

		Select (lcCursorSchimb)
	Endscan

	Update (lcCursorSchimb) Set proc_tvav = 1 Where Empty(Nvl(proc_tvav,0))

	&& modificare v 2.0.111 : pretvtva <> pretvtvanou 
	Select Distinct Cont, acont, proc_tvav, id_gestiune,nume_gestiune From (lcCursorSchimb) With (Buffering = .T.) ;
		Where stoc <> 0 AND pretvtva <> pretvtvanou Into Cursor SCDURI ;
		Order By nume_gestiune, id_gestiune, Cont, acont NOFILTER

	lnNrDoc = loAct.nract
	lnNnir = loAct.nnir

*!*	modificare	ROAGEST v 2.0.105
	Select Count(Distinct id_gestiune) As nrgestiuni From SCDURI Into Cursor crsgstscd
	Select crsgstscd
	If nrgestiuni > 1
		poGeneratorNumere.activeazaBuffer(lnIdTipDoc,lnTipBuffer)
	Endif
	If Used('crsgstscd')
		Use In crsgstscd
	Endif
*!*	modificare	ROAGEST v 2.0.105	^
	Select SCDURI
	Go Top
	lnIdGestPrec = id_gestiune
	Scan
		lnValdif = 0
		lnValdiftva = 0
		lcCont = Cont
		lcAcont = Nvl(acont,'')
		lnProc_tvav = proc_tvav
		lnIdGestIn = id_gestiune
		lcGestiune = nume_gestiune
		If lnIdGestPrec <> lnIdGestIn
*!*	modificare	ROAGEST v 2.0.105
*!*					lnNrDoc = lnNrDoc + 1
*!*					lnNnir = 0
			lnNnir = poGeneratorNumere.aloca_numar(lnIdTipDoc,lnIdGestIn)
			lnNrDoc = lnNnir
*!*	modificare	ROAGEST v 2.0.105	^
		Endif

		Select (lcCursorSchimb)
		Sum Round((pretvtvanou-pretvtva)/proc_tvav*stoc,gnPc) To lnValdif For Cont = lcCont And Nvl(acont,'') = lcAcont And proc_tvav = lnProc_tvav And id_gestiune = lnIdGestIn
		Sum Round((pretvtvanou-pretvtva)*(proc_tvav-1)/proc_tvav*stoc,gnPc) To lnValdiftva For Cont = lcCont And Nvl(acont,'') = lcAcont And proc_tvav = lnProc_tvav And id_gestiune = lnIdGestIn
		loAct.suma = lnValdif
		loAct.SCD = lcCont
		loAct.ascd = lcAcont
		loAct.proc_tva = lnProc_tvav
		loAct.id_gestin = lnIdGestIn
		loAct.gestin = lcGestiune
		loAct.nract = lnNrDoc
		loAct.nnir = lnNnir

		loActTva.suma = lnValdiftva
		loActTva.SCD = lcCont
		loActTva.ascd = lcAcont
		loActTva.proc_tva = lnProc_tvav
		loActTva.id_gestin = lnIdGestIn
		loActTva.gestin = lcGestiune
		loActTva.nract = lnNrDoc
		loActTva.nnir = lnNnir

		Select actactan
		Append Blank
		Gather Name loAct
		Append Blank
		Gather Name loActTva

		Select rul_temp
		Replace dataact With loAct.dataact, nnir With loAct.nnir, proc_tva With loAct.proc_tva,nract With loAct.nract For id_gestiune = lnIdGestIn

		lnIdGestPrec = lnIdGestIn
		Select SCDURI
	Endscan

	Delete From actactan Where suma = 0

	Do completare_parteneri_gestiune In ointroduceri.prg
	Do completare_gruputil_analitice In oproceduri_comune.prg
	Do completare_tva_analitice In oproceduri_comune.prg

	Use In (Select("crsDocumente"))
*!*		Select Distinct a.nract,a.nnir,a.dataact,b.id_gestiune,b.nume_gestiune From actactan a Left Join rul_temp b On a.nract = b.nract Order By a.nract Into Cursor crsDocumente

	Select Distinct a.nract,a.nnir,a.dataact,a.id_gestin As id_gestiune,a.gestin From actactan a Where Alltrim(a.SCC) <> '4428' Order By a.nract Into Cursor crsDocumente
	Select actactan
	Go Top
	Do Form verificare With .T.,.T.,3  && cu buton de precedent
	lnReturn = gnButon
	If lnReturn = 1
		lnReturn = scrie_note_schimbare_pret()
		If lnReturn = 1
*!*	modificare	ROAGEST v 2.0.105
			poGeneratorNumere.dezactiveazaBuffer(lnIdTipDoc)
*!*	modificare	ROAGEST v 2.0.105	^
			listeaza_schimbare_pret()
*!*	modificare	ROAGEST v 2.0.105
		Else
			poGeneratorNumere.dezaloca_buffer(lnIdTipDoc,.T.)
			Select actactan
			Delete All
			Insert Into actactan Select * From crsaatemp
*!*	modificare	ROAGEST v 2.0.105	^
		Endif
*!*	modificare	ROAGEST v 2.0.105
	Else
		poGeneratorNumere.dezaloca_buffer(lnIdTipDoc,.T.)
		Select actactan
		Delete All
		Insert Into actactan Select * From crsaatemp
*!*	modificare	ROAGEST v 2.0.105	^
	Endif
	Use In (Select("crsDocumente"))
Endif
Use In (Select("crsaatemp"))
Return lnReturn
Endfunc	&&	creeaza_note_schimbare_pret
*****************************************************************************************************************************************************
Function scrie_note_schimbare_pret
Local lcSql, lcSelect,lnReturn
lcSelect = Select()

lnSucces = SQLSetprop(gnHandle,"Transactions",2)
If lnSucces < 0
	AMESSAGEBOX("Programul nu a trecut pe tranzactie manuala",4+48,'Lista preturi')
	lnReturn = 2
Else
	lcSqlTranzactie = [COMMIT]
	Use In (Select("crsActIntermediar"))
	Use In (Select("crsRulIntermediar"))

	Select * From actactan Into Cursor crsActIntermediar
	Select * From rul_temp Into Cursor crsRulIntermediar
	Select actactan
	Delete All
	Select rul_temp
	Delete All

	Select crsDocumente
	Scan
		lnNrAct = nract
		lnNnir = nnir
		Select actactan
		Append From Dbf('crsActIntermediar') For (nract = lnNrAct)

		Select rul_temp
		Append From Dbf('crsRulIntermediar') For (nract = lnNrAct)

		If lnNnir = 0
			Select rul_temp
			lnIdGestiune = id_gestiune
*!*	modificare ROAGEST v 2.0.105
*!*					poGeneratorNumere.resetNumere()
*!*	modificare ROAGEST v 2.0.105	^
			lnNnir = poGeneratorNumere.aloca_numar(2,lnIdGestiune)
			Select actactan
			Replace All nnir With lnNnir

			Select rul_temp
			Replace All nnir With lnNnir
		Endif

		Select actactan
		lnSuccesScriere = oscrie_in_fisiere(0,.F.,.T.)
		If lnSuccesScriere < 0
			lcSqlTranzactie = [ROLLBACK]
*!*	modificare ROAGEST v 2.0.105
*!*					poGeneratorNumere.dezaloca_numar(2)
*!*	modificare ROAGEST v 2.0.105	^
			Exit
		Else
			lcSqlS = [begin delete from act_temp; delete from rul_temp; end;]
			lnSuccesScriere = goExecutor.oExecute(lcSqlS)
			If lnSuccesScriere < 0
				AMESSAGEBOX(goExecutor.cEroare,64,"Eroare")
				lcSqlTranzactie = [ROLLBACK]
*!*	modificare ROAGEST v 2.0.105
*!*						poGeneratorNumere.dezaloca_numar(2)
*!*	modificare ROAGEST v 2.0.105	^
				Exit
			Endif
		Endif

		Select actactan
		Delete All
		Select rul_temp
		Delete All
		Select crsDocumente
	Endscan

	Use In (Select("crsActIntermediar"))
	Use In (Select("crsRulIntermediar"))

*!*	modifica preturi politica
	Select crsschimb
	lnIdPol = id_pol
	Scan
		lnIdPolArt = id_pol_art
		lnIdVenchelt = id_venchelt
		lnProc_tvav = proc_tvav
		lnPret = pretnou
		lnPretftva = Iif(preturi_cu_tva=0,lnPret,Iif(!Isnull(lnProc_tvav),Round(Round(lnPret,gnPPretV)/lnProc_tvav,gnPPretV),lnPret))
		lnPretctva = Iif(preturi_cu_tva=0,Iif(!Isnull(lnProc_tvav),Round(Round(lnPret,gnPPretV) +  Round(lnPret,gnPPretV) *(lnProc_tvav -1),gnPPretV),lnPretftva),lnPret)

		lcSql = [begin ] + gcS + [.pack_preturi.modifica_pret_pol_pret_art(] + ;
			ALLTRIM(Str(lnIdPolArt)) + [,] + ; 										&& id_pol_art
		Alltrim(Str(lnPret,20,4)) + [,] + ; 									&& pret
		Alltrim(Str(lnPretftva,20,4)) + [,] + ;  								&& pretftva
		Alltrim(Str(lnPretctva ,20,4)) + [,] + ; 								&& pretctva
		Iif(Isnull(lnIdVenchelt), 'NULL',Alltrim(Str(lnIdVenchelt))) + [,] + ; 	&& id_venchelt
		Iif(Isnull(lnProc_tvav), 'NULL', Alltrim(Str(lnProc_tvav,20,4))) + ; 	&& proc_tvav
		[); end;]
		lnSucces = goExecutor.oExecute(lcSql)
		If lnSucces < 0
			AMESSAGEBOX(goExecutor.cEroare,0+16, 'Eroare')
			Exit
		Endif
	Endscan

	If lnSucces > 0
*!* MODIFICARE DATAORA, UTIL in CRM_POLITICI_PRETURI
		lcSql = [begin pack_preturi.modifica_politica_dataora(] + ;
			ALLTRIM(Str(lnIdPol)) + [,] + ; && id_pol
		Alltrim(Str(gnIdUtil)) + ; && id_util
		[); end;]
		lnSucces = goExecutor.oExecute(lcSql)
		If lnSucces < 0
			AMESSAGEBOX(goExecutor.cEroare,0+16, 'Eroare')
			lcSqlTranzactie = [ROLLBACK]
		Else
			lcSqlTranzactie = [COMMIT]
		Endif
	Else
		lcSqlTranzactie = [ROLLBACK]
	Endif

*!* COMMIT / ROLLBACK
	If lcSqlTranzactie = [ROLLBACK]
		lnReturn = 2
	Else
		lnReturn = 1
	Endif

	lnSucces2 = goExecutor.oExecute(lcSqlTranzactie)
	If lnSucces2 < 0
		AMESSAGEBOX(lcSql + Chr(13) + goExecutor.cEroare,0+16,"Eroare")
	Endif

	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!',0+48,'Atentie!')
	Endif

Endif
Select (lcSelect)
Return lnReturn
Endfunc	&&	scrie_note_schimbare_pret
*****************************************************************************************************************************************************
Procedure listeaza_schimbare_pret
	Private pcDataOra, poAct
	Local lnNrInreg,lnTotalDocumente,lcCursorListareTemp,lcCursorListare
	pcDataOra = get_ora(2)
	poAct = Createobject('Custom')
	AddProperty(poAct,'id_gestiune',0)
	AddProperty(poAct,'nract',0)
	AddProperty(poAct,'dataact',{})
	AddProperty(poAct,'gestin',[])
	
	lcCursorSchimb = [schimbpretstoc]
	lcCursorListare = [cList]
	Use In (Select(lcCursorListare))
	*!*	modificare	v 2.0.110
	Local ox As ReportListener
	ox = Createobject('ReportListener')
	ox.DynamicLineHeight = .F.
	ox.ListenerType = 1
	lnTotalDocumente = Reccount('crsDocumente')

	*!*	lcCursorTemp = lcCursorSchimb
	*!*	IF TYPE(lcCursorSchimb + '.tvavnou') <> 'N'
	*!*		lcCursorTemp = SYS(2015)
	*!*		Select *, CAST(0 as N(16,4)) as tvavnou From (lcCursorSchimb) Into Cursor (lcCursorTemp)	
	*!*	ENDIF 

	*!*	lnPretvtvanou - lnPretvNou
	*!*	pretvtvanou - pretvnou

	lcCursorListareTemp = m.lcCursorSchimb
	* La operatiile de schimbare de pret la care nu se schimba procentul de TVA, ca nu exista coloana TVAVNOU. O adaug
	IF TYPE(lcCursorSchimb + '.tvavnou') <> 'N'
		lcCursorListareTemp = SYS(2015)
		Select *, ;
			ROUND(pretvtvanou * (Iif(Nvl(proc_tva,1) = 0, 1, Nvl(proc_tva,1)) - 1) / Iif(Nvl(proc_tva,1) = 0, 1, Nvl(proc_tva,1)), m.gnPPretV) as tvavnou ;
			From (lcCursorSchimb) ;
			Into Cursor (lcCursorListareTemp)	
	ENDIF  

	IF TYPE(lcCursorListareTemp + '.partener_rezervare') = 'U'
		lcCursorListareTempX = SYS(2015)
		Select *, '' as partener_rezervare ;
			From (m.lcCursorListareTemp) ;
			Into Cursor (lcCursorListareTempX)	
		
		IF m.lcCursorListareTemp <> m.lcCursorSchimb
			USE IN (SELECT(m.lcCursorSchimb))
		ENDIF 
		
		lcCursorListareTemp = m.lcCursorListareTempX
	ENDIF  
	SET STEP ON 
	*!*	modificare	v 2.0.110	^
	Select crsDocumente
	Scan
	*!*	modificare	v 2.0.110
		lnNrInreg = Recno()
	*!*	modificare	v 2.0.110	^
		poAct.id_gestiune = id_gestiune
		poAct.nract = nract
		poAct.dataact = dataact
		poAct.gestin = gestin

		WAIT WINDOW 'Pregatire raport - proces verbal ' + ALLTRIM(STR(poAct.nract)) + ' - ' + ALLTRIM(STR(lnNrInreg)) + '/' + ALLTRIM(STR(lnTotalDocumente)) NOWAIT 

	*!*		modificare v 2.0.99:  and stoc<>0
		IF TYPE(lcCursorSchimb + '.nract') = 'N'
			Select * From (lcCursorListareTemp) Where id_gestiune = poAct.id_gestiune AND nract = poAct.nract And stoc<>0  order by partener_rezervare, DENUMIRE Into Cursor (lcCursorListare)
		ELSE
			Select * From (lcCursorListareTemp) Where id_gestiune = poAct.id_gestiune And stoc<>0  order by partener_rezervare, DENUMIRE Into Cursor (lcCursorListare)	
		ENDIF 	
	*!*		modificare v 2.0.99 ^
		Select (lcCursorListare)
	*!*	modificare	v 2.0.110
	*!*			Keyboard "{ctrl+f10}"
	*!*			Report Form rap_schimbPret To Printer Prompt Preview
		If lnNrInreg <> lnTotalDocumente
			goExport.export2frx(lcCursorListare,[rap_schimbPret],.F.,2,[],[NOPAGEEJECT],ox)
		Else
			goExport.export2frx(lcCursorListare,[rap_schimbPret],.F.,1,[],[],ox)
		Endif
	*!*	modificare	v 2.0.110	^
		Use In (Select(lcCursorListare))
		
		Select crsDocumente
	Endscan
	*!*	modificare	v 2.0.110
	Release ox
	*!*	modificare	v 2.0.110	^

	IF m.lcCursorListareTemp <> m.lcCursorSchimb
		USE IN (SELECT(lcCursorListareTemp))
	ENDIF 

	Release poAct
Endproc	&&	listeaza_schimbare_pret
*****************************************************************************************************************************************************
Procedure relisteaza_schimbare_pret
	Private pnNrAct1, pnNrAct2
	Local lcCursorSchimb, lnNr
	lcCursorSchimb = [schimbpretstoc]
	Store 0 To pnNrAct1, pnNrAct2
	Do Form frm_cere_text With 'Numar','pnNrAct1','Numarul procesului verbal - inceput' To lnNr
	pnNrAct2 = m.pnNrAct1
	Do Form frm_cere_text With 'Numar','pnNrAct2','Numarul procesului verbal - sfarsit' To lnNr

	If pnNrAct1 <> 0 AND pnNrAct2 <> 0
	*!*		TEXT TO lcSql TEXTMERGE NOSHOW 
	*!*	select a.id_set,
	*!*	       a.id_rul,
	*!*	       a.dataact,
	*!*	       a.nract,
	*!*	       a.id_gestiune,
	*!*	       c.nume_gestiune,
	*!*	       b.denumire,
	*!*	       b.codmat,
	*!*	       a.serie,
	*!*	       a.stoc,
	*!*	       a.pretvtva,
	*!*	       a.pretvtvanou,
	*!*	       a.pretv,
	*!*	       a.pretvnou,
	*!*	       a.tvav,
	*!*	       a.tvavnou,
	*!*	       a.proc_tvav,
	*!*	       a.proc_tvavnou,
	*!*	       round(a.stoc*(a.pretvnou - a.pretv), 2) as difvalv,       
	*!*	       round(a.stoc*(a.tvavnou - a.tvav), 2) as difvaltva,
	*!*	       round(a.stoc*(a.pretvtvanou - a.pretvtva), 2) as difvalvvtva 
	*!*	  from (select MIN(id_set) as id_set,
	*!*	               0 as id_rul,
	*!*	               dataact,
	*!*	               nract,
	*!*	               id_gestiune,
	*!*	               id_articol,
	*!*	               serie,
	*!*	               sum(decode(cant, 0, cante, 0)) as stoc,
	*!*	               max(decode(cant, 0, proc_tvav, 0)) as proc_tvav,
	*!*	               max(decode(cante, 0, proc_tvav, 0)) as proc_tvavnou,
	*!*	               max(decode(cant, 0, pretv, 0)) as pretv,
	*!*	               max(decode(cante, 0, pretv, 0)) as pretvnou,
	*!*	               max(decode(cant, 0, tvav, 0)) as tvav,
	*!*	               max(decode(cante, 0, tvav, 0)) as tvavnou,
	*!*	               max(decode(cant, 0, pretv + tvav, 0)) as pretvtva,
	*!*	               max(decode(cante, 0, pretv + tvav, 0)) as pretvtvanou
	*!*	          from rul
	*!*	         where nract between ?pnNrAct1 and ?pnNrAct2
	*!*	           and sters = 0
	*!*	           and luna = ?gnLuna
	*!*	           and an = ?gnAn
	*!*	           and id_set in (245, 52, 269)
	*!*	         group by dataact,
	*!*	                  nract,
	*!*	                  id_gestiune,
	*!*	                  id_articol,
	*!*	                  serie) a
	*!*	  left join nom_articole b
	*!*	    on a.id_articol = b.id_articol
	*!*	  left join nom_gestiuni c
	*!*	    on a.id_gestiune = c.id_gestiune
	*!*		union all
	*!*	select 999 as id_set,
	*!*		   0 as id_rul,
	*!*		   a.dataact,
	*!*	       a.nract,
	*!*	       a.id_gestiune,
	*!*	       c.nume_gestiune,
	*!*	       b.denumire,
	*!*	       b.codmat,
	*!*	       a.serie,
	*!*	       a.stoc,
	*!*	       a.pretvtva,
	*!*	       a.pretvtvanou,
	*!*	       a.pretv,
	*!*	       a.pretvnou,
	*!*	       a.tvav,
	*!*	       a.tvavnou,       
	*!*	       a.proc_tvav,
	*!*	       a.proc_tvavnou,
	*!*	       round(a.stoc*(a.pretvnou - a.pretv), 2) as difvalv,       
	*!*	       round(a.stoc*(a.tvavnou - a.tvav), 2) as difvaltva,
	*!*	       round(a.stoc*(a.pretvtvanou - a.pretvtva), 2) as difvalvvtva       
	*!*	  from (select dataact,
	*!*	               nract,
	*!*	               id_gestiune,
	*!*	               id_articol,
	*!*	               serie,
	*!*	               sum(decode(cant, 0, cante, 0)) as stoc,
	*!*	               max(decode(cant, 0, proc_tvav, 0)) as proc_tvav,
	*!*	               max(decode(cante, 0, proc_tvav, 0)) as proc_tvavnou,
	*!*	               max(decode(cant, 0, pretv, 0)) as pretv,
	*!*	               max(decode(cante, 0, pretv, 0)) as pretvnou,
	*!*	               max(decode(cant, 0, tvav, 0)) as tvav,
	*!*	               max(decode(cante, 0, tvav, 0)) as tvavnou,               
	*!*	               max(decode(cant, 0, pretv + tvav, 0)) as pretvtva,
	*!*	               max(decode(cante, 0, pretv + tvav, 0)) as pretvtvanou
	*!*	          from rul
	*!*	         where nract between ?pnNrAct1 and ?pnNrAct2
	*!*	           and sters = 0
	*!*	           and luna = ?gnLuna
	*!*	           and an = ?gnAn
	*!*	           and id_set = 999
	*!*	         group by dataact, nract, id_gestiune, id_articol, serie) a
	*!*	  left join nom_articole b
	*!*	    on a.id_articol = b.id_articol
	*!*	  left join nom_gestiuni c
	*!*	    on a.id_gestiune = c.id_gestiune
	*!*		ENDTEXT 	
	SET STEP ON 
		TEXT TO lcSql TEXTMERGE NOSHOW 
	select a.id_set,
	       a.id_rul,
	       a.id_part_rez,
	       p.denumire as partener_rezervare,
	       a.dataact,
	       a.nract,
	       a.id_gestiune,
	       c.nume_gestiune,
	       b.denumire,
	       b.codmat,
	       a.serie,
	       a.stoc,
	       a.pretvtva,
	       a.pretvtvanou,
	       a.pretv,
	       a.pretvnou,
	       a.tvav,
	       a.tvavnou,
	       a.proc_tvav,
	       a.proc_tvavnou,
	       round(a.stoc*(a.pretvnou - a.pretv), 2) as difvalv,       
	       round(a.stoc*(a.tvavnou - a.tvav), 2) as difvaltva,
	       round(a.stoc*(a.pretvtvanou - a.pretvtva), 2) as difvalvvtva 
	  from (select MIN(id_set) as id_set,
	  			   id_part_rez,
	               0 as id_rul,
	               dataact,
	               nract,
	               id_gestiune,
	               id_articol,
	               serie,
	               sum(decode(cant, 0, cante, 0)) as stoc,
	               max(decode(cant, 0, proc_tvav, 0)) as proc_tvav,
	               max(decode(cante, 0, proc_tvav, 0)) as proc_tvavnou,
	               max(decode(cant, 0, pretv, 0)) as pretv,
	               max(decode(cante, 0, pretv, 0)) as pretvnou,
	               max(decode(cant, 0, tvav, 0)) as tvav,
	               max(decode(cante, 0, tvav, 0)) as tvavnou,
	               max(decode(cant, 0, pretv + tvav, 0)) as pretvtva,
	               max(decode(cante, 0, pretv + tvav, 0)) as pretvtvanou
	          from rul
	         where nract between ?pnNrAct1 and ?pnNrAct2
	           and sters = 0
	           and luna = ?gnLuna
	           and an = ?gnAn
	           and id_set in (245, 52, 269, 999)
	         group by id_part_rez,
	         		  dataact,
	                  nract,
	                  id_gestiune,
	                  id_articol,
	                  serie) a
	  left join nom_articole b
	    on a.id_articol = b.id_articol
	  left join nom_gestiuni c
	    on a.id_gestiune = c.id_gestiune
	  left join nom_parteneri p
	    ON a.id_part_rez = p.id_part  
		ENDTEXT 	
		          
		WAIT WINDOW 'Selectie date din rulaje...' NOWAIT 
		lnSucces = goExecutor.oExecute(lcSql,lcCursorSchimb)
		If lnSucces < 0
			AMESSAGEBOX(goExecutor.cEroare,16,"Eroare")
		Else
			If Reccount(lcCursorSchimb) > 0
				Use In (Select("crsDocumente"))
				Select Distinct nract,id_gestiune,dataact,nume_gestiune As gestin From (lcCursorSchimb) ORDER BY nract, dataact, nume_gestiune Into Cursor crsDocumente
				listeaza_schimbare_pret()
				
				IF AMESSAGEBOX('Doriti export in format XLS?',4+32,_Screen.Caption) = 6
					Select * From (lcCursorSchimb) order by partener_rezervare, nract, dataact, nume_gestiune, denumire Into Cursor crsCentralizatorSchimbPretTemp
					goExport.export2xls('crsCentralizatorSchimbPretTemp', [centralizator_schimbpret])
					USE IN (SELECT('crsCentralizatorSchimbPretTemp'))
				ENDIF 
							
				Use In (Select("crsDocumente"))
			Else
				AMESSAGEBOX("Nu exista procese verbale din aceasta plaja de numere in luna curenta!",48,"Atentie")
			Endif
		Endif
		Use In (Select(lcCursorSchimb))
	Else
		AMESSAGEBOX("Numarul procesului verbal trebuie sa fie diferit de 0!",48,"Atentie")
	Endif

Endproc	&&	listeaza_schimbare_pret
*****************************************************************************************************************************************************
Procedure listeaza_centralizator_schimbpret
Lparameters tnTipGest
Private pcTitlu,pdDataI,pdDataF,plGrupe,pnOptiune
Store {} To pdDataI,pdDataF
Local lofrmperioada,loCauta,lcSql,lnSucces,lcCursor,lcExplicatie,lcTitlu,lcIntrebare,lnNrOptiuni
lofrmperioada = Createobject('frm_perioada_zzllaaaa')
lofrmperioada.Show(1)
If !Empty(Nvl(pdDataI,{})) And !Empty(Nvl(pdDataF,{}))
	Local loCauta
	loCauta = caut_grupa_articole(.T.)
	If gnButon = 1
		lcCursor = [crscentrschpret]
		If loCauta.id_grupa = 0 And Alltrim(loCauta.grupa) = [<TOATE INREGISTRARILE>]
			lcExplicatie = []
			pnOptiune = 1
			lcTitlu = [P.V.SCHIMBARE PRET]
			lcIntrebare="Doriti ca centralizatorul sa fie grupat dupa :"
			lnNrOptiuni=2
			Local loFrmOpt
			loFrmOpt=Createobject("frm_optiune",lcTitlu,lcIntrebare,lnNrOptiuni,[grupele de articole;numarul de document (nedefalcate dupa gestiune);],.T.)
			loFrmOpt.Show(1)
			Release loFrmOpt
			If pnOptiune = 1
				plGrupe = .T.
			Else
				plGrupe = .F.
			Endif
		Else
			lcExplicatie = [ - GRUPA ] + Alltrim(loCauta.grupa)
			plGrupe = .F.
		Endif
		*!*	modificare	07.11.2012	:	la total, am pus gnPc in loc de gnPa
		lcSql = [select a.nract,a.dataact,NVL(d.denumire,c.nume_gestiune) as denumire,] + ;
			IIF(plGrupe,[NVL(g.grupa,'')],['']) + [ as grupa, ] + ;
			[MAX(d.id_part) as id_part, MAX(c.id_gestiune) as id_gestiune, ] + ;
			[sum(round(a.pretvtva*decode(a.cant,0,(-1)*a.cante,a.cant),] + Alltrim(Str(gnPc)) + [)) as total,] + ;
			[sum(round(a.pretvtva*a.cante,] + Alltrim(Str(gnPc)) + [)) as valoare_ctva_vechi,] + ;			
			[sum(round(a.pretvtva*a.cant,] + Alltrim(Str(gnPc)) + [)) as valoare_ctva_nou,] + ;						
			[sum(round(a.pretv*a.cante,] + Alltrim(Str(gnPc)) + [)) as valoare_ftva_vechi,] + ;			
			[sum(round(a.pretv*a.cant,] + Alltrim(Str(gnPc)) + [)) as valoare_ftva_nou,] + ;						
			[sum(round(a.tva*a.cante,] + Alltrim(Str(gnPc)) + [)) as valoare_tva_vechi,] + ;			
			[sum(round(a.tva*a.cant,] + Alltrim(Str(gnPc)) + [)) as valoare_tva_nou ] + ;
			[from rul a ] + ;
			[left join asociere_parteneri_gestiuni b on a.id_gestiune = b.id_gestiune ] + ;
			[left join nom_gestiuni c on b.id_gestiune = c.id_gestiune ] + ;
			[left join nom_parteneri d on b.id_part = d.id_part ] + ;
			[left join nom_articole e on a.id_articol = e.id_articol ] + ;
			[left join gest_art_sbgr f on e.id_subgrupa = f.id_subgrupa and f.sters = 0 ] + ;
			[left join gest_art_gr g on f.id_grupa = g.id_grupa and g.sters = 0 ] + ;
			[where a.dataact between to_date('] + Dtoc(pdDataI,1) + [', 'YYYYMMDD') and to_date('] + Dtoc(pdDataF,1) + [', 'YYYYMMDD') ] + ;
			[and a.id_set in (52, 245, 269, 999) and a.sters = 0] + Strtran(gcCondSucursala,[id_sucursala],[a.id_sucursala]) + [ ] + ;
			IIF(loCauta.id_grupa = 0 And Alltrim(loCauta.grupa) = [<TOATE INREGISTRARILE>],[],[and NVL(g.id_grupa,0) = ] + Alltrim(Str(loCauta.id_grupa)) + [ ]) + ;
			[group by a.nract,a.dataact,NVL(d.denumire,c.nume_gestiune)] + ;
			IIF(plGrupe,[,NVL(g.grupa,'')],[]) + [ ] + ;
			[order by ] + Iif(plGrupe,[4,],[]) + [2, 1, 3 ]
		lnSucces = goExecutor.oExecute(lcSql,lcCursor)
		If lnSucces < 0
			AMESSAGEBOX(goExecutor.cEroare,16,"Eroare")
		Else
			pcTitlu = [CENTRALIZATOR PROCESE VERBALE DE SCHIMBARE PRET DE VANZARE ( ] + Dtoc(pdDataI) + [ - ] + Dtoc(pdDataF) + [ )] + lcExplicatie
			goExport.export2frx(lcCursor,[centralizator_schimbpret])
			IF AMESSAGEBOX('Doriti export in format XLS?',4+32,_Screen.Caption) = 6
				goExport.export2xls(lcCursor, [centralizator_schimbpret])
			ENDIF 
		Endif
		If Used(lcCursor)
			Use In (lcCursor)
		Endif
	Endif
Endif
Release lofrmperioada,loCauta,lcSql,lnSucces,lcCursor,pcTitlu,pdDataI,pdDataF,plGrupe,pnOptiune
Endproc	&&	listeaza_centralizator_schimbpret
*****************************************************************************************************************************************************
Procedure centralizator_articole_schimbpret
Local loFrmPret
loFrmPret=Createobject('frm_centralizator_schimbare_pret')
loFrmPret.Show(1)
Release loFrmPret
Endproc &&	centralizator_articole_schimbpret
*****************************************************************************************************************************************************


PROCEDURE instiintaripret
	PRIVATE poInstiintarepret, poInstiintarepret_det
	LOCAL lcSchema,lcSelect,lcOrder,lcGroup,lcFiltru,lcFiltruOriginal,llModParam,llAfiseaza,lcSelect1,lcOrder1,lcFiltru1,;
	lcFiltruOriginal1   
	STORE NULL TO poInstiintaripret, poInstiintaripret_det 
	lcSchema = []
	lcSelect = [select *  from vinstiintaripret ]
	lcOrder = [ dataora desc ]
	lcgroup = []
	lcFiltru = []
	lcFiltruOriginal = [ sters=0 ]
	llModParam = .T.
	llAfiseaza = .F.

	gencursor('poInstiintaripret','cInstiintaripret', lcSelect, lcFiltru, lcSchema, lcOrder, llAfiseaza, lcgroup, llModParam, lcFiltruOriginal) 
	poInstiintaripret.ca_baza1.afisare()
	
	lcSelect1 = [select * from instiintaripret_vdetalii ] 
	lcOrder1 = [ denumire ]
	lcFiltru1 = []
	lcFiltruOriginal1 = [ 1=2 ]
	gencursor('poInstiintaripret_det ','cInstiintaripret_det', lcSelect1,lcFiltru1,lcSchema,lcOrder1,llAfiseaza,lcgroup, llModParam,lcFiltruOriginal1)
	poInstiintaripret_det.ca_baza1.afisare()
	
	SELECT cInstiintaripret
	GO TOP 
	loFrm = CREATEOBJECT("instiintaripret")
	loFrm.show(1)
ENDPROC && instiintaripret 

*******************************************************************
*** Modificare preturi la schimbarea de TVA
*** Actualizare liste de preturi
*** Procese verbale schimbare de pret pe baza de lista de preturi (optional), pentru anumite gestiuni/toate, pentru anumite subgrupe articole/toate
*** 01.07.2010 19%-24%
*** 01.06.2010 24%-9% alimente
*******************************************************************
PROCEDURE schimba_pret_tva
	LOCAL loFrmSchimbarePret
		
		* createobject da eroare (check1???)
		DO FORM frm_schimbare_pret_tva
	
*!*		loFrmSchimbarePret = CREATEOBJECT("schimbpret_masa_tva")
*!*		loFrmSchimbarePret.show(1)
ENDPROC && schimba_pret	