
gnHandle = SQLCONNECT('ROA_ARGENTA', 'ARGENTA', '123')

SET PROCEDURE TO D:\CONTAFIN_ORACLE\COMUN\PROGRAME\OPROCEDURI_COMUNE.PRG ADDITIVE 

PRIVATE goExecutor, gcS
gcS = 'ARGENTA'
goExecutor = CREATEOBJECT("oExecutor")
goExecutor.nHandle = gnHandle

LOCAL lcEroare, lnAn1, lnLuna1, lnAn2, lnLuna2
LOCAL lnRecno, i, lnSucces

lcEroare = ''
lnAn1 = 1995
lnLuna1 = 1
lnAn2 = 2006
lnLuna2 = 2
 
SELECT crsPartenerDiferente
lnRecno = RECCOUNT()
i = 0
SCAN
	SCATTER NAME loPartener
	i = i + 1
	WAIT WINDOW TRANSFORM(I) + '/' + TRANSFORM(LNRECNO) NOWAIT 
*	lcEroare = modifica_id_partener(loPartener.id_part1, loPartener.id_part, lnAn1, lnLuna1, lnAn2, lnLuna2)
	lcSql = [update nom_parteneri set inactiv = 1 where id_part = ] + TRANSFORM(loPartener.id_part1)
	lnSucces = goExecutor.oExecute(lcSql)
	IF lnSucces < 0
		lcEroare = goExecutor.cEroare
	ENDIF 	
	
	IF !EMPTY(lcEroare)
		aMESSAGEBOX(lcEroare)
		EXIT 
	ENDIF 
ENDSCAN 


IF !EMPTY(lcEroare)
	aMESSAGEBOX(lcEroare)
ENDIF 
	
SQLDISCONNECT(0)

*** =================================================================================== ***
*** MODIFICARE ID_PARTENER IN CAZUL IN CARE EXISTA ACELASI PARTENER DE MAI MULTE ORI    ***
*** IN NOMENCLATORUL DE PARTENERI                                                       ***
*** MARIUS.MUTU                                                                         ***
*** 15.02.2006                                                                          ***
*** =================================================================================== ***
PROCEDURE modifica_id_partener
	LPARAMETERS tnIdPartProst, tnIdPartBun, tnAn1, tnLuna1, tnAn2, tnLuna2


	LOCAL  lnAn1, lnLuna1, lnAn2, lnLuna2, lnSucces, lnSucces2, lcEroare
	LOCAL lcSql, lcCursor
	PRIVATE lnIdPartProst,  tnIdPartBun, lnInit, lnFinal
	
	lcEroare = ''

	lnSucces = 1
	lnSucces2 = 1

	lnIdPartProst = 0
	lnIdPartBun = 0
	lnInit = 0
	lnFinal = 0

	IF EMPTY(tnIdPartProst) OR EMPTY(tnIdPartBun) OR EMPTY(tnAn1) OR EMPTY(tnLuna1) OR EMPTY(tnAn2) OR EMPTY(tnLuna2)
		lcEroare = 'Completati parametrii'
		lnSucces = -1
	ENDIF 
	
	IF lnSucces > 0
		lnIdPartProst = tnIdPartProst
		lnIdPartBun = tnIdPartBun

		lnInit = tnAn1 * 12 + tnLuna1
		lnFinal = tnAn2 * 12 + tnLuna2
		IF lnInit > lnFinal
			lcEroare = 'Luna de sfarsit trebuie sa fie mai mare sau egala decat luna de inceput'
			lnSucces = -1
		ENDIF
	ENDIF 	

	IF lnSucces > 0

&& TRANZACTIE MANUALA
		lnSucces = SQLSETPROP(gnhandle,"Transactions",2)
		IF lnSucces < 0
			lcEroare = goExecutor.cEroare
		ENDIF
	ENDIF

&& ACT : ID_PARTD
	IF lnSucces > 0
		lcSql = [update ] + gcs + [.act set id_partd = ?lnIdPartBun where id_partd = ?lnIdPartProst and an*12+luna between ?lnInit and ?lnFinal]
		lnSucces = goExecutor.oExecute(lcSql)
		IF lnSucces < 0
			lcEroare = goExecutor.cEroare
		ENDIF
	ENDIF

