*!* 24.01.2011
*!* marius.mutu
*!* viz_balanta_contabilitate - balanta cumulata

*!* 07.11.2011
*!* marius.mutu
*!* aleg_document_pereche
*!* conditie sucursala si analitic

*!* 22.04.2020
*!* verificare_note_contabile - se repun documente.sters = 0 daca s-a folosit id_fact pentru pereche si este sters in documente
*!* din diferite motive in documente se marcheaza sters documente care exista inca???

*!*	26.01.2021
*!*	viz_act - am adaugat cont_bancad si cont_bancac

*!* 15.09.2021
*!* verific_analitic - acont_alt, explicatie_alt

******************************** INCEPUT: viz_act ********************************
Procedure viz_act
	Lparameters tnCurs,tcValuta

	*** verificare INAINTE_DE
	Do inainte With "ACT" In oinainte_de.prg

	*** creez cursorul actjur fara date
	Private poactjur,ACTJUR,poact,act,porull,rull
	Store '' To poactjur,poact,porull

	*!* 24.03.2008
	*!*	If m.nivel=0
	*!*		If At([6;],gcAcces)>0
	pcschema=['SERIE_ACT C(10),ID_ACT N(20),LUNA N(2),AN N(4),COD N(20),DATAIREG D,nract N(20),DATAACT D,'+]+;
		['EXPLICATIA C(100),SCD C(4),ASCD C(4),SCC C(4),ASCC C(4),SUMA N(20,gnPC),PERECHED N(14),DATAACTD D,'+]+;
		['PERECHEC N(14),DATAACTC D,SUMA_VAL N(20,gnPval),ID_VALUTA N(5),NUME_VAL C(5),CURS N(10,gnPcurs2),DATASCAD D,NEIMPOZAB N(20,gnPC),'+]+;
		['NNIR N(14),ID_UTIL N(5),UTIL C(30),DATAORA T,ID_UTILS N(5),UTILS C(30),DATAORAS T,'+]+;
		['ID_RESPONSABIL N(5),NRESP C(30),ID_VENCHELT N(5),DST_CHLT C(100),ID_LUCRARE N(5),NRORD C(50),ID_CTR N(5),	CONTRACT C(30),'+]+;
		['ID_SECTIE N(5),SECTIE C(30),PROC_TVA N(5,2),ID_SET N(20),ID_FACT N(20),ID_PARTD N(10),PARTD C(50),COD_FISCALD C(30), ID_PARTC N(10),'+]+;
		['PARTC C(50), COD_FISCALC C(30),ID_SUCURSALA N(5),SUCURSALA C(50),STERS N(1),ID_FDOC N(5),FDOC C(30),EXPLICATIE_TVA C(100),ID_JTVA_COLOANA N(4),'+]+;
		['EXPLICATIA4 C(100),EXPLICATIA5 C(100),ID_GESTIN N(5),GESTIN C(50),ID_GESTOUT N(5),GESTOUT C(50),ID_FACTD N(20),ID_FACTC N(20),'+]+;
		['VALIDAT N(1),ID_UTILV N(5), UTILV C(30), DATAORAV T,CONT_BANCAD C(50),BANCAD C(5),CONT_BANCAC C(50), BANCAC C(50), '+]+;
		['TAXCODE N(6), TAXNAME C(250), SAFT_DESCRIERE C(250), SAFT_PROCENT N(6,2),PAYMENTCODE C(9),PAYMENTNAME C(250), REGISTRU C(20)']

	pcselect=['select SERIE_ACT,ID_ACT, LUNA, AN, COD, DATAIREG, NRACT, DATAACT, '+]+;
		['EXPLICATIA, SCD, ASCD, SCC, ASCC, SUMA, PERECHED, DATAACTD,'+]+;
		['PERECHEC, DATAACTC, SUMA_VAL, ID_VALUTA, NUME_VAL, CURS, DATASCAD, NEIMPOZAB, '+]+;
		['NNIR, ID_UTIL, UTIL, DATAORA, ID_UTILS, UTILS, DATAORAS, '+]+;
		['ID_RESPONSABIL, NRESP, ID_VENCHELT, DST_CHLT, ID_LUCRARE, NRORD, ID_CTR, CONTRACT, '+]+;
		['ID_SECTIE, SECTIE, PROC_TVA, ID_SET, ID_FACT, ID_PARTD, PARTD, COD_FISCALD, ID_PARTC, '+]+;
		['PARTC, COD_FISCALC, ID_SUCURSALA, SUCURSALA, STERS, ID_FDOC, FDOC, EXPLICATIE_TVA ,ID_JTVA_COLOANA ,'+]+;
		['EXPLICATIA4, EXPLICATIA5, ID_GESTIN, GESTIN, ID_GESTOUT, GESTOUT, ID_FACTD, ID_FACTC, '+]+;
		['VALIDAT, ID_UTILV, UTILV, DATAORAV,CONT_BANCAD,BANCAD,CONT_BANCAC,BANCAC,TAXCODE,TAXNAME,SAFT_DESCRIERE,SAFT_PROCENT,PAYMENTCODE,PAYMENTNAME,REGISTRU'+]+;
		[' from vact_tot where 2=2']
	pcfiltru=[sters=0 and luna=]+Alltrim(Str(gnluna))+[ and an=]+Alltrim(Str(gnan))
	*!*		Else
	*!*			pcschema=['SERIE_ACT C(10),ID_ACT N(20),LUNA N(2),AN N(4),COD N(20),DATAIREG D,NRACT N(14),DATAACT D,'+]+;
	*!*				['EXPLICATIA C(100),SCD C(4),ASCD C(4),SCC C(4),ASCC C(4),SUMA N(20,gnPA),PERECHED N(14),'+]+;
	*!*				['PERECHEC N(14),SUMA_VAL N(20,gnPval),ID_VALUTA N(5),NUME_VAL C(5),CURS N(10,gnPcurs),DATASCAD D,NEIMPOZAB N(20,gnPA),'+]+;
	*!*				['NNIR N(10),ID_UTIL N(5),UTIL C(30),DATAORA T,ID_UTILS N(5),UTILS C(30),DATAORAS T,'+]+;
	*!*				['ID_RESPONSABIL N(5),NRESP C(30),ID_VENCHELT N(5),DST_CHLT C(100),ID_LUCRARE N(5),NRORD C(50),ID_CTR N(5),CONTRACT C(30),'+]+;
	*!*				['ID_SECTIE N(5),SECTIE C(30),PROC_TVA N(5,2),ID_SET N(20),ID_FACT N(20),ID_PARTD N(10),PARTD C(50),ID_PARTC N(10),'+]+;
	*!*				['PARTC C(50),ID_SUCURSALA N(5),SUCURSALA C(50),ID_FDOC N(5),FDOC C(30),EXPLICATIE_TVA C(100),ID_JTVA_COLOANA N(4),'+]+;
	*!*				['EXPLICATIA4 C(100),EXPLICATIA5 C(100),ID_GESTIN N(5),GESTIN C(50),ID_GESTOUT N(5),GESTOUT C(50),ID_FACTD N(20),ID_FACTC N(20),sters n(1),'+]+;
	*!*				['VALIDAT N(1),ID_UTILV N(5), UTILV C(30), DATAORAV T']

	*!*			pcselect=['select SERIE_ACT,ID_ACT, LUNA, AN, COD, DATAIREG, NRACT, DATAACT,'+]+;
	*!*				['EXPLICATIA, SCD, ASCD, SCC, ASCC, SUMA, PERECHED,'+]+;
	*!*				['PERECHEC, SUMA_VAL, ID_VALUTA, NUME_VAL, CURS, DATASCAD, NEIMPOZAB,'+]+;
	*!*				['NNIR, ID_UTIL, UTIL, DATAORA, ID_UTILS, UTILS, DATAORAS, '+]+;
	*!*				['ID_RESPONSABIL, NRESP, ID_VENCHELT, DST_CHLT, ID_LUCRARE, NRORD, ID_CTR, CONTRACT,'+]+;
	*!*				['ID_SECTIE, SECTIE, PROC_TVA, ID_SET, ID_FACT, ID_PARTD, PARTD, ID_PARTC, '+]+;
	*!*				['PARTC, ID_SUCURSALA, SUCURSALA, ID_FDOC, FDOC, EXPLICATIE_TVA ,ID_JTVA_COLOANA ,'+]+;
	*!*				['EXPLICATIA4, EXPLICATIA5, ID_GESTIN, GESTIN, ID_GESTOUT, GESTOUT, ID_FACTD, ID_FACTC, 0 as sters, '+]+;
	*!*				['VALIDAT, ID_UTILV, UTILV, DATAORAV '+] + ;
	*!*				[' from ] + gcS + [.vact_tot where 2=2']
	*!*			pcfiltru=[luna=]+Alltrim(Str(gnluna))+[ and an=]+Alltrim(Str(gnan))

	*!*		Endif
	*!* 24.03.2008 ^
	* din afisactual
	*!*	If m.nivel>1
	If At([6;],gcAcces)=0
		pcfiltru = pcfiltru + [ AND ID_UTIL=]+Alltrim(Str(gnidutil))+[ ]
	Endif

	pcfiltru=[1=2]

	*!*	pcschema=['']
	pcorder=[dataireg,id_act]
	llAfisare=.F.
	gencursor('poactjur','actjur',pcselect,pcfiltru,pcschema,pcorder,llAfisare)
	poactjur.ca_baza1.afisare()
	Select ACTJUR
	*COPY TO c:\act.dbf

	pcselect=['select * from  act where 1=2']
	pcfiltru=[1=2]
	pcschema=['']
	pcorder=[dataireg]
	llAfisare=.F.
	gencursor('poact','act',pcselect,pcfiltru,pcschema,pcorder,llAfisare)
	poact.ca_baza1.afisare()

	pcselect=['select * from rul where 1=2']
	pcfiltru=[1=2]
	pcschema=['']
	pcorder=[]
	llAfisare=.F.
	gencursor('porull','rull',pcselect,pcfiltru,pcschema,pcorder,llAfisare)
	porull.ca_baza1.afisare()

	update_jtva_coloane("", "crsJtvaTemp", 0) && baza si neimpozabile pentru modificare explicatie TVA in rulaje
	
	Clear Class "afisjurcom"
	Select ACTJUR
	OJUR=Createobject('AFISJURcom',tnCurs,tcValuta)
	If .F.
		If NNN>10000
			OJUR.EACTAN=.T.
		Endif
	Endif
	
	OJUR.Show(1)
	Release OJUR
	Use In (SELECT('ACTJUR'))
	USE IN (SELECT('crsJtvaTemp'))
	
	Release poactjur,poact,porull

Endproc
******************************** SFARSIT: viz_act ********************************

************************** INCEPUT: aleg_document_pereche *****************************

