*!* 12.04.2011
*!* marius.mtuu
*!* viz_flux
*!* salvez si refolosesc lista id act incasari/plati tip compensari de care trebuie sa se tina cont la flux

*!*	lcComentariu = FormulaFlux2Comentariu([substr(scd,1,3) in ('758','759', '760')],'D',1,"",0,"")
*!*	MessageBox(lcComentariu)

*!* 24.06.2011
*!* marius.mutu
*!* viz_flux - se creeaza si coloanele defalcate pe luni pentru perioada precedenta
*!* dadea eroare cand se calcula defalcat pe luni + perioada precedenta

PROCEDURE viz_flux
	PARAMETERS tnLunaI, tnAnulI, tnLunaF, tnAnulF, tnModel, tlCompensari, tlPrecedent, tlDefalcat
	&& tnModel 1 = FORMULE FLUX MAI VECHI; 2 = FORMULE FLUX CONTAFIN CONPRESS
	&& tlCompensari daca se afiseaza compensarile din registrul jurnal pentru luarea in considerare in calcul
	&& tlDefalcat 1 = daca se creeaza cate o coloana pentru fiecare luna sau se cumuleaza lunile intr-o singura coloana
	IF EMPTY(tnModel)
		tnModel = 2
	ENDIF
	LOCAL i, j, lcPrecedent, lcCurent

	PRIVATE pnLuna, pnAnul, pnLI, pnAI, pnLF, pnAF, pnSI, pnSF, pnModel, pnNuCalculeazaTotaluri, pcIdsAct
	STORE 0 TO pnLuna, pnAnul, pnLI, pnAI, pnLF, pnAF, pnSI, pnSF

	LOCAL lcMesaje, lnDifSoldFPrecedent, lnDifSoldFCurent
	lcMesaje = ""
	lnDifSoldFPrecedent = 0
	lnDifSoldFCurent = 0

	pnModel = tnModel
	pnNuCalculeazaTotaluri = 0
	pcIdsAct = ''
	llDefalcat = IIF(PCOUNT() = 8, tlDefalcat, .F.)
	llPrecedent = tlPrecedent AND !m.llDefalcat && daca se defalca pe luni, nu mai am perioada precedenta, doar curenta

	IF !initializeaza_sucursala() &&	oinit_optiuni.prg
		RETURN
	ENDIF

	lcPrecedent = []
	lcCurent = PADL(INT(tnLunaI), 2, '0') + '/' + PADL(INT(tnAnulI), 4, '0') + ' - ' + PADL(INT(tnLunaF), 2, '0') + '/' + PADL(INT(tnAnulF), 4, '0') && pentru listare - precedent

	lnParcurgeri = 1
	IF m.llPrecedent
		lnParcurgeri = 2
		lcPrecedent = PADL(INT(tnLunaI), 2, '0') + '/' + PADL(INT(tnAnulI) - 1, 4, '0') + ' - ' + PADL(INT(tnLunaF), 2, '0') + '/' + PADL(INT(tnAnulF) - 1, 4, '0') && pentru listare - precedent
	ENDIF

	*!* 03.05.2011
	lcCursorFlux = [Select Rand, denumire, Cast(0 As N(14,2)) As precedent, Cast(0 As N(14,2)) As curent, ] + ;
		[suma, formula, Total, tip, si, sf ]


	FOR iLunaFlux = tnAnulI * 12 + tnLunaI TO tnAnulF * 12 + tnLunaF
		lnLunaFlux = INT(MOD(m.iLunaFlux, 12))
		lnAnFlux = INT(FLOOR(iLunaFlux / 12))

		IF m.lnLunaFlux = 0
			m.lnLunaFlux = 12
			m.lnAnFlux = m.lnAnFlux - 1
		ENDIF

		lcCursorFlux = m.lcCursorFlux + [, CAST(0 as N(14,2)) as l] + PADL(m.lnLunaFlux, 2, "0") + [_] + ALLTRIM(STR(m.lnAnFlux))
		*!* 24.06.2011
		IF m.llPrecedent
			lnLunaFluxPrec = lnLunaFlux
			lnAnFluxPrec = lnAnFlux - 1
			lcCursorFlux = m.lcCursorFlux + [, CAST(0 as N(14,2)) as l] + PADL(m.lnLunaFluxPrec, 2, "0") + [_] + ALLTRIM(STR(m.lnAnFluxPrec))
		ENDIF
		*!* 24.06.2011 ^		
	ENDFOR
	lcCursorFlux = m.lcCursorFlux + [ From cIntermediar Into Cursor cFlux Readwrite]
	*!* 03.05.2011 ^
	FOR j = 1 TO lnParcurgeri && 1 = precedent/curent 2 = curent/nimic
		lnAnulI = tnAnulI
		lnLunaI = tnLunaI
		lnAnulF = tnAnulF
		lnLunaF = tnLunaF

		IF j = 1 AND m.llPrecedent
			lnAnulI = (lnAnulI - 1)
			lnAnulF = (lnAnulF - 1)
		ENDIF


		pnLI = lnLunaI
		pnAI = lnAnulI
		pnLF = lnLunaF
		pnAF = lnAnulF
		pnSI = 0
		pnSF = 0

		FOR i = lnAnulI * 12 + lnLunaI TO lnAnulF * 12 + lnLunaF
			pnLuna = INT(MOD(i, 12))
			pnAnul = INT(FLOOR(i / 12))

			IF pnLuna = 0
				pnLuna = 12
				pnAnul = pnAnul - 1
			ENDIF
			*!* 03.05.2011
			lcColoanaLuna = "l" + PADL(m.pnLuna, 2, "0") + [_] + ALLTRIM(STR(m.pnAnul))
			*!* 03.05.2011 ^			
			WAIT WINDOW 'Luna ' + PADL(ALLTRIM(STR(pnLuna)), 2, '0') + ' ' + ALLTRIM(STR(pnAnul)) NOWAIT
			pcIdsAct = ''
			*!* 12.04.2011
			lnSucces = goExecutor.oFunction2Value([pack_mg_flux.GetIdsActCompensari(] + ALLTRIM(STR(pnLuna)) + [, ] + ALLTRIM(STR(pnAnul)) + [)], @pcIdsAct)
			IF lnSucces < 0
				AMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
				RETURN
			ELSE
				pcIdsAct = NVL(pcIdsAct, '')
			ENDIF
			*!* 12.04.2011 ^

			IF tlCompensari
				lcSql = [{call PACK_MG_FLUX.GetCompensari(] + ALLTRIM(STR(pnLuna)) + [, ] + ALLTRIM(STR(pnAnul)) + [)}]
				lnSucces = goExecutor.oExecute(lcSql, 'crsCompensariTemp')
				IF lnSucces < 0
					AMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
					RETURN
				ELSE
					IF RECCOUNT('crsCompensariTemp') > 0
						*!* 12.04.2011					
						SELECT *, ALLTRIM(STR(id_act)) + ',' $ pcIdsAct + ',' AS ales FROM crsCompensariTemp INTO CURSOR crsCompensari READWRITE
						*!* 12.04.2011 ^
						loFrmCompensari = CREATEOBJECT("frm_compensari")
						loFrmCompensari.lb_titlu_alb_b121.CAPTION = 'Compensari ' + PADL(ALLTRIM(STR(pnLuna)), 2, '0') + ' ' + ALLTRIM(STR(pnAnul))
						loFrmCompensari.SHOW(1)

						pcIdsAct = ''
						SELECT crsCompensari
						SET FILTER TO
						SCAN FOR ales
							pcIdsAct = pcIdsAct + ',' + ALLTRIM(STR(id_act))
						ENDSCAN
						IF !EMPTY(pcIdsAct)
							pcIdsAct = SUBSTR(pcIdsAct, 2)
						ENDIF
					ENDIF

					USE IN (SELECT('crsCompensariTemp'))
					USE IN (SELECT('crsCompensari'))
				ENDIF
			ENDIF && tlCompensari

			lcSql = [begin PACK_MG_FLUX.calc_flux(] + ALLTRIM(STR(pnLuna)) + [, ] + ALLTRIM(STR(pnAnul)) + [, ] + ALLTRIM(STR(pnNuCalculeazaTotaluri)) + [, ] + ALLTRIM(STR(pnModel)) + [, '] + ALLTRIM(pcIdsAct) + ['); end;]
			lnSucces = goExecutor.oExecute(lcSql)

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



			* Set Textmerge On To Memvar lcMesaje Noshow

			lcSql = [select * from mg_flux_trezorerie where rand = 0 ]
			lcCursor = 'cNerepartizate'
			lnSucces = goExecutor.oExecute(lcSql, lcCursor)
			IF lnSucces < 0
				AMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
			ENDIF

			SELECT COUNT(*) AS CNT FROM cNerepartizate INTO CURSOR cNr
			SELECT cNr
			lnNr = CNT

			IF USED('cNr')
				USE IN cNr
			ENDIF

			SET TEXTMERGE ON TO MEMVAR lcMesaje ADDITIVE  NOSHOW


			IF lnNr  > 0
				\*** Luna <<Padl(Alltrim(Str(pnLuna)),2,'0')>>/<<Alltrim(Str(pnAnul))>>, urmatoarele inregistrari nu au fost repartizate: <<CHR(13)+CHR(10)>>
				\   nract         debit=credit         suma
				SELECT cNerepartizate
				SCAN
					\   <<PADR(nract,14," ")>> <<PADR(scd,4," ")>>=<<PADR(scc,4," ")>> <<PADL(ALLTRIM(TRANSFORM(suma,get_mask(20,gnPA))),20," ")>>  <<CHR(13)>>
					SELECT cNerepartizate
				ENDSCAN
		\<<CHR(13)+CHR(10)>>
			ENDIF
			USE IN cNerepartizate

			SET TEXTMERGE TO
			***--------------------


			lcSql = [select * FROM mg_flux order by rand]
			lcCursor = 'cIntermediar'
			lnSucces = goExecutor.oExecute(lcSql, lcCursor)
			IF lnSucces < 0
				AMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
				LOOP
			ENDIF

			IF (i = lnAnulI * 12 + lnLunaI) AND (j = 1) && in prima luna creez cursorul cFLux
				&lcCursorFlux


				&& completez sumele pe coloana precedent/curent cumulat
				IF j = 1 AND m.llPrecedent
					REPLACE ALL precedent WITH suma IN cFlux
				ELSE
					REPLACE ALL curent WITH suma IN cFlux
				ENDIF

				&& completez sumele defalcat pentru luna curenta
				REPLACE ALL &lcColoanaLuna WITH suma IN cFlux
			ELSE
				&& scanez si insumez
				lnsuma = 0
				SELECT cFlux
				SCAN
					lcRand = RAND
					SELECT cIntermediar
					LOCATE FOR RAND = lcRand
					IF FOUND()
						lnsuma = suma
						SELECT cFlux
						IF j = 1 AND m.llPrecedent
							REPLACE precedent WITH precedent + m.lnsuma
						ELSE
							REPLACE curent WITH curent + m.lnsuma
						ENDIF
						*!* 03.05.2011
						REPLACE &lcColoanaLuna WITH m.lnsuma
						*!* 03.05.2011 ^						
					ENDIF
					SELECT cFlux
				ENDSCAN
			ENDIF && (i = lnAnulI*12 + lnLunaI) And (j = 1) && in prima luna creez cursorul cFLux

			USE IN (SELECT('cIntermediar'))

			*** solduri initiale, finale luna curenta 
			pnSI = 0
			pnSF = 0
			lcSql = [begin PACK_MG_FLUX.get_SI_balanta(?pnLuna, ?pnAnul, ?@pnSI); end;]
			lnSucces = goExecutor.oExecute(lcSql)

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

			lcSql = [begin PACK_MG_FLUX.get_SF_balanta(?pnLuna, ?pnAnul, ?@pnSF); end;]
			lnSucces = goExecutor.oExecute(lcSql)

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

			lnDifSoldF = 0

			SELECT cFlux
			REPLACE &lcColoanaLuna WITH pnSI FOR si = 1
			IF pnNuCalculeazaTotaluri = 0 && daca se calculeaza totalurile in baza de date compar soldul final calculat cu cel din balanta
				LOCATE FOR sf = 1
				IF FOUND()
					IF &lcColoanaLuna <> m.pnSF
						lnDifSoldF = m.pnSF - (&lcColoanaLuna + m.pnSI) && soldul initial nu era inclus in randul calculat
					ENDIF
				ENDIF
			ENDIF
			REPLACE &lcColoanaLuna WITH m.pnSF FOR sf = 1

			*!*				Set Textmerge On To Memvar lcMesaje Additive  Noshow 
			IF lnDifSoldF <> 0
				lcMesaje = lcMesaje + CHR(13) + CHR(10) + STRTRAN(SUBSTR(lcColoanaLuna, 2), "_", " ") + ' DIFERENTA INTRE SOLD FINAL TREZORERIE CALCULAT SI SOLD FINAL DIN BALANTA DE VERIFICARE: ' + ALLTRIM(TRANSFORM(lnDifSoldF, '999 999 999 999.99'))
			ENDIF
			*** solduri initiale, finale luna curenta ^
		ENDFOR && i = lnAnulI*12 + lnLunaI To lnAnulF*12 + lnLunaF

		*** solduri initiale, finale cumulat precedent/curent
		lcSql = [begin PACK_MG_FLUX.get_SI_balanta(?pnLI, ?pnAI, ?@pnSI); end;]
		lnSucces = goExecutor.oExecute(lcSql)

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

		lcSql = [begin PACK_MG_FLUX.get_SF_balanta(?pnLF, ?pnAF, ?@pnSF); end;]
		lnSucces = goExecutor.oExecute(lcSql)

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

		lcDifSoldFPrecedent = 0
		lcDifSoldFCurent = 0

		SELECT cFlux
		IF j = 1 AND m.llPrecedent
			REPLACE precedent WITH pnSI FOR si = 1
			IF pnNuCalculeazaTotaluri = 0 && daca se calculeaza totalurile in baza de date compar soldul final calculat cu cel din balanta
				LOCATE FOR sf = 1
				IF FOUND()
					IF precedent <> pnSF
						lnDifSoldFPrecedent = pnSF - (precedent + pnSI)
					ENDIF
				ENDIF
			ENDIF
			REPLACE precedent WITH pnSF FOR sf = 1
		ELSE
			REPLACE curent WITH pnSI FOR si = 1
			IF pnNuCalculeazaTotaluri = 0 && daca se calculeaza totalurile in baza de date compar soldul final calculat cu cel din balanta
				LOCATE FOR sf = 1
				IF FOUND()
					IF curent <> pnSF
						lnDifSoldFCurent = pnSF - (curent + pnSI) && soldul initial nu era inclus in randul calculat
					ENDIF
				ENDIF
			ENDIF
			REPLACE curent WITH pnSF FOR sf = 1
		ENDIF
		*!*				Set Textmerge On To Memvar lcMesaje Additive  Noshow 
		IF lnDifSoldFPrecedent <> 0
			lcMesaje = lcMesaje + CHR(13) + CHR(10) + 'DIFERENTA INTRE SOLD FINAL TREZORERIE CALCULAT SI SOLD FINAL DIN BALANTA DE VERIFICARE: ' + ALLTRIM(TRANSFORM(lnDifSoldFPrecedent, '999 999 999 999.99'))
		ENDIF
		IF lnDifSoldFCurent <> 0
			lcMesaje = lcMesaje + CHR(13) + CHR(10) + 'DIFERENTA INTRE SOLD FINAL TREZORERIE CALCULAT SI SOLD FINAL DIN BALANTA DE VERIFICARE: ' + ALLTRIM(TRANSFORM(lnDifSoldFCurent, '999 999 999 999.99'))
		ENDIF
		*** solduri initiale, finale cumulat precedent/curent ^		
	ENDFOR && j

	lcFisier = gcTempPath + "mesaje.txt"
	STRTOFILE(lcMesaje, lcFisier)

	IF !EMPTY(lcMesaje)
		MODIFY FILE (lcFisier)
	ENDIF
	***------------------------------------------------

	SELECT cFlux
	GO TOP

	SELECT cFlux
	lovf = CREATEOBJECT('frm_flux', m.llPrecedent, lcPrecedent, lcCurent)
	lovf.ADDPROPERTY("lDefalcat", tlDefalcat)
	*!* 03.05.2011
	*** adaug coloane in grid pentru luni defalcat
	IF m.llDefalcat
		lnColumnOffset = lovf._grdrow1.COLUMNCOUNT
		lovf._grdrow1.COLUMNCOUNT = m.lnColumnOffset + (tnAnulF * 12 + tnLunaF) - (tnAnulI * 12 + tnLunaI) + 1
		i = 0
		FOR iLunaFlux = tnAnulI * 12 + tnLunaI TO tnAnulF * 12 + tnLunaF
			lnLunaFlux = INT(MOD(m.iLunaFlux, 12))
			lnAnFlux = INT(FLOOR(iLunaFlux / 12))
			i = i + 1
			IF m.lnLunaFlux = 0
				m.lnLunaFlux = 12
				m.lnAnFlux = m.lnAnFlux - 1
			ENDIF
			lcColoanaLuna = "l" + PADL(m.lnLunaFlux, 2, "0") + [_] + ALLTRIM(STR(m.lnAnFlux))
			lnCurentColumnIndex = m.lnColumnOffset + i
			WITH lovf._grdrow1
				.COLUMNS(m.lnCurentColumnIndex).NAME = lcColoanaLuna
				.&lcColoanaLuna..CONTROLSOURCE = "cFlux." + m.lcColoanaLuna
				.&lcColoanaLuna..FORMAT = "RK"
				.&lcColoanaLuna..INPUTMASK = get_mask(14, gnPA)
				.&lcColoanaLuna..Header1.CAPTION = STRTRAN(SUBSTR(m.lcColoanaLuna, 2), "_", "/")
				.&lcColoanaLuna..Header1.ALIGNMENT = 2
			ENDWITH
		ENDFOR && iLunaFlux = lnAnulI*12 + lnLunaI To lnAnulF*12 + lnLunaF

		lovf._grdrow1.cPrecedent.VISIBLE = .F.
		lovf._grdrow1.cCurent.VISIBLE = .F.
		*!* lovf._grdrow1.cCurent.Header1.Caption = PADL(INT(tnLunaI), 2, '0') + "/" + ALLTRIM(STR(INT(tnAnulI))) + " - " + PADL(INT(tnLunaF), 2, '0') + "/" + ALLTRIM(STR(INT(tnAnulF)))
	ENDIF && m.llDefalcat
	lovf.grid_column_bind()
	*!* 03.05.2011 ^
	lovf.SHOW(1)

	IF USED('cFlux')
		USE IN cFlux
	ENDIF


