Procedure refacere
	Lparameters tcSursa,tcLunar,tcCont,tnLuna,tnAn
	*!* 11.02.2008 
	*!* TREBUIE SA FIE SETAT pack_contafin.SET_ID_SUCURSALA INAINTE DE REFACERE/SCRIERE

	LOCAL lcExecute, lcSql
	
	Private lcLunar,lcCont,lnSucces,lnLuna,lnAn
	lnSucces = -1
	If Empty(tnLuna)
		lnLuna=gnLuna
	Else
		lnLuna=tnLuna
	Endif

	If Empty(tnAn)
		lnAn=gnAn
	Else
		lnAn=tnAn
	Endif

	lcProc = "REFAC_" + Upper(Alltrim(tcSursa))
	lcLunar=Alltrim(tcLunar)
	If Empty(tcCont)
		lcCont = ""
	Else
		lcCont = Alltrim(tcCont)
	Endif

	Do Case
		Case lcProc == 'REFAC_BALANTA'
			lcSql = [begin PACK_REFACERI.] + lcProc + [('] + gcS +[',] + Alltrim(Str(lnAn)) + [,] +;
				ALLTRIM(Str(lnLuna)) + [,] + lcLunar + [); end;]

		Case lcProc == 'REFAC_BALANTA_PARTENERI'
			lcSql = [begin PACK_REFACERI.] + lcProc + [('] + gcS +[',] + Alltrim(Str(lnAn)) + [,] +;
				ALLTRIM(Str(lnLuna)) + [,'] + lcCont + [',] + lcLunar + [); end;]

		Case lcProc == 'REFAC_IREG_PARTENERI'

			lcSql = [begin PACK_REFACERI.] + lcProc + [('] + gcS +[',] + Alltrim(Str(lnAn)) + [,] +;
				ALLTRIM(Str(lnLuna)) + [,'] + lcCont + [',] + lcLunar + [,0); end;]

		Case lcProc == 'REFAC_TVA_2007'
			lcSql = [begin ] + gcS + [.PACK_REFACERI.] + lcProc + [('] + lcCont + [',] + Alltrim(Str(lnAn)) + [,] + ;
				ALLTRIM(Str(lnLuna)) + [); end;]

		Case lcProc == 'REFAC_TVA'
			Select infisiere
			If lcCont = '4426'
				Locate For Cont = '4426'
				lcCorespD = Alltrim(coresp_d)
				lcCorespC = Alltrim(coresp_c)
				lcCorespDtva = Alltrim(coresp_d) + [,4428]
				lcCorespCtva = Alltrim(coresp_c)
				*lcExceptii = [767]
				lcExceptii = [-1]
				lcTabel = [cump]
				lcSql = [select distinct cont_c as exceptie from ] + gcS + [.exceptii_ireg where cont in (] + lcCorespD + [) and invers = 1]
			Endif
			If lcCont = '4427'
				Select infisiere
				Locate For Cont = '4427'
				lcCorespD = Alltrim(coresp_d)
				lcCorespC = Alltrim(coresp_c) + [,5121,5311]
				lcCorespDtva = Alltrim(coresp_d)
				lcCorespCtva = Alltrim(coresp_c) + [,4428]
				lcExceptii = [419]
				lcTabel = [vanz]
				lcSql = [select distinct cont_c as exceptie from ] + gcS + [.exceptii_ireg where cont in (] + lcCorespC + [) and invers = 1]
			Endif

			lnSucces = goExecutor.oExecute(lcSql,'cont_exceptii')
			If lnSucces > 0
				Select cont_exceptii
				Scan
					lcExceptii = lcExceptii + ',' + Alltrim(exceptie)
				Endscan
				Use In cont_exceptii
			Else
				amessagebox(lcProc + CRLF + goExecutor.cEroare,0+16,"Eroare")
			Endif

			lcListaCampuri = get_lista_Act()
			lcSql = [begin pack_REFACERI.REFAC_TVA('] + gcS +[',?lcTabel, pack_contafin.getCotaTVAStandard(?gnLuna,?gnAn), 1.09, '] + lcCorespDtva +[', '] + lcCorespD +[', '] + lcCorespCtva +[', '] + lcCorespC +[',] + lcCont + [, '] + lcExceptii +[',?lnAn, ?lnLuna,1,'] + lcListaCampuri + ['  ); end;]

		Case lcProc == 'REFAC_STOC'
			lcSql = [begin pack_refaceri.refac_stoc(?gcS,?lnAn,?lnLuna,] + lcLunar + [); end;]

		Case lcProc == 'REFAC_STOC_OBINV'
			lcSql = [begin pack_refaceri.refac_stoc_obinv(?gcS,?lnAn,?lnLuna,] + lcLunar + [); end;]

		Otherwise
			lcSql = []
	Endcase

	If !Empty(lcSql)
		*!* 11.02.2008 
		lcExecute = [begin pack_contafin.SET_ID_SUCURSALA(?gnIdSucursala); end;]
		lnSucces = goExecutor.oExecute(lcExecute)
		If lnSucces < 0
			amessagebox(goExecutor.cEroare,0+16,"Eroare")
		ELSE 
			lnSucces = goExecutor.oExecute(lcSql)
			If lnSucces < 0
				amessagebox(lcProc + CRLF + goExecutor.cEroare,0+16,"Eroare")
			ENDIF
		ENDIF 	
		*!* 11.02.2008 ^
	Endif
	Return lnSucces
Endproc