Procedure aleg_document_pereche
	Parameters tnFel,toAct,tcTabel
	Local lcSel,lcSelAct

	*** tnFel : tipul soldului
	*** toAct : obiect cu varibilele din tabel
	*** tcTabel : tabelul in care se varsa datele

	*lcControl = ALLTRIM(tcControl)
	*lcSelAct = &lcControl..RecordSource

	lcSelAct = Alltrim(tcTabel)
	Select (lcSelAct)
	lnRand = Recno()
	lnSucces=1

	If tnFel = 0                  && ACTIV
		pcContul = Alltrim(Nvl(toAct.scc,[]))
		pcContCoresp = Alltrim(Nvl(toAct.scd,[]))
		pcACont = Alltrim(Nvl(toAct.ascc,[NULL]))
		pnIdPart = Nvl(toAct.Id_partc,0)
		pcNume = Alltrim(Nvl(toAct.partc,[]))
		pnPereche = [perecheC]
		pnIdPereche = [id_factC]
		pnPozCont = 1
	Else                               && PASIV
		pcContul = Alltrim(Nvl(toAct.scd,[]))
		pcContCoresp = Alltrim(Nvl(toAct.scc,[]))
		pcACont = Alltrim(Nvl(toAct.ascd,[NULL]))
		pnIdPart = Nvl(toAct.Id_partd,0)
		pcNume = Alltrim(Nvl(toAct.partd,[]))
		pnPereche = [perecheD]
		pnIdPereche = [id_factD]
		pnPozCont = 0
	Endif
	lcFis = 'actcv' + Alltrim(pcContul)
	lcTitluSpec = []

	*!*	lcSelect = [select decode(tip_sold,'A',0,'P',1,-1) as tip_sold from ] + gcs + [.vplcont_sintetic where cont = ?pcContul and an = ?gnAn]
	*!*	lcCursor = [crsSold]
	*!*	lnSucces = goexecutor.oExecute(lcSelect,lcCursor)
	*!*	IF lnSucces < 0
	*!*		MESSAGEBOX('Modificare:Tip Sold ' +goExecutor.cEroare,0+16,"Eroare")
	*!*	ENDIF

	*!*	IF lnSucces > 0
	*!*		SELECT crsSold
	*!*		LOCATE
	*!*		IF !EOF()
	*!*			pnFelCont = tip_sold
	*!*		ELSE
	*!*			pnFelCont = -1
	*!*		ENDIF

	*!*		IF pnFelCont = -1 && dc e bifunctional sau nu e definit
	*!*			PRIVATE eActiv
	*!*			STORE .T. TO eActiv
	*!*			PRIVATE loCont
	*!*			loCont = CREATEOBJECT("custom")
	*!*			ADDPROPERTY(loCont,'cont',pcContul)
	*!*			ADDPROPERTY(loCont,'acont',pcAcont)

	*!*			Ol=CREATEOBJECT("frm_sel_cont")
	*!*			WITH Ol
	*!*				.titlufrumos1.CAPTION= 'Tipul soldului'
	*!*				.cboCont.visible = .f.
	*!*				.lblCont.Caption = loCont.cont
	*!*				.lblAcont.Caption = loCont.acont
	*!*				.terminat1.enabled = .t.
	*!*				.ocont=loCont
	*!*				.HEIGHT = 190
	*!*			ENDWITH
	*!*			Ol.SHOW(1)
	*!*			RELEASE loCont
	*!*
	*!*			IF buton = 2
	*!*				lnSucces = -1
	*!*			ELSE
	*!*				pnFelCont = IIF(eActiv,0,1)
	*!*			ENDIF
	*!*		ENDIF


	*!*	*!*		lcSelect = [select count(*) as ePereche from ] + gcs + [.vcoresp_tip_cont where cont = ?pcContul and fel_cont = ?pnFelCont and cu_inregistrari = 1 ] + ;
	*!*	*!*					[and ?pcContul not in (select cont from ] + gcs + [.exceptii_ireg where cont_c = ?pcContCoresp and invers = 1 and debit =?pnPozCont)]
	*!*	*!*		lcCursor = [crsTest]
	*!*	*!*		lnSucces = goexecutor.oExecute(lcSelect,lcCursor)
	*!*	*!*		IF lnSucces < 0
	*!*	*!*			MESSAGEBOX('Modificare:Verific existenta pereche ' +goExecutor.cEroare,0+16,"Eroare")
	*!*	*!*		ENDIF
	*!*	ENDIF

	*!*	IF lnSucces > 0
	*!*		SELECT crsTest
	*!*		LOCATE
	*!*		IF ePereche = 0
	*!*			lnSucces = -1
	*!*			toact.&pnPereche = 0
	*!*			toact.&pnIdPereche = 0
	*!*			MESSAGEBOX('Nu trebuie completat documentul pereche!',0,'Informare')
	*!*		ENDIF
	*!*	ENDIF

	If lnSucces > 0
		If Type('toAct.Suma_val')# 'U' And !Empty(toAct.Suma_val)
			llval = .T.
			pnSuma = toAct.Suma_val
			lcFormular = [ocompensari_val]
			If Type('toAct.Id_Valuta')# 'U'
				pnIdValuta = toAct.Id_Valuta
			Else
				pnIdValuta = 0
			Endif
		Else
			llval = .F.
			pnSuma = toAct.Suma
			lcFormular = [ocompensari]
		Endif

		pcDenumire = [Partener ] + pcContul
		pcCond = [ an = ?gnAn and luna = ?gnluna]

		If llval
			pcCond= pcCond + [ and ABS(i.precvaldeb + i.valdebit - i.precvalcred - i.valcredit)>0 and i.id_valuta = ?pnIdValuta ]
		Else
			pcCond= pcCond + [ and (i.precvaldeb + i.valdebit - i.precvalcred - i.valcredit = 0) ]
		Endif

		pcselect = ['select i.* FROM Vireg_parteneri i where 2=2 ']
		*!* 07.11.2011
		If Alltrim(pcACont) # [NULL]
			pcfiltru = [ i.id_part = ?pnIdPart AND ABS(i.precdeb + i.debit - i.preccred - i.credit)<>0 AND i.cont = ?pcContul and NVL(acont,'x') = NVL(?pcACont,'x') and ] + pcCond
		Else
			pcfiltru = [ i.id_part = ?pnIdPart AND ABS(i.precdeb + i.debit - i.preccred - i.credit)<>0 AND i.cont = ?pcContul and acont is null and ] + pcCond
		ENDIF
		pcfiltru = m.pcfiltru + m.gcCondSucursala
		*!* 07.11.2011 ^
		pcschema = ['']
		pcorder = ['']

		Private podateintrod
		Store '' To podateintrod

		gencursor('podateintrod','crs_actcv',pcselect,pcfiltru,[''],'')
		If Type('podateintrod') # 'O'
			lnSucces = -1
		Endif
	Endif

	If lnSucces > 0
		If Used(lcFis)
			Use In &lcFis
		Endif

		If tnFel = 0
			lcSel = [SELECT *, ACONT AS ASCC, nume_val as numeval, curs as cursschimb, precdeb + debit as totctva, preccred+credit as achitat, ] +;
				[precvaldeb + valdebit AS sumaval, precVALcred+VALcredit as achitatval, ] +;
				[.f. as ales, 00000000000000.0000 as sumaachi, 000000000000.0000 as sumaachi2, 00000000000000.0000 as achilei, 00000000000000.0000 as difplus, 00000000000000.0000 as difminus, 000000.0000 as cursval, 000000.0000 as cursdif ] +;
				[FROM crs_actcv order by dataact INTO CURSOR ] + lcFis + [ READWRITE ]
		Else
			lcSel = [SELECT *, ACONT AS ASCD, nume_val as numeval, curs as cursschimb, preccred + credit as totctva, precdeb+debit as achitat, ] + ;
				[precvalcred + valcredit as sumaval, precVALdeb+VALdebit as achitatval, ] + ;
				[.f. as ales, 00000000000000.0000 as sumaachi, 00000000000000.0000 as sumaachi2, 00000000000000.0000 as achilei, 00000000000000.0000 as difplus, 00000000000000.0000 as difminus, 000000.0000 as cursval, 000000.0000 as cursdif ] + ;
				[FROM crs_actcv order by dataact INTO CURSOR ] + lcFis + [ READWRITE ]
		Endif
		&lcSel
		If Used('crs_actcv')
			Use In crs_actcv
		Endif

		If pcACont # [NULL]
			lcTitluSpec = [ / Analitic: ] + pcACont
		Endif

		Select (lcFis)
		Clear Class (lcFormular)
		OPLATA=Createobject(lcFormular)
		OPLATA.titlufrumos1.Caption = pcDenumire + [: ] + pcNume + lcTitluSpec
		OPLATA.pcFis = lcFis
		OPLATA.Suma = pnSuma
		*OPLATA.pnFelCont = pnFelCont
		OPLATA.Show(1)
		Clear Class (lcFormular)

		If gnButon = 1
			Select (lcSelAct)
			Delete
			Select (lcFis)
			Scan For ales
				Scatter Name oper
				Select (lcSelAct)
				Append Blank
				Gather Name toAct
				Replace &pnIdPereche With oper.id_fact, &pnPereche With oper.nract, Suma With oper.sumaachi
				If Type('toAct.Suma_val')# 'U'
					Replace Suma_val With oper.sumaachi2
				Endif
				Select (lcFis)
			Endscan
		Else
			lnSucces = -1
		Endif
	Endif

	If lnSucces < 0
		Select &lcSelAct
		lcUpdate = [update ] + lcSelAct + [ set ] + pnPereche + [= ] + Alltrim(Str(toAct.&pnPereche)) + [ WHERE RECNO() = ] + Alltrim(Str(lnRand))
		&lcUpdate
		*UPDATE (lcSelAct) SET &pnPereche = toact.&pnPereche WHERE RECNO() = lnRand
	Else
		Select (lcSelAct)
		Do nrord With lcSelAct
	Endif

	If Used(lcFis)
		Use In (lcFis)
	Endif
	If Used('crsTest')
		Use In crsTest
	Endif

	Select (lcSelAct)
	*&lcControl..SetFocus

Endproc && aleg_document_pereche

************************** SFARSIT: aleg_document_pereche *****************************

************************** INCEPUT: exista_cont_in_plan_conturi *****************************
Function exista_cont_in_plan_conturi
	Parameters tcCont
	LOCAL lcSelect

	lcSelect = SELECT()
	llExista = .F.
	tcCont = Alltrim(tcCont)

	lcSql=[select count(*) as exista_cont FROM ] + gcS + [.vplcont_sintetic where cont=?tcCont and inactiv = 0 and an = ?gnAn ]
	lcCursor = 'crs_cont'
	lnSucces = goExecutor.oExecute(lcSql,lcCursor)
	If lnSucces < 0
		aMESSAGEBOX('VERIFICARE CONT ' + Chr(13) + goExecutor.cEroare,0+16,"Eroare")
	Endif
	If lnSucces > 0
		Select crs_cont
		Locate
		llExista = NVL(exista_cont,0) > 0
	ENDIF
	
	If !llExista
		aMESSAGEBOX('Acest cont nu este configurat in planul de conturi!',48,'Atentie!')
	Endif
	USE IN (SELECT('crs_cont'))
	SELECT (lcSelect)
	
	Return llExista
	************************** SFARSIT: exista_cont_in_plan_conturi *****************************

	************************** INCEPUT: verific_partener *****************************
Function verific_partener
	Parameters tcCont, tcColNume, tcColId, tcTabel

	ll_l=.F.

	If Empty(tcCont) Or Type('tccont')#'C'
		Return ll_l
	Else
		lcCont = Alltrim(tcCont)
	Endif

	If Empty(tcColNume) Or Type('tcColNume')#'C'
		Return ll_l
	Else
		lcColNume = Alltrim(tcColNume)
	Endif

	If Empty(tcColId) Or Type('tcColId')#'C'
		Return ll_l
	Else
		lcColID = Alltrim(tcColId)
	Endif

	If Empty(tcTabel) Or Type('tcTabel')#'C'
		lcTabel = Alias()
	Else
		lcTabel = Alltrim(tcTabel)
	Endif


	lnId_part = 0
	lcNume = ''

	lcSql=[select count(*) as valoare FROM ] + gcS + [.vconfig_cont_ireg where to_number(cont) = ] + lcCont
	lcCursor = 'c_part'
	lnSucces = goExecutor.oExecute(lcSql,lcCursor)

	If lnSucces < 0
		aMESSAGEBOX('VERIFICARE CONT ' + Chr(13) + goExecutor.cEroare,0+16,"Eroare")
	Else
		ll_l = .T.
		Select c_part
		If valoare > 0
			lcTitlu = 'Nume partener ' + lcCont
			llNou = .T.
			*!*	modificare	10.12.2010
			loCauta = CautPartenerContabilitate(GetHash([cTitlu=>] + Alltrim(lcTitlu)+[??cCont=>] + Alltrim(lcCont) + [??] + ;
				[lAdaugCorespondente=>1??lVerificaANAF=>1]))
			*!*				locauta = caut_parteneri(lcCont, lcTitlu,,llNou)
			*!*	modificare	10.12.2010	^
			If !Empty(loCauta.id_part)
				lnId_part=loCauta.id_part
				lcNume=Alltrim(loCauta.denumire)
			Endif
		Endif

		Select (lcTabel)
		Replace &lcColID With lnId_part, &lcColNume With lcNume
	Endif

	If Used('c_part')
		Use In c_part
	Endif

	Return ll_l
	************************** SFARSIT: verific_partener *****************************

	************************** INCEPUT: verific_analitic *****************************
Function verific_analitic
	Parameters tlClick, tcCont, tcacont, tcColoana, tcTabel
	Local lcTabel, ll_l, lcAcont, lcSql, lcCursor, lnSucces

	m.den=''
	ll_l=.F.
	lcAcont = []
	If Empty(tcCont)
		Return ll_l
	Else
		pcCont = Alltrim(tcCont)
	Endif

	If Empty(tcacont) Or Type('tcacont')#'C'
		pcACont = []
	Else
		pcACont = tcacont
	Endif

	If Empty(tcTabel) Or Type('tcTabel')#'C'
		lcTabel = Alias()
	Else
		lcTabel = Alltrim(tcTabel)
	Endif

	If Used('TCEVA')
		Use In tceva
	Endif

	TEXT TO lcSql NOSHOW 