&& ACT : ID_PARTC
	IF lnSucces > 0
		lcSql = [update ] + gcs + [.act set id_partc = ?lnIdPartBun where id_partc = ?lnIdPartProst and an*12+luna between ?lnInit and ?lnFinal]
		lnSucces = goExecutor.oExecute(lcSql)
		IF lnSucces < 0
			lcEroare = goExecutor.cEroare
		ENDIF
	ENDIF

&& IREG_PARTENERI
	IF lnSucces > 0
		lcSql = [update ] + gcs + [.ireg_parteneri set id_part = ?lnIdPartBun where id_part = ?lnIdPartProst and an*12+luna between ?lnInit and ?lnFinal]
		lnSucces = goExecutor.oExecute(lcSql)
		IF lnSucces < 0
			lcEroare = goExecutor.cEroare
		ENDIF
	ENDIF


&& BALANTA PARTENERI
	IF lnSucces > 0
		FOR I = lnInit TO lnFinal
			lnLuna=MOD(I,12)
			lnAn=INT(I/12)
			IF lnLuna=0
				lnLuna=12
				lnAn=lnAn-1
			ENDIF


			lcSql = [SELECT ?lnIdPartBun as id_part, an, luna, NVL(cont,'    ') as cont, NVL(acont,'    ') as acont, id_valuta, ] +;
				[sum(precdeb1) as precdeb1,sum(preccred1) as preccred1,sum(precdeb) as precdeb,sum(preccred) as preccred,] +;
				[sum(precvaldeb1) as precvaldeb1,sum(precvalcred1) as precvalcred1,sum(precvaldeb) as precvaldeb,sum(precvalcred) as precvalcred,] +;
				[sum(debit) as debit,sum(credit) as credit,sum(valdebit) as valdebit,sum(valcredit) as valcredit ]+;
				[ FROM ] + gcs + [.BALANTA_PARTENERI WHERE ID_PART IN (?lnIdPartBun,?lnIdPartProst) AND ] +;
				[ AN = ?lnAn and luna = ?lnLuna ] + ;
				[ GROUP BY AN, LUNA, CONT, ACONT, ID_VALUTA ]
			lcCursor = [crsBalanta]

			lnSucces = goExecutor.oExecute(lcSql,lcCursor)
			IF lnSucces < 0
				lcEroare = goExecutor.cEroare
				EXIT
			ENDIF

			IF lnSucces > 0
				lcDel = [DELETE FROM ] + gcs + [.BALANTA_PARTENERI WHERE ID_PART IN (?lnIdPartBun,?lnIdPartProst) AND ] +;
					[ AN = ?lnAn and luna = ?lnLuna]
				lnSucces = goExecutor.oExecute(lcDel)
				IF lnSucces < 0
					lcEroare = goExecutor.cEroare
					EXIT
				ENDIF
			ENDIF

			IF lnSucces > 0
				SELECT crsBalanta
				SCAN
					SCATTER NAME loB
					loB.CONT = ALLTRIM(loB.CONT)
					loB.acont = ALLTRIM(loB.acont)
					lcIns = [INSERT INTO ] + gcs + [.BALANTA_PARTENERI ] + ;
						[(an,luna,cont,acont,id_part,id_valuta,] + ;
						[precdeb1,preccred1,precdeb,preccred,] + ;
						[precvaldeb1,precvalcred1,precvaldeb,precvalcred,] + ;
						[debit,credit,valdebit,valcredit) VALUES ] + ;
						[(?loB.an,?loB.luna,?loB.cont,?loB.acont,?loB.id_part,?loB.id_valuta,] + ;
						[?loB.precdeb1,?loB.preccred1,?loB.precdeb,?loB.preccred,] + ;
						[?loB.precvaldeb1,?loB.precvalcred1,?loB.precvaldeb,?loB.precvalcred,] + ;
						[?loB.debit,?loB.credit,?loB.valdebit,?loB.valcredit) ]
					lnSucces = goExecutor.oExecute(lcIns)
					IF lnSucces < 0
						lcEroare = goExecutor.cEroare
						EXIT
					ENDIF
				ENDSCAN
			ENDIF
			IF USED('crsBalanta')
				USE IN crsBalanta
			ENDIF

		ENDFOR
	ENDIF

