*!* 29.04.2015
*!* marius.mutu
*!* lans_ireg_parteneri - adaugare coloana RTVAI - pentru verificare RTVAI la cautare

*!* 07.05.2018
*!* lans_balanta_parteneri - includere cont 5081 depozite bancare la vizualizarea Solduri banci lei/valuta - acelasi cont si pentru lei si pentru valuta

*!* 05.07.2018
*!* marius.mutu
*!* lans_balanta_parteneri, IsCalendarInit - verificare inainte de pentru mai multe conturi (ex: solduri banci "5121,5081,5126")

*!* 27.08.2018
*!* marius.mutu
*!* lans_ireg_parteneri - corectare precvaldeb, precvalcred pentru cont de pasiv

*!* 15.04.2020
*!* marius.mutu
*!* lans_ireg_parteneri - adaugare coloane contvc, acontvc, id_mf pentru ratele de la 47x venituri/cheltuieli in avans

*!*	24.10.2023
*!*	marius.mutu
*!*	lans_ireg_parteneri, lans_balanta_parteneri: + categorie_entitate

*!*	APEL DE PROCEDURA
*!*	DO lans_ireg_parteneri WITH tlTest,tcCont,tlActiv

*-----------------------------------------------------------

Procedure lans_ireg_parteneri
	Parameters tlTest, tcCont, tlactiv, tlTitluTot, tcDenumire, tcDenDebit, tcDenCredit
	*!*		tlTitluTot = daca denumirea titlului este totala i.e.: Nu trebuie sa mai adaug Balanta parteneri
	*!*		tcDenumire = titlul balantei
	*!*		tcDenDebit = peste tot pe unde apare debit se va inlocui cu aceasta denumire
	*!*		tcDenCredit = peste tot pe unde apare credit se va inlocui cu aceasta denumire
	Local lcCont, llActiv, llParametri, llTitluTot, lcDenumire, lcDenDebit, lcDenCredit, llAfisare
	Local Ol As "frm_sel_cont"
	Local Oreg As "FRM_IREG_PARTENERI"
	Local lcFiltruOriginal, lcSqlCount, llAfisareTot, llSucces, lnInregistrariAfisare, lnsucces
	Local loCont
	*:Global buton, pcCont, tcFis2, tlVisible
	Private pnRecCnt

	llParametri = .F.

	If Empty(tlTitluTot)
		llTitluTot = .F.
	Else
		llTitluTot = tlTitluTot
	Endif

	If Empty(tcDenumire)
		lcDenumire = ""
	Else
		lcDenumire = tcDenumire
	Endif

	If Empty(tcDenDebit)
		lcDenDebit = "Debit"
	Else
		lcDenDebit = tcDenDebit
	Endif
	If Empty(tcDenCredit)
		lcDenCredit = "Credit"
	Else
		lcDenCredit = tcDenCredit
	Endif

	If !Empty(tcCont)
		lcCont = Alltrim(tcCont)
	Else
		lcCont = ''
	Endif

	If !Empty(tlactiv)
		llActiv = tlactiv
	Else
		llActiv = .F.
	Endif


	llParametri = .F.
	*If PCOUNT() = 3
	*!*	IF !EMPTY(tlActiv) AND !EMPTY(tcCont) AND !EMPTY(tlActiv)
	*!*		llParametri = .T.
	*!*	Endif
	If !Empty(tcCont)
		llParametri = .T.
	Endif
	Local NOU, lnTdeb, lnTcred, lnSold, lcContPart, lclista
	Store 0 To lnTdeb, lnTcred, lnSold
	NOU = .T.

	If glPrimaLuna
		NOU = .F.
	Endif

	IF !USED('saft_tip_facturi')
		update_saft_tip_facturi()
	ENDIF 
		
	Private plActiv
	Store .T. To plActiv
	Private eActiv
	Store .T. To eActiv
	If !llParametri
		Private polista, pcschema1, pcselect1, pcfiltru1, pcorder1
		Store "" To polista
		If Used('clista')
			Use In clista
		Endif
		pcschema1 = ['cont c(4),acont c(4),explicatie c(50),fel_cont n(1)']
		pcselect1 = ['select cont,rpad(CHR(32),4,CHR(32)) as acont,explicatie,fel_cont from ] + gcS + [.config_cont_ireg where 1=2']
		pcfiltru1 = [cu_inregistrari=1]
		pcorder1 = [cont]
		llAfisare = .F.
		gencursor('polista', 'clista', pcselect1, pcfiltru1, pcschema1, pcorder1, llAfisare)
		polista.ca_baza1.afisare()

		Select clista
		loCont = myscatter('blank')

		Ol = Createobject("frm_sel_cont")
		With Ol
			.Lb_titlu_alb_b121.Caption =  'Selectati contul'
			If Empty(.cboCont.RowSource)
				.cboCont.RowSource = "clista.cont,explicatie"
				.cboCont.ColumnWidths = '40,150'
			Endif
			.ocont = loCont
			If Empty(.cAlias)
				.cAlias = Left(.cboCont.RowSource, At(".", .cboCont.RowSource) - 1)
			Endif
			.Height = 190
			.lHide = .T.
		Endwith
		Ol.Show(1)
		eActiv = Iif(Ol.nFel_Cont = 0, .T., .F.)
		Ol.Release

		If buton = 2
			Use In clista
			Return
		Endif

		lcContPart = loCont.Cont
		If !llTitluTot And Empty(lcDenumire)
			lcDenumire = "Inregistrari  " + Alltrim(clista.explicatie) + "( " + lcContPart + " )"
		Else
			If !Empty(lcDenumire) And !llTitluTot
				lcDenumire = "Inregistrari " + lcDenumire + "( " + lcContPart + " )"
			Endif
		Endif
		Use In clista
		plActiv = eActiv
		llActiv = eActiv
	Else
		eActiv = llActiv
		plActiv = llActiv
		lcContPart = lcCont
		If !llTitluTot And Empty(lcDenumire)
			lcDenumire = "Inregistrari " + "( " + lcContPart + " )"
		Else
			If !Empty(lcDenumire) And !llTitluTot
				lcDenumire = "Inregistrari " + lcDenumire + "( " + lcContPart + " )"
			Endif
		Endif
	Endif


	*** verificare INAINTE_DE
	Do inainte With "IREG_PARTENERI", lcContPart In oinainte_de.prg

	If tlTest
		Do test_ireg With lcContPart, llActiv
	Endif

	pcCont = lcContPart

	Private poireg_parteneri
	Local lcSelect, lcFiltru, lcSchema, lcOrder, lcGroup, llModParam, lcFiltruOrigina
	poireg_parteneri = Null
	Store '' To lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcGroup

	lcSchema = [id_ireg_part n(20),an n(4), luna n(2),ID_FACT N(20),id_part n(20),cont c(4),acont c(4), ID_VALUTA N(5), ID_VENCHELT N(5), PROC_TVA N(8,2),] + ;
		[PRECDEB N(20,4),PRECCRED N(20,4),PRECVALDEB N(20,4),PRECVALCRED N(20,4),] + ;
		[debit n(20,4),credit n(20,4),valdebit n(20,4), valcredit n(20,4),] + ;
		[nract N(20),SERIE_ACT C(10),DATAACT D,DATAIREG D,DATASCAD D,CURS N(18,6),] + ;
		[COD N(20),EXPLICATIA C(100),EXPLICATIA4 C(100),EXPLICATIA5 C(100),] + ;
		[ID_RESPONSABIL N(10),ID_FDOC N(5),ID_LUCRARE N(10),ID_CTR N(5),ID_SET N(20),ID_ACT N(20),] + ;
		[NUME C(100),COD_FISCAL C(30),FDOC C(50),NRESP C(50),NRORD C(50),CONTRACT C(30),NUME_VAL C(10),VENCHELT C(50),ID_JTVA_COLOANA N(4),EXPLICATIE_TVA C(100),] + ;
		[ID_SUCURSALA N(5), SUCURSALA C(100), DATAREFPEN D, NRZILEPEN N(10), PROCPEN N(7,3), VALPEN N(20,4), DPRIMA_RATA D, DULTIMA_RATA D, RATA N(20,4), ] + ;
		[CONTVC C(4), ACONTVC C(4), ID_MF I, DATA_OPERATIE D, TVAI N(1,0), COD_FISCALFRO C(30), ALES N(1), ] + ;
		[CONT_BANCA C(30), BANCA C(100), SWIFT_BANCA C(11), ADRESA_BANCA C(150), TIP_SAFT N(3), TIP_SAFTNAME C(250),INSTITUTIE_PUBLICA N(1),ENTITATE_AFILIATA N(1),CATEGORIE_ENTITATE c(150)]

	lcSelect = [SELECT I.ID_IREG_PART, I.AN, I.LUNA, ID_FACT, I.ID_PART, I.CONT, I.ACONT, I.ID_VALUTA, I.ID_VENCHELT, I.PROC_TVA,] + ;
		[I.PRECDEB, I.PRECCRED, I.PRECVALDEB, I.PRECVALCRED,] + ;
		[I.DEBIT, I.CREDIT, I.VALDEBIT, I.VALCREDIT,] + ;
		[I.NRACT, I.SERIE_ACT, I.DATAACT, I.DATAIREG, I.DATASCAD, I.CURS,] + ;
		[I.COD, I.EXPLICATIA, I.EXPLICATIA4, I.EXPLICATIA5,] + ;
		[I.ID_RESPONSABIL, I.ID_FDOC, I.ID_LUCRARE, I.ID_CTR,I.ID_SET, I.ID_ACT,] + ;
		[I.NUME,I.COD_FISCAL,I.FDOC,I.NRESP,I.NRORD,I.CONTRACT,I.NUME_VAL,I.VENCHELT, I.ID_JTVA_COLOANA, I.EXPLICATIE_TVA,] + ;
		[I.ID_SUCURSALA,I.SUCURSALA, ] + ;
		[CAST(NULL AS DATE) AS DATAREFPEN, CAST(0 AS NUMBER(10)) AS NRZILEPEN, CAST(0.000 AS NUMBER(6,3)) AS PROCPEN, CAST(0.0000 AS NUMBER(20,4)) AS VALPEN, ] + ;
		[DPRIMA_RATA, DULTIMA_RATA, RATA, CONTVC, ACONTVC, ID_MF, DATA_OPERATIE, ] + ;
		"0 as TVAI, REGEXP_REPLACE(I.COD_FISCAL, '[^[:digit:]]', '') AS COD_FISCALFRO, 0 as ALES, " + ;
		"I.CONT_BANCA, I.BANCA, I.SWIFT_BANCA, I.ADRESA_BANCA, I.TIP_SAFT, I.TIP_SAFTNAME,I.INSTITUTIE_PUBLICA,I.ENTITATE_AFILIATA,I.CATEGORIE_ENTITATE " + ;
		[ FROM VIREG_PARTENERI I]

	* Calculez numarul de inregistrari. Daca numarul este mai mic de min(500, gnInregistrariAfisare) afisez toate inregistrarile in loc sa intru cu 1=2
	lnInregistrariAfisare = Iif(Type('gnInregistrariAfisare') = 'N', m.gnInregistrariAfisare, 500)

	lcSqlCount = [SELECT COUNT(*) as nr FROM ireg_parteneri where an=?gnAn and luna=?gnLuna and CONT in ('] + Alltrim(Strtran(m.lcContPart, [,], [','])) + [') ]
	pnRecCnt = 0
	llSucces = goExecutor.oSelecteaza2Value(m.lcSqlCount, @pnRecCnt)
	llAfisareTot = (Nvl(m.pnRecCnt, 0) <= m.lnInregistrariAfisare)

	lcFiltru = [1=2]
	lcOrder = [dataact]
	llAfisare = .F.
	llModParam = .T.
	lcFiltruOriginal = []
	&& DACA SUNT PE O SUCURSALA - SELECTEZ DOAR INREGISTRARILE DE PE SUCURSALA CURENTA
	If !Isnull(gnIdSucursala)
		lcFiltruOriginal = Substr(gcCondSucursala, 6)
	Endif

	*!*	pcfiltru1 = [cont = '] + Alltrim(pcCont) + [' and luna = ] + Alltrim(Str(gnLuna)) + [ and an = ] + Alltrim(Str(gnAn))
	gencursor('poireg_parteneri', 'actcv', lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcGroup, llModParam, lcFiltruOriginal)
	*!*	PARAMETERS tcnume, tcalias, tcselect, tcfiltru, tcschema, tcorder, tlAfisare, tcgroup, tlModParam, tcFiltruOriginal
	poireg_parteneri.ca_baza1.afisare()


	Select actcv
	tcFis2 = "ActCv"
	tlVisible = .T.

	Local c
	c = "nume+ALLTRIM(STR(YEAR(dataact)))+RIGHT('0'+ALLTRIM(STR(MONTH(dataact))),2)+RIGHT('0'+ALLTRIM(STR(DAY(dataact))),2)"
	buton = 1

	Sele actcv


	Private pcAnalitic, pcLucrare
	Store '' To pcAnalitic, pcLucrare

	lnsucces = update_jtva_coloane(, "jtva_temp")


	Select actcv
	Oreg = Createobject("FRM_IREG_PARTENERI", m.llAfisareTot)
	*DO FORM frm_ireg_parteneri NAME oreg noshow

	Select actcv
	With Oreg
		.lActiv = plActiv
		.cCont = lcContPart
		*!*		.LABEL10.Caption=Proper(tctitlu)&&& trebuie facut
		.Lb_titlu_alb_b121.Caption = Proper(lcDenumire)
		.grid1.cTotCred.Visible = .T.
		.Cont = Allt(pcCont)
		.fisier = Alltrim(tcFis2)
		*.Ck_valuta.VISIBLE = tlVisible
		*.CK_explicatia.VISIBLE = tlVisible
		*.ck_scadente.VISIBLE = tlVisible
		* .CHECK9.VISIBLE = tlVisible
		.grid1.cDataScad.Visible = tlVisible
		.grid1.cTotDebVal.Visible = tlVisible
		.grid1.cTotCredVal.Visible = tlVisible
		.grid1.cSoldVal.Visible = tlVisible
		.grid1.cNume_val.Visible = tlVisible
		.grid1.cCurs.Visible = tlVisible
		.grid1.cExplicatia.Visible = tlVisible
		.grid1.cCod_fiscal.Visible = tlVisible     && 24.02.09
		If !tlVisible
			.CHECK3.Caption = 'Regularizate'
			.CHECK4.Caption = 'Neregularizate'
			.check10.Caption = 'Regularizat'
			.grid1.cTotCred.header1.Caption = 'Regularizat'
			.grid1.cDataScad.Width = 0
		Endif
		If !plActiv

			.grid1.cSoldFinal.ControlSource = "(Preccred+credit)-(precdeb+debit)"
			.grid1.cSoldVal.ControlSource = "(precvalcred+valcredit)-(precvaldeb+valdebit)"
			*.ck_sold.camp_nume = "credit+preccred-precdeb-debit"
			.grid1.cTotDeb.ControlSource = "preccred+credit"
			.grid1.cTotCred.ControlSource = "precdeb+debit"
			.grid1.cTotDebVal.ControlSource = "precvalcred+valcredit"
			.grid1.cTotCredVal.ControlSource = "precvaldeb+valdebit"
			.grid1.cDebit.ControlSource = "credit"
			.grid1.cCredit.ControlSource = "debit"
			.grid1.cValDebit.ControlSource = "valcredit"
			.grid1.cValCredit.ControlSource = "valdebit"
			.grid1.cPrecDeb.ControlSource = "preccred"
			.grid1.cPrecCred.ControlSource = "precdeb"
			.grid1.cPrecValDeb.ControlSource = "precvalcred"
			.grid1.cPrecValCred.ControlSource = "precvaldeb"

			.grid1.cTotDeb.header1.Caption = "Total " + lcDenCredit
			.grid1.cTotCred.header1.Caption = "Total " + lcDenDebit
			.grid1.cTotDebVal.header1.Caption = "Total " + lcDenCredit + " valuta"
			.grid1.cTotCredVal.header1.Caption = "Total " + lcDenDebit + " valuta"
			.grid1.cDebit.header1.Caption = lcDenCredit
			.grid1.cCredit.header1.Caption = lcDenDebit
			.grid1.cValDebit.header1.Caption = lcDenCredit + " valuta"
			.grid1.cValCredit.header1.Caption = lcDenDebit + " valuta"
			.grid1.cPrecDeb.header1.Caption = "Prec " + lcDenCredit
			.grid1.cPrecCred.header1.Caption = "Prec " + lcDenDebit
			.grid1.cPrecValDeb.header1.Caption = "Prec Valuta " + lcDenCredit
			.grid1.cPrecValCred.header1.Caption = "Prec Valuta " + lcDenDebit
		Else
			.grid1.cSoldFinal.ControlSource = "(precdeb+debit)-(preccred+credit)"
			.grid1.cSoldVal.ControlSource = "(precvaldeb+valdebit)-(precvalcred+valcredit)"
			*.ck_sold.camp_nume = "precdeb+debit-credit-preccred"
			.grid1.cTotDeb.header1.Caption = "Total " + lcDenDebit
			.grid1.cTotCred.header1.Caption = "Total " + lcDenCredit
			.grid1.cTotDebVal.header1.Caption = "Total " + lcDenDebit + " valuta"
			.grid1.cTotCredVal.header1.Caption = "Total " + lcDenCredit + " valuta"
			.grid1.cDebit.header1.Caption = lcDenDebit
			.grid1.cCredit.header1.Caption = lcDenCredit
			.grid1.cValDebit.header1.Caption = lcDenDebit + " valuta"
			.grid1.cValCredit.header1.Caption = lcDenCredit + " valuta"
			.grid1.cPrecDeb.header1.Caption = "Prec " + lcDenDebit
			.grid1.cPrecCred.header1.Caption = "Prec " + lcDenCredit
			.grid1.cPrecValDeb.header1.Caption = "Prec Valuta " + lcDenDebit
			.grid1.cPrecValCred.header1.Caption = "Prec Valuta " + lcDenCredit
		Endif
		If Type('pcTotctva') # 'U' And Type('pcAchitat') # 'U'
			.grid1.cTotCred.header1.Caption = pcAchitat
			.grid1.cTotDeb.header1.Caption = pcTotctva
		Endif
		If Type('pcSumaTotal') # 'U' And Type('pcSumaAchi') # 'U'
			.CHECK13.Caption = pcSumaTotal
			.check10.Caption = pcSumaAchi
		Endif
		If Type('actcv.nresp') # 'U'
			.grid1.cNresp.Visible = .T.
			.grid1.cNresp.ControlSource = 'nresp'
			*.Ck_responsabil.VISIBLE = .T.
		Endif
		*!*			IF plActiv
		*!*				.grid1.SETALL("DynamicForeColor", "IIF(ABS((preccred+credit)-(precdeb+debit))=0,RGB(0,0,0), iif(((precdeb+debit) < (preccred+credit)),RGB(255,0,0),RGB(0,0,255)))", "Column")
		*!*			ELSE
		*!*				.grid1.SETALL("DynamicForeColor", "IIF(ABS((preccred+credit)-(precdeb+debit))=0,RGB(0,0,0), iif(((precdeb+debit) > (preccred+credit)),RGB(255,0,0),RGB(0,0,255)))", "Column")
		*!*			ENDIF
		If plActiv
			.grid1.SetAll("DynamicForeColor", "IIF(ABS((preccred+credit)-(precdeb+debit))=0,RGB(0,0,0), iif(((precdeb+debit) < (preccred+credit)), RGB(166,0,0), RGB(0,89,168)))", "Column")
		Else
			.grid1.SetAll("DynamicForeColor", "IIF(ABS((preccred+credit)-(precdeb+debit))=0,RGB(0,0,0), iif(((precdeb+debit) > (preccred+credit)), RGB(166,0,0), RGB(0,89,168)))", "Column")
		Endif

	Endwith
	Oreg.Show(1)
	*!*	Select actcv
	*!*	If Used('actcv')
	*!*		Use In actcv
	*!*	Endif
	*!*	Release ofis
	Release Oreg
	Use In actcv
	Use In jtva_temp