select p.acont || nvl2(p.cont_alt, ' - ' || p.cont_alt, '') || nvl2(p.cod, ' - ' || p.cod, '') || ' - ' || nvl(p.explicatie, '') as den, p.CONT, p.ACONT FROM vplcont_ANALITIC p where cont = ?pcCont and inactiv = 0 and an = ?gnAn order by acont
	ENDTEXT 

	lcCursor = 'tceva'
	lnSucces = goExecutor.oExecute(lcSql,lcCursor)
	If lnSucces < 0
		aMESSAGEBOX('oOperatii_comune.VERIFIC_ANALITIC ' + Chr(13) + goExecutor.cEroare,0+16,"Eroare")
	Endif

	If lnSucces > 0
		Select tceva
		Locate
		If Eof()
			If !Empty(tcacont) And !Isnull(tcacont)
				aMESSAGEBOX('Nu au fost definite simboluri analitice pentru contul ' + pcCont,48,"Atentie")
			Endif
			lnSucces = -1
		Else
			If !tlClick
				If Empty(tcacont) Or Isnull(tcacont) && exista analitic si nu e completat
					tlClick = .T.
				Endif
			Endif
		Endif
	Endif

	If lnSucces > 0
		Select tceva
		If tlClick
			Do caut_alfa_cursor With 'tceva','den','Alegeti simbolul analitic','m.den'
			Select tceva
			Locate For Alltrim(den) = Alltrim(m.den)
			pcACont = acont
		Else
			Locate For Alltrim(Cont) = pcCont And Alltrim(acont)=Alltrim(pcACont)
			If !Found()
				Do caut_alfa_cursor With 'tceva','den','Alegeti simbolul analitic','m.den'
				Select tceva
				Locate For Alltrim(den) = Alltrim(m.den)
				pcACont = acont
			Endif
		Endif
	Endif

	IF !EMPTY(m.lcTabel) AND !EMPTY(m.tcColoana) AND USED(m.lcTabel)
		If lnSucces > 0
			Select (lcTabel)
			Replace &tcColoana With pcACont
			ll_l = .T.
		Else
			Select (lcTabel)
			Replace &tcColoana With ''
		ENDIF
	ELSE 
		ll_l = (m.lnSucces > 0)
	ENDIF 

	Use In (SELECT('tceva'))

	Select (lcTabel)
	Return ll_l

	************************** SFARSIT: verific_analitic *****************************
	************************** INCEPUT: verificare_note_contabile *****************************
Procedure verificare_note_contabile
	Parameters tcAct,tlVerificAnalitic,tlAlegPartener, tlNuVerificCont

	*!*	03.05.2013 : am adaugat lcIdFact, lcMesajIdFact
	Local lcInMesaj, lcInMesajAcont, lcInMesajP, lcInMesajIreg, lcMesaj, lcInMesajPSters, lcAct, lnId_set, ll_return, lcIdFact, lcMesajIdFact
	Store '' To lcInMesaj, lcInMesajAcont, lcInMesajP, lcInMesajIreg, lcMesaj, lcAct, lcInMesajPSters, lcIdFact, lcMesajIdFact
	Store .T. To ll_return

	If Empty(tcAct) Or Type('tcAct') # 'C'
		lcAct = Alias()
	Else
		lcAct = Alltrim(tcAct)
	Endif

	Select (lcAct)
	lnNrNota=1
	Scan For Suma <> 0
		lcScd = Alltrim(Nvl(scd,''))
		lcScc = Alltrim(Nvl(scc,''))
		*!*	07.05.2013 : verific id_fact de pe notele de TVA devenit exigibil ( 4426 - 4428 si 4428 - 4427 ), id_factc
		*!*	 si id_factd sa nu fie marcate ca sterse in tabela "documente"
		lcIdFact = Iif(id_fact>0 and tva_incasare=1 and ((scd = [4426] and scc = [4428]) or (scd = [4428] and scc = [4427])),Alltrim(Str(id_fact)),[])
		lcIdFact = lcIdFact + Iif(id_factc>0,Iif(!Empty(lcIdFact),[,],[]) + Alltrim(Str(id_factc)),[])
		lcIdFact = lcIdFact + Iif(id_factd>0,Iif(!Empty(lcIdFact),[,],[]) + Alltrim(Str(id_factd)),[])
		*!*	07.05.2013	^
		*!* 11.03.2008
		*!* tlNuVerificCont - nu se verifica conturile
		If !tlNuVerificCont
			*!* la clasele 8 si 9 se poate sa nu fie contul corespondent completat
			If Empty(lcScd) And !Inlist(Left(lcScc,1),'8','9')
				ll_return = .F.
				lcMesaj = lcMesaj + ',' + 'contul debitor'
			Endif
			If Empty(lcScc) And !Inlist(Left(lcScd,1),'8','9')
				ll_return = .F.
				lcMesaj = lcMesaj + ',' + 'contul creditor'
			Endif
		Endif
		*!* 11.03.2008 ^
		If Empty(nract)
			ll_return = .F.
			lcMesaj = lcMesaj + ',' + 'nr.document'
		Endif
		If (!Empty(Suma_val) Or !Empty(Curs)) And Empty(Id_Valuta)
			ll_return = .F.
			lcMesaj = lcMesaj + ',' + 'nume valuta'
		Endif
		If Type('cu_tva')<>'U'
			If cu_tva = 1 And Empty(Nvl(id_jtva_coloana,0))
				ll_return = .F.
				lcMesaj = lcMesaj + ',' + 'explicatie TVA'
			Endif
		Endif
		If !ll_return
			*!*	modificare ROAPRODUCTIE v 2.0.2
			*!*				aMESSAGEBOX("La nota nr. "+Alltrim(Str(lnNrNota))+" nu ati completat campu"+ Iif(At([,],lcMesaj,2)>0,[rile],[l]) + ;
			*!*					": "+Substr(lcMesaj,2,60)+"...",0+48,"Atentie")
			lcMesaj = "La nota nr. "+Alltrim(Str(lnNrNota))+" nu ati completat campu"+ Iif(At([,],lcMesaj,2)>0,[rile],[l]) + ;
				": "+Substr(lcMesaj,2,60)+"..." + Chr(13) + Chr(10) + Chr(13)+ Chr(10)
			*!*	modificare ROAPRODUCTIE v 2.0.2	^
			Exit
		Endif
		lnNrNota=lnNrNota+1
	Endscan

	If ll_return
		lcMesaj = []

		Select (lcAct)
		Go Top
		lnId_set=id_set

		*!*	modificare	migrare v 1.0	>	v 2.0 (am si note cu suma 0)
		*!*		Select Distinct scd As Cont From (lcAct) ;
		*!*			WHERE Suma # 0 And !Empty(Nvl(scd,'')) ;
		*!*			UNION ;
		*!*			SELECT Distinct scc As Cont From (lcAct) ;
		*!*			WHERE Suma # 0 And !Empty(Nvl(scc,'')) ;
		*!*			INTO Cursor tcont

		*!*		If _Tally = 0
		*!*			Use In tcont
		Select Distinct scd As Cont From (lcAct) ;
			WHERE !Empty(Nvl(scd,'')) ;
			UNION ;
			SELECT Distinct scc As Cont From (lcAct) ;
			WHERE !Empty(Nvl(scc,'')) ;
			INTO Cursor tcont
		*!*		Endif
		*!*	modificare	migrare v 1.0	>	v 2.0	^

		lcLista = [-1]

		i = 0
		Select tcont
		Scan
			If Empty(Nvl(Cont,''))
				Loop
			Endif
			i = i + 1
			lcLista = lcLista + ',' + Alltrim(Cont)
		Endscan

		lcSql = 'select distinct c.cont as contpart, c.fel_cont, c.cu_inregistrari, c.explicatie as explic_cont,e.cont_c as exceptie, e.debit as pozitie, e.invers, 0 as gasit ' + ;
			'from ' + gcS + '.vconfig_cont_ireg c left join ' + gcS + '.exceptii_ireg e on c.cont = e.cont and e.invers = 1 ' + ;
			'where to_number(c.cont) in (' + lcLista + ')'
		lcCursor = 'verif_part'

		lnSucces = goExecutor.oExecute(lcSql,lcCursor)
		If lnSucces < 0
			aMESSAGEBOX('Modificare:Verific completare id_part ' +goExecutor.cEroare,0+16,"Eroare")
		Endif

		If lnSucces > 0
			If Reccount('verif_part') > 0
				Select (lcAct)
				Scan For !Empty(Suma)

					Scatter Name loCont
					Select verif_part
					Locate For contpart=loCont.scd
					If Found()
						If Empty(loCont.Id_partd) And !(loCont.scd$lcInMesajP)
							lcInMesajP=lcInMesajP+','+loCont.scd
							Replace gasit With 1
						Endif
						If Empty(loCont.pereched) And cu_inregistrari = 1 And fel_cont = 1 And !(loCont.scd$lcInMesajIreg)
							Locate For contpart=loCont.scd And inlist(upper(exceptie), 'X', upper(loCont.scc)) And fel_cont = 1 And pozitie = 0 And invers = 1
							If !Found()
								lcInMesajIreg = lcInMesajIreg + ',' + loCont.scd
							Endif
						Endif
						*!*	modificare	06.11.2007
					Else
						If !Empty(loCont.Id_partd)
							Select (lcAct)
							lcInMesajPSters = lcInMesajPSters + ',' + loCont.scd
							Replace Id_partd With 0,partd With ''
						Endif
						*!*	modificare	06.11.2007	^
					Endif

					Select verif_part
					Locate For contpart=loCont.scc
					If Found()
						If Empty(loCont.Id_partc) And !(loCont.scc$lcInMesajP)
							lcInMesajP=lcInMesajP+','+loCont.scc
							Replace gasit With 1
						Endif
						If cu_inregistrari = 1 And fel_cont = 0 And Empty(loCont.perechec) And !(loCont.scc$lcInMesajIreg)
							Locate For contpart=loCont.scc And inlist(upper(exceptie), 'X', upper(loCont.scd)) And fel_cont = 0 And pozitie = 1 And invers = 1
							If !Found()
								lcInMesajIreg = lcInMesajIreg + ',' + loCont.scc
							Endif
						Endif
						*!*	modificare	06.11.2007
					Else
						If !Empty(loCont.Id_partc)
							Select (lcAct)
							lcInMesajPSters = lcInMesajPSters + ',' + loCont.scc
							Replace Id_partc With 0,partc With ''
						Endif
						*!*	modificare	06.11.2007	^
					Endif
					Select (lcAct)
				Endscan
				*!*	modificare	06.11.2007
			Else
				Select (lcAct)
				Scan
					If !Empty(Id_partd)
						lcInMesajPSters = lcInMesajPSters + ',' + Alltrim(scd)
						Replace Id_partd With 0,partd With ''
					Endif
					If !Empty(Id_partc)
						lcInMesajPSters = lcInMesajPSters + ',' + Alltrim(scc)
						Replace Id_partc With 0,partc With ''
					Endif
				Endscan
			Endif
			*!*	modificare	06.11.2007	^
		Endif

		*!*	modificare 07.05.2013
		If lnSucces > 0 And !Empty(Nvl(lcIdFact,[]))
			lcSql = [select pack_contafin.verifica_id_documente(']+lcIdFact+[') as rez from dual]
			lcCursor = 'crsverifdoc'
			lnSucces = goExecutor.oExecute(lcSql,lcCursor)
			If lnSucces < 0
				aMESSAGEBOX('Modificare:Verific id documente ' +goExecutor.cEroare,0+16,"Eroare")
			Else
				select (lcCursor)
			 	lcMesajIdFact = alltrim(nvl(rez,''))
			 	use in (lcCursor)
			 	
				if !empty(nvl(lcMesajIdFact,[]))
					llDocumentePlus = (Occurs(',',lcMesajIdFact)>0)
					IF AMESSAGEBOX('Document' + iif(m.llDocumentePlus,'ele','ul') + ' ' + lcMesajIdFact  + ;
						' a fost marcat sters in lista de documente!' +  + Chr(13) + Chr(10) + Chr(13) + Chr(10) + ;
						'Doriti sa ' + iif(m.llDocumentePlus,'le','il') + ' marcati activ?',4+32,_SCREEN.Caption) = 6
						lcSql = 'UPDATE DOCUMENTE SET STERS = 0 WHERE ID_DOC IN (' + m.lcIdFact + ')'
						llSucces = goExecutor.oExecuta(m.lcSql)
						IF m.llSucces
							lcMesajIdFact = ''
						ENDIF 	
					ENDIF && messagebox
				ENDIF && empty
			ENDIF && lnSucces					
		ENDIF && lnSucces				
		*!*	modificare 07.05.2013	^

		If lnSucces > 0 And tlVerificAnalitic
			lcSql=[select CONT, ACONT FROM ] + gcS + [.vplcont_ANALITIC where inactiv = 0 and an = ?gnAn order by cont ]
			lcCursor = 'plcontana'
			lnSucces = goExecutor.oExecute(lcSql,lcCursor)

			If lnSucces < 0
				aMESSAGEBOX('Modificare:Verific completare analitic ' +goExecutor.cEroare,0+16,"Eroare")
			Endif

			If lnSucces > 0
				Select (lcAct)
				Scan For !Empty(Suma)
					Scatter Name loCont
					If Empty(Nvl(loCont.ascd, ''))
						Select plcontana
						Locate For Alltrim(Cont)=Alltrim(loCont.scd)
						If Found()
							If !(loCont.scd$lcInMesaj)
								lcInMesaj=lcInMesaj+','+loCont.scd
							Endif
						Endif
					Else
						Select plcontana
						Locate For Alltrim(Cont)=Alltrim(loCont.scd) And Alltrim(acont) = Alltrim(loCont.ascd)
						If !Found()
							If !(Alltrim(loCont.scd) + '.' + Alltrim(loCont.ascd)$lcInMesajAcont)
								lcInMesajAcont = lcInMesajAcont + ',' + Alltrim(loCont.scd) + '.' + Alltrim(loCont.ascd)
							Endif
						Endif
					Endif
					If Empty(Nvl(loCont.ascc,''))
						Select plcontana
						Locate For Cont=loCont.scc
						If Found()
							If !(loCont.scc$lcInMesaj)
								lcInMesaj=lcInMesaj+','+loCont.scc
							Endif
						Endif
					Else
						Select plcontana
						Locate For Alltrim(Cont)=Alltrim(loCont.scc) And Alltrim(acont) = Alltrim(loCont.ascc)
						If !Found()
							If !(Alltrim(loCont.scc) + '.' + Alltrim(loCont.ascc)$lcInMesajAcont)
								lcInMesajAcont = lcInMesajAcont + ',' + Alltrim(loCont.scc) + '.' + Alltrim(loCont.ascc)
							Endif
						Endif
					Endif
					Select (lcAct)
				Endscan
				Release loCont
			Endif
		Endif

		*!*	modificare 07.05.2013
		if !empty(nvl(lcMesajIdFact,[]))
			lcMesaj = lcMesaj + 'Document' + iif(Occurs(',',lcMesajIdFact)>0,'ele','ul') + ' ' + lcMesajIdFact  + ;
				' nu mai exista in baza de date!' + Chr(13) + Chr(10) + Chr(13) + Chr(10)
			ll_return = .F.
		Endif				
		*!*	modificare 07.05.2013	^

		If !Empty(lcInMesaj)
			lcInMesaj = Substr(lcInMesaj,2)
			*!*	modificare ROAPRODUCTIE v 2.0.2
			*!*				If Occurs(',',lcInMesaj) > 0
			*!*					lcMesaj = 'Nu ati completat simbolurile analitice pentru conturile:'
			*!*				Else
			*!*					lcMesaj = 'Nu ati completat simbolul analitic pentru contul'
			*!*				Endif
			*!*				aMESSAGEBOX(lcMesaj+ ' '+ lcInMesaj+' !',48,"Atentie")
			If Occurs(',',lcInMesaj) > 0
				lcInMesaj = 'simbolurile analitice pentru conturile: '+ lcInMesaj
			Else
				lcInMesaj = 'simbolul analitic pentru contul '+ lcInMesaj
			Endif
			lcMesaj = lcMesaj + 'Nu ati completat ' + lcInMesaj + ' !' + Chr(13) + Chr(10) + Chr(13) + Chr(10)
			*!*	modificare ROAPRODUCTIE v 2.0.2	^
			ll_return = .F.
		Endif

		If !Empty(lcInMesajAcont)
			lcInMesajAcont = Substr(lcInMesajAcont,2)
			If Occurs(',',lcInMesajAcont) > 0
				*!*	modificare ROAPRODUCTIE v 2.0.2
				*!*					lcMesaj = 'Nu exista conturile analitice in planul de conturi: '
				*!*				Else
				*!*					lcMesaj = 'Nu exista contul analitic in planul de conturi: '
				*!*				Endif
				*!*				aMESSAGEBOX(lcMesaj + ' ' + lcInMesajAcont +' !',48,"Atentie")
				lcInMesajAcont = 'conturile analitice in planul de conturi: ' + lcInMesajAcont
			Else
				lcInMesajAcont = 'contul analitic in planul de conturi: ' + lcInMesajAcont
			Endif
			lcMesaj = lcMesaj + 'Nu exista ' + lcInMesajAcont +' !' + Chr(13) + Chr(10) + Chr(13) + Chr(10)
			*!*	modificare ROAPRODUCTIE v 2.0.2	^
			ll_return = .F.
		Endif

		If !Empty(lcInMesajP)
			lcInMesajP = Substr(lcInMesajP,2)
			If Occurs(',',lcInMesajP) > 0
				*!*	modificare ROAPRODUCTIE v 2.0.2
				*!*					lcMesaj = 'Nu ati completat partenerii pentru conturile:'
				*!*				Else
				*!*					lcMesaj = 'Nu ati completat partenerul pentru contul '
				*!*				Endif
				*!*				aMESSAGEBOX(lcMesaj+' '+ lcInMesajP+' !',48,"Atentie")
				lcInMesajP = 'partenerii pentru conturile: ' + lcInMesajP
			Else
				lcInMesajP = 'partenerul pentru contul ' + lcInMesajP
			Endif
			*!*	modificare ROAPRODUCTIE v 2.0.2	^
			If tlAlegPartener      && dc nu pot sa ma intorc sa completez partenerii
				If Used('verif_part')
					*!*	modificare ROAPRODUCTIE v 2.0.2
					aMESSAGEBOX('Nu ati completat '+ lcInMesajP+' !',48,"Atentie")
					*!*	modificare ROAPRODUCTIE v 2.0.2	^
					Select verif_part
					Scan For gasit = 1
						lcCont = Alltrim(contpart)
						lcTitlu = Alltrim(explic_cont)
						*!*	modificare	10.12.2010
						loPart = CautPartenerContabilitate(GetHash([cTitlu=>] + Alltrim(lcTitlu) + [??] + ;
							[cCont=>] + Alltrim(lcCont) + [??] + ;
							[lAdaugCorespondente=>1??lVerificaANAF=>1]))
						*!*							loPart =  caut_parteneri(lcCont , lcTitlu)
						*!*	modificare	10.12.2010	^
						Select (lcAct)
						Replace All Id_partd With loPart.id_part, partd With loPart.denumire For Alltrim(scd) = lcCont And Id_partd = 0
						Replace All Id_partc With loPart.id_part, partc With loPart.denumire For Alltrim(scc) = lcCont And Id_partc = 0
						Release loPart
						Select verif_part
					Endscan
					ll_return = .F. 	&&	modificare 02.07.2007 : ca sa apese din nou pe terminat si sa se reverifice notele
					*!*	modificare ROAPRODUCTIE v 2.0.2
				Else
					lcMesaj = lcMesaj + 'Nu ati completat '+ lcInMesajP + ' !' + Chr(13) + Chr(10) + Chr(13) + Chr(10)
					*!*	modificare ROAPRODUCTIE v 2.0.2	^
				Endif
			Else
				*!*	modificare ROAPRODUCTIE v 2.0.2
				lcMesaj = lcMesaj + 'Nu ati completat '+ lcInMesajP + ' !' + Chr(13) + Chr(10) + Chr(13) + Chr(10)
				*!*	modificare ROAPRODUCTIE v 2.0.2	^
				ll_return = .F.
			Endif
		Endif

		If !Empty(lcInMesajIreg)
			lcInMesajIreg = Substr(lcInMesajIreg,2)
			If Occurs(',',lcInMesajIreg) > 0
				*!*	modificare ROAPRODUCTIE v 2.0.2
				*!*					lcMesaj = 'Nu ati completat doc. pereche pentru conturile:'
				*!*				Else
				*!*					lcMesaj = 'Nu ati completat doc. pereche pentru contul '
				*!*				Endif
				*!*				aMESSAGEBOX(lcMesaj+' '+lcInMesajIreg+' !',48,"Atentie")
				lcInMesajIreg = 'doc. pereche pentru conturile: ' + lcInMesajIreg
			Else
				lcInMesajIreg = 'doc. pereche pentru contul ' + lcInMesajIreg
			Endif
			lcMesaj = lcMesaj + 'Nu ati completat '+ lcInMesajIreg + ' !' + Chr(13) + Chr(10) + Chr(13) + Chr(10)
			*!*	modificare ROAPRODUCTIE v 2.0.2	^
			ll_return = .F.
		Endif

		*!*	modificare	06.11.2007
		If !Empty(lcInMesajPSters)
			lcInMesajPSters = Substr(lcInMesajPSters,2)
			If Occurs(',',lcInMesajPSters) > 0
				*!*	modificare ROAPRODUCTIE v 2.0.2
				*!*					lcMesaj = 'Au fost stersi partenerii corespunzatori conturilor:'
				*!*				Else
				*!*					lcMesaj = 'A fost sters partenerul corespunzator contului'
				*!*				Endif
				*!*				aMESSAGEBOX(lcMesaj+ ' '+ lcInMesajPSters+' !',48,"Atentie")
				lcInMesajPSters = 'Au fost stersi partenerii corespunzatori conturilor: ' + lcInMesajPSters
			Else
				lcInMesajPSters = 'A fost sters partenerul corespunzator contului ' + lcInMesajPSters
			Endif
			lcMesaj = lcMesaj + lcInMesajPSters + ' !' + Chr(13) + Chr(10) + Chr(13) + Chr(10)
			*!*	modificare ROAPRODUCTIE v 2.0.2	^
			ll_return = .F.
		Endif
		*!*	modificare	06.11.2007	^

		*!* modificare 14.11.2007
		*!* Verificare mai multe nr act pe acelasi Id fact
		Select Distinct id_fact,nract From &lcAct Where !Inlist(Nvl(id_fact,0),0,-1) ;
			and !(tva_incasare=1 and ((scd = [4426] and scc = [4428]) or (scd = [4428] and scc = [4427]))) ;	&&	modificare ROACONT v 2.4.4
			Into Cursor cduplicatetemp1
		Select id_fact, Count(*) As nr From cduplicatetemp1 ;
			GROUP By id_fact ;
			INTO Cursor cduplicatetemp

		Use In (Select("cduplicatetemp1"))


		Select cduplicatetemp
		Locate For nr>1
		If Found()
			*!*	modificare ROAPRODUCTIE v 2.0.2
			*!*				lcMesaj = 'Nu este posibil ca pe acelasi document sa existe doua numere diferite.'
			*!*				aMESSAGEBOX(lcMesaj,0+48,"Atentie")
			lcMesaj = lcMesaj + 'Nu este posibil ca pe acelasi document sa existe doua numere diferite.'
			*!*	modificare ROAPRODUCTIE v 2.0.2	^
			ll_return = .F.
		Endif
		Use In (Select("cduplicatetemp"))

		*!*	modificare ROAPRODUCTIE v 2.0.2
		If !Empty(lcMesaj)
			aMESSAGEBOX(Space(45) + "REZULTATE VERIFICARI" + Chr(13)+ Chr(10) + Replicate([=],60) + Chr(13)+ Chr(10) + lcMesaj,48,"Atentie")
		Endif
		*!*	modificare ROAPRODUCTIE v 2.0.2	^

		*!* modificare 14.11.2007 ^

		If lnSucces < 0
			ll_return = .F.
		Endif

		If Used('verif_part')
			Use In verif_part
		Endif
		If Used('plcontana')
			Use In plcontana
		Endif
		If Used('tcont')
			Use In tcont
		Endif
	Else
		If !Empty(lcMesaj)
			aMESSAGEBOX(Space(45) + "REZULTATE VERIFICARI" + Chr(13)+ Chr(10) + Replicate([=],60) + Chr(13)+ Chr(10) + lcMesaj,48,"Atentie")
		Endif
	Endif

	Select (lcAct)
	Return ll_return