ENDPROC && viz_flux
***-------------------------------------------------------------------------------------
PROCEDURE lanseaza_excel_flux
	PARAMETERS tcalias, tlTip, toGridObject


	LOCAL loExcelXML AS "ExcelXml" OF "ExcelXml.prg"
	LOCAL x AS "XL_flux" OF "EXCELX"
	LOCAL lcFile, lcexcel
	*:Global OLEAPP
	LOCAL llEsteExcel
	llEsteExcel = isComobject("Excel.Application")
	
	IF !m.llEsteExcel
		*CopyToExcelSimple("flux_trezorerie.xls", "", m.tcalias, "", "*", ".T.")

		loExcelXML = NEWOBJECT("ExcelXml", "ExcelXml.prg")

		WITH loExcelXML
			.GridObject = toGridObject
			.HasFilter = .F.
			.LockHeader = .F.
			.SheetName = "Flux Trezorerie"
			.OpenAfterSaving = .T.
			lcFile = PUTFILE("Flux trezorerie", "flux_trezorerie", "xls")
			IF .SAVE(m.lcFile)
				AMESSAGEBOX("Fisierul s-a salvat!", 64)
			ELSE
				AMESSAGEBOX("Fisierul nu s-a salvat!", 48)
			ENDIF
		ENDWITH
		
		RETURN
	ENDIF


	PRIVATE lcTabel

	*!*	llEsteExcel = isComobject("Excel.Application")
	*!*	If !llEsteExcel
	*!*		Do mesaj With "Instalati Microsoft Excel",""
	*!*		Return
	*!*	Endif

	lcTabel = ALLTRIM(tcalias)

	*!*	lcNumeDirExcel = Addbs(Strtran(CALEFIRMA,"\\","\"))+"Excel\"
	*!*	If !Directory(lcNumeDirExcel)
	*!*		Md (lcNumeDirExcel)
	*!*	ENDIF
	*!*	lcexcel = lcNumeDirExcel +"Flux de trezorerie_"+Sys(2)+".XLS"

	lcexcel = ADDBS(STRTRAN(gcTempPath, "\\", "\")) + "Flux de trezorerie_" + SYS(2) + ".XLS"

	x = NEWOBJECT("XL_flux", "EXCELX") && alternatively you can drop this class on a VFP form
	x.SAVEAS = lcexcel && PART.XLS to be created in your TEMP folder

	SELECT (lcTabel)

	DIMENSION x.oWorkSheet[1] && need four pages
	x.oWorkSheet[1] = "Flux"
	ADDPROPERTY(x, "lTip", tlTip)
	x.GO() && remember this calls .populate_pages().
	RELEASE x

	**************************8

	OLEAPP = GETOBJECT("", "Excel.Application")
	IF TYPE('OLEAPP')!= 'O'
		OLEAPP = CREATEOBJECT("Excel.Application")
	ENDIF
	OLEAPP.WorkBooks.OPEN(lcexcel)
	OLEAPP.VISIBLE = 1

	RETURN
ENDPROC &&lanseaza_excel_flux
***------------------------------------------------------------------------------------
PROCEDURE viz_formule_flux
	LPARAMETERS tnModel

	LOCAL lcSql, lnSucces, lcCursor
	PRIVATE pcDataOra, pnModel
	lcCursor = 'cFormule'

	pcDataOra = Get_Ora(2)
	&& tnModel 1 = FORMULE FLUX MAI VECHI; 2 = FORMULE FLUX CONTAFIN CONPRESS
	IF EMPTY(tnModel)
		pnModel = 2
	ELSE
		pnModel = tnModel
	ENDIF


	lcSql = [select * from mg_flux_formule where model = ?pnModel order by rand]
	lnSucces = goExecutor.oExecute(lcSql, lcCursor)
	IF lnSucces < 0
		AMESSAGEBOX(lcSql, 0 + 32, 'Eroare')
		RETURN
	ENDIF

	SELECT cFormule
	REPLACE ALL comentariu WITH FormulaFlux2Comentariu(debit, 'D', tip, CONT, TOTAL, ftotal) + IIF(!EMPTY(credit), " " + FormulaFlux2Comentariu(credit, 'C', tip, CONT, 0, ""), "")

	SELECT DISTINCT RAND, denumire FROM cFormule INTO CURSOR cFluxParinte READWRITE
	SELECT * FROM cFormule INTO CURSOR cFluxCopil READWRITE

	SELECT cFluxCopil
	INDEX ON RAND TAG RAND

	SELECT cFluxParinte
	SET RELATION TO RAND INTO cFluxCopil ADDITIVE

	poff = CREATEOBJECT("frm_formule")
	poff.SHOW(1)


	USE IN (SELECT('cFluxCopil'))
	USE IN (SELECT('cFluxParinte'))
	USE IN (SELECT('cFormule'))


ENDPROC && viz_formule_flux

***---------------------------------------------------------------------------------------------
PROCEDURE viz_conturi_flux
	lcSql = [select cont from mg_flux_conturi order by cont]
	lnSucces = goExecutor.oExecute(lcSql, "cConturiFlux")
	IF lnSucces < 0
		AMESSAGEBOX(lcSql, 0 + 32, 'Eroare')
		RETURN
	ENDIF

	loFrmConturi = CREATEOBJECT("frm_conturi_flux")
	loFrmConturi.SHOW(1)
	USE IN (SELECT('cConturiFlux'))
ENDPROC && viz_conturi_flux

***---------------------------------------------------------------------------------------------
PROCEDURE FormulaFlux2Comentariu
	LPARAMETERS tcFormula, tcDebit_credit, tnTip, tcContTip2, tnTotal, tcFTotal

	&& cFormuleFlux.debit,'D',cFormuleFlux.tip,cFormuleFlux.cont,cFormuleFlux.total,cFormuleFlux.ftotal

	LOCAL lcFormula, lcDebit_credit, lcCautInc, lcListaConturi, lcListaContAfis, lnTip, lcContTip2, llTotal, lcFTotal

	IF !EMPTY(NVL(tcDebit_credit, ''))
		lcDebit_credit = ALLTRIM(UPPER(NVL(tcDebit_credit, '')))
	ELSE
		lcDebit_credit = ''
	ENDIF
	IF !EMPTY(NVL(tcFormula, ''))
		lcFormula = ALLTRIM(NVL(tcFormula, ''))
	ELSE
		lcFormula = ''
	ENDIF
	IF !EMPTY(NVL(tnTip, 0))
		lnTip = tnTip
	ELSE
		lnTip = 0
	ENDIF
	IF !EMPTY(NVL(tcContTip2, ''))
		lcContTip2 = ALLTRIM(NVL(tcContTip2, ''))
	ELSE
		lcContTip2 = ''
	ENDIF
	STORE '' TO lcListaConturi, lcListaContAfis
	llTotal = NVL(tnTotal, 0) = 1

	IF !EMPTY(NVL(tcFTotal, ''))
		lcFTotal = ALLTRIM(NVL(tcFTotal, ''))
	ENDIF

	IF EMPTY(lcFormula) AND EMPTY(lcFTotal)
		RETURN ''
	ENDIF

	IF !llTotal
		DO CASE
			CASE lcDebit_credit = 'D'
				lcCautInc = [substr(scd,1,3) in (] && [inlist(left(scd,3)]
			CASE lcDebit_credit = 'C'
				lcCautInc = [substr(scc,1,3) in (] && [inlist(left(scc,3)]
		ENDCASE

		lnInc = AT(lcCautInc, lcFormula)
		IF lnInc > 0
			lcCautSf = [')]
			lnSF = AT(lcCautSf, lcFormula)
		ENDIF

		lnLen = LEN(lcFormula) - LEN(lcCautInc) && 19
		lcListaConturi = SUBSTR(lcFormula, LEN(lcCautInc) + 1, lnLen - 1)
		lcListaConturi = STRTRAN(lcListaConturi, ['], [])

		lnConturi = GETWORDCOUNT(lcListaConturi, [,])
		IF lnConturi = 1
			lcCont = GETWORDNUM(lcListaConturi, 1, [,])
			lcListaContAfis = lcListaContAfis + lcCont
		ELSE
			FOR i = 1 TO lnConturi
				lcCont = GETWORDNUM(lcListaConturi, i, [,])
				DO CASE
					CASE i = 1
						lcListaContAfis = lcListaContAfis + lcCont + [ ]
					CASE i = 2
						lcListaContAfis = lcListaContAfis + [ (] + lcCont + [, ]
					OTHERWISE
						lcListaContAfis = lcListaContAfis + lcCont + [, ]
				ENDCASE
			ENDFOR
			lcListaContAfis = SUBSTR(lcListaContAfis, 1, LEN(lcListaContAfis) - 2)
			lcListaContAfis = lcListaContAfis + [)]
		ENDIF

		DO CASE
			CASE lnTip = 1
				DO CASE
					CASE lcDebit_credit = 'D'
						lcTraducere = [Platile din perioada selectata de tipul ] + lcListaContAfis + [ = 5xxx.]
					CASE lcDebit_credit = 'C'
						lcTraducere = [Incasarile din perioada selectata de tipul 5xxx = ] + lcListaContAfis + [.]
				ENDCASE
			CASE lnTip = 2
				DO CASE
					CASE lcDebit_credit = 'D'
						lcTraducere = [Platile din perioada selectata de tipul ] + lcContTip2 + [ = 5xxx, ]
						lcTraducere = lcTraducere + [pentru care s-au gasit inregistrari de tipul ] + lcListaContAfis + [ = ] + lcContTip2 + [ in Registrul Jurnal Total.]

					CASE lcDebit_credit = 'C'
						lcTraducere = [Incasarile din perioada selectata de tipul 5xxx = ] + lcContTip2 + [, ]
						lcTraducere = lcTraducere + [pentru care s-au gasit inregistrari de tipul ] + lcContTip2 + [ = ] + lcListaContAfis + [ in Registrul Jurnal Total.]
				ENDCASE
			OTHERWISE
				lcTraducere = ''
		ENDCASE
	ENDIF

	IF llTotal
		lcTraducere = [Suma randurilor ] + STRTRAN(lcFTotal, 'R', '')
		*lcTraducere = STRTRAN(lcTraducere, '0', ' ')
	ENDIF

	RETURN lcTraducere

ENDPROC && FormulaFlux2Comentariu