Endproc && lans_ireg_parteneri
*---------------------------------------------------------------------------------

Procedure lans_balanta_parteneri
	Lparameters tcCont, tlactiv, tlTitluTot, tcDenumire, tcDenDebit, tcDenCredit, tnCurs, tcValuta &&initital cu 2 parametrii
	*!* 	tcCont: "4111" sau "5121,5126,5081"
	*!*		tlTitluTot = daca denumirea titlului este totala i.e.: Nu trebuie sa mai adaug Balanta parteneri
	*!*		tcDenumire = titlul balantei
	*!*		tcDenDebit = peste tot pe unde apare debit se va inlocui cu aceasta denumire
	*!*		tcDenCredit = peste tot pe unde apare credit se va inlocui cu aceasta denumire

	Local llParametri, lcCont, llActiv, llTitluTot, lcDenumire, lcDenDebit, lcDenCredit, lnConturi, lnCont
	Local OVIZ As "frm_bal_parteneri"
	Local Ol As "frm_sel_cont"
	Local lcFiltruOriginal, lcGroup, lcSchema, lcSqlCount, lcViz, llAfisare, llAfisareTot
	Local llModParam, llSucces, lnInregistrariAfisare, lnSemn, loCont
	*:Global gcAcces, i,
	PRIVATE pnRecCnt
	
	llParametri = .F.
	lcCont = ''
	llActiv = .F.
	If Empty(tlTitluTot)
		llTitluTot = .F.
	Else
		llTitluTot = tlTitluTot
	Endif

	If Empty(tcDenumire)
		lcDenumire = ""
	Else
		lcDenumire = tcDenumire
	Endif

	If Empty(tcDenDebit)
		lcDenDebit = "Debit"
	Else
		lcDenDebit = tcDenDebit
	Endif
	If Empty(tcDenCredit)
		lcDenCredit = "Credit"
	Else
		lcDenCredit = tcDenCredit
	Endif
	*!*	IF PCOUNT() < 2
	If Empty(tcCont) And Empty(tlactiv)
		llParametri = .F.
	Else
		llParametri = .T.
		lcCont = Alltrim(tcCont)
		llActiv = tlactiv
	Endif

	Local NOU, lnTdeb, lnTcred, lnSold, lcContPart, lclista
	Store 0 To lnTdeb, lnTcred, lnSold
	NOU = .T.

	If .F.
		Select calendar
		Go Top
		If an = pcAn And NL = pcNl
			NOU = .F.
		Endif
	Endif
	*!*	IF glPrimaLuna
	*!*		nou = .F.
	*!*	ENDIF

	Private polista, pcschema1, pcselect1, pcfiltru1, pcorder1
	Store "" To polista


	If !llParametri

		If Used('clista')
			Use In clista
		Endif

		pcschema1 = ['cont c(4),acont c(4),explicatie c(50),fel_cont n(1)']
		pcselect1 = ['select cont,rpad(CHR(32),4,CHR(32)) as acont,explicatie,fel_cont from ] + gcS + [.config_cont_ireg where 1=2']
		*!*			pcschema1=['cont c(4),acont c(4),explicatie c(50)']
		*!*			pcselect1=['select distinct cont,rpad(CHR(32),4,CHR(32)) as acont,explicatie from ]+gcS+[.vcoresp_tip_cont where 1=2']
		pcfiltru1 = [2=2]
		pcorder1 = [cont]
		llAfisare = .F.
		gencursor('polista', 'clista', pcselect1, pcfiltru1, pcschema1, pcorder1, llAfisare)
		polista.ca_baza1.afisare()

		*!*	SELECT DISTINCT cont, '' as acont FROM coresp_tip_cont INTO CURSOR clista
		Select clista
		loCont = myscatter('blank')

		Private eActiv
		Store .T. To eActiv

		Ol = Createobject("frm_sel_cont")
		With Ol
			.Lb_titlu_alb_b121.Caption = 'Selectati contul'
			If Empty(.cboCont.RowSource)
				.cboCont.RowSource = "clista.cont,explicatie"
				.cboCont.ColumnWidths = '40,150'
			Endif
			.ocont = loCont
			If Empty(.cAlias)
				.cAlias = Left(.cboCont.RowSource, At(".", .cboCont.RowSource) - 1)
			Endif
			.Height = 190
			.lHide = .T.
		Endwith
		Ol.Show(1)
		eActiv = Iif(Ol.nFel_Cont = 0, .T., .F.)
		Ol.Release

		If buton = 2
			Use In clista
			Return
		Endif

		lcContPart = loCont.Cont
		If !llTitluTot And Empty(lcDenumire)
			lcDenumire = "Balanta " + Alltrim(clista.explicatie) + "( " + lcContPart + " )"
		Else
			If !Empty(lcDenumire) And !llTitluTot
				lcDenumire = "Balanta " + lcDenumire + "( " + lcContPart + " )"
			Endif
		Endif
		Use In clista
	Else
		lcContPart = lcCont
		eActiv = llActiv

		If !llTitluTot And Empty(lcDenumire)
			lcDenumire = "Balanta " + "( " + lcContPart + " )"
		Else
			If !Empty(lcDenumire) And !llTitluTot
				lcDenumire = xc
			Endif
		Endif
	Endif

	If eActiv
		lnSemn = -1
	Else
		lnSemn = 1
	Endif


	*** verificare INAINTE_DE
	lnConturi = Getwordcount(m.lcContPart, ",") && "4111" sau "5121,5126,5081"
	For lnCont = 1 To lnConturi
		Do inainte With "BALANTA_parteneri", Getwordnum(m.lcContPart, m.lnCont, ",") In oinainte_de.prg
	Endfor

	Private pobalpartext, pobalparttot
	Local lcSelect, lcSchemaTot, lcSchemaExt, lcFiltru, lcOrder
	*!*		PRIVATE pobalpartint,pcschema3,pcselect3,pcfiltru3,pcorder3,pcgroup3

	Store Null To pobalpartext, pobalparttot

	lcSchema = [ID_BAL_PART N(20), PRECDEB1 N(19,2),PRECCRED1 N(19,2),PRECDEB N(19,2),PRECCRED N(19,2), ] + ;
		[DEB N(19,2),CRED N(19,2),PRECVALDEB1 N(19,2),PRECVALCRED1 N(19,2),PRECVALDEB N(19,2), ] + ;
		[PRECVALCRED N(19,2),VALDEBIT N(19,2),VALCREDIT N(19,2),NUME_VAL C(5),ID_PART N(10), ] + ;
		[NUME C(50),COD_FISCAL C(30),REG_COMERT C(20),CONT C(4),ACONT C(4),AN N(4),LUNA N(2),TOTCRED N(19,2),TOTDEB N(19,2), ] + ;
		[TOTVALCRED N(19,2),TOTVALDEB N(19,2),ID_VALUTA N(5),ID_SUCURSALA N(5),SUCURSALA C(100),] + ;
		[SOLDPREC1 N(19,2),SOLDPREC N(19,2),SOLD N(19,2),SOLDFINAL N(19,2),RULANDEB N(19,2),RULANCRED N(19,2),RULANPDEB N(19,2),RULANPCRED N(19,2),SOLDPRECVAL N(19,2),SOLDFINALVAL N(19,2),] + ;
		[CONT_BANCA C(32), BANCA C(100), SWIFT_BANCA C(100), ADRESA_BANCA C(250), CATEGORIE_ENTITATE C(150),] + ;
		[ADRESA C(250), TELEFON C(250), EMAIL C(100)]

	lcSelect = [select p.ID_BAL_PART, p.PRECDEB1,p.PRECCRED1,p.PRECDEB,p.PRECCRED, ] + ;
		[p.DEBIT as DEB,p.CREDIT as CRED,p.PRECVALDEB1,p.PRECVALCRED1,p.PRECVALDEB, ] + ;
		[p.PRECVALCRED,p.VALDEBIT,p.VALCREDIT,p.NUME_VAL,p.ID_PART, ] + ;
		[p.NUME,p.COD_FISCAL,p.reg_comert,p.CONT,p.ACONT,p.AN,p.LUNA, ] + ;
		[p.PRECCRED+p.CREDIT as TOTCRED,p.PRECDEB+p.DEBIT as TOTDEB, ] + ;
		[p.PRECVALCRED+p.VALCREDIT as TOTVALCRED,p.PRECVALDEB+p.VALDEBIT as TOTVALDEB,p.ID_VALUTA,p.ID_SUCURSALA,p.SUCURSALA ,] + ;
		Iif(eActiv, [p.PRECDEB1-p.PRECCRED1], [p.PRECCRED1-p.PRECDEB1]) + [ AS SOLDPREC1,] + ;
		Iif(eActiv, [p.PRECDEB-p.PRECCRED], [p.PRECCRED-p.PRECDEB]) + [ AS SOLDPREC,] + ;
		Iif(eActiv, [p.DEBIT-p.CREDIT], [p.CREDIT-p.DEBIT]) + [ AS SOLD,] + ;
		Iif(eActiv, [p.TOTDEB-p.TOTCRED], [p.TOTCRED-p.TOTDEB]) + [ AS SOLDFINAL,] + ;
		[p.TOTDEB-p.PRECDEB1 AS RULANDEB,] + ;
		[p.TOTCRED-p.PRECCRED1 AS RULANCRED,] + ;
		[p.TOTDEB-p.PRECDEB1-p.debit AS RULANPDEB,] + ;
		[p.TOTCRED-p.PRECCRED1-p.credit AS RULANPCRED,] + ;
		Iif(eActiv, [p.PRECVALDEB-p.PRECVALCRED], [p.PRECVALCRED-p.PRECVALDEB]) + [ AS SOLDPRECVAL,] + ;
		Iif(eActiv, [p.TOTVALDEB-p.TOTVALCRED], [p.TOTVALCRED-p.TOTVALDEB]) + [ AS SOLDFINALVAL,] + ;
		[p.cont_banca, p.banca, p.swift_banca, p.adresa_banca, p.categorie_entitate, ] + ;		
		[(select stringagg(adresa) as adresa from vadrese_parteneri where id_part = p.id_part group by id_part) as ADRESA,] + ;
		[(select stringagg(telefon1) as telefon from vadrese_parteneri where id_part = p.id_part group by id_part) as TELEFON,] + ;
		[(select stringagg(email) as email from vadrese_parteneri where id_part = p.id_part group by id_part) as EMAIL] + ;
		[ from vbalanta_parteneri p ]

	lcFiltru = [1=2]
	lcOrder = [nume,acont]
	llAfisare = .F.
	lcGroup = []
	llModParam = .T.
	* 5081 apare si la banca lei 5121 si la banca valuta 5124 si separ dupa valuta
	Do Case
		Case Type('tcCont') = 'C' And '5121' $ tcCont
			lcFiltruOriginal = [(P.CONT in ('5121', '5126') OR (P.CONT = '5081' AND NVL(P.ID_VALUTA,0) IN (SELECT 0 FROM DUAL UNION SELECT ID_VALUTA FROM VNOM_VALUTE WHERE MONEDA_NATIONALA = 1)))]
		Case Type('tcCont') = 'C' And '5124' $ tcCont
			lcFiltruOriginal = [(P.CONT in ('5124', '5127') OR (P.CONT = '5081' AND NVL(P.ID_VALUTA,0) NOT IN (SELECT 0 FROM DUAL UNION SELECT ID_VALUTA FROM VNOM_VALUTE WHERE MONEDA_NATIONALA = 1)))]
		Otherwise
			lcFiltruOriginal = []
	Endcase
	&& DACA SUNT PE O SUCURSALA - SELECTEZ DOAR INREGISTRARILE DE PE SUCURSALA CURENTA
	If !Isnull(gnIdSucursala)
		lcFiltruOriginal = Substr(gcCondSucursala, 6)
	Endif

	gencursor('pobalpartext', 'xtemp', lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcGroup, llModParam, lcFiltruOriginal)
	pobalpartext.ca_baza1.afisare()

	lcSelect = [select 0 as ID_BAL_PART, SUM(p.PRECDEB1) AS PRECDEB1,SUM(p.PRECCRED1) AS PRECCRED1,SUM(p.PRECDEB) AS PRECDEB,SUM(p.PRECCRED) AS PRECCRED, ] + ;
		[SUM(p.DEBIT) as DEB,SUM(p.CREDIT) as CRED,0 AS PRECVALDEB1,0 AS PRECVALCRED1,0 AS PRECVALDEB, ] + ;
		[0 AS PRECVALCRED,0 AS VALDEBIT,0 AS VALCREDIT,'LEI' AS NUME_VAL,p.ID_PART, ] + ;
		[p.NUME,p.COD_FISCAL,p.REG_COMERT,p.CONT,p.ACONT,p.AN,p.LUNA, ] + ;
		[SUM(p.PRECCRED+p.CREDIT) as TOTCRED,SUM(p.PRECDEB+p.DEBIT) as TOTDEB, ] + ;
		[SUM(p.PRECVALCRED+p.VALCREDIT) as TOTVALCRED,SUM(p.PRECVALDEB+p.VALDEBIT) as TOTVALDEB,0 AS ID_VALUTA,p.ID_SUCURSALA,p.SUCURSALA ,] + ;
		[SUM(] + Iif(eActiv, [p.PRECDEB1-p.PRECCRED1], [p.PRECCRED1-p.PRECDEB1]) + [) AS SOLDPREC1,] + ;
		[SUM(] + Iif(eActiv, [p.PRECDEB-p.PRECCRED], [p.PRECCRED-p.PRECDEB]) + [) AS SOLDPREC,] + ;
		[SUM(] + Iif(eActiv, [p.DEBIT-p.CREDIT], [p.CREDIT-p.DEBIT]) + [) AS SOLD,] + ;
		[SUM(] + Iif(eActiv, [p.TOTDEB-p.TOTCRED], [p.TOTCRED-p.TOTDEB]) + [) AS SOLDFINAL,] + ;
		[SUM(p.TOTDEB-p.PRECDEB1) AS RULANDEB, ] + ;
		[SUM(p.TOTCRED-p.PRECCRED1) AS RULANCRED, ] + ;
		[SUM(p.TOTDEB-p.PRECDEB1-p.debit) AS RULANPDEB,] + ;
		[SUM(p.TOTCRED-p.PRECCRED1-p.credit) AS RULANPCRED,] + ;
		[0 as SOLDPRECVAL, 0 AS SOLDFINALVAL,] + ;
		[p.cont_banca, p.banca, p.swift_banca, p.adresa_banca,p.categorie_entitate,] + ;
		[(select stringagg(adresa) as adresa from vadrese_parteneri where id_part = p.id_part group by id_part) as ADRESA,] + ;
		[(select stringagg(telefon1) as telefon from vadrese_parteneri where id_part = p.id_part group by id_part) as TELEFON,] + ;
		[(select stringagg(email) as email from vadrese_parteneri where id_part = p.id_part group by id_part) as EMAIL] + ;
		[ from vbalanta_parteneri p]

	* Calculez numarul de inregistrari. Daca numarul este mai mic de min(300, gnInregistrariAfisare) afisez toate inregistrarile in loc sa intru cu 1=2
	lnInregistrariAfisare = Iif(Type('gnInregistrariAfisare') = 'N', m.gnInregistrariAfisare, 300)

	lcSqlCount = [SELECT COUNT(*) as nr FROM balanta_parteneri where an=?gnAn and luna=?gnLuna and CONT in ('] + Alltrim(Strtran(lcContPart, [,], [','])) + [') ]
	pnRecCnt = 0
	llSucces = goExecutor.oSelecteaza2Value(m.lcSqlCount, @pnRecCnt)
	llAfisareTot = (Nvl(m.pnRecCnt, 0) <= m.lnInregistrariAfisare)

	lcFiltru = [1=2]
	lcOrder = [p.nume,p.acont]
	lcGroup = [p.CONT,p.ACONT,p.AN,p.LUNA,p.ID_PART,p.NUME,p.COD_FISCAL, p.REG_COMERT,p.ID_SUCURSALA,p.SUCURSALA, p.cont_banca, p.banca, p.swift_banca, p.adresa_banca, p.categorie_entitate]
	llAfisare = .F.
	llModParam = .T.
	* 5081 apare si la banca lei 5121 si la banca valuta 5124 si separ dupa valuta
	Do Case
		Case Type('tcCont') = 'C' And '5121' $ tcCont
			lcFiltruOriginal = [(P.CONT in ('5121', '5126') OR (P.CONT = '5081' AND NVL(P.ID_VALUTA,0) IN (SELECT 0 FROM DUAL UNION SELECT ID_VALUTA FROM VNOM_VALUTE WHERE MONEDA_NATIONALA = 1)))]
		Case Type('tcCont') = 'C' And '5124' $ tcCont
			lcFiltruOriginal = [(P.CONT in ('5124', '5127') OR (P.CONT = '5081' AND NVL(P.ID_VALUTA,0) NOT IN (SELECT 0 FROM DUAL UNION SELECT ID_VALUTA FROM VNOM_VALUTE WHERE MONEDA_NATIONALA = 1)))]
		Otherwise
			lcFiltruOriginal = []
	Endcase
	&& DACA SUNT PE O SUCURSALA - SELECTEZ DOAR INREGISTRARILE DE PE SUCURSALA CURENTA
	If !Isnull(gnIdSucursala)
		lcFiltruOriginal = Substr(gcCondSucursala, 6)
	Endif
	gencursor('pobalparttot', 'xtemp', lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcGroup, llModParam, lcFiltruOriginal)
	pobalparttot.ca_baza1.afisare()


	If gcNumeProgram = [ROAMANAGER]
		*!*			.but_reface1.Visible = .F.
		*!*			.but_modifica1.Visible = .F.
		gcAcces = Strtran(Strtran(gcAcces, [3;], []), [4;], [])
	Endif

	OVIZ = Createobject("frm_bal_parteneri", tnCurs, tcValuta, m.llAfisareTot)
	With OVIZ
		*!*		.LABEL10.Caption='SITUATIA ANALITICA - BALANTA PARTENERI (' + Alltrim(lcContPart) + ')'
		.Lb_titlu_alb_b121.Caption = Proper(lcDenumire)

		If !Empty(tcValuta)
			.Lb_titlu_alb_b121.Caption = .Lb_titlu_alb_b121.Caption + ;
				" Evaluarea in valuta  1 " + Alltrim(tcValuta) + "=" + Alltrim(Str(tnCurs, 10, gnPval)) + " LEI"
		Endif
		If eActiv
			.grid1.cSold.ControlSource = 'sold'
			.grid1.cSoldFinal.ControlSource = 'soldfinal'
			.grid1.cSoldPrec.ControlSource = 'soldprec'
			.grid1.cSoldPrec1.ControlSource = 'soldprec1'

			.grid1.cSoldFinalVal.ControlSource = 'soldfinalval'
			.grid1.cSoldPrecVal.ControlSource = 'soldprecval'
			*!*			.grid1.column6.header1.Caption='Sold (deb-cred)'
			*!*			.grid1.COLUMN4.header1.Caption='Debit'
			*!*			.grid1.COLUMN5.header1.Caption='Credit'
			.grid1.cSold.header1.Caption = "Sold(" + Alltrim(lcDenDebit) + "-" + Alltrim(lcDenCredit) + ")"&&'Sold (cred-deb)'
			.grid1.cDeb.header1.Caption = lcDenDebit&&Debit'
			.grid1.cCred.header1.Caption = lcDenCredit&&'Credit'
			.grid1.cPrecDeb.header1.Caption = "Prec." + lcDenDebit&&Debit'
			.grid1.cPrecCred.header1.Caption = "Prec." + lcDenCredit&&'Credit'
			.grid1.cTotDeb.header1.Caption = "Total" + lcDenDebit&&Debit'
			.grid1.cTotCred.header1.Caption = "Total" + lcDenCredit&&'Credit'
			.pcfel = 'A'
		Else
			.grid1.cSold.ControlSource = 'sold'
			.grid1.cSoldFinal.ControlSource = 'soldfinal'
			.grid1.cSoldPrec.ControlSource = 'soldprec'
			.grid1.cSoldPrec1.ControlSource = 'soldprec1'

			.grid1.cSoldFinalVal.ControlSource = 'soldfinalval'
			.grid1.cSoldPrecVal.ControlSource = 'soldprecval'
			.grid1.cSold.header1.Caption = "Sold(" + Alltrim(lcDenCredit) + "-" + Alltrim(lcDenDebit) + ")" &&'Sold (cred-deb)'
			.grid1.cDeb.header1.Caption = lcDenDebit &&Debit'
			.grid1.cCred.header1.Caption = lcDenCredit &&'Credit'
			.grid1.cPrecCred.header1.Caption = "Prec." + lcDenCredit && 'Credit'
			.grid1.cPrecDeb.header1.Caption = "Prec." + lcDenDebit && 'Debit'
			*!* .grid1.column11.controlsource = "preccred"
			*!* .grid1.column12.controlsource = "precdeb"
			.grid1.cTotCred.header1.Caption = "Total" + lcDenCredit&&'Credit'
			.grid1.cTotDeb.header1.Caption = "Total" + lcDenDebit&&'Debit'
			*!* .grid1.COLUMN15.controlsource= "totCred" &&Credit'
			*!* .grid1.COLUMN16.controlsource= "TotDeb" &&'Debit'
			.pcfel = 'P'

		Endif
		.grid1.cSoldPrecVal.Visible = .F.
		.grid1.cValDebit.Visible = .F.
		.grid1.cValCredit.Visible = .F.
		.grid1.cSoldFinalVal.Visible = .F.
		.grid1.cNume_val.Visible = .F.
		.TABEL = 'BALANTA_PARTENER'
		.pcCont = Alltrim(lcContPart)
		.grid1.cAvans.Width = 0
		.grid1.cAvansPrec.Width = 0
		.grid1.cTotAvans.Width = 0
		.grid1.cAvans.Visible = .F.
		.grid1.cAvansPrec.Visible = .F.
		.grid1.cTotAvans.Visible = .F.
		*!*			.label7.VISIBLE = .F.
		*!*			.text4.VISIBLE = .F.
		*!*			.TEXT5.VISIBLE = .F.
		*!*			.text9.VISIBLE = .F.
	Endwith
	If !NOU
		With OVIZ.grid1
			.column2.ColumnOrder = 2
			For i = 9 To 16
				lcViz = '.column' + Alltrim(Str(i)) + '.visible=.f.'
				*lcWidth='.column'+ALLTRIM(STR(i))+'.width=0'
				&lcViz
				*&lcWidth
			Endfor
		Endwith
	Endif

	*!*		*!* arat coloana sucursala doar pe mama
	*!*		OVIZ.grid1.cSucursala.visible = glEMama


	OVIZ.Show(1)
	Use In xtemp
	*!*	ENDIF