Endproc && verificare_note_contabile
************************** SFARSIT: verificare_note_contabile *****************************


*******************************************
* PROCEDURE Sterge_Nota( tnCod, tnId_Set )
* Date : 08/07/2005, 13:03:45
* author : marius.mutu
* description:
*******************************************
Procedure sterge_nota
	Lparameters tnCod, tnId_Set
	Local lnSucces
	lnSucces = -1

	If Empty(tnCod)
		tnCod = 0
	Endif
	If Empty(tnId_Set)
		tnId_Set = 0
	Endif
	If tnCod + tnId_Set = 0
		Return
	Endif

	Local lcWhere
	lcWhere = []

	If !Empty(tnCod)
		lcWhere = [ and cod = ]	+ Transform(tnCod)
	Endif
	If !Empty(tnId_Set)
		lcWhere = [ and id_set = ]	+ Transform(tnId_Set)
	Endif
	If !Empty(lcWhere)
		lcWhere = Substr(lcWhere,6)
	Endif

	lcSql = [select * from ] + gcS + [.vact where ] + lcWhere + [ and an = ?gnAn and luna = ?gnLuna]+gcCondSucursala
	lcCursor = [actactan]

	lnSucces = goExecutor.oExecute(lcSql,lcCursor)
	goExecutor.oReset()
	If lnSucces < 0
		aMESSAGEBOX('Cautare Nota:' + Chr(13) + goExecutor.cEroare,0+16,"Eroare")
		Return
	Endif

	Select actactan
	If Reccount() > 0
		Clear Class "verificare"
		overif=Createobject('verificare')
		overif.Show(1)
		If buton#2
			lnSucces = OSCRIE_IN_FISIERE(2,.F.)
		Else
			lnSucces = -1
		Endif
	Endif

	If Used('actactan')
		Use In actactan
	Endif
	Release overif

	Return lnSucces