&& MASINI_CLIENTI
	IF lnSucces > 0
		lcSql = [update ] + gcs + [.dev_masiniclienti set id_partener = ?lnIdPartBun where id_partener = ?lnIdPartProst]
		lnSucces = goExecutor.oExecute(lcSql)
		IF lnSucces < 0
			lcEroare = goExecutor.cEroare
		ENDIF
	ENDIF

&& CON_LUCRARI
	IF lnSucces > 0
		lcSql = [update ] + gcs + [.con_lucrari set id_part = ?lnIdPartBun where id_part = ?lnIdPartProst]
		lnSucces = goExecutor.oExecute(lcSql)
		IF lnSucces < 0
			lcEroare = goExecutor.cEroare
		ENDIF
	ENDIF


&& RUL	-	id_responsabil
	IF lnSucces > 0
		lcSql = [update ] + gcs + [.rul set id_responsabil = ?lnIdPartBun where id_responsabil = ?lnIdPartProst]
		lnSucces = goExecutor.oExecute(lcSql)
		IF lnSucces < 0
			lcEroare = goExecutor.cEroare
		ENDIF
	ENDIF

&& RUL	-	id_responsabilc
	IF lnSucces > 0
		lcSql = [update ] + gcs + [.rul set id_responsabilc = ?lnIdPartBun where id_responsabilc = ?lnIdPartProst]
		lnSucces = goExecutor.oExecute(lcSql)
		IF lnSucces < 0
			lcEroare = goExecutor.cEroare
		ENDIF
	ENDIF

&& RUL_OBINV
	IF lnSucces > 0
		lcSql = [update ] + gcs + [.rul_obinv set id_responsabil = ?lnIdPartBun where id_responsabil = ?lnIdPartProst]
		lnSucces = goExecutor.oExecute(lcSql)
		IF lnSucces < 0
			lcEroare = goExecutor.cEroare
		ENDIF
	ENDIF

&& STOC_OBINV
	IF lnSucces > 0
		lcSql = [update ] + gcs + [.stoc_obinv set id_responsabil = ?lnIdPartBun where id_responsabil = ?lnIdPartProst]
		lnSucces = goExecutor.oExecute(lcSql)
		IF lnSucces < 0
			lcEroare = goExecutor.cEroare
		ENDIF
	ENDIF

&& CON_CONTRACTE
	IF lnSucces > 0
		lcSql = [update ] + gcs + [.con_contracte set id_part = ?lnIdPartBun where id_part = ?lnIdPartProst]
		lnSucces = goExecutor.oExecute(lcSql)
		IF lnSucces < 0
			lcEroare = goExecutor.cEroare
		ENDIF
	ENDIF

	IF lnSucces > 0
		lnSucces2 = goExecutor.oExecute('COMMIT')
		IF lnSucces2 < 0
			lcEroare = goExecutor.cEroare
		ENDIF
	ELSE
		lnSucces2 = goExecutor.oExecute('ROLLBACK')
		IF lnSucces2 < 0
			lcEroare = goExecutor.cEroare
		ENDIF
	ENDIF

&& inactiv
	IF lnSucces > 0
		lcSql = [update ] + gcs + [.nom_parteneri set inactiv = 1 where id_part = ?lnIdPartProst]
		lnSucces = goExecutor.oExecute(lcSql)
		IF lnSucces < 0
			lcEroare = goExecutor.cEroare
		ENDIF
	ENDIF

	IF lnSucces > 0
		lnSucces2 = goExecutor.oExecute('COMMIT')
		IF lnSucces2 < 0
			lcEroare = goExecutor.cEroare
		ENDIF
	ELSE
		lnSucces2 = goExecutor.oExecute('ROLLBACK')
		IF lnSucces2 < 0
			lcEroare = goExecutor.cEroare
		ENDIF
	ENDIF

&& TRANZACTIE AUTOMATA
	lnSucces = SQLSETPROP(gnhandle,"Transactions",1)
	IF lnSucces < 0
		lcEroare = goExecutor.cEroare
	ENDIF

	RETURN lcEroare

ENDPROC && modifica_id_partener