Endproc && lans_balanta_parteneri
*----------------------------------------------------------------------------------------------


*---------------------------------- Inceput lans_balanta_cumulata ----------------------------------
Procedure lans_balanta_cumulata


	pcselect = [select explicatie, id_coloana from ] + gcS + [.coloane]
	pcfiltru = [2=2]
	pcschema = ['']
	pcorder = [explicatie]
	pccoloane = [explicatie]
	pcTitlu = [Alegeti Balanta]
	pcFiltruOriginal = [camp is null and tabel is null and id_prg_owner = 2 and configurabil = 1]
	locauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitlu, "", .F., pcFiltruOriginal)

	If Empty(locauta.id_coloana) Or Isnull(locauta.id_coloana)
		Return
	Endif

	pnIdBal = locauta.id_coloana


	pcTitluCol = []
	pcNumeCol = []
	lcSel = [{call pack_balante_cumulate.balante_cumulate(?@pcNumeCol,?@pcTitluCol,?gcS,?pnIdBal,?gnAn,?gnLuna)}]
	lcSchema = []
	lcCursor = 'crs_bal'
	lnsucces = goExecutor.oExecute(lcSel, lcCursor)

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


	pcNumeCol = [nume;cod_fiscal;acont;] + pcNumeCol
	pcTitluCol = [Partener,Cod Fiscal,Analitic,] + pcTitluCol
	Select (lcCursor)
	Scatter Name loto Blank


	obalp = Createobject('frm_bal_parteneri_cumulata')
	obalp.ototal = loto
	With obalp.ct_grid_order1
		.cselect = lcSel
		.cschema = lcSchema
		.cTitlu_coloane = pcTitluCol
		.cNume_coloane = pcNumeCol
		.cFiltruOriginal = []
		.cFiltru = []
		.cOrder = []
		.cTitlu = []
		.cnumeCursor = lcCursor
		.lmodparam = .T.
	Endwith
	obalp.cTitlu = locauta.explicatie
	obalp.Show()

	If Used(lcCursor)
		Use In (lcCursor)
	Endif