Endproc
*----------------------------------sfarsit procedura Sterge_Nota----------------------------------
*******************************************
* PROCEDURE scrie_nota_import( tnId_Set, tcCursorImport )
* Date : 08/07/2005, 14:04:32
* author : marius.mutu
* description:
*******************************************
Procedure scrie_nota_import( tnId_Set, tlVerificAnalitic, tlCompletareParteneri, tcCursorImport,taValori )
	&&taValori -- parametru pentru lans
	Local lnId_set, lcCursor, lnSucces
	Local llVerificAnalitic, llCompletareParteneri
	lnSucces = -1
 
	lnId_set = tnId_Set
	lcCursor = tcCursorImport
	llVerificAnalitic = tlVerificAnalitic
	llCompletareParteneri = tlCompletareParteneri

	If Type('taValori',1)#[A]
		lnBut = lans(lnId_set)
	Else
		lnBut = lans(lnId_set,.F.,.T.,@taValori)
	Endif

	If lnBut = 1
		lcListaCampuri = Lista_Campuri(lcCursor)
		Select actactan
		Scatter Name oact
		Zap
		*!*			INSERT INTO actactan (scd,ascd,scc,ascc,suma, explicatia) SELECT scd, ascd, scc, ascc, suma, explicatia FROM crs_inchidere
		lcInsert = [INSERT INTO ACTACTAN (] + lcListaCampuri + [) select ] + lcListaCampuri + [ from ] + lcCursor
		&lcInsert


		Select actactan
		Scan
			lcGather = [GATHER NAME oact FIELDS EXCEPT ] + lcListaCampuri
			&lcGather
		Endscan


*!*			v2.5.51 - 15.09.2014 &&modificare facuta pentru a putea modifica nota de inchidere de salarii
*!*			Select actactan
*!*			LOCATE
*!*			Do Form verificare With llVerificAnalitic, llCompletareParteneri
*!*			If gnButon = 1
*!*				Select actactan
*!*				lnSucces  = OSCRIE_IN_FISIERE(0)
*!*			Endif
		lcJurnal = []
		update_jtva_coloane(m.lcJurnal, 'crsExplicatiiTVATemp', 1)

		Select .F. As ales, 0 As Cu_tva, Cast(0 As N(2)) As tipnota, a.*, b.denumire As explicatie_tva_2 ;
			From actactan a Left Join crsExplicatiiTVATemp b On a.id_jtva_coloana = b.id_jtva_coloana ;
			Into Cursor tact Readwrite

		Update tact Set explicatie_tva = explicatie_tva_2
		Use In (Select('crsExplicatiiTVATemp'))

		Select tact
		Go Top
		llNotaNoua = .T.
		llMaximize = .T.
		loForm = Createobject([frm_modific2007], m.lnId_Set, m.llNotaNoua)
		loForm.lb_titlu_alb_b121.Caption = 'Nota' && 'Exigibilizare TVA Incasare'
		Select tact
		loForm.Show(1, m.llMaximize)

		If buton = 1
			Use In (Select('actactan'))

			Select tact
			Replace id_jtva_coloana With Null, proc_tva With 0 For Cu_tva = 0
			Select * From tact Into Cursor actactan READWRITE WHERE suma <>0

			Select actactan
			Replace All id_util With gnIdUtil, id_set With m.lnId_Set
			lnSucces  = OSCRIE_IN_FISIERE(0)
		Endif && buton = 1
*!*			v2.5.51 - 15.09.2014 ^

	Endif

	If Used('actactan')
		Use In actactan
	Endif

	Return lnSucces


Endproc
*----------------------------------sfarsit procedura scrie_nota_import----------------------------------

&& ------- INCEPUT ------- ultima_zi_din_luna
Function ultima_zi_din_luna
	Parameters tnAnul, tnLuna

	Local ldData, lnAn, lnLuna
	If Type('tnAnul')='C'
		tnAnul=Val(tnAnul)
	Endif

	If Type('tnLuna')='C'
		tnLuna=Val(tnLuna)
	Endif

	If Empty(tnAnul) Or Type('tnAnul')#'N'
		lnAn = gnan
	Else
		lnAn = tnAnul
	Endif
	If Empty(tnLuna) Or Type('tnLuna')#'N'
		lnLuna = gnluna
	Else
		lnLuna = tnLuna
	Endif

	ldData = Date(lnAn, lnLuna, 1)
	ldData = Gomonth(ldData,1)
	ldData = Date(Year(ldData), Month(ldData), 1) - 1

	Return ldData
Endfunc
&& ------- SFARSIT ------- ultima_zi_din_luna

&& -------------------------- INCEPUT do_assign_analitic ------------------------------
Procedure do_assign_analitic
	Parameters tcCont,pcAct,pcRul

	Private pcCont,pcAct,pcRul,pParamP,pParamS
	Store 0 To pParamP,pParamS
	lcAnalitic = ''
	lcAlias = Alias()

	pcCont = Alltrim(tcCont)

	lcSel = [SELECT * from ] + gcS + [.config_analitice WHERE cont = ?pcCont]
	lcCursor = 'crs_cfg_ana'
	lnSucces = goExecutor.oExecute(lcSel,lcCursor)
	If lnSucces < 0
		aMESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
	Endif

	If lnSucces > 0
		If Reccount('crs_cfg_ana')=0
			Use In crs_cfg_ana
			lnSucces = -1
		Endif
	Endif

	If lnSucces > 0
		Select crs_cfg_ana
		Scatter Name ocfg
		lcCampPrefix = Nvl(Alltrim(ocfg.camp_leg_prefix),'')
		lcCampSufix = Nvl(Alltrim(ocfg.camp_leg_sufix),'')

		If !Empty(lcCampPrefix)
			If Type('&pcRul..'+lcCampPrefix) # 'U'
				pParamP = &pcRul..&lcCampPrefix
			Else
				If Type('&pcAct..'+lcCampPrefix) # 'U'
					pParamP = &pcAct..&lcCampPrefix
				Endif
			Endif
		Endif

		If !Empty(lcCampSufix)
			If Type('&pcRul..'+lcCampSufix) # 'U'
				pParamS = &pcRul..&lcCampSufix
			Else
				If Type('&pcAct..'+lcCampSufix) # 'U'
					pParamS = &pcAct..&lcCampSufix
				Endif
			Endif
		Endif

		lcSel = [{call fconturi_analitice(?gcs,?pcCont,0,?pParamP,?pParamS)}]
		lcCursor = 'crs_analitice'
		lnSucces = goExecutor.oExecute(lcSel,lcCursor)

		If lnSucces < 0
			aMESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
		Endif
	Endif

	&& iau Primul Simbol Analitic din Tabel - ordonat pt ca e selectat cu Distinct
	If lnSucces > 0
		Select crs_analitice
		Go Top
		lcAnalitic = Alltrim(acont)
	Endif

	&& verificare analiticului cu Planul de Conturi
	If lnSucces > 0
		*!*		lcSel = [SELECT cont,acont from ] + gcs + [.vplcont_analitic WHERE cont = ?pcCont and acont = ?lcAnalitic and an = ?gnAn ]
		*!*		lcCursor = 'crs_verific'
		*!*		lnSucces = goExecutor.oExecute(lcSel,lcCursor)
		*!*		IF lnSucces < 0
		*!*			MESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
		*!*		ENDIF

		lnSucces = verific_analitic_(pcCont, lcAnalitic, .T.)
	Endif

	If lnSucces > 0
		If Reccount('crs_verific')=0
			lnSucces = -1
		Endif
	Endif

	If Used('crs_cfg_ana')
		Use In crs_cfg_ana
	Endif
	If Used('crs_verific')
		Use In crs_verific
	Endif
	If Used('crs_analitice')
		Use In crs_analitice
	Endif
	If Used('crs_verific')
		Use In crs_verific
	Endif

	If lnSucces < 0
		lcAnalitic = ''
	Endif

	Select (lcAlias)
	Return lcAnalitic

	&& -------------------------- SFARSIT do_assign_analitic ------------------------------

	&& -------------------------- INCEPUT verific_cont ------------------------------
Procedure verific_cont
	Parameters tcCont, tlNoMessage

	Private pcCont
	pcCont = Alltrim(tcCont)

	&& verificarea contului cu Planul de Conturi
	lcSel = [SELECT cont from ] + gcS + [.vplcont_sintetic WHERE TRIM(cont) = ?pcCont and an = ?gnAn ]
	lcCursor = 'crs_verific'
	lnSucces = goExecutor.oExecute(lcSel,lcCursor)
	If lnSucces < 0
		aMESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
	Endif

	If lnSucces > 0
		If Reccount('crs_verific')=0
			lnSucces = -1
		Endif
	Endif

	If lnSucces < 0 And !tlNoMessage
		aMESSAGEBOX('Acest cont nu este definit in planul de conturi!',0+48, 'Atentie')
	Endif

	Return lnSucces

Endproc

&& -------------------------- SFARSIT verific_cont ------------------------------

&& -------------------------- INCEPUT verific_analitic ------------------------------
Procedure verific_analitic_
	Parameters tcCont, tcacont, tlNoMessage

	Private pcCont, pcACont
	pcCont = Alltrim(tcCont)
	pcACont = Alltrim(tcacont)

	&& verificare contului cu Planul de Conturi
	lcSel = [SELECT cont, acont from ] + gcS + [.vplcont_analitic WHERE TRIM(cont) = ?pcCont and TRIM(acont) = ?pcAcont and an = ?gnAn ]
	lcCursor = 'crs_verific'
	lnSucces = goExecutor.oExecute(lcSel,lcCursor)
	If lnSucces < 0
		aMESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
	Endif



	If lnSucces > 0
		If Reccount('crs_verific')=0
			lnSucces = -1
		Endif
	Endif

	If lnSucces < 0 And !tlNoMessage
		aMESSAGEBOX('Acest analitic nu este definit in planul de conturi!',0+48, 'Atentie')
	Endif
	Return lnSucces

Endproc

&& -------------------------- SFARSIT verific_analitic ------------------------------

*!* vizualizare balanta, balanta c8, balanta c9
Procedure viz_balanta_contabilitate
	Lparameters tcBal, tlCumulat

	Local loFrmPerioada, lnAn1, lnLuna1, lnAn2, lnLuna2, lcPerioada, lnInit, lnFinal
	Private pcondper
	pcondper = ""

	If tlCumulat
		loFrmPerioada=Createobject('frm_perioada_luni')
		loFrmPerioada.Show(1)

		If gnButon=2
			Return
		Endif

		If At('_',pcondper) > 0
			lnAn1 = Val(Substr(pcondper,3,4))
			lnLuna1 = Val(Substr(pcondper,1,2))
			lnAn2 = Val(Substr(pcondper,10,4))
			lnLuna2 = Val(Substr(pcondper,8,2))

			lcPerioada = Substr(pcondper,1,2)+'/'+Substr(pcondper,3,4) + ' - ' + Substr(pcondper,8,2)+'/'+Substr(pcondper,10,4)
		Else
			lnAn1 = Val(Substr(pcondper,3,4))
			lnLuna1 = Val(Substr(pcondper,1,2))
			lnAn2 = Val(Substr(pcondper,3,4))
			lnLuna2 = Val(Substr(pcondper,1,2))

			lcPerioada = Substr(pcondper,1,2)+'/'+Substr(pcondper,3,4) + ' - ' + Substr(pcondper,1,2)+'/'+Substr(pcondper,3,4)
		Endif
		lnInit = lnAn1 * 12 + lnLuna1
		lnFinal = lnAn2 * 12 + lnLuna2
		Do  viz_balanta With  , , , , , , m.lnLuna1, m.lnAn1, m.lnLuna2, m.lnAn2, m.tcBal		
	ELSE 
		Do  viz_balanta With  , , , , , , , , , , m.tcBal	
	Endif

	

Endproc && viz_balanta_contabilitate

*********************************************************************************************
* PROCEDURE viz_balanta(  )
* Date : 08/09/2004, 16:00:20
* author : marius.mutu
* description:
* tnAn1, tnLuna1, tnAn2, tnLuna2 - luna initiala, luna finala sau luna curenta
******************************************* INCEPUT:viz_balanta *******************************************
Procedure viz_balanta
	Parameters tlFaraInainte_de, tnId_sectie, tlEval_valuta, tnCurs, tcValuta, tcFormular, tnLuna1, tnAn1, tnLuna2, tnAn2, tcBal
	&& tcBal = "bal/bal_c8/bal_c9" && balanta clasele  1-7/ balanta clasa 8 / balanta clasa 9

	Local lnAn1, lnLuna1, lnAn2, lnLuna2, lcBal, lcProceduraInainte, lcCaption, lcAntetOriginal
	lnAn1 = gnan
	lnLuna1 = gnluna
	lnAn2 = gnan
	lnLuna2 = gnluna
	Private m.sprecdeb1,m.spreccred1,m.ssoldideb, m.ssoldicred, m.sprecdeb,m.spreccred,m.sruldeb,m.srulcred,m.stotdeb,m.stotcred,m.ssolddeb,m.ssoldcred
	Store 0 To m.sprecdeb1,m.spreccred1,m.ssoldideb, m.ssoldicred, m.sprecdeb,m.spreccred,m.sruldeb,m.srulcred,m.stotdeb,m.stotcred,m.ssolddeb,m.ssoldcred

	If Empty(tcBal) Or Pcount() < 11
		lcBal = "bal"
	Else
		lcBal = Iif(Lower(tcBal)$"bal/bal_c8/bal_c9", Lower(tcBal), "bal")
	Endif

	lcCaption = "Balanta de verificare"
	Do Case
		Case lcBal = "bal"
			lcProceduraInainte = "BALANTA"
			lcCaption = "Balanta de verificare"
		Case lcBal = "bal_c8"
			lcProceduraInainte = "BALANTA_C8"
			lcCaption = "Balanta de verificare clasa 8"
		Case lcBal = "bal_c9"
			lcProceduraInainte = "BALANTA_C9"
			lcCaption = "Balanta de verificare clasa 9"
	Endcase

	*** verificare INAINTE_DE
	If !tlFaraInainte_de
		Do inainte With lcProceduraInainte In oinainte_de.prg
	Endif

	Private T, lccont1, lccont2
	Store '' To lccont1, lccont2
	T='.t.'

	Local lnId_sectie, llCentru, llEval_valuta, lnCurs, lcValuta
	Store .F. To llCentru
	If !Empty(tnId_sectie)
		lnId_sectie = tnId_sectie
	Endif
	llEval_valuta = tlEval_valuta
	lnCurs = tnCurs
	lcValuta = tcValuta

	If Pcount() < 10 Or Empty(tnAn1) Or Empty(tnLuna1) Or Empty(tnAn2) Or Empty(tnLuna2)
		lnAn1 = gnan
		lnLuna1 = gnluna
		lnAn2 = gnan
		lnLuna2 = gnluna
	Else
		lnAn1 = tnAn1
		lnLuna1 = tnLuna1
		lnAn2 = tnAn2
		lnLuna2 = tnLuna2
	Endif

	If !Empty(lnId_sectie)
		llCentru = .T.
		If Used("tbalanta")
			Use In tbalanta
		Endif

		*!*	lcSel = [{call pack_mg_sectie.make_balante_centru(]+Alltrim(Str(lnId_sectie))+[,]+Alltrim(Str(lnLuna1))+[,]+Alltrim(Str(lnAn1))+[,]+Alltrim(Str(lnLuna2))+[,]+Alltrim(Str(lnAn2))+[)}]
		lcSel = [begin pack_mg_sectie.make_balante_centru(]+Alltrim(Str(lnId_sectie))+[,]+ ;
			Alltrim(Str(lnLuna1))+[,]+Alltrim(Str(lnAn1))+[,]+Alltrim(Str(lnLuna2))+[,]+Alltrim(Str(lnAn2))+[); end;]
		lnSucces = goExecutor.oExecute(lcSel)

		If lnSucces < 0
			aMESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
			Return
		Endif
	Endif

	Do make_tbalanta With llCentru, tnLuna1, tnAn1, tnLuna2, tnAn2, lcBal


	If llEval_valuta
		lcProc_eval = 'eval_balanta'
		Do &lcProc_eval With lnCurs
	Endif

	&& Adaugat 03.05.2006 - pt. Balanta in engleza Alfred Knight
	Private pcSold1ian, pcPrec, pcRul, pcTotal, pcSolduri, pcCont, pcDenumire, plBal_alt
	pcSI1 = 'Solduri initiale 1 Ian.'
	pcSI = 'Solduri initiale'
	pcTSP = 'Total sume precedente'
	pcRLC = 'Rulajele lunii curente'
	pcTS = 'Total Sume'
	pcSF = 'Solduri finale'
	pcTR = 'Total rulaje'
	pcCont = "Cont"
	pcDenumire = "Denumire"
	plBal_alt = .F.
	***

	Sele tbalanta
	* DO FORM afisbal_ana
	If !Empty(tcFormular) And Type('tcFormular')= 'C'
		loBal = Createobject(tcFormular)
	Else
		loBal = Createobject("frm_balanta")
	Endif

	If llCentru Or llEval_valuta
		lcAntetOriginal = gcAntet
	Endif

	Do Case
		Case llCentru

			lcSql=[select sectie from vnom_sectii where id_sectie= ]+Alltrim(Str(lnId_sectie))
			lnSucces=goExecutor.oExecute(lcSql,'crsSectie')
			If lnSucces < 0
				aMESSAGEBOX(goExecutor.cEroare,0+16,'Eroare')
			Endif
			Select crsSectie
			lcCentru_profit = sectie
			If Used('crsSectie')
				Use In crsSectie
			Endif

			lcCaption = "BALANTA DE VERIFICARE - " + Alltrim(lcCentru_profit) + " " + Padl(Int(lnLuna1),2,'0') + '.' + Alltrim(Str(lnAn1,4,0)) + ' - ' + Padl(Int(lnLuna2),2,'0') + '.' + Alltrim(Str(lnAn2,4,0))
			gcAntet = Alltrim(gcAntet) + " - Centru: "+ lcCentru_profit
		Case llEval_valuta
			lcCaption = "Evaluarea Balantei in valuta  1 "+lcValuta+ "=" +Alltrim(Str(lnCurs,10,gnPCurs))+" LEI"
			gcAntet = Alltrim(gcAntet) + " " + lcCaption
		Otherwise
			gcAntet = Alltrim(gcAntet)
	Endcase

	*If llCentru Or llEval_valuta
	With loBal
		.lb_titlu_alb_b121.Caption = lcCaption + ;
			IIF(!EMPTY(tnAn2), " " + ALLTRIM(PADL(ROUND(tnLuna1,0),2,'0')) + '/' + ALLTRIM(PADL(ROUND(tnAn1,0),4,'0')) + '-' + ALLTRIM(PADL(ROUND(tnLuna2,0),2,'0')) + '/' + ALLTRIM(PADL(ROUND(tnAn2,0),4,'0')), "")
		*Endif
		*!*	modificare 23.02.2008
		.lCentru = llCentru
		.nluna1 = IIF(EMPTY(tnLuna1), 0, ROUND(tnLuna1,0))
		.nan1 = IIF(EMPTY(tnAn1), 0, ROUND(tnAn1,0))
		.nluna2 = IIF(EMPTY(tnLuna2), 0, ROUND(tnLuna2,0))
		.nan2 = IIF(EMPTY(tnAn2), 0, ROUND(tnAn2,0))
		.cbal = lcBal
		.cprocedurainainte = lcProceduraInainte
		*!*	modificare 23.02.2008	^
	Endwith
	loBal.Show(1)

	If llCentru Or llEval_valuta
		gcAntet =lcAntetOriginal
	Endif

	If Used("tbalanta")
		Use In tbalanta
	Endif

Endproc && viz_balanta
******************************************* SFARSIT: viz_balanta *******************************************
********************************************************************************************************************
*** CREEAZA TBALANTA DIN BAL+BALANA+TOTALURI
Procedure make_tbalanta
	Parameters tlCentru, tnLuna1, tnAn1, tnLuna2, tnAn2, tcBal, tlNuContAlternativ
	* tcBal = "bal/bal_c8/bal_c9" && balanta clasele  1-7/ balanta clasa 8 / balanta clasa 9
	* tlNuContAlternativ: default (.F.) .T. nu se inlocuieste cont/acont cu cont_alt, acont_alt
	
	Local llCentru, lcBal, lcVbal, lcVBalana
	llCentru = tlCentru

	&& DACA SUNT PE O SUCURSALA - SELECTEZ DOAR INREGISTRARILE DE PE SUCURSALA CURENTA
	Local lcFiltruSucursala
	lcFiltruSucursala = ""
	If !Isnull(gnIdSucursala)
		lcFiltruSucursala = Substr(gcCondSucursala,6)
	Endif

	If Empty(tcBal) Or Pcount() < 6
		lcBal = "bal"
	Else
		lcBal = Iif(Lower(tcBal)$"bal/bal_c8/bal_c9", Lower(tcBal), "bal")
	Endif
	lcVbal = "VBAL"
	lcVBalana = "VBALANA"

	Do Case
		Case lcBal = "bal"
			lcVbal = "VBAL"
			lcVBalana = "VBALANA"
		Case lcBal = "bal_c8"
			lcVbal = "VBAL_C8"
			lcVBalana = "VBALANA_C8"
		Case lcBal = "bal_c9"
			lcVbal = "VBAL_C9"
			lcVBalana = "VBALANA_C9"
	Endcase

	If Used('TBALANTA')
		Use In tbalanta
	Endif

	Local lnAn1, lnLuna1, lnAn2, lnLuna2
	If Pcount() < 5 Or Empty(tnAn1) Or Empty(tnLuna1) Or Empty(tnAn2) Or Empty(tnLuna2)
		lnAn1 = gnan
		lnLuna1 = gnluna
		lnAn2 = gnan
		lnLuna2 = gnluna
	Else
		lnAn1 = tnAn1
		lnLuna1 = tnLuna1
		lnAn2 = tnAn2
		lnLuna2 = tnLuna2
	Endif

	LNPRECEDENT=0



	Local lcSelect, lcFiltru, lcSchema1, lcOrder, llAfisare, lcGroup, llModParam, lcFiltruOriginal
	Store '' To lcSelect, lcFiltru, lcSchema1, lcOrder, llAfisare, lcGroup, llModParam, lcFiltruOriginal

	Private potbal1, potbal2
	Store Null To potbal1, potbal2

	&&	PARAMETERS tcnume, tcalias, tcselect, tcfiltru, tcschema, tcorder, tlAfisare, tcgroup, tlModParam, tcFiltruOriginal
	If llCentru
		Private pcselect1,pcfiltru1,pcschema1,potbal1,tbal1,pcselect2,pcfiltru2,pcschema2,potbal2,tbal2
		Store "" To potbal1,potbal2
		lcSelect = [select rpad(SUBSTR(cont,1,1),4,' ') as g1,rpad(SUBSTR(cont,1,2),4,' ') as g2,rpad(SUBSTR(cont,1,3),4,' ') as g3,]+;
			[cont as g4,cont,rpad(' ',4,' ') acont, id_bal,denumire, '' as cont_alt, '' as cod,precdeb,preccred,ruldeb,rulcred,]+;
			[totdeb,totcred,solddeb,soldcred,precdeb1,preccred1,4 as bnivel, difana, ]+;
			[cast (null as number(5)) as id_sucursala, '' as sucursala ] + ;
			[from mg_tmp_bal]
		lcFiltru = []
		lcSchema = []
		lcOrder = []
		llAfisare = .F.
		lcGroup = []
		llModParam = .T.
		lcFiltruOriginal = [AN * 12 + LUNA BETWEEN ] +Alltrim(Str(lnAn1*12+lnLuna1)) + [ AND ] + Alltrim(Str(lnAn2*12+lnLuna2))

		gencursor('potbal1','tbal1', lcSelect, lcFiltru, lcSchema1, lcOrder, llAfisare, lcGroup, llModParam, lcFiltruOriginal)
		potbal1.ca_baza1.afisare()

		lcSelect = [select rpad(SUBSTR(cont,1,1),4,CHR(32)) as g1,rpad(SUBSTR(cont,1,2),4,CHR(32)) as g2,rpad(SUBSTR(cont,1,3),4,CHR(32)) as g3,]+;
			[cont as g4,cont,acont, id_balana as id_bal,denumire, '' as cont_alt, '' as cod,precdeb,preccred,ruldeb,rulcred,]+;
			[totdeb,totcred,solddeb,soldcred,precdeb1,preccred1, 5 as bnivel, 0 as difana, ]+;
			[cast (null as number(5)) as id_sucursala, '' as sucursala ] + ;
			[from mg_tmp_balana]
		lcFiltru = []
		lcOrder = []
		lcSchema = []
		llAfisare=.F.
		lcGroup = []
		llModParam = .T.
		lcFiltruOriginal=[AN * 12 + LUNA BETWEEN ] +Alltrim(Str(lnAn1*12+lnLuna1)) + [ AND ] + Alltrim(Str(lnAn2*12+lnLuna2))

		gencursor('potbal2','tbal2', lcSelect, lcFiltru, lcSchema1, lcOrder, llAfisare, lcGroup, llModParam, lcFiltruOriginal)
		potbal2.ca_baza1.afisare()
	Else
		*** BALANTA SINTETICA CU TOATE INREGISTRARILE