Endproc && lans_balanta_cumulata
*---------------------------------- Sfarsit lans_balanta_cumulata ----------------------------------


*---------------------------------- Inceput configurare_balanta_cumulata ----------------------------------
Procedure configurare_balanta_cumulata
	Private pnIdBalanta, pnIdColoana
	Store 0 To pnIdBalanta, pnIdColoana

	pcselect1 = [select explicatie,explicatie2, id_coloana from ] + gcS + [.coloane ]
	pcfiltru1 = [camp is null and tabel is null and id_prg_owner = 2 and configurabil = 1]
	pcschema1 = ['']
	pcorder1 = [explicatie]
	pccoloane1 = [explicatie; explicatie2]
	pcTitluCol1 = [Titlu Balanta,Conturi]
	pcTitlu1 = [Lista Balante Configurate]

	pcselect2 = [select f.id_calcul, f.id_op_col , f.ordine, f.id_coloana, c.camp, c.explicatie from ] + gcS + [.sal_calcul f left join ] + ;
		gcS + [.coloane c on f.id_op_col = c.id_coloana and f.coloana = 1]
	pcfiltru2 = [f.id_coloana =?pnIdBalanta]
	pcschema2 = ['']
	pcorder2 = [f.ordine]
	pccoloane2 = [explicatie; ordine]
	pcMask2 = '[1]=;[2]=REPLICATE("9",3)'
	pcTitluCol2 = [Titlu coloana, Ordine]
	pcTitlu2 = [Coloane Balanta]

	pcselect3 = [select id_calcul, id_coloana, id_op_col, explicatie, camp, coloana, ordine from ] + gcS + [.cont_vformule_balante ]
	pcfiltru3 = [id_coloana =?pnIdColoana]
	pcschema3 = ['']
	pcorder3 = [ordine]
	pccoloane3 = [camp;explicatie;ordine]
	pcMask3 = '[1]=;[2]=;[3]=REPLICATE("9",3)'
	pcTitluCol3 = [Camp,Explicatie,Ordine]
	pcTitlu3 = [Formula Coloane]


	obalp = Createobject('config_balante_parteneri')
	With obalp.Ct_grid_search1
		.cselect = pcselect1
		.cschema = pcschema1
		.cTitlu_coloane = pcTitluCol1
		.cNume_coloane = pccoloane1
		.cFiltruOriginal = pcfiltru1
		.cFiltru = [2=2]
		.cOrder = pcorder1
		.cTitlu = pcTitlu1
		.cnumeCursor = 'crs_NumeBal'
		.lmodparam = .T.
	Endwith
	With obalp.Ct_grid_search2
		.cselect = pcselect2
		.cschema = pcschema2
		.cTitlu_coloane = pcTitluCol2
		.cNume_coloane = pccoloane2
		.cFiltruOriginal = pcfiltru2
		.cFiltru = [2=2]
		.cOrder = pcorder2
		.cTitlu = pcTitlu2
		.cMask = pcMask2
		.cnumeCursor = 'crs_ColoaneBal'
		.lmodparam = .T.
	Endwith
	With obalp.Ct_grid_search3
		.cselect = pcselect3
		.cschema = pcschema3
		.cTitlu_coloane = pcTitluCol3
		.cNume_coloane = pccoloane3
		.cFiltruOriginal = pcfiltru3
		.cFiltru = [2=2]
		.cOrder = pcorder3
		.cTitlu = pcTitlu3
		.cMask = pcMask3
		.cnumeCursor = 'crs_FormulaBal'
		.lmodparam = .T.
	Endwith
	obalp.Show()