*!* 25.01.2011
*!*			lcSelect = [select rpad(SUBSTR(cont,1,1),4,' ') as g1, rpad(SUBSTR(cont,1,2),4,' ') as g2, rpad(SUBSTR(cont,1,3),4,' ') as g3, ]+;
*!*				[cont as g4, cont,rpad(' ',4,' ') acont, id_bal, denumire, precdeb, preccred, ruldeb, rulcred, ]+;
*!*				[totdeb, totcred, solddeb, soldcred, precdeb1, preccred1, 4 as bnivel, difana, ]+;
*!*				[id_sucursala, sucursala ] + ;
*!*				[from ] + lcVbal

		lcSelect = [select rpad(SUBSTR(cont,1,1),4,' ') as g1, rpad(SUBSTR(cont,1,2),4,' ') as g2, rpad(SUBSTR(cont,1,3),4,' ') as g3, ]+;
			[cont as g4, cont,rpad(' ',4,' ') acont, MAX(id_bal) as id_bal, denumire, ] + ;
			[cont_alt, cod, ] + ;
			[SUM(case when an*12+luna = ] +Alltrim(Str(lnAn1*12+lnLuna1)) + [ then precdeb else 0 end) as precdeb, ] + ;
			[SUM(case when an*12+luna = ] +Alltrim(Str(lnAn1*12+lnLuna1)) + [ then preccred else 0 end) as preccred, ] + ;			
			[SUM(ruldeb) as ruldeb, SUM(rulcred) as rulcred, ]+;
			[SUM(case when an*12+luna = ] +Alltrim(Str(lnAn2*12+lnLuna2)) + [ then totdeb else 0 end) as totdeb, ] + ;
			[SUM(case when an*12+luna = ] +Alltrim(Str(lnAn2*12+lnLuna2)) + [ then totcred else 0 end ) as totcred, ] + ;			
			[SUM(case when an*12+luna = ] +Alltrim(Str(lnAn2*12+lnLuna2)) + [ then solddeb else 0 end) as solddeb, ] + ;
			[SUM(case when an*12+luna = ] +Alltrim(Str(lnAn2*12+lnLuna2)) + [ then soldcred else 0 end ) as soldcred, ] + ;			
			[SUM(case when an*12+luna = ] +Alltrim(Str(lnAn1*12+lnLuna1)) + [ then precdeb1 else 0 end) as precdeb1, ] + ;
			[SUM(case when an*12+luna = ] +Alltrim(Str(lnAn1*12+lnLuna1)) + [ then preccred1 else 0 end) as preccred1, ] + ;		
			[4 as bnivel, MAX(difana) as difana, id_sucursala, sucursala ] + ;			
			[from ] + lcVbal

		lcFiltru = []
		lcSchema = []
		lcOrder = []
		llAfisare = .F.
		lcGroup = [cont, denumire, cont_alt, cod, id_sucursala, sucursala]
		llModParam = .T.
		lcFiltruOriginal = [AN * 12 + LUNA BETWEEN ] +Alltrim(Str(lnAn1*12+lnLuna1)) + [ AND ] + Alltrim(Str(lnAn2*12+lnLuna2)) + gcCondSucursala

		gencursor('potbal1','tbal1', lcSelect, lcFiltru, lcSchema1, lcOrder, llAfisare, lcGroup, llModParam, lcFiltruOriginal)
		potbal1.ca_baza1.afisare()

		*** BALANTA ANALITICA CU TOATE INREGISTRARILE
*!*			lcSelect = [select rpad(SUBSTR(cont,1,1), 4, CHR(32)) as g1, rpad(SUBSTR(cont,1,2), 4, CHR(32)) as g2, rpad(SUBSTR(cont,1,3),4,CHR(32)) as g3,]+;
*!*				[cont as g4, cont, acont, id_balana as id_bal, denumire, precdeb, preccred, ruldeb, rulcred, ]+;
*!*				[totdeb, totcred, solddeb, soldcred, precdeb1, preccred1, 5 as bnivel, 0 as difana, ]+;
*!*				[id_sucursala, sucursala ] + ;
*!*				[from  ] + lcVBalana

		lcSelect = [select rpad(SUBSTR(cont,1,1), 4, CHR(32)) as g1, rpad(SUBSTR(cont,1,2), 4, CHR(32)) as g2, rpad(SUBSTR(cont,1,3),4,CHR(32)) as g3,]+;
			[cont as g4, cont, acont, MAX(id_balana) as id_bal, denumire, ] + ;
			[cont_alt, cod, ] + ;
			[SUM(case when an*12+luna = ] +Alltrim(Str(lnAn1*12+lnLuna1)) + [ then precdeb else 0 end) as precdeb, ] + ;
			[SUM(case when an*12+luna = ] +Alltrim(Str(lnAn1*12+lnLuna1)) + [ then preccred else 0 end) as preccred, ] + ;			
			[SUM(ruldeb) as ruldeb, SUM(rulcred) as rulcred, ]+;
			[SUM(case when an*12+luna = ] +Alltrim(Str(lnAn2*12+lnLuna2)) + [ then totdeb else 0 end) as totdeb, ] + ;
			[SUM(case when an*12+luna = ] +Alltrim(Str(lnAn2*12+lnLuna2)) + [ then totcred else 0 end ) as totcred, ] + ;			
			[SUM(case when an*12+luna = ] +Alltrim(Str(lnAn2*12+lnLuna2)) + [ then solddeb else 0 end) as solddeb, ] + ;
			[SUM(case when an*12+luna = ] +Alltrim(Str(lnAn2*12+lnLuna2)) + [ then soldcred else 0 end ) as soldcred, ] + ;					
			[SUM(case when an*12+luna = ] +Alltrim(Str(lnAn1*12+lnLuna1)) + [ then precdeb1 else 0 end) as precdeb1, ] + ;
			[SUM(case when an*12+luna = ] +Alltrim(Str(lnAn1*12+lnLuna1)) + [ then preccred1 else 0 end) as preccred1, ] + ;
			[5 as bnivel, 0 as difana, id_sucursala, sucursala ] + ;			
			[from  ] + lcVBalana
		*!* 25.01.2011 ^			
		lcFiltru = []
		lcOrder = []
		lcSchema = []
		llAfisare=.F.
		lcGroup = [cont, acont, denumire, cont_alt, cod, id_sucursala, sucursala]
		llModParam = .T.
		lcFiltruOriginal=[AN * 12 + LUNA BETWEEN ] +Alltrim(Str(lnAn1*12+lnLuna1)) + [ AND ] + Alltrim(Str(lnAn2*12+lnLuna2)) + gcCondSucursala

		gencursor('potbal2','tbal2', lcSelect, lcFiltru, lcSchema1, lcOrder, llAfisare, lcGroup, llModParam, lcFiltruOriginal)
		potbal2.ca_baza1.afisare()
	Endif

	Local lcBal1
	lcBal1 = 'TBAL1'

	*!* 12.02.2008
	&& daca sunt pe o mama - cumulez balantele de pe sucursale
	&& TOTALURILE PE CLASE, GRUPE LE FAC PE BALANTA CENTRALIZATA && TG01 in loc de TBAL1
	If glEMama

		*!* 07.03.2008
		*!* SELECTEZ CONT, PRECDEB, PRECCRED CENTRALIZATE
		*!* SELECTEZ PRECDEB, PRECCRED DIN CURSOR SI RULAJELE DIN SUMA(SUCURSALE.RULAJE)
		*!* DACA FAC DOAR SUMA(PRECDEB), SUMA(PRECCRED) DIN SUCURSALE PIERD SOLDAREA SUMELOR LA 1 IANUARIE

		*!* 01.04.2008
		*!* am luat sum(precdeb1) din luna curenta in loc de sum(precdeb) din luna ianuarie
		TEXT to lcSql TEXTMERGE noshow
select nvl(a.cont, b.cont) as cont,
case when Nvl(a.precdeb,0) > Nvl(a.preccred,0) then abs(Nvl(a.precdeb,0)-Nvl(a.preccred,0)) else 0 end + nvl(b.debit,0) as precdeb,
case when Nvl(a.precdeb,0) < Nvl(a.preccred,0) then abs(Nvl(a.precdeb,0)-Nvl(a.preccred,0)) else 0 end + nvl(b.credit,0) as preccred
from
(select cont, sum(precdeb1) as precdeb, sum(preccred1) as preccred
  from bal
 where an = <<lnAn1>>
   and luna = <<lnLuna1>>
   group by cont) a full join
(select cont, sum((case when 2005*12+7> an*12+luna
      and 2005*12+7<=pack_sesiune.getan()*12+pack_sesiune.getluna()
      then ROUND(ruldeb / 10000,2) else ruldeb end)) as debit, sum((case when 2005*12+7> an*12+luna
      and 2005*12+7<=pack_sesiune.getan()*12+pack_sesiune.getluna()
      then ROUND(rulcred / 10000,2) else rulcred end)) as credit
  from bal
 where an = <<lnAn1>>
   and luna between 1 and <<lnLuna1-1>>
   group by cont) b on a.cont = b.cont
		ENDTEXT

		lnSucces = goExecutor.oExecute(lcSql, "crsBalPrecedente")
		If lnSucces < 0
			aMESSAGEBOX(goExecutor.cEroare)
			Create Cursor crsBalPrecedente (Cont c(4), precdeb N(10,2), preccred N(10,2))
		Endif

		TEXT to lcSql TEXTMERGE noshow
select nvl(a.cont, b.cont) as cont, nvl(a.acont, b.acont) as acont,
case when Nvl(a.precdeb,0) > Nvl(a.preccred,0) then abs(Nvl(a.precdeb,0)-Nvl(a.preccred,0)) else 0 end + nvl(b.debit,0) as precdeb,
case when Nvl(a.precdeb,0) < Nvl(a.preccred,0) then abs(Nvl(a.precdeb,0)-Nvl(a.preccred,0)) else 0 end + nvl(b.credit,0) as preccred
from
(select cont, acont, sum(precdeb1) as precdeb, sum(preccred1) as preccred
  from balana
 where an = <<lnAn1>>
   and luna = <<lnLuna1>>
   group by cont,acont) a full join