Endproc && configurare_balanta_cumulata
*---------------------------------- Sfarsit configurare_balanta_cumulata ----------------------------------

*!*	*---------------------------------- Inceput lans_balanta_cumulata_401_409 ----------------------------------
*!*	PROCEDURE lans_balanta_cumulata_401_409


*!*	pcTitluCol = []
*!*	pcNumeCol = []
*!*	lcSel = [select nume,cod_fiscal,acont,(preccred-precdeb-(bprecdeb-bpreccred)) as soldprec,] + ;
*!*			[(bdebit-bcredit) as avanscur,debit as productie,credit as incasat,precdeb,preccred,] + ;
*!*			[(credit-debit-(bdebit-bcredit)) as soldcur,(bprecdeb-bpreccred) as avansprec,] + ;
*!*			[((bprecdeb-bpreccred)+(bdebit-bcredit)) as avanstot,(preccred+credit-(precdeb+debit)-(bprecdeb-bpreccred+bdebit-bcredit)) as soldfinal,] + ;
*!*			[(precdeb+debit) as totdeb,(preccred+credit) as totcred from ] + GCS + [.vbalanta_401_409 where an = ]+;
*!*			ALLTRIM(STR(gnan)) + [ and luna = ] + ALLTRIM(STR(gnluna))
*!*	lcSchema = []
*!*	lcCursor = 'crs_bal'
*!*	lnSucces = goExecutor.oExecute(lcSel,lcCursor)

*!*	IF lnSucces < 0
*!*		MESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
*!*		RETURN
*!*	ENDIF


*!*	pcNumeCol = [nume;cod_fiscal;acont;soldprec;avanscur;productie;incasat;precdeb;preccred;soldcur;avansprec;avanstot;soldfinal;totdeb;totcred]
*!*	pcTitluCol = [Partener,Cod Fiscal,Analitic,Sold Precedent,Avans curent,Productie,Incasat,Precdeb,Preccred,Sold curent,Avans curent,Avans total,Sold final,Totdeb,Totcred]
*!*	SELECT (lcCursor)
*!*	SCATTER NAME loto BLANK


*!*	obalp = CREATEOBJECT('frm_bal_parteneri_cumulata')
*!*	obalp.ototal = loto
*!*	WITH obalp.ct_grid_order1
*!*		.cselect = lcSel
*!*		.cschema = lcSchema
*!*		.cTitlu_coloane = pcTitluCol
*!*		.cNume_coloane = pcNumeCol
*!*		.cFiltruOriginal = []
*!*		.cFiltru = []
*!*		.cOrder = []
*!*		.cTitlu = []
*!*		.cnumeCursor = lcCursor
*!*		.lmodparam = .T.
*!*	ENDWITH
*!*	obalp.ctitlu = "BALANTA FURNIZORI CUMULATA"
*!*	obalp.show()