(select cont, acont, sum((case when 2005*12+7> an*12+luna
      and 2005*12+7<=pack_sesiune.getan()*12+pack_sesiune.getluna()
      then ROUND(ruldeb / 10000,2) else ruldeb end)) as debit, sum((case when 2005*12+7> an*12+luna
      and 2005*12+7<=pack_sesiune.getan()*12+pack_sesiune.getluna()
      then ROUND(rulcred / 10000,2) else rulcred end)) as credit
  from balana
 where an = <<lnAn1>>
   and luna between 1 and <<lnLuna1-1>>
   group by cont,acont) b on a.cont = b.cont and a.acont = b.acont
		ENDTEXT

		lnSucces = goExecutor.oExecute(lcSql, "crsBalanaPrecedente")
		If lnSucces < 0
			aMESSAGEBOX(goExecutor.cEroare)
			Create Cursor crsBalanaPrecedente (Cont c(4), acont c(4), precdeb N(10,2), preccred N(10,2))
		Endif


		Sele G1, G2, G3, G4,;
			Cont, acont, 0000000000000 As id_bal, denumire, ;
			cont_alt, cod, ;
			SUM(precdeb) As precdeb, Sum(preccred) As preccred,;
			SUM(ruldeb) As ruldeb, Sum(rulcred) As rulcred, Sum(totdeb) As totdeb, Sum(totcred) As totcred,;
			SUM(solddeb) As solddeb, Sum(soldcred)As soldcred, ;
			SUM(precdeb1) As precdeb1, Sum(preccred1) As preccred1,;
			6 As bnivel, Max(difana) As difana, ;
			00000 As id_sucursala, Space(100) As sucursala ;
			FROM tbal1 ;
			GROUP By G1, G2, G3, G4, Cont, acont, denumire, cont_alt, cod ;
			INTO Cursor TG01a Readwrite

		Sele G1, G2, G3, G4,;
			Cont, acont, 0000000000000 As id_bal, denumire, ;
			cont_alt, cod, ;			
			SUM(precdeb) As precdeb, Sum(preccred) As preccred,;
			SUM(ruldeb) As ruldeb, Sum(rulcred) As rulcred, Sum(totdeb) As totdeb, Sum(totcred) As totcred,;
			SUM(solddeb) As solddeb, Sum(soldcred)As soldcred, ;
			SUM(precdeb1) As precdeb1, Sum(preccred1) As preccred1,;
			7 As bnivel, 0 As difana, ;
			00000 As id_sucursala, Space(100) As sucursala ;
			FROM tbal2 ;
			GROUP By G1, G2, G3, G4, Cont, acont, denumire, cont_alt, cod ;
			INTO Cursor TG02a Readwrite

	 	*** BALANTA SINTETICA CENTRALIZATA
		Sele a.G1, a.G2, a.G3, a.G4,;
			a.Cont, a.acont, a.id_bal, a.denumire, ;
			a.cont_alt, a.cod, ;
			Nvl(b.precdeb, Cast(0 As N(16,4))) As precdeb, Nvl(b.preccred, Cast(0 As N(16,4))) As preccred,;
			a.ruldeb, a.rulcred, Nvl(b.precdeb,0)+a.ruldeb As totdeb, Nvl(b.preccred,0)+a.rulcred As totcred,;
			Iif(Nvl(b.precdeb,0)+a.ruldeb > Nvl(b.preccred,0)+a.rulcred, Abs(Nvl(b.precdeb,0)+a.ruldeb - Nvl(b.preccred,0) - a.rulcred), Cast(0 As N(16,4))) As solddeb, ;
			Iif(Nvl(b.precdeb,0)+a.ruldeb < Nvl(b.preccred,0)+a.rulcred, Abs(Nvl(b.precdeb,0)+a.ruldeb - Nvl(b.preccred,0) - a.rulcred), Cast(0 As N(16,4))) As soldcred, ;
			Iif(a.precdeb1 > a.preccred1, Abs(a.precdeb1-a.preccred1), Cast(0 As N(16,4))) As precdeb1, ;
			Iif(a.precdeb1 < a.preccred1, Abs(a.precdeb1-a.preccred1), Cast(0 As N(16,4))) As preccred1, ;
			a.bnivel, a.difana, ;
			a.id_sucursala, a.sucursala ;
			FROM TG01a a Left Join crsBalPrecedente b On a.Cont = b.Cont ;
			INTO Cursor TG01 Readwrite

	 	*** BALANTA ANALITICA CENTRALIZATA
		Sele a.G1, a.G2, a.G3, a.G4,;
			a.Cont, a.acont, a.id_bal, a.denumire, ;
			a.cont_alt, a.cod, ;			
			Nvl(b.precdeb, Cast(0 As N(16,4))) As precdeb, Nvl(b.preccred, Cast(0 As N(16,4))) As preccred,;
			a.ruldeb, a.rulcred, Nvl(b.precdeb,0)+a.ruldeb As totdeb, Nvl(b.preccred,0)+a.rulcred As totcred,;
			Iif(Nvl(b.precdeb,0)+a.ruldeb > Nvl(b.preccred,0)+a.rulcred, Abs(Nvl(b.precdeb,0)+a.ruldeb - Nvl(b.preccred,0) - a.rulcred), Cast(0 As N(16,4))) As solddeb, ;
			Iif(Nvl(b.precdeb,0)+a.ruldeb < Nvl(b.preccred,0)+a.rulcred, Abs(Nvl(b.precdeb,0)+a.ruldeb - Nvl(b.preccred,0) - a.rulcred), Cast(0 As N(16,4))) As soldcred, ;
			Iif(a.precdeb1 > a.preccred1, Abs(a.precdeb1-a.preccred1), Cast(0 As N(16,4))) As precdeb1, ;
			Iif(a.precdeb1 < a.preccred1, Abs(a.precdeb1-a.preccred1), Cast(0 As N(16,4))) As preccred1, ;
			a.bnivel, a.difana, ;
			a.id_sucursala, a.sucursala ;
			FROM TG02a a Left Join crsBalanaPrecedente b  On a.Cont = b.Cont And a.acont = b.acont ;
			INTO Cursor TG02 Readwrite

		*!* 07.03.2008 ^

		lcBal1 = 'tg01'
	Else
		Sele G1, G2, G3, G4,;
			Cont, acont, 0000000000000 As id_bal, denumire, ;
			cont_alt, cod, ;
			SUM(precdeb) As precdeb, Sum(preccred) As preccred,;
			SUM(ruldeb) As ruldeb, Sum(rulcred) As rulcred, Sum(totdeb) As totdeb, Sum(totcred) As totcred,;
			SUM(solddeb) As solddeb, Sum(soldcred)As soldcred, ;
			SUM(precdeb1) As precdeb1, Sum(preccred1) As preccred1,;
			5 As bnivel, Max(difana) As difana, ;
			00000 As id_sucursala, Space(100) As sucursala ;
			FROM tbal1 ;
			WHERE .F. ;
			GROUP By G1, G2, G3, G4, Cont, acont, denumire, cont_alt, cod ;
			INTO Cursor TG01

		Sele G1, G2, G3, G4,;
			Cont, acont, 0000000000000 As id_bal, denumire, ;
			cont_alt, cod, ;			
			SUM(precdeb) As precdeb, Sum(preccred) As preccred,;
			SUM(ruldeb) As ruldeb, Sum(rulcred) As rulcred, Sum(totdeb) As totdeb, Sum(totcred) As totcred,;
			SUM(solddeb) As solddeb, Sum(soldcred)As soldcred, ;
			SUM(precdeb1) As precdeb1, Sum(preccred1) As preccred1,;
			5 As bnivel, 0 As difana, ;
			00000 As id_sucursala, Space(100) As sucursala ;
			FROM tbal2 ;
			WHERE .F. ;
			GROUP By G1, G2, G3, G4, Cont, acont, denumire, cont_alt, cod ;
			INTO Cursor TG02

		lcBal1 = 'tbal1'
	Endif
	*!* 12.02.2008 ^


	Sele G1, Space(4) As G2, Space(4) As G3, Space(4) As G4,;
		SPACE(4) As Cont, Space(4) As acont, 0000000000000 As id_bal, Padr("TOTAL "+Alltrim(G1),30," ") As denumire, ;
		SPACE(20) As cont_alt, Space(20) As cod, ;
		SUM(precdeb) As precdeb, Sum(preccred) As preccred,;
		SUM(ruldeb) As ruldeb, Sum(rulcred) As rulcred, Sum(totdeb) As totdeb, Sum(totcred) As totcred,;
		SUM(solddeb) As solddeb, Sum(soldcred)As soldcred, ;
		SUM(precdeb1) As precdeb1, Sum(preccred1) As preccred1,;
		1 As bnivel, 0 As difana, ;
		00000 As id_sucursala, Space(100) As sucursala ;
		FROM &lcBal1;
		GROUP By G1 ;
		INTO Cursor TG1

	Sele G1, G2, Space(4) As G3, Space(4) As G4, ;
		SPACE(4) As Cont, Space(4) As acont, 0000000000000 As id_bal, Padr("TOTAL "+Alltrim(G2),30," ")As denumire, ;
		SPACE(20) As cont_alt, Space(20) As cod, ;		
		SUM(precdeb) As precdeb, Sum(preccred) As preccred, ;
		SUM(ruldeb) As ruldeb, Sum(rulcred) As rulcred, Sum(totdeb) As totdeb, Sum(totcred) As totcred,;
		SUM(solddeb) As solddeb, Sum(soldcred) As soldcred, ;
		SUM(precdeb1) As precdeb1, Sum(preccred1) As preccred1, ;
		2 As bnivel, 0 As difana, ;
		00000 As id_sucursala, Space(100) As sucursala ;
		FROM &lcBal1 ;
		GROUP By G1, G2 ;
		INTO Cursor TG2

	Sele G1, G2, G3, Space(4) As G4,;
		SPACE(4) As Cont, Space(4) As acont, 0000000000000 As id_bal, Padr("TOTAL "+Alltrim(G3),30," ") As denumire, ;
		SPACE(20) As cont_alt, Space(20) As cod, ;		
		SUM(precdeb) As precdeb, Sum(preccred) As preccred,;
		SUM(ruldeb) As ruldeb, Sum(rulcred) As rulcred, Sum(totdeb) As totdeb, Sum(totcred) As totcred,;
		SUM(solddeb) As solddeb, Sum(soldcred) As soldcred, ;
		SUM(precdeb1) As precdeb1, Sum(preccred1) As preccred1,;
		3 As bnivel, 0 As difana, ;
		00000 As id_sucursala, Space(100) As sucursala ;
		FROM &lcBal1 ;
		GROUP By G1, G2, G3 ;
		INTO Cursor TG3

	* 20 de caractere la cont, acont pentru ca completez ulterior cu cont_alt C(20)
	Select g1,g2,g3,g4,PADR(cont,20, ' ') cont,PADR(acont, 20, ' ') acont,id_bal,denumire,cont_alt,cod,precdeb1,preccred1,precdeb,preccred,ruldeb,rulcred,totdeb,totcred,solddeb,soldcred,bnivel,difana,id_sucursala,sucursala, .F. As bifa, Space(8) As g5 From TG01 ; && BALANTA SINTETICA CENTRALIZATA / SAU CURSOR GOL
	Union ;
		Select g1,g2,g3,g4,PADR(cont,20, ' ') cont,PADR(acont, 20, ' ') acont,id_bal,denumire,cont_alt,cod,precdeb1,preccred1,precdeb,preccred,ruldeb,rulcred,totdeb,totcred,solddeb,soldcred,bnivel,difana,id_sucursala,sucursala, .F. As bifa, Space(8) As g5 From tbal1 ; && BALANTA SINTETICA CU TOATE INREGISTRARILE
	Union ;
		SELECT g1,g2,g3,g4,PADR(cont,20, ' ') cont,PADR(acont, 20, ' ') acont,id_bal,denumire,cont_alt,cod,precdeb1,preccred1,precdeb,preccred,ruldeb,rulcred,totdeb,totcred,solddeb,soldcred,bnivel,difana,id_sucursala,sucursala, .F. As bifa, Space(8) As g5 From TG3 ; && TOTALURI GRUPA 3 DIN BALANTA CENTRALIZATA / SUCURSALA / FIRMA INDEPENDENTA
	Union ;
		SELECT g1,g2,g3,g4,PADR(cont,20, ' ') cont,PADR(acont, 20, ' ') acont,id_bal,denumire,cont_alt,cod,precdeb1,preccred1,precdeb,preccred,ruldeb,rulcred,totdeb,totcred,solddeb,soldcred,bnivel,difana,id_sucursala,sucursala, .F. As bifa, Space(8) As g5 From TG2 ; && TOTALURI GRUPA 2 DIN BALANTA CENTRALIZATA / SUCURSALA / FIRMA INDEPENDENTA
	Union ;
		SELECT g1,g2,g3,g4,PADR(cont,20, ' ') cont,PADR(acont, 20, ' ') acont,id_bal,denumire,cont_alt,cod,precdeb1,preccred1,precdeb,preccred,ruldeb,rulcred,totdeb,totcred,solddeb,soldcred,bnivel,difana,id_sucursala,sucursala, .F. As bifa, Space(8) As g5 From TG1 ; && TOTALURI GRUPA 1 DIN BALANTA CENTRALIZATA / SUCURSALA / FIRMA INDEPENDENTA
	Union ;
		SELECT g1,g2,g3,g4,PADR(cont,20, ' ') cont,PADR(acont, 20, ' ') acont,id_bal,denumire,cont_alt,cod,precdeb1,preccred1,precdeb,preccred,ruldeb,rulcred,totdeb,totcred,solddeb,soldcred,bnivel,difana,id_sucursala,sucursala, .F. As bifa, Space(8) As g5 From tbal2 ; && BALANTA ANALITICA CU TOATE INREGISTRARILE
	Union ;
		SELECT g1,g2,g3,g4,PADR(cont,20, ' ') cont,PADR(acont, 20, ' ') acont,id_bal,denumire,cont_alt,cod,precdeb1,preccred1,precdeb,preccred,ruldeb,rulcred,totdeb,totcred,solddeb,soldcred,bnivel,difana,id_sucursala,sucursala, .F. As bifa, Space(8) As g5 From TG02 ;	&& BALANTA ANALITICA CENTRALIZATA / SAU CURSOR GOL
	ORDER By G1,G2,G3,G4,sucursala ;
	Into Cursor tbalanta Readwrite


	Use In tbal1
	Use In tbal2
	Use In TG01
	Use In TG02
	Use In TG1
	Use In TG2
	Use In TG3

	Select tbalanta
	Replace All g5 With Left(G1,1)+Substr(G2,2,1)+Substr(G3,3,1)
	Replace All g5 With Allt(g5)+Iif(bnivel<4,'z',Substr(G4,4,1))
	Replace All g5 With Left(Alltrim(g5)+'xxxx',4)+acont
	Replace All g5 With Left(Alltrim(g5)+'zzzzzzzz',8)
	
	* Completez contul alternativ
	IF !m.tlNuContAlternativ
		REPLACE ALL cont WITH cont_alt FOR EMPTY(NVL(acont,'')) AND !EMPTY(NVL(cont_alt,'')) && cont sintetic alternativ
		REPLACE ALL acont WITH cont_alt FOR !EMPTY(NVL(acont,'')) AND !EMPTY(NVL(cont_alt,'')) && cont analitic alternativ
	ENDIF 
	
	*lcIndex = ADDBS(gcTempPath) + 'tbalanta.cdx'
	lcIndex = Addbs(gcTempPath) + 'tbalanta_'+Alltrim(Sys(2))+'.cdx' && ca sa pot deschid balanta din cont si manager in acelasi timp
	Index On g5 Tag g5 Of (lcIndex)
	Set Order To g5

	Return "TBALANTA"
Endproc && MAKE_TBALANTA
******************************************************************************************
Procedure Eval_balanta
	Parameters tnCurs

	If tnCurs = 0
		tnCurs = 1
	Endif

	Select tbalanta

	Repl All precdeb1 With Round(precdeb1/tnCurs,gnPval)
	Repl All preccred1 With Round(preccred1/tnCurs,gnPval)
	Repl All precdeb With Round(precdeb/tnCurs,gnPval)
	Repl All preccred With Round(preccred/tnCurs,gnPval)
	Repl All solddeb With Round(solddeb/tnCurs,gnPval)
	Repl All soldcred With Round(soldcred/tnCurs,gnPval)
	Repl All ruldeb With Round(ruldeb/tnCurs,gnPval)
	Repl All rulcred With Round(rulcred/tnCurs,gnPval)
	Repl All totdeb With Round(totdeb/tnCurs,gnPval)
	Repl All totcred With Round(totcred/tnCurs,gnPval)

Endproc && eval_balanta