*!*	IF USED(lcCursor)
*!*		USE IN (lcCursor)
*!*	ENDIF

*!*	ENDPROC && lans_balanta_cumulata
*!*	*---------------------------------- Sfarsit lans_balanta_cumulata ----------------------------------

*!*	*---------------------------------- Inceput lans_balanta_cumulata_4111_419 ----------------------------------
*!*	PROCEDURE lans_balanta_cumulata_4111_419


*!*	pcTitluCol = []
*!*	pcNumeCol = []
*!*	lcSel = [select nume,cod_fiscal,acont,(precdeb-preccred-(bpreccred-bprecdeb)) as soldprec,] + ;
*!*			[(bcredit-bdebit) as avanscur,debit as productie,credit as incasat,precdeb,preccred,] + ;
*!*			[(debit-credit-(bcredit-bdebit)) as soldcur,(bpreccred-bprecdeb) as avansprec,] + ;
*!*			[((bpreccred-bprecdeb)+(bcredit-bdebit)) as avanstot,(precdeb+debit-(preccred+credit)-(bpreccred-bprecdeb+bcredit-bdebit)) as soldfinal,] + ;
*!*			[(preccred+credit) as totdeb,(precdeb+debit) as totcred from ] + GCS + [.vbalanta_4111_419 where an = ]+;
*!*			ALLTRIM(STR(gnan)) + [ and luna = ] + ALLTRIM(STR(gnluna))
*!*	lcSchema = []
*!*	lcCursor = 'crs_bal'
*!*	lnSucces = goExecutor.oExecute(lcSel,lcCursor)

*!*	IF lnSucces < 0
*!*		MESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
*!*		RETURN
*!*	ENDIF


*!*	pcNumeCol = [nume;cod_fiscal;acont;soldprec;avanscur;productie;incasat;precdeb;preccred;soldcur;avansprec;avanstot;soldfinal;totdeb;totcred]
*!*	pcTitluCol = [Partener,Cod Fiscal,Analitic,Sold Precedent,Avans curent,Productie,Incasat,Precdeb,Preccred,Sold curent,Avans curent,Avans total,Sold final,Totdeb,Totcred]
*!*	SELECT (lcCursor)
*!*	SCATTER NAME loto BLANK


*!*	obalp = CREATEOBJECT('frm_bal_parteneri_cumulata')
*!*	obalp.ototal = loto
*!*	WITH obalp.ct_grid_order1
*!*		.cselect = lcSel
*!*		.cschema = lcSchema
*!*		.cTitlu_coloane = pcTitluCol
*!*		.cNume_coloane = pcNumeCol
*!*		.cFiltruOriginal = []
*!*		.cFiltru = []
*!*		.cOrder = []
*!*		.cTitlu = []
*!*		.cnumeCursor = lcCursor
*!*		.lmodparam = .T.
*!*	ENDWITH
*!*	obalp.ctitlu = "BALANTA CLIENTI CUMULATA"
*!*	obalp.show()

*!*	IF USED(lcCursor)
*!*		USE IN (lcCursor)
*!*	ENDIF

*!*	ENDPROC && lans_balanta_cumulata
*!*	*---------------------------------- Sfarsit lans_balanta_cumulata ----------------------------------

*---------------------------------- Inceput lans_balanta_cumulata_401_409 ----------------------------------
Procedure lans_balanta_cumulata_401_409

	Private pobalpartfc
	Store "" To pobalpartfc
	Local lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcGroup, llModParam, lcFiltruOriginal

	lcSelect = [select id_part, nume,cod_fiscal,acont, id_valuta, nume_val, (preccred-precdeb-(bprecdeb-bpreccred)) as soldprec, ] + ;
		[(bdebit-bcredit) as avanscur,debit,credit,precdeb,preccred, ] + ;
		[(credit-debit-(bdebit-bcredit)) as soldcur,(bprecdeb-bpreccred) as avansprec, ] + ;
		[((bprecdeb-bpreccred)+(bdebit-bcredit)) as avanstot,(preccred+credit-(precdeb+debit)-(bprecdeb-bpreccred+bdebit-bcredit)) as soldfinal, ] + ;
		[(precvalcred-precvaldeb-(bprecvaldeb-bprecvalcred)) as soldprecval, valdebit, valcredit, ] + ;
		[(precvalcred+valcredit-(precvaldeb+valdebit)-(bprecvaldeb-bprecvalcred+bvaldebit-bvalcredit)) as soldfinalval, ] + ;
		[(precdeb+debit) as totdeb,(preccred+credit) as totcred, id_sucursala, sucursala from vbalanta_401_409 ]

	lcOrder = [nume,acont]
	lcFiltru = [1=2]
	llAfisare = .F.
	llModParam = .T.
	lcFiltruOriginal = [an = ] + Alltrim(Str(gnan)) + [ and luna = ] + Alltrim(Str(gnluna))
	&& DACA SUNT PE O SUCURSALA - SELECTEZ DOAR INREGISTRARILE DE PE SUCURSALA CURENTA
	If !Isnull(gnIdSucursala)
		lcFiltruOriginal = lcFiltruOriginal + gcCondSucursala
	Endif

	gencursor('pobalpartfc', 'balpartfc', lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcGroup, llModParam, lcFiltruOriginal)


	obalp = Createobject('frm_balpart_fc')
	obalp.Lb_titlu_alb_b121.Caption = "BALANTA FURNIZORI CUMULATA"
	obalp.WindowState = 2
	obalp.Show()

	If Used('balpartfc')
		Use In balpartfc
	Endif

Endproc && lans_balanta_cumulata_401_409
*---------------------------------- Sfarsit lans_balanta_cumulata_401_409 ----------------------------------

*---------------------------------- Inceput lans_balanta_cumulata_4111_419 ----------------------------------
Procedure lans_balanta_cumulata_4111_419

	Private pobalpartfc
	Store "" To pobalpartfc
	Local lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcGroup, llModParam, lcFiltruOriginal

	lcSelect = [select id_part, nume,cod_fiscal,acont, id_valuta, nume_val, (precdeb-preccred-(bpreccred-bprecdeb)) as soldprec, ] + ;
		[(bcredit-bdebit) as avanscur,debit,credit,precdeb,preccred, ] + ;
		[(debit-credit-(bcredit-bdebit)) as soldcur,(bpreccred-bprecdeb) as avansprec, ] + ;
		[((bpreccred-bprecdeb)+(bcredit-bdebit)) as avanstot,(precdeb+debit-(preccred+credit)-(bpreccred-bprecdeb+bcredit-bdebit)) as soldfinal, ] + ;
		[(precvaldeb-precvalcred-(bprecvalcred-bprecvaldeb)) as soldprecval, valdebit, valcredit, ] + ;
		[(precvaldeb+valdebit-(precvalcred+valcredit)-(bprecvalcred-bprecvaldeb+bvalcredit-bvaldebit)) as soldfinalval, ] + ;
		[(preccred+credit) as totdeb,(precdeb+debit) as totcred, id_sucursala, sucursala from vbalanta_4111_419]

	lcOrder = [nume,acont]
	lcFiltru = [1=2]
	llAfisare = .F.
	llModParam = .T.
	lcFiltruOriginal = [an = ] + Alltrim(Str(gnan)) + [ and luna = ] + Alltrim(Str(gnluna))
	&& DACA SUNT PE O SUCURSALA - SELECTEZ DOAR INREGISTRARILE DE PE SUCURSALA CURENTA
	If !Isnull(gnIdSucursala)
		lcFiltruOriginal = lcFiltruOriginal + gcCondSucursala
	Endif

	gencursor('pobalpartfc', 'balpartfc', lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcGroup, llModParam, lcFiltruOriginal)


	obalp = Createobject('frm_balpart_fc')
	obalp.Lb_titlu_alb_b121.Caption = "BALANTA CLIENTI CUMULATA"
	obalp.grid1.column5.header1.Caption = "Productie"
	obalp.grid1.column6.header1.Caption = "Incasat"
	obalp.WindowState = 2
	obalp.Show()

	If Used('balpartfc')
		Use In balpartfc
	Endif

Endproc && lans_balanta_cumulata_4111_419
*---------------------------------- Sfarsit lans_balanta_cumulata_4111_419 ----------------------------------
Procedure  raport_bal_parteneri
	Local loFrm
	loFrm = Createobject("frm_date_rap_balpart_temp")
	loFrm.Show(1)
Endproc
**************************************************************************************************************

*********************************************
*** marcheaza/verifica/sterge o luna de initializare pentru o entitate LI/BP/BV/BP/IP si un cont
*** LI (luna initializare), BP (balanta de parteneri), BV (balanta verificare sintetica), BA (balanta de verificare analitica), IP (inregistrari parteneri)
*** se foloseste pentru a nu se reface situatiile de initializare
*** lLunaInitializare = IsCalendarInit('SET', 'IP/BP', lcCont)
*********************************************
Procedure IsCalendarInit
	Lparameters tcTip, tcEntitate, tcCont
	*** tcTip:	GET (DEFAULT): .T./.F. daca exista inregistrarea in calendar_init
	***			SET: initializeaza calendar_init
	***			DEL: sterge din calendar_init

	Private pcCont, pcEntitate, pcTip, pnRezultat
	Local llInit
	llInit = .F.
	pcTip = Upper(Alltrim(m.tcTip)) && GET/SET/DEL
	pcTip = Iif(!Inlist(m.pcTip, 'GET', 'SET', 'DEL'), 'GET', m.pcTip)

	pcEntitate = Upper(Alltrim(m.tcEntitate))
	pcCont = Iif(!Empty(m.tcCont), Alltrim(m.tcCont), '')
	lcCont = m.pcCont
	pnRezultat = 0

	lnConturi = Getwordcount(m.lcCont, ",") && "4111" sau "5121,5126,5081"
	For lnCont = 1 To lnConturi
		pcCont = Getwordnum(m.lcCont, m.lnCont, ",")
		goExecutor.oExecuta('begin pack_firma.LUNA_INITIALIZARE_CONT(?pcTip, ?gnAn, ?gnLuna, ?pcEntitate, ?pcCont, ?gnIdUtil, ?@pnRezultat); end;')
		If m.pnRezultat <> 0
			llInit = .T.
		Endif
	Endfor

	Return (m.llInit)
Endproc && IsCalendarInit

*********************************************
*** verifica daca o luna este blocata la refacere: luna initiala, luna inchisa, situatie blocata
*** .T. = nu se reface, .F. = se poate reface
*********************************************
Function IsBlocatRefacere
	Lparameters tcEntitate, tcCont

	Private pcCont, pcEntitate, pnRezultat

	pcEntitate = Upper(Alltrim(m.tcEntitate))
	pcCont = Iif(!Empty(m.tcCont), Alltrim(m.tcCont), '')

	pnRezultat = 0
	goExecutor.oSelect2Value('select pack_firma.IS_BLOCAT_REFACERE(?gnAn, ?gnLuna, ?pcEntitate, ?pcCont) from dual', @pnRezultat)

	Return (m.pnRezultat <> 0)
Endfunc