*!* 08.08.2011
*!* marius.mutu
*!* note_fara_predefinire
*!* se restaureaza nota fara predefinire neterminata anterior (fatal error) la intrarea in nota fara predefinire

*!* 20.10.2011
*!* marius.mutu
*!* note_fara_predefinire
*!* prima linie adaugata in cursor se completeaza si campul id_sucursala
*!* intr-o sucursala nu se putea modifica prima linie din cauza ca tact.id_sucursala (0) era diferit de gnIdSucursala (1)

*!* 22.08.2013
*!* marius.mutu
*!* repunere_venchelt_avans 
*!* repunere automata pentru cheltuielile/veniturile in avans cu rate definite

*!* 11.08.2014
*!* marius.mutu
*!* note_fara_predefinire
*!* #4039 tratare eroare explicatie_tva de 2 ori in tact (explicatie_tva_a si explicatie_tva_b)

*!*	24.10.2014
*!*	marius.mutu
*!*	oxSet.SAVE: recreez xml note fara schema inline. pack_seturi.modifica_set dadea eroare cu schema inline

*!*	20.03.2015
*!*	marius.mutu
*!*	repunere_venchelt_avans: se tine cont de ratele si lista_mf sterse, provenite din modificari


*!* 08.03.2018
*!* marius.mutu
*!* import_extras_mt940 corectare

*!*	09.03.2017
*!*	repunere_venchelt_avans
*!*	corectare nume partener debit

*!* 09.05.2018
*!* marius.mutu
*!* Inchidere_salarii - import din Contafin

*!* 25.09.2018
*!* marius.mutu
*!*	stornare_plinc - se da un id_fact distinct pentru notele de stornare incasare/plata 413 = 4111/401=403 astfel incat sa nu apara doua inregistrari 413/403 cu acelasi id_fact +/- care nu se pot inchide

*!* 02.07.2019
*!* marius.mutu
*!*	repunere_venchelt_avans - cont 4754 SUBVENTII

*!*	14.04.2020
*!*	marius.mutu
*!*	repunere_venchelt_avans - ireg_parteneri join imob_nom_mf.acont

*!*	27.01.2021
*!*	repunere_venchelt_avans - am limitat selectia intre luna de inceput si luna de expirare a ratelor imobilizarii
*!* punea rate la nesfarsit

*!* 06.05.2021
*!* note_fara_predefinire
*!* nu se reincarca nota salvata anterior pentru 90023 import extras bancar

*!*	25.06.2025
*!*	cheltprofit1_ana - completare taxcode pentru impozit venit/profit

*!*	29.07.2025
*!*	cheltprofit1_ana, cheltprofit2_ana - corectie taxcode pentru impozit venit/profit

*!* 29.05.2026 
*!* repunere_venchelt_avans
*!* se foloseste cu prioritate explicatia4 si explicatia5 din imob_nom_mf
*!* asa cum sunt initializate in ireg_parteneri > editare rate in avans

******************************************************************************************************
*** INCEPUT PROCEDURA SELECT_CONT
Procedure SELECT_CONT
	Private pcselect, pcfiltru, pcschema, pcorder, poplcont, poplcontana, llAfisare
	Private lcCont && contul ales din planul de conturi o sa-l returnez de forma "411 .CLI1" SAU "411 "
	Store .F. To m.llAfisare
	Store "" To m.poplcont, m.poplcontana, m.lcCont
	If Used("plcont")
		Use In plcont
	Endif
	If Used("plcontana")
		Use In plcontana
	Endif

	pcschema = ['ID_PLCONT N(5),ACONT C(4),EXPLICATIE C(100),EXPLICATIES C(30),CONT C(4),TIP_SOLD C(1),AN N(4),TIP_CONT N(1),INACTIV N(1),NEFOLOSIT N(1)']
	pcselect = ['select id_plcont,acont,explicatie,explicaties,cont,tip_sold,an,tip_cont,inactiv,nefolosit from ] + gcs + [.vplcont_sintetic where 2=2']
	pcfiltru = [an=] + Alltrim(Str(gnAn)) + [ and SUBSTR(explicatie,1,3)!='   ']
	pcorder = [cont]
	gencursor("poplcont", "plcont", m.pcselect, m.pcfiltru, m.pcschema, m.pcorder, m.llAfisare)
	m.poplcont.ca_baza1.afisare()

	pcschema = ['ID_PLCONT N(5),ACONT C(4),EXPLICATIE C(100),EXPLICATIES C(30),CONT C(4),TIP_SOLD C(1),AN N(4),TIP_CONT N(1),INACTIV N(1),NEFOLOSIT N(1)']
	pcselect = ['select id_plcont,acont,explicatie,explicaties,cont,tip_sold,an,tip_cont,inactiv,nefolosit from ] + gcs + [.vplcont_analitic where 1=2']
	pcfiltru = [1=2]
	pcorder = []
	gencursor("poplcontana", "plcontana", m.pcselect, m.pcfiltru, m.pcschema, m.pcorder, m.llAfisare)
	m.poplcontana.ca_baza1.afisare()

	Clear Class "frm_contnou"
	ofrmcontnou = Createobject("frm_contnou", 'lcCont')
	m.ofrmcontnou.Show(1)
	*!*	Do Form frm_contnou With "lcCont"

	If Used("plcont")
		Use In plcont
	Endif
	If Used("plcontana")
		Use In plcontana
	Endif
	Release m.poplcont, m.poplcontana, m.ofrmcontnou
	Return m.lcCont
Endproc
*** SFARSIT PROCEDURA SELECT_CONT
********************************************************************************************************************
*** CREEAZA TBALANTA DIN BAL+BALANA+TOTALURI
*!*	PROCEDURE make_tbalanta
*!*		IF USED('TBALANTA')
*!*			USE IN tbalanta
*!*		ENDIF

*!*		LNPRECEDENT=0

*!*		PRIVATE pcselect1,pcfiltru1,pcschema1,potbal1,tbal1,pcselect2,pcfiltru2,pcschema2,potbal2,tbal2
*!*		STORE "" TO potbal1,potbal2
*!*		pcselect1 = ["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 '+]+;
*!*			['from ] + gcs + [.Vbal where 1=2']
*!*		pcfiltru1 = [AN = ] +ALLTRIM(STR(gnAn)) + [ AND LUNA = ] + ALLTRIM(STR(gnluna))
*!*		pcorder1 = ['']
*!*		pcschema1 = ['']
*!*		llAfisare = .F.
*!*		gencursor('potbal1','tbal1',pcselect1,pcfiltru1,pcschema1,pcorder1,llAfisare)
*!*		potbal1.ca_baza1.afisare()

*!*		pcselect2 = ['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 '+]+;
*!*			['from  ] + gcs + [.Vbalana where 1=2']
*!*		pcfiltru2 = [AN = ] +ALLTRIM(STR(gnAn)) + [ AND LUNA = ] + ALLTRIM(STR(gnluna))
*!*		pcorder2 = ['']
*!*		pcschema2 = ['']
*!*		llAfisare = .F.
*!*		gencursor('potbal2','tbal2',pcselect2,pcfiltru2,pcschema2,pcorder2,llAfisare)
*!*		potbal2.ca_baza1.afisare()

*!*		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, ;
*!*			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;
*!*			FROM tbal1 ;
*!*			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, ;
*!*			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;
*!*			FROM tbal1 ;
*!*			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, ;
*!*			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;
*!*			FROM tbal1 ;
*!*			GROUP BY G1, G2, G3 ;
*!*			INTO CURSOR TG3

*!*		SELECT * FROM tbal1 ;
*!*			UNION ;
*!*			SELECT * FROM TG1 ;
*!*			UNION ;
*!*			SELECT * FROM TG2 ;
*!*			UNION ;
*!*			SELECT * FROM TG3 ;
*!*			UNION ;
*!*			SELECT * FROM tbal2 ;
*!*			INTO CURSOR tbalanta READWRITE;
*!*			ORDER BY 1,2,3,4


*!*		USE IN tbal1
*!*		USE IN tbal2
*!*		USE IN TG1
*!*		USE IN TG2
*!*		USE IN TG3

*!*		SELECT tbalanta
*!*		ALTER TABLE tbalanta ADD COLUMN bifa l
*!*		ALTER TABLE tbalanta ADD COLUMN g5 c(8)
*!*		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)
*!*		lcIndex = ADDBS(gcTempPath) + 'tbalanta.cdx'
*!*		INDEX ON g5 TAG g5 OF (lcIndex)
*!*		SET ORDER TO g5


*!*		RETURN "TBALANTA"
*!*	ENDPROC && MAKE_TBALANTA

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





Proc cheltprofit1_ana

	lnBut = lans(10506)
	If m.lnBut = 1
		Select actactan
		Replace All nrACT With 10, explicatia With 'INCHID.IMPOZIT PE PROFIT', proc_tva With 0, id_set With 90001
		UPDATE actactan SET taxcode = 103000 WHERE LEFT(scc,1) = '4' AND EMPTY(NVL(taxcode,0))			
		Locate
		lVerificAnalitic = .F.
		lCompletareParteneri = .T.
		Do Form verificare With m.lVerificAnalitic, m.lCompletareParteneri

		If gnButon = 1
			Select actactan
			lnSucces  = OSCRIE_IN_FISIERE(0)
			If m.lnSucces > 1
				Do mesaj With 'Cheltuiala profit.', 'Inchiderea s-a efectuat.'
			Endif
		Endif
		If Used('actactan')
			Use In actactan
		Endif
	Endif

	Return &&cheltprofit1

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

Proc cheltprofit2_ana

	lnBut = lans(10505)

	If m.lnBut = 1
		Select actactan
		Replace All nrACT With 10, explicatia With 'INCHID.IMPOZIT PE VENIT', proc_tva With 0, id_set With 90002
		UPDATE actactan SET taxcode = 121000 WHERE LEFT(scc,1) = '4' AND EMPTY(NVL(taxcode,0))
		Locate
		lVerificAnalitic = .F.
		lCompletareParteneri = .T.
		Do Form verificare With m.lVerificAnalitic, m.lCompletareParteneri
		If gnButon = 1
			Select actactan
			lnSucces  = OSCRIE_IN_FISIERE(0)
			If m.lnSucces > 1
				Do mesaj With 'Cheltuiala profit.', 'Inchiderea s-a efectuat.'
			Endif
		Endif
	Endif

	If Used('actactan')
		Use In actactan
	Endif

	Return &&cheltprofit2

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

Procedure plati_impozite
	Parameters tn_idset

	If !Used('actactan')
		Return
	Endif

	If Used('plimp')
		Use In plimp
	Endif

	lcSql = [select id_note, explicatie, scd, ascd, scc, ascc, in_valuta, cu_tva, id_set, ordine,] + ;
		[ptva, id_jtva_coloana, id_jtva_nepl, taxcode, paymentcode from note_contabile where id_set = ] + Alltrim(Str(m.tn_idset))
	lcCursor = [cnote_contabile]
	lnSucces = goExecutor.oExecute(m.lcSql, m.lcCursor)
	If m.lnSucces < 0
		amessagebox('Note contabile ' + Chr(13) + goExecutor.cEroare, 0 + 16, "Eroare")
		Return
	Endif

	*!*	modificare	v 2.5.32	:	am pus a.id_factd, a.id_factc, a.pereched, a.perechec in loc de 000000000000000000
	Select N.*, 00000000000000.0000 As suma, 00000000000000 As nrACT, a.id_responsabil, ;
		Iif(Alltrim(N.scd) = Alltrim(a.scd), a.id_partd, 000000000000000000) As id_partd, ;
		Iif(Alltrim(N.scc) = Alltrim(a.scc), a.id_partc, 000000000000000000) As id_partc, ;
		Iif(N.scd = a.scd, a.partd, Space(100)) As partd, ;
		Iif(N.scc = a.scc, a.partc, Space(100)) As partc, ;
		a.nresp, a.id_sectie, a.sectie, a.id_venchelt, a.dst_chlt, ;
		Cast(a.id_factd As N(18)) As id_factd, Cast(a.id_factc As N(18))  As id_factc, Cast(a.pereched As N(18)) As pereched, ;
		Cast(a.perechec As N(18)) As perechec, Padr(explicatie, 100, ' ') As explicatia ;
		From cnote_contabile N Left Join actactan a On N.id_set = a.id_set ;
		Where N.id_set = m.tn_idset ;
		Into Cursor plimp Readwrite Order By ordine
	*---------------------------
	If Used("crsBal")
		Use In crsBal
	Endif
	If Used("crsBalana")
		Use In crsBalana
	Endif

	lcSql = "select cont,acont,explicaties as DENUMIRE from plcont where inactiv = 0 and an = ?gnAn " + ;
		" and cont in (select scd from note_contabile where id_set = " + Alltrim(Str(m.tn_idset)) + ;
		" union " + ;
		" select scc from note_contabile where id_set = " + Alltrim(Str(m.tn_idset)) + ")"


	lcCursorBal = "crsPlcont"
	lnSucces = goExecutor.oExecute(m.lcSql, m.lcCursorBal)
	If m.lnSucces < 0
		amessagebox(goExecutor.cEroare, 0 + 16, "Eroare")
		Return
	Endif
	Select Distinct Cont, denumire From crsPlcont Where Empty(Nvl(ACONT, '')) Into Cursor crsBal
	Select Distinct Cont, ACONT, denumire From crsPlcont Where !Empty(Nvl(ACONT, '')) Into Cursor crsBalana
	Use In (Select('crsPlcont'))

	Select  a.Id_note, a.scd, b.ACONT As ascd, a.scc, a.ascc, a.In_valuta, a.Cu_tva, ;
		a.id_set, a.ordine, a.Ptva, a.suma, a.nrACT, a.id_responsabil, ;
		a.id_partd, a.id_partc, a.partd, a.partc, a.nresp, a.id_sectie, ;
		a.sectie, a.id_venchelt, a.dst_chlt, a.id_factd, a.id_factc, ;
		a.pereched, a.perechec, Padr(Nvl(b.denumire, a.explicatia), 100, ' ') As explicatia, ;
		a.taxcode, a.paymentcode ;
		From    plimp a Join crsBalana b On a.scd = b.Cont ;
		Into Cursor plimptmp1

	Select  a.Id_note, a.scd, a.ascd, a.scc, a.ascc, a.In_valuta, a.Cu_tva, ;
		a.id_set, a.ordine, a.Ptva, a.suma, a.nrACT, a.id_responsabil, ;
		a.id_partd, a.id_partc, a.partd, a.partc, a.nresp, a.id_sectie, ;
		a.sectie, a.id_venchelt, a.dst_chlt, a.id_factd, a.id_factc, ;
		a.pereched, a.perechec, Padr(Nvl(b.denumire, a.explicatia), 100, ' ') As explicatia, ;
		a.taxcode, a.paymentcode ;
		From plimp a Join crsBal b On a.scd = b.Cont ;
		Where a.scd Not In (Select scd From plimptmp1) ;
		Into Cursor plimptmp2

	If Used("crsBal")
		Use In crsBal
	Endif
	If Used("crsBalana")
		Use In crsBalana
	Endif
	If Used("plimp")
		Use In plimp
	Endif

	Select * From plimptmp1 ;
		Union ;
		Select * From plimptmp2 ;
		Into Cursor plimp Readwrite

	If Used("plimptmp1")
		Use In plimptmp1
	Endif
	If Used("plimptmp2")
		Use In plimptmp2
	Endif
	*===========================================

	Use In (SELECT('cnote_contabile'))

	Select actactan
	Locate
	Scatter Name m.poVar
	Zap

	Select plimp
	Replace All ascd With '' For Isnull(ascd)
	Replace All ascc With '' For Isnull(ascc)
	Replace All explicatia With Alltrim(explicatia) + Iif(!Empty(m.poVar.explicatia), ' ' + Alltrim(m.poVar.explicatia), '')
	Go Top

	SELECT plimp
	SCAN 
		SCATTER NAME oplimp
		
		SELECT actactan
		APPEND BLANK 
		GATHER NAME poVar
		GATHER NAME oplimp
		SELECT plimp 
	ENDSCAN 

	USE IN (SELECT('plimp'))
	
	Select .F. As ales, 0 As Cu_tva, Cast(0 As N(2)) As tipnota, a.*, Space(100) As explicatie_tva ;
			From actactan a ;
			Into Cursor tact Readwrite

	UPDATE tact SET id_sucursala = m.gnIdSucursala		

	Use In (Select('crsExplicatiiTVATemp'))

	Select tact
	Go Top
	llNotaNoua = .T.
	llMaximize = .T.
	loForm = Createobject([frm_modific2007], m.tn_idset, m.llNotaNoua)
	loForm.lb_titlu_alb_b121.Caption = 'Plati impozite'
	Select tact
	loForm.Show(1, m.llMaximize)

	If m.gnButon = 1
		Use In (Select('actactan'))

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

		Select actactan
		Replace All id_util With gnIdUtil, id_set With m.tn_idset
		lnSucces  = OSCRIE_IN_FISIERE(0)
	Endif && gnButon = 1



*!*		Clear Class "FRM_plati_impozite"
*!*		obj = Createobject('FRM_plati_impozite')
*!*		obj.oact = m.poVar
*!*		m.obj.Show()

*!*		If gnButon = 2
*!*			Do deschid_actc
*!*			Return
*!*		Else
*!*			Select actactan
*!*			Do OSCRIE_IN_FISIERE.prg
*!*		Endif

Endproc &&plati_impozite


*******************************************
* PROCEDURE Inchidere_salarii(  )
* Date : 08/07/2005, 08:58:55
* author : marius.mutu
* description:
*******************************************
Procedure Inchidere_salarii

	Local lcCursor, llVerificAnalitic, llCompletareParteneri
	Local lcAct, lcCSectie, lcDirContafin, lcFile, lcScc, lcScd, lcSql, llStergeNotaPrecedenta, llSucces
	Local lnCod, lnIdLucrare, lnIdSectie, lnIdVenchelt, lnId_Set, lnSucces

	lcCursor = []
	If gnNotaSal = 0 && fara program de salarii
		lcCursor = ImportTable()
	Endif



	If gnNotaSal = 1 &&nota de inchidere simpla
		lcSql = [begin PACK_SALARII.calcul_nota('] + gcs + [',] + Alltrim(Str(gnAn)) + [,] + Alltrim(Str(gnluna)) + [,' '); end;]&&[select * from ] + gcS + [.calendar]
		lcCursor = [crsRezultate]
		lnSucces = goExecutor.oExecute(m.lcSql)

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

		lcSql = [select * from ] + gcs + [.sal_vtmp_nota order by ordine ]
		lcCursor = [crsRezultate]
		lnSucces = goExecutor.oExecute(m.lcSql, m.lcCursor)

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

		*!*			Select crsRezultate
		*!*			BROWSE 

		Select nume_camp As explicatia, scd, scc, ascd, ascc, suma From crsRezultate Into Cursor crsNota Readwrite && Where suma <> 0
		Use In crsRezultate
		lcCursor = [crsNota]
		Select &lcCursor

	Endif

	If gnNotaSal = 2 &&nota de inchidere pe sectii
		lcSql = [begin PACK_SALARII.calcul_nota_sectii('] + gcs + [',] + Alltrim(Str(gnAn)) + [,] + Alltrim(Str(gnluna)) + [); end;]&&[select * from ] + gcS + [.calendar]
		lcCursor = [crsRezultate]
		lnSucces = goExecutor.oExecute(m.lcSql)

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

		lcSql = [select * from ] + gcs + [.sal_vtmp_nota_sect order by ordine ]
		lcCursor = [crsRezultate]
		lnSucces = goExecutor.oExecute(m.lcSql, m.lcCursor)

		If m.lnSucces < 0
			amessagebox(goExecutor.cEroare, 0 + 16, "Eroare")
		Endif
		Select crsRezultate
		Select nume_camp As explicatia, scd, scc, ascd, ascc, suma, id_sectie From crsRezultate  Where suma <> 0  Into Cursor crsNota Readwrite
		Use In crsRezultate
		lcCursor = [crsNota]
		Select &lcCursor
	Endif

	If gnNotaSal = 3 &&nota de inchidere pe analitice
		lcSql = [begin PACK_SALARII.calcul_nota_analit('] + gcs + [',] + Alltrim(Str(gnAn)) + [,] + Alltrim(Str(gnluna)) + [); end;]&&[select * from ] + gcS + [.calendar]
		lcCursor = [crsRezultate]
		lnSucces = goExecutor.oExecute(m.lcSql)

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

		lcSql = [select * from ] + gcs + [.sal_vtmp_nota_sect order by scd ]
		lcCursor = [crsRezultate]
		lnSucces = goExecutor.oExecute(m.lcSql, m.lcCursor)

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

		Select crsRezultate
		Replace All ascd With '' For Left(scd, 1) = '4'


		Select nume_camp As explicatia, scd, scc, ascd, ascc, suma From crsRezultate Where suma <> 0  Into Cursor crsNota Readwrite
		Use In crsRezultate
		lcCursor = [crsNota]
		Select &lcCursor
	Endif

	If gnNotaSal = 4 &&nota de inchidere pe centre de profit (model fruvimed)
		lcSql = [begin PACK_SALARII.calcul_nota_chelt('] + gcs + [',] + Alltrim(Str(gnAn)) + [,] + Alltrim(Str(gnluna)) + [); end;]&&[select * from ] + gcS + [.calendar]
		lcCursor = [crsRezultate]
		lnSucces = goExecutor.oExecute(m.lcSql)

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

		lcSql = [select * from ] + gcs + [.sal_vtmp_nota_chelt order by ordine ]
		lcCursor = [crsRezultate]
		lnSucces = goExecutor.oExecute(m.lcSql, m.lcCursor)
		Select crsRezultate

		If m.lnSucces < 0
			amessagebox(goExecutor.cEroare, 0 + 16, "Eroare")
		Endif
		Select crsRezultate
		Select nume_camp As explicatia, scd, scc, ascd, ascc, suma, id_sectie, ;
			id_venchelt, id_lucrare, sectie, nrord, dst_chlt, Nvl(id_partd, 0000000000) As id_partd, Nvl(id_partc, 0000000000) As id_partc From crsRezultate  Where suma <> 0  Into Cursor crsNota Readwrite

		Use In crsRezultate
		lcCursor = [crsNota]
		Select &lcCursor
	Endif


	If gnNotaSal = 5 &&nota de inchidere pe sucursale (model conpress group)
		lcSql = [begin PACK_SALARII.calcul_nota_sucursale('] + gcs + [',] + Alltrim(Str(gnAn)) + [,] + Alltrim(Str(gnluna)) + [); end;]&&[select * from ] + gcS + [.calendar]
		lcCursor = [crsRezultate]
		lnSucces = goExecutor.oExecute(m.lcSql)

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

		lcSql = [select * from ] + gcs + [.sal_vtmp_nota_sucursale order by ordine ]
		lcCursor = [crsRezultate]
		lnSucces = goExecutor.oExecute(m.lcSql, m.lcCursor)
		Select crsRezultate

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

		Select crsRezultate
		Select nume_camp As explicatia, scd, scc, ascd, ascc, suma, id_sectie, id_sucursala, ;
			sectie, sucursala, Nvl(id_partd, 0000000000) As id_partd, Nvl(id_partc, 0000000000) As id_partc From crsRezultate  Where suma <> 0  Into Cursor crsNota Readwrite

		Use In crsRezultate
		lcCursor = [crsNota]
		Select &lcCursor
	Endif


	If m.gnNotaSal = 7 && nota de inchidere import Contafin
		lcDirContafin = Getdir('', 'Directorul firmei Contafin', 'Directorul firmei Contafin', 64)
		lcAct = Addbs(m.lcDirContafin) + 'AN' + Alltrim(Str(m.gnAn)) + '\DATE' + Padl(Alltrim(Str(m.gnluna, 2, 0)), 2, '0') + '\ACT.DBF'
		If File(m.lcAct)
			Use (m.lcAct) In 0 Shared Alias c_act_temp
			Select explicatia, scd, scc, ascd, ascc, sectie, nrord, dst_chlt, suma From c_act_temp Where id_set = 90008 Into Cursor cActTemp
			Use In (Select('c_act_temp'))
			If Reccount('cActTemp') = 0
				amessagebox('Nu exista nici o nota cu tipul de operatie 90008 in Registrul jurnal din Contafin!', 0 + 48, _Screen.Caption)
			Else
				lcSql = [select * from sal_vtmp_nota_chelt where 1=2 order by ordine ]
				lcCursor = [crsRezultate]
				lnSucces = goExecutor.oExecute(m.lcSql, m.lcCursor)
				Select crsRezultate

				If m.lnSucces < 0
					amessagebox(goExecutor.cEroare, 0 + 16, "Eroare")
				Endif
				Select crsRezultate
				Select nume_camp As explicatia, scd, scc, ascd, ascc, suma, id_sectie, ;
					id_venchelt, id_lucrare, sectie, nrord, dst_chlt, Nvl(id_partd, 0000000000) As id_partd, Nvl(id_partc, 0000000000) As id_partc From crsRezultate  Where suma <> 0  Into Cursor crsNota Readwrite

				Use In crsRezultate
				lcCursor = [crsNota]
				Select &lcCursor

				Select crsNota
				Append From Dbf('cActTemp')
				Use In (Select('cActTemp'))
				Select crsNota
				Scan
					lnIdSectie = GetIdSectie(crsNota.sectie)
					lnIdLucrare = GetIdLucrare(crsNota.nrord)
					lnIdVenchelt = GetIdVenchelt(crsNota.dst_chlt)
					Select crsNota
					Replace id_sectie With m.lnIdSectie, id_lucrare With m.lnIdLucrare, id_venchelt With m.lnIdVenchelt
				Endscan
			Endif && RECCOUNT
		Else
			amessagebox('Nu exista fisierul ' + m.lcAct, 0 + 48, _Screen.Caption)
			Return
		Endif && FILE(m.lcAct)
	Endif && gnNotaSal = 7

	If m.gnNotaSal = 8 && nota de inchidere import xlsx Smartbill sau Saga
		lcSql = [select * from sal_vtmp_nota_chelt where 1=2 order by ordine ]
		lcCursor = [crsRezultate]
		llSucces = goExecutor.oExecuta(m.lcSql, m.lcCursor)

		Select nume_camp As explicatia, scd, scc, ascd, ascc, suma, id_sectie, ;
			id_venchelt, id_lucrare, sectie, nrord, dst_chlt, Nvl(id_partd, 0000000000) As id_partd, Nvl(id_partc, 0000000000) As id_partc, ;
			CAST(null as N(6)) as taxcode, CAST(null as C(250)) as taxname, CAST(null as C(9)) as paymentcode, CAST(null as C(250)) as paymentname ;
			From crsRezultate  ;
			Where suma <> 0 ;
			Into Cursor crsNota Readwrite


		lcCursor = [crsNota]

		Use In (SELECT('crsRezultate'))

		lcFile = GETFILE('xlsx','Fisier','Deschide',0, 'Fisierul note contabile SmartBill/Saga/ROA (xlsx)')
		If File(m.lcFile)
			CREATE CURSOR cXLSXTemp (c1 v(250), c2 v(250), c3 v(250), c4 v(250), c5 v(250), c6 v(250), c7 v(250), c8 v(250), c9 v(250), c10 v(250), c11 v(250), c12 v(250), c13 v(250), c14 v(250), c15 v(250) )

*!*				llSucces = appendfromxlsx(m.lcFile, 'cXLSXTemp')
			llSucces = appendfromxlsx(m.lcFile, 'cXLSXTemp', '', 1, '' , .T.)
		
			IF m.llSucces AND USED('cXLSXTemp')
				SELECT cXLSXTemp 
				GO TOP 

				DO CASE 
					CASE ALLTRIM(LOWER(c2)) = 'ndp' && SAGA
					SELECT c3 as explicatia, c4 as scd, c5 as scc, VAL(c6) as suma, c10 as csectie, CAST(0 as N(10)) as id_sectie, SPACE(100) as sectie FROM cXLSXTemp WHERE VAL(c6) <> 0 INTO CURSOR cActTemp READWRITE 
					IF RECCOUNT('cActTemp') = 0
						amessagebox('Nu exista valori in fisier pe coloana 6 (suma)!', 0 + 48, _Screen.Caption)
					ELSE 
						SELECT distinct UPPER(csectie) as csectie FROM cActTemp WHERE !EMPTY(NVL(cActTemp.cSectie,'')) INTO CURSOR cSectiiTemp
						SELECT cSectiiTemp
						SCAN 
							lcCSectie = ALLTRIM(csectie)
							loSectie = GetSectieByCsectie(m.lcCSectie)
							UPDATE cActTemp SET id_sectie = loSectie.id_sectie, sectie = loSectie.sectie WHERE ALLTRIM(csectie) == m.lcCSectie AND !EMPTY(NVL(loSectie.id_sectie, 0))
						ENDSCAN  	
						USE IN (SELECT('cSectiiTemp'))
						
						* Completez scd, scc pentru notele cu x = % sau % = x
						SELECT cActTemp
						GO TOP 
						lcScd = ALLTRIM(scd)
						lcScc = ALLTRIM(scc)
						SCAN
							IF EMPTY(NVL(scd, ''))
								REPLACE scd WITH m.lcScd
							ELSE 
								lcScd = ALLTRIM(scd)								
							ENDIF 
							IF EMPTY(NVL(scc, ''))
								REPLACE scc WITH m.lcScc
							ELSE 
								lcScc = ALLTRIM(scc)								
							ENDIF 							
						ENDSCAN 
						DELETE FROM cActTemp WHERE ALLTRIM(scd) = '%' OR ALLTRIM(scc) = '%'
					ENDIF

				CASE ALLTRIM(LOWER(c2)) = 'roa' && ROA - asemanator cu Saga + ascd, ascc, lucrare, sectie, dst_chlt
					* DATA	NDP	EXPLICATIE	CONT_D	ACONT_D CONT_C	ACONT_C SUMA	COD_VALUTA	CURS	SUMA_VAL	CATEGORIE	SECTIE	LUCRARE	DST_CHLT

					SELECT c3 as explicatia, c4 as scd, c5 as ascd, c6 as scc, c7 as ascc, VAL(c8) as suma, ;
						c12 as csectie, c13 as sectie, CAST(0 as N(10)) as id_sectie, c14 as nrord, CAST(0 as N(10)) as id_lucrare, ;
						c15 as dst_chlt, CAST(0 as N(10)) as id_venchelt ;
						FROM cXLSXTemp ;
						WHERE VAL(c8) <> 0 ;
						INTO CURSOR cActTemp READWRITE 

					IF RECCOUNT('cActTemp') = 0
						amessagebox('Nu exista valori in fisier pe coloana 8 (suma)!', 0 + 48, _Screen.Caption)
					ELSE 
						SELECT distinct UPPER(csectie) as csectie FROM cActTemp WHERE !EMPTY(NVL(cActTemp.cSectie,'')) INTO CURSOR cSectiiTemp
						SELECT cSectiiTemp
						SCAN 
							lcCSectie = ALLTRIM(csectie)
							loSectie = GetSectieByCsectie(m.lcCSectie)
							UPDATE cActTemp SET id_sectie = loSectie.id_sectie, sectie = loSectie.sectie WHERE ALLTRIM(csectie) == m.lcCSectie AND !EMPTY(NVL(loSectie.id_sectie, 0))
						ENDSCAN  	
						USE IN (SELECT('cSectiiTemp'))
												
					ENDIF
					
				OTHERWISE && SMARTBILL
					SELECT c3 as explicatia, c7 as scd, c8 as scc, VAL(c9) as suma, SPACE(10) as csectie, CAST(0 as N(10)) as id_sectie, SPACE(100) as sectie FROM cXLSXTemp WHERE VAL(c9) <> 0 AND !EMPTY(NVL(c7,'')) and !EMPTY(NVL(c8,'')) INTO CURSOR cActTemp READWRITE 
					IF RECCOUNT('cActTemp') = 0
						amessagebox('Nu exista valori in fisier pe coloanele G (scd), H (scc) si I (suma) !', 0 + 48, _Screen.Caption)
					ENDIF
				ENDCASE   	
			ENDIF 	

			USE IN (SELECT('cXLSXTemp'))
		Endif &&  File(m.lcFile)
		
		* Note goale
		If !USED('cActTemp') OR Reccount('cActTemp') = 0
			lcSql = [select nume_camp as explicatia, scd, ascd, scc, ascc from sal_nota_campuri t where ] + ALLTRIM(STR(m.gnAn*12+m.gnLuna)) + [ between nvl(lunaaninc, 1900*12+1) and nvl(lunaansf, 2099*12+12) order by ordine]
			llSucces = goExecutor.oExecuta(m.lcSql, 'cActTemp')						
		ENDIF 

		Select crsNota
		Append From Dbf('cActTemp')
		Use In (Select('cActTemp'))
	
		UPDATE crsNota SET id_sectie = GetIdSectie(crsNota.sectie) WHERE !EMPTY(NVL(crsNota.sectie,'')) AND EMPTY(NVL(crsNota.id_sectie,0))
		UPDATE crsNota SET id_lucrare = GetIdLucrare(crsNota.nrord) WHERE !EMPTY(NVL(crsNota.nrord,'')) AND EMPTY(NVL(crsNota.id_lucrare,0))
		UPDATE crsNota SET id_venchelt = GetIdVenchelt(crsNota.dst_chlt) WHERE !EMPTY(NVL(crsNota.dst_chlt,'')) AND EMPTY(NVL(crsNota.id_venchelt,0))
	
		IF m.gl406
			UPDATE crsNota SET taxcode = 412000, taxname = 'Contributia individuala de asigurari sociale retinuta de la asigurati' WHERE scc = '4315'
			UPDATE crsNota SET taxcode = 432000, taxname = 'Contributia pentru asigurari de sanatate retinuta de la asigurati' WHERE scc = '4316'
			UPDATE crsNota SET taxcode = 480000, taxname = 'Contributie asiguratorie pentru munca' WHERE scc = '436'						
			UPDATE crsNota SET taxcode = 602000, taxname = 'Impozit pe veniturile din salarii si asimilate salariilor' WHERE scc = '444'			
		ENDIF

	Endif && gnNotaSal = 8


	If !Used(m.lcCursor) Or Empty(m.lcCursor)
		Return
	Endif

	llStergeNotaPrecedenta = .T.
	lnId_Set = 90008
	lnCod = 0
	llVerificAnalitic = .T.
	llCompletareParteneri = .T.

	If m.llStergeNotaPrecedenta
		lnSucces = sterge_nota(m.lnCod, m.lnId_Set)
	Endif


	If m.lnSucces > 0
		Select (m.lcCursor)
		lnSucces = scrie_nota_import(m.lnId_Set, m.llVerificAnalitic, m.llCompletareParteneri, m.lcCursor)
	Endif

	If Used(m.lcCursor)
		Use In (m.lcCursor)
	Endif

Endproc
*----------------------------------sfarsit procedura Inchidere_salarii ----------------------------------
Procedure viz_plcont

	Private poHelp
	Store '' To m.poHelp

	Local lcSchema1, lcSelect1, lcOrder1, lcFiltru1, lcFiltruOriginal, llAfiseaza, lnAn, lcSelectAnMax
	lcSchema1 = []
	******* modificare v 2.0.92
	lcSelectAnMax = [select max(help_an) as help_an from syn_helpcont]
	goExecutor.oExecute(m.lcSelectAnMax, 'cHelpContAn')
	lnAn = cHelpContAn.help_an

	lcSelect1 = [select * from syn_helpcont]

	lcOrder1 = [cont]
	lcGroup = []
	lcFiltru1 = []
	*!*	lcFiltruOriginal = [help_an=]+Alltrim(Str(gnAn))
	******* modificare v 2.0.92 ^
	lcFiltruOriginal = [help_an=] + Alltrim(Str(m.lnAn))
	llModParam = .T.
	llAfiseaza = .F.

	gencursor('poHelp', 'cHelpCont', m.lcSelect1, m.lcFiltru1, m.lcSchema1, m.lcOrder1, m.llAfiseaza,  m.lcGroup, m.llModParam, m.lcFiltruOriginal)
	m.poHelp.ca_baza1.afisare()


	Select cHelpCont

	*lcIndex1 = ADDBS(gcTempPath) + 'helpcont_'+ALLTRIM(SYS(2))+'.cdx'
	lcIndex1 = Addbs(gcTempPath) + 'helpcont.cdx'
	Index On Cont Tag Cont Of (m.lcIndex1)
	Set Order To Cont

	lcIndex2 = Addbs(gcTempPath) + 'helpcont.cdx'
	Index On nrnod Tag nrnod Of (m.lcIndex2)
	Set Order To nrnod


	Select * From cHelpCont Into Cursor test_helpcont

	Select cHelpCont
	ohelpcont = Createobj('help_pltree')
	m.ohelpcont.Show(1)


Endproc

************************************
** Lansare import extras cont MT940
************************************
Procedure lans_import_extras
	LPARAMETERS tcClassType, tcFileExt, tcFileType, tcContBanca
	* tcClassType: RAIFFEISEN / CREDITEUROPE
	* tcFileExt: TXT / XML
	* tcFileType: MT940 (optional)
	* tcContBanca: 5121/5124/5125 (optional)
	Local lcHashParam, lnIdSet, loAct
	lcHashParam = ''
	lcHashParam = IIF(!EMPTY(m.tcClassType), [cClassType=>] + m.tcClassType + [??], [])
	lcHashParam = m.lcHashParam + IIF(!EMPTY(m.tcFileExt), [cFileExt=>] + m.tcFileExt + [??], [])
	lcHashParam = m.lcHashParam + IIF(!EMPTY(m.tcFileType), [cFileType=>] + m.tcFileType + [??], [])
	lcHashParam = m.lcHashParam + IIF(!EMPTY(m.tcContBanca), [cContBanca=>] + m.tcContBanca, [])

	lnIdSet = 90023
	loAct = Null
	Do note_fara_predefinire With m.lnIdSet, , m.loAct, m.lcHashParam In ocont2003.prg
Endproc &&

************************************
** Import extras bancar in tAct (note fara predefinire)
************************************
Procedure import_extras
	Lparameters tcAct, tcHashParam

	* extras cont 
	Local loImport As "ImportNote"
	Local lcClass, lcClassType, lcCont, lcContBanca, lcFile, lcFileExt, lcFileType, lcHashParam, lcParam
	Local ldDataIreg, llSucces, loHash

	lcHashParam = Iif(!Empty(m.tcHashParam), m.tcHashParam, '')
	loHash = GetHash(m.lcHashParam)
	lcClass = "ExtrasBanca"
	lcFile = m.loHash.GetValue('cFile') && fisierul de import (optional)
	lcClassType = m.loHash.GetValue('cClassType') && RAIFFEISEN
	lcFileExt = m.loHash.GetValue('cFileExt')
	lcFileType = m.loHash.GetValue('cFileType')
	lcContBanca = m.loHash.GetValue('cContBanca')
	lcParam = Iif(!Empty(m.lcContBanca), "cContBanca=>" + m.lcContBanca, "")

	loImport = Createobject("ImportNote", m.lcFile, m.lcClass, m.lcClassType, m.lcFileType, m.lcFileExt, m.lcParam) && oproceduri_import.prg
	llSucces = m.loImport.Import()

	IF m.llSucces
		ldDataIreg = Gomonth(Date(m.gnAn, m.gnluna, 1), 1) - 1
		* cursor cActTemp (denumire, iban, nr, data, suma, explicatie, scd, scc, id_partd, id_partc, partd, partc, id_fdoc, fdoc)

		If Used('cActTemp')
			* sterg partenerii si documentele pereche de pe conturile care nu au parteneri, documente
			llSucces = goExecutor.oExecuta('SELECT distinct cont, cu_inregistrari FROM vconfig_cont_ireg order by cont', 'cConturiPartTemp')
			IF m.llSucces
				SELECT a.cont, IIF(!ISNULL(b.cont), 1, 0) as epart, NVL(b.cu_inregistrari, 0) as cu_inregistrari ;
					FROM (SELECT scd as cont FROM cActTemp ;
					  UNION ;
					  SELECT scc as cont FROM cActTemp) a left join cConturiPartTemp b on a.cont = b.cont ;
					INTO CURSOR cConturiTemp

				SELECT cConturiTemp
				SCAN FOR epart = 0
					lcCont = ALLTRIM(cont)
					IF epart = 0
						UPDATE cActTemp SET id_partd = 0, partd = '', id_factd = 0, pereched = 0 WHERE ALLTRIM(scd) = m.lcCont
						UPDATE cActTemp SET id_partc = 0, partc = '', id_factc = 0, perechec = 0 WHERE ALLTRIM(scc) = m.lcCont
					ELSE
						IF cu_inregistrari = 0
							UPDATE cActTemp SET id_factd = 0, pereched = 0 WHERE ALLTRIM(scd) = m.lcCont
							UPDATE cActTemp SET id_factc = 0, perechec = 0 WHERE ALLTRIM(scc) = m.lcCont
						ENDIF
					ENDIF
				ENDSCAN
				USE IN (SELECT('cConturiTemp'))
				USE IN (SELECT('cConturiPartTemp'))
			ENDIF && llSucces


			Select nr As nrACT, Data As dataact, Iif(Year(Data) * 12 + Month(Data) = m.gnAn * 12 + m.gnluna, Data, m.ldDataIreg) As dataireg, suma, ;
				Cast(Upper(Alltrim(explicatie) + Iif(!Empty(Nvl(denumire, '')), ' ' + Alltrim(denumire), '') + ;
						Iif(!Empty(Nvl(cod_fiscal, '')), ' ' + Alltrim(cod_fiscal), '')) As C(100)) As explicatia, ;
				scd, scc, ascd, ascc, id_partd, id_partc, partd, partc, ;
				id_factd, id_factc, pereched, perechec, ;
				id_fdoc, fdoc, ;
				Cast(gnIdSucursala As N(5) Null) As id_sucursala ;
				From cActTemp ;
				Into Cursor cActTemp2

			If _Tally > 0
				Select (m.tcAct)
				Delete All
				Append From Dbf('cActTemp2')
			Else
				amessagebox('Nu s-a importat nici o inregistrare!', 0 + 64, _Screen.Caption)
			Endif

			Use In (Select('cActTemp2'))
			Select (m.tcAct)
			Go Top
	
		ENDIF && used
	ENDIF && llSucces

	Release m.loImport
	RETURN m.llSucces
Endproc && import_extras

Procedure note_fara_predefinire
	Lparameters tnIdSet, toSet, toAct, tcHashParam
	*** tnIdSet = 99999, 99998 (note fara predefinire * = nu se fac verificari de conturi, analitice, parteneri, documente pereche)
	*** tnIdSet <> 99999, 99998 - note definite de utilizator
	*** toSet (default .F./NULL): Obiect cand este modul de editare nota definita de utilizator din frm_config_tabele.scx
	*** toAct (default .F./NULL): este completat cu date din formularul de introducere date lans() pentru notele definite de utilizator si apelate din meniul de introducere
	*** tcHashParam (optional): se transmite la import_extras

	*** drepturi pe butonul de stergere
	Local loBackupXML As "backupxml"
	Local lcCursor, lcSql, lcTitlu, lcXMLFile, lcXMLFileName, llEditare, llImportExtras, llMaximize
	Local llNotaFaraPredefinire, llNotaNoua, llRestoredBackupSet, llSucces, llVizualizare, lnIdSet
	Local lnSucces, loForm, llRul
	llRestoredBackupSet = .F.
	llVizualizare = .F.
	llRul = .T. && se salveaza si rulajele
	llNotaFaraPredefinire = Inlist(m.tnIdSet, 99999, 99998, 90023) && 99999 NOTE FARA PREDEFINIRE, 99998 NOTE FARA PREDEFINIRE*, 90023 IMPORT EXTRAS MT940
	llImportExtras = (m.tnIdSet = 90023)

	*:Global gcAcces
	gcAcces = [4;] + gcAcces
	*** drepturi pe butonul de stergere ^

	lcXMLFile = ""
	lnSucces = 0
	lnIdSet = Iif(Empty(m.tnIdSet), 99999, m.tnIdSet)
	llMaximize = .T.
	llNotaNoua = .T.
	llEditare = (Type('toSet.lEditare') = 'L' and toSet.lEditare) && din meniul Initializare > Configurare note > Note definite de utilizator - nu exista actactan din lans() sau modificare registru jurnal
	lcTitlu = "Nota fara predefinire"

	*** nu se pot face introduceri in luna inchisa sau in firma mama
	If m.glLunaInchisa Or m.glEMama
		Return
	Endif

	*** REINCARCARE NOTA FARA PREDEFINIRE SALVATA ANTERIOR IN FORMAT XML SI NETERMINATA (FATAL ERROR)
	If !m.llEditare
	 	IF !m.llImportExtras
	 		* Nu incarc nota daca import extras
			lcXMLFileName =  'nota_' + Alltrim(Str(m.tnIdSet)) && Iif(m.tnIdSet = 99998, 'notafarapredefinire2', Iif(m.tnIdSet = 99999, 'notafarapredefinire', 'nota'))
			lcXMLFile = ExistsXML(m.lcXMLFileName)
			loBackupXML = Createobject("backupxml", m.lcXMLFileName) && oproceduri_comune.prg
			If m.loBackupXML.ExistsBackupSet() And amessagebox('Exista o nota nefinalizata.' + Chr(13) + Chr(10) + 'Doriti sa o reincarcati?', 4 + 32, _Screen.Caption) = 6
				llRestoredBackupSet = m.loBackupXML.RestoreBackupSet()
			ENDIF
		ENDIF && llImportExtras
	Endif && llEditare

	update_jtva_coloane("", "crsJtvaTemp", 1)

	If !m.llRestoredBackupSet
		* 1. toSet = 'O' modificare set definit de utilizator
		* 2. m.llNotaFaraPredefinire = .T. nota fara predefinire
		* 3. nota definita de utilizator, lans() creaza actactan (posibil din vact, fara coloanele sters, validat)

		If m.llEditare Or m.llNotaFaraPredefinire OR !EMPTY(NVL(m.tnIdSet,0))
			llSucces = .T.
			IF m.llEditare Or m.llNotaFaraPredefinire
				llSucces = goExecutor.oExecuta([select * from vact_tot where 1=2], [v_act])
				If m.llSucces
					Select * From v_act Into Cursor actactan Readwrite
					Use In (Select('v_act'))
				ENDIF 
			ENDIF 		
			
			IF m.llSucces			
				* Creez cursoare trul, trul_obinv

				lcSql = [select * from vrul_tot where 1=2]
				lcCursor = [v_rul]

				llSucces = goExecutor.oExecuta(lcSql,lcCursor)

				If m.llSucces		
					Select *, ;
						valoare + valtva As valoarectva, ;
						valoarev + valtvav As valoarevctva ;
						From v_rul ;
						Into Cursor trul READWRITE 
						
					Use In (SELECT('v_rul'))

					lcSql = [select * from vrul_obinv_tot where 1=2]
					lcCursor = [v_rul_obinv]

					llSucces = goExecutor.oExecuta(lcSql,lcCursor)
				Endif

				If m.llSucces
					Select *, ;
						valoare + valtva As valoarectva, ;
						valoarev + valtvav As valoarevctva ;
						From v_rul_obinv ;
						Into Cursor trul_obinv READWRITE 			

					Use In (SELECT('v_rul_obinv'))
				Endif
			ENDIF && llSucces
	
			IF !m.llSucces
				USE IN (SELECT('tact'))
				USE IN (SELECT('trul'))
				USE IN (SELECT('trul_obinv'))
				Use In (Select('crsJtvaTemp'))
				RETURN 
			ENDIF 
		ENDIF && toSet

		If Type('actactan.sters') = 'U'
			Select a.*, 0 As sters, Cast(0 As N(5)) As id_utils, {//:}  As dataoras From actactan a Into Cursor actactanTemp Readwrite
			Use In (Select('actactan'))
			Select * From actactanTemp Into Cursor actactan Readwrite
			Use In (Select('actactanTemp'))
		Endif
		If Type('actactan.validat') = 'U'
			Select a.*, 0 As Validat, Cast(0 As N(5)) As id_utilv, {//:}  As dataorav From actactan a Into Cursor actactanTemp Readwrite
			Use In (Select('actactan'))
			Select * From actactanTemp Into Cursor actactan Readwrite
			Use In (Select('actactanTemp'))
		Endif

		If Type('actactan.explicatie_tva') = 'U'
			Select a.*, jtva.denumire As explicatie_tva ;
				From actactan a Left Join crsJtvaTemp jtva On a.id_jtva_coloana = jtva.id_jtva_coloana ;
				Into Cursor actactanTemp Readwrite

			Use In (Select('actactan'))
			Select * From actactanTemp Into Cursor actactan Readwrite
			Use In (Select('actactanTemp'))
		Endif

		Select .F. As ales, Iif(Empty(Nvl(a.id_jtva_coloana, 0)), 0, 1) As Cu_tva, Cast(0 As N(2)) As tipnota, a.* ;
			From actactan a ;
			Into Cursor tact Readwrite


		*!*	modificare	v 2.5.40
		lcSql = "SELECT nume_set FROM xsets WHERE id_set = " + Alltrim(Str(m.lnIdSet))
		lnSucces = goExecutor.oSelect2Value(m.lcSql, @m.lcTitlu)
		If m.lnSucces < 0
			amessagebox(goExecutor.cEroare, 0 + 16, "Eroare")
		Endif
		
		If !Used('saft_taxtable')
			update_saft_taxtable()
		ENDIF 	
		
		*!*			If !m.llNotaFaraPredefinire &&	And Type('toSet') = 'O'
		If m.llEditare	&&	modificare note
			* Nu sunt linii in actactan/tAct din modificare Registru Jurnal
			* le adaug din xnote pentru editare
			
			Text To m.lcSql Textmerge Noshow
		        SELECT decode(NVL(a.id_jtva_coloana, 0), 0, 0, 1) As Cu_tva, 
		           Cast(0 As Number(2)) As tipnota,
		             cast(0 as number(20)) as id_act,
		             cast(0 as number(2)) as luna,
		             cast(0 as number(4)) as an,
		             cast(0 as number(20)) as cod,
		             a.dataireg,
		             a.serie_act,
		             a.nract,
		             a.dataact,
		             a.explicatia,
		             a.xscd as scd,
		             a.xascd as ascd,
		             a.xscc as scc,
		             a.xascc as ascc,
		             a.suma,
		             a.pereched,
		             a.perechec,
		             a.suma_val,
		             a.id_valuta,
		             v.nume_val,
		             a.curs,
		             a.datascad,
		             0 AS neimpozab,
		             a.nnir,
		             cast(0 as number(5)) as id_util,
		             '' AS util,
		             sysdate as dataora,
		             cast(0 as number(5)) as id_utils,
		             '' AS utils,
		             sysdate as dataoras,
		             a.id_responsabil,
		             resp.denumire AS nresp,
		             a.id_venchelt,
		             venchelt.explicatie AS dst_chlt,
		             a.id_lucrare,
		             lucr.nrord,
		             a.id_ctr,
		             (case when ctr.numar is not null then ctr.numar || '/' else '' end) || TO_CHAR(ctr.data,'DD.MM.YYYY') as contract,
		             a.id_sectie,
		             sectii.sectie,
		             a.proc_tva,
		             a.id_set,
		             NVL(a.id_fact, 0) as id_fact,
		             a.id_partd,
		             part1.denumire AS partd,
		             a.id_partc,
		             part.denumire AS partc,
		             cast(0 as number(5)) as id_sucursala,
		             '' as sucursala,
		             a.id_fdoc,
		             fdoc.fel_document AS fdoc,
		             a.explicatia4,
		             a.explicatia5,
		             cast(0 as number(5)) as id_gestin,
		             '' AS gestin,
		             cast(0 as number(5)) as id_gestout,
		             '' AS gestout,
		             NVL(a.id_factd, 0) as id_factd,
		             NVL(a.id_factc, 0) as id_factc,
		             a.id_jtva_coloana,
		             jtva.denumire as explicatie_tva,
		             cast(0 AS NUMBER(1)) AS validat,
		             cast(0 as number(5)) as id_utilv,
		             '' as utilv,
		             SYSDATE AS dataorav,
		             NVL(doc.tva_incasare,0) as tva_incasare,
		             a.taxcode,
		             a.paymentcode
		             from xnote a 
		          LEFT JOIN nom_fdoc fdoc ON a.id_fdoc = fdoc.id_fdoc
		          LEFT JOIN nom_parteneri part ON a.id_partc = part.id_part
		          LEFT JOIN nom_parteneri part1 ON a.id_partd = part1.id_part
		          LEFT JOIN vnom_venchel venchelt ON a.id_venchelt = venchelt.id_venchelt
		          LEFT JOIN nom_parteneri resp ON a.id_responsabil = resp.id_part
		          LEFT JOIN nom_sectii sectii ON a.id_sectie = sectii.id_sectie
		          LEFT JOIN vnom_lucrari lucr ON a.id_lucrare = lucr.id_lucrare
		          LEFT JOIN nom_valute v ON a.id_valuta = v.id_valuta
				  LEFT JOIN contracte ctr ON ctr.id_ctr = a.id_ctr          
		          LEFT JOIN jtva_coloane jtva ON a.id_jtva_coloana = jtva.id_jtva_coloana
		          LEFT JOIN documente doc on a.id_fact = doc.id_doc        	
				where a.id_set = <<m.lnIdSet>>
				order by a.nr_nota
			Endtext
			llSucces = goExecutor.oExecuta(m.lcSql, 'tactTemp')

			If !m.llSucces
				Return
			Else
				Select tact
				Append From Dbf('tactTemp')
				Use In (Select('tactTemp'))
			Endif
		Endif

	ENDIF && !m.llRestoredBackupSet

	*!*	modificare	v 2.5.41
	If !m.llEditare
		Update tact Set id_sucursala = Nvl(gnIdSucursala, 0)
		Update trul Set id_sucursala = Nvl(gnIdSucursala, 0)
		Update trul_obinv Set id_sucursala = Nvl(gnIdSucursala, 0)				
	Endif
	*!*	modificare	v 2.5.41	^
	*** REINCARCARE NOTA FARA PREDEFINIRE SALVATA ANTERIOR IN FORMAT XML SI NETERMINATA (FATAL ERROR) ^
	lcTitlu = Alltrim(m.lcTitlu)
	lcTitlu = Iif(m.llEditare, "EDITARE ", "") +  m.lcTitlu + " " + Alltrim(Str(m.lnIdSet))

	If Reccount('tact') = 0
		Select tact
		Append Blank
		Replace dataireg With GetDataIreg() && oproceduri_comune.prg
		Replace dataact With dataireg, datascad With Gomonth(dataact, 1)
		*!* 20.10.2011
		Replace id_sucursala With Nvl(gnIdSucursala, 0)
		*!* 20.10.2011 ^
	Endif

	Select tact
	Go Top

	*!* lansez procedura de import MT940
	llSucces = .T.
	If m.llImportExtras
		llSucces = import_extras('tAct', m.tcHashParam)
	Endif
	IF m.llSucces
	
		loForm = Createobject([frm_modific2024], m.lnIdSet, m.llNotaNoua, m.loBackupXML, m.toSet, m.llVizualizare)
		*DO FORM frm_modific_2007 NAME loForm LINKED WITH m.lnIdSet, m.llNotaNoua, m.loBackupXML, m.toSet, m.llVizualizare NOSHOW 
		loForm.lb_titlu_alb_b121.Caption = m.lcTitlu
		Select tact
		loForm.Show(1, m.llMaximize)

		*** SALVEZ NOTELE FARA PREDEFINIRE INAINTE DE SCRIEREA IN BAZA DE DATE
		If m.llNotaFaraPredefinire And Type('loBackupXML') = 'O' And Used('tact')
			m.loBackupXML.SaveBackupSet("tact")
			m.loBackupXML.SaveBackupSet("trul")
			m.loBackupXML.SaveBackupSet("trul_obinv")						
		ENDIF
		
		If buton = 1
			Use In (Select('actactan'))
			
			Replace id_jtva_coloana With Null, proc_tva With 0 For cu_tva = 0 In tact
			Select * From tact Into Cursor actactan Readwrite
			Select * From trul Into Cursor rul_temp Readwrite			
			Select * From trul_obinv Into Cursor rul_temp_obinv Readwrite						

			Replace All id_util With gnIdUtil, sters With 0 In actactan
			Replace All id_util With gnIdUtil, sters With 0 In rul_temp
			Replace All id_util With gnIdUtil, sters With 0 In rul_temp_obinv			

			lnSucces  = oscrie_in_fisiere(0, .F., m.llRul)
			llSucces = (m.lnSucces > 0)
			
			If m.llSucces
				*** STERG NOTELE FARA PREDEFINIRE SALVATE DACA OPERATIA S-A INCHEIAT CU SUCCES
				If m.llNotaFaraPredefinire And Type('loBackupXML') = 'O'
					m.loBackupXML.DeleteBackupSet()
				Endif

			Endif
		ENDIF && buton
	ENDIF && llSucces	

	Use In (Select('actactan'))
	Use In (Select('tact'))
	Use In (Select('trul'))
	Use In (Select('trul_obinv'))
	Use In (Select('rul_temp'))			
	Use In (Select('crsJtvaTemp'))

Endproc && note_fara_predefinire


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

Procedure inchidere_DIURNE

	Local lcCursorInchidere, lcSql, lcCursor, lnSucces
	lcCursorInchidere = ""
	Private pnIdSet

	*!*	llStergeNotaPrecedenta = .T.
	*!*	lnIdSet = 90008
	*!*	lnCod = 0
	*!*	llVerificAnalitic = .T.
	*!*	llCompletareParteneri = .T.
	pnIdSet = 90020
	*!*	pnIdSet = 90008



	lcSql = [select * from ] + gcs + [.vact where id_set = ?pnIdSet and an = ?gnAn and luna = ?gnLuna] + ;
		gcCondSucursala
	lcCursor = [actactan]

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

	Select actactan
	If Reccount() > 0
		Clear Class "verificare"
		overif = Createobject('verificare')
		m.overif.Show(1)
		If buton = 2
			If Used('actactan')
				Use In actactan
			Endif
			Release m.overif
			Return
		Else
			Do OSCRIE_IN_FISIERE.prg With 2, .F.
		Endif
	Endif

	lnBut = lans(m.pnIdSet)
	If m.lnBut = 1
		pnSectie = 0

		*!*		lcCursorInchidere = GET_CURSOR_INCHIDERE_AMORTIZARI(pnTip, pnSectie, gnAn, gnluna, "crs_inchidere") && oproceduri_comune_imob.prg

		lcSql = [select * from sal_vdiurne_sume  ]
		lcCursorInchidere = [crs_inchidere]
		lnSucces = goExecutor.oExecute(m.lcSql, m.lcCursorInchidere)

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

		If !Used(m.lcCursorInchidere)
			lnBut = 2 && RENUNT
		Endif
	Endif

	If m.lnBut = 1
		Select actactan
		Scatter Name m.oact
		Zap
		Select crs_inchidere

		*!* 09.05.2007
		*!* marius.mutu
		Insert Into actactan (scd, ascd, scc, suma, explicatia, id_sectie, sectie, id_partc, partc, id_sucursala, sucursala) ;
			Select scd, ascd, scc, suma - acordat, explicatia, id_sectie, sectie, id_partc, partc, id_sucursala, sucursala From crs_inchidere Where suma <> 0

		Select actactan
		Scan
			Gather Name m.oact Fields Except scd, ascd, scc, ascc, suma, id_sectie, sectie, id_partc, partc, id_sucursala, sucursala
		Endscan
		*!* 09.05.2007 ^
		Select actactan
		Locate
		lVerificAnalitic = .T.
		lCompletareParteneri = .T.
		Do Form verificare With m.lVerificAnalitic, m.lCompletareParteneri

		If gnButon = 1
			Select actactan
			lnSucces  = OSCRIE_IN_FISIERE(0)
		Endif
	Endif

	If Used('crs_inchidere')
		Use In crs_inchidere
	Endif
	If Used('actactan')
		Use In actactan
	Endif

Endproc && inchidere_amortizari

*_________________________________

**************************************************
*** verifica analitice si parteneri din cursorul din act_temp
*** se foloseste pentru scrieri direct pe server (vezi inchidere_tva)
**************************************************
Procedure verificare_completare_act(tcCursorVerificare, tlVerificAnalitic, tlAlegPartener, tcSirDifAcont, tcSirDifPart)

	Local lcCursorFinal, llSucces, lcSelect, llExit
	*:Global gnButon
	tcSirDifAcont = ""
	tcSirDifPart = ""
	gnButon = 1
	llSucces = .F.
	lcCursorFinal = [actactan]

	lcSelect = Select()

	Select a.*, a.suma As totftva, a.suma As tottva, Ttod(a.dataactt) As dataact, ;
		Ttod(a.datairegt) As dataireg, Ttod(a.datascadt) As datascad, ;
		0 As pozitie_1, 0 As pozitie_2 ;
		From (m.tcCursorVerificare) a ;
		Into Cursor (m.lcCursorFinal) Readwrite

	Select (m.lcCursorFinal)

	Do Form verificare With m.tlVerificAnalitic, m.tlAlegPartener

	If m.gnButon = 1
		llExit = .F.
		Select (m.lcCursorFinal)
		Scan For (m.tlVerificAnalitic And (Nvl(ascd, '') <> Nvl(ascd1, '') Or Nvl(ascc, '') <> Nvl(ascc1, ''))) Or ;
				(m.tlAlegPartener And (Nvl(id_partd, 0) <> Nvl(id_partd1, 0) Or Nvl(id_partc, 0) <> Nvl(id_partc1, 0)))

			If m.tlVerificAnalitic And (Nvl(ascd, '') <> Nvl(ascd1, '') Or Nvl(ascc, '') <> Nvl(ascc1, ''))
				tcSirDifAcont = m.tcSirDifAcont + Alltrim(Str(id_act)) + [|] + Alltrim(Nvl(ascd, '')) + [|] + Alltrim(Nvl(ascc, '')) + [;]
			Endif

			If m.tlAlegPartener And (Nvl(id_partd, 0) <> Nvl(id_partd1, 0) Or Nvl(id_partc, 0) <> Nvl(id_partc1, 0))
				If (Like([41*], scd) And Nvl(id_partd, 0) <> Nvl(id_partd1, 0)) ;
						Or (Like([41*], scc) And Nvl(id_partc, 0) <> Nvl(id_partc1, 0))
					amessagebox("Nu puteti modifica clientul!", 48, "Atentie")
					llExit = .T.
					Exit
				Else
					tcSirDifPart = m.tcSirDifPart + Alltrim(Str(id_act)) + [|] + Alltrim(Str(Nvl(id_partd, 0))) + [|] + Alltrim(Str(Nvl(id_partc, 0))) + [;]
				Endif
			Endif && nvl
		Endscan

		llSucces = !m.llExit

	Endif && gnButon = 1

	Use In (Select(m.lcCursorFinal))
	Select(m.lcSelect)

	Return m.llSucces
Endproc


***********************
Procedure repunere_venchelt_avans
	Lparameters tcCont
	*** tcCont: 471;472

	Local loForm As [frm_modific2007]
	Local lcSql, lcCrsCheltuieli, lcSel, llNotaNoua, llSucces, lnButon, lnIdSet, lnSucces
	Private pcCond, pdDataF, pdDataI, pnFiscala, loAct, pnIdTipImobilizare, pcCont, pnIdSet

	pcCont = Iif(Empty(m.tcCont), '471', m.tcCont)
	pnIdTipImobilizare = Iif(m.pcCont = '471', 4, Iif(m.pcCont = '472',  5, 6)) && 4 = cheltuieli in avans / 5 = venituri in avans / 6 = subventii 4754

	pnIdSet = Iif(m.pcCont = '471', 10611, 10612)

	Use In (Select('actactan'))
	*** STERGERE NOTA ANTERIOARA	
	lcSql = [select * from vact where id_set = ?pnIdSet and an = ?gnAn and luna = ?gnLuna ] + m.gcCondSucursala
	If m.pnIdSet = 10612 && 10612 este comun la 472 = 7xx si 475x = 7xx
		lcSql = [select * from vact where id_set = ?pnIdSet and an = ?gnAn and luna = ?gnLuna and scd = ?pcCont ] + m.gcCondSucursala
	Endif

	lcCursor = [actactan]

	llSucces = goExecutor.oExecuta(m.lcSql, m.lcCursor)
	If !m.llSucces
		Return
	Endif

	Select actactan
	If Reccount() > 0
		Clear Class "verificare"
		overif = Createobject('verificare')
		m.overif.Show(1)
		If buton = 2
			Use In (Select('actactan'))
			Release m.overif
			Return
		Endif
		Do OSCRIE_IN_FISIERE.prg With 2, .F.
	Endif
	*** STERGERE NOTA ANTERIOARA ^

	llNotaNoua = .T.
	lnButon = lans(m.pnIdSet)

	If m.lnButon = 2
		Return
	Endif

	*** Selectie din imobilizari
	Text To m.lcSql Textmerge Noshow
	SELECT I.ID_FACT,
	       I.ID_PART,
	       I.NRACT,
	       I.EXPLICATIA,
	       NVL(MF.DENUMIRE, I.EXPLICATIA4) AS EXPLICATIA4,
	       NVL(MF.EXPLICATIA, I.EXPLICATIA5) AS EXPLICATIA5,
	       I.ID_RESPONSABIL,
	       I.ID_LUCRARE,
	       I.ID_CTR,
	       P.DENUMIRE AS NUME,
	       P.COD_FISCAL,
	       R.DENUMIRE AS NRESP,
	       I.ID_VENCHELT,
	       VC.EXPLICATIE AS VENCHELT,       
	       L.NRORD,
	       (case
	         when c.numar is not null then
	          c.numar || '/'
	         else
	          ''
	       end) || TO_CHAR(c.data, 'DD.MM.YYYY') as contract,
	       I.ID_SUCURSALA,
	       NF.SUCURSALA,
    	   I.CONT,
	       I.ACONT,
	       MF.CONTVC,
	       MF.ACONTVC,
	       MF.ID_SECTIE,
	       S.SECTIE,
	       MF.AN, 
	       MF.LUNA, 
           MF.AN_EXP,
           MF.LUNA_EXP,	       
	       MF.ID_MF,
           MF.DENUMIRE AS DENUMIRE_IMOB,
	       MF.CONTVC,
	       MF.ACONTVC,
	       MF.DATA_OPERATIE,
	       MF.DPRIMA_RATA,
	       MF.DULTIMA_RATA,
	       (CASE when v.moneda_nationala = 1 OR NVL(i.id_valuta,0)= 0 then (CASE
	         WHEN I.AN = MF.AN_EXP AND I.LUNA = MF.LUNA_EXP THEN
	          MF.ULTIMA_RATA
	         ELSE
	          MF.RATA
	       END) else 0.00 end) AS SUMA,
	       (case when v.moneda_nationala = 0 then (CASE
	         WHEN I.AN = MF.AN_EXP AND I.LUNA = MF.LUNA_EXP THEN
	          MF.ULTIMA_RATA
	         ELSE
	          MF.RATA
	       END) else 0.00 end) AS SUMA_VAL,
	       i.id_valuta,
	       v.nume_val,
	       i.curs
	  FROM IREG_PARTENERI I LEFT JOIN NOM_PARTENERI P ON I.ID_PART = P.ID_PART
	  LEFT JOIN VNOM_VENCHEL VC ON I.ID_VENCHELT = VC.ID_VENCHELT
	  LEFT JOIN CONTRACTE C ON I.ID_CTR = C.ID_CTR
	  LEFT JOIN VNOM_SUCURSALE NF ON I.ID_SUCURSALA = NF.ID_SUCURSALA
	  left join vnom_valute v on i.id_valuta = v.id_valuta
	  JOIN (SELECT NMF.ID_FACT,
	                    NMF.ID_MF,
                        NMF.DENUMIRE,	                    
                        NMF.EXPLICATIA,
	                    LMF.CONT,
	                    LMF.ACONT,
	                    NMF.CONT AS CONTVC,
	                    NMF.ACONT AS ACONTVC,
	                    OMF.DATA_OPERATIE,
	                    CASE
	                      WHEN RMF.LUNA IS NOT NULL THEN
	                       ADD_MONTHS(TO_DATE(RMF.AN || RMF.LUNA, 'YYYYMM'), 1) - 1
	                      ELSE
	                       CAST(NULL AS DATE)
	                    END AS DPRIMA_RATA,
	                    CASE
	                      WHEN RMF.LUNA_EXP IS NOT NULL THEN
	                       ADD_MONTHS(TO_DATE(RMF.AN_EXP || RMF.LUNA_EXP,
	                                          'YYYYMM'),
	                                  1) - 1
	                      ELSE
	                       CAST(NULL AS DATE)
	                    END AS DULTIMA_RATA,
	                    RMF.AN,
	                    RMF.LUNA,
	                    RMF.AN_EXP,
	                    RMF.LUNA_EXP,
	                    RMF.RATA,
	                    RMF.ULTIMA_RATA,
	                    LMF.ID_LUCRARE,
	                    LMF.ID_SECTIE,
	                    LMF.ID_RESPONSABIL
	               FROM IMOB_NOM_MF NMF
	               JOIN IMOB_LISTA_MF LMF
	                 ON NMF.ID_MF = LMF.ID_MF
	                AND NMF.STERS = 0
	               JOIN (SELECT MF1.ID_MF, MAX(MF1.ID_LISTA_MF) ID_LISTA_MF
	                      FROM IMOB_LISTA_MF MF1
	                      JOIN IMOB_NOM_MF MF2 ON MF1.ID_MF = MF2.ID_MF
	                      WHERE MF2.ID_TIP_IMOBILIZARE IN (4, 5, 6)
	                      GROUP BY MF1.ID_MF) LMF2
	                 ON LMF.ID_LISTA_MF = LMF2.ID_LISTA_MF
	               JOIN IMOB_OPERATII_MF OMF
	                 ON NMF.ID_MF = OMF.ID_MF
	                AND OMF.STERS = 0
	               JOIN IMOB_CALCUL_RATE RMF
	                 ON NMF.ID_MF = RMF.ID_MF
	                AND RMF.STERS = 0
	              WHERE NMF.ID_TIP_IMOBILIZARE IN (4, 5, 6)) MF
	    ON I.ID_FACT = MF.ID_FACT AND I.AN*12+I.LUNA BETWEEN MF.AN*12+MF.LUNA AND MF.AN_EXP*12+MF.LUNA_EXP
	   AND NVL(MF.CONT, 'x') = NVL(I.CONT, 'x')
	   and NVL(MF.ACONT, 'x') = NVL(I.ACONT, 'x')	  
	  LEFT JOIN VNOM_LUCRARI L ON MF.ID_LUCRARE = L.ID_LUCRARE 
	  LEFT JOIN NOM_SECTII S ON MF.ID_SECTIE = S.ID_SECTIE
	  LEFT JOIN NOM_PARTENERI R ON MF.ID_RESPONSABIL = R.ID_PART	  
	  WHERE I.AN = ?m.gnAn AND I.LUNA = ?m.gnLuna AND I.CONT = ?m.pcCont <<STRTRAN(m.gcCondSucursala,'and id_sucursala', 'and i.id_sucursala',1,1,1)>>
	Endtext

	llSucces = goExecutor.oExecuta(m.lcSql, 'crsVenChelt')
	If !m.llSucces
		Return
	Endif
	
	* Calculez suma in lei pentru ratele in valuta
	UPDATE crsVenChelt SET suma = ROUND(suma_val * curs, m.gnPC) WHERE suma_val <> 0
	
	*** Completare ACT
	Select actactan
	Go Top
	Scatter Name m.loAct
	Zap

	If m.pcCont = '471'
		* 6xx = 471
		Insert Into actactan (scd, ascd, scc, ascc, id_partc, partc, id_sectie, sectie, id_lucrare, nrord, id_responsabil, nresp, ;
			    id_ctr, contract, suma, suma_val, id_valuta, nume_val, curs, id_factc, perechec, explicatia, explicatia4, explicatia5, id_sucursala) ;
			Select contvc As scd, acontvc As ascd, ;
			Cont As scc, ACONT As ascc, ;
			id_part As id_partc, nume As partc, ;
			Nvl(id_sectie, Cast(0 As I)) As id_sectie, Nvl(sectie, Space(50)) As sectie, ;
			Nvl(id_lucrare, Cast(0 As I)) As id_lucrare, Nvl(nrord, Space(50)) As nrord, ;
			Nvl(id_responsabil, Cast(0 As I)) As id_responsabil, Nvl(nresp, Space(50)) As nresp, ;
			Nvl(id_ctr, Cast(0 As I)) As id_ctr, Nvl(contract, Space(50)) As contract, suma, suma_val, id_valuta, nume_val, curs, ;
			id_fact As id_factc, nrACT As perechec, ;
			explicatia, ;
			'Rata ' + Alltrim(Str(((m.gnAn * 12 + m.gnluna) - (an * 12 + luna) + 1))) + '/' + Alltrim(Str(((an_exp * 12 + luna_exp) - (an * 12 + luna) + 1))) + ' ' + Alltrim(Nvl(explicatia4, '')) As explicatia4, ;
			explicatia5, ;
			id_sucursala ;
			From crsVenChelt ;
			Where !Empty(Nvl(suma, 0)) OR !Empty(Nvl(suma_val, 0))
	Else
		* 472 = 7xx
		Insert Into actactan (scd, ascd, scc, ascc, id_partd, partd, id_sectie, sectie, id_lucrare, nrord, id_responsabil, nresp, ;
			    id_ctr, contract, suma, suma_val, id_valuta, nume_val, curs, id_factd, pereched, explicatia, explicatia4, explicatia5, id_sucursala) ;
			Select Cont As scd, ACONT As ascd, ;
			contvc As scc, acontvc As ascc, ;
			id_part As id_partd, nume As partd, ;
			Nvl(id_sectie, Cast(0 As I)) As id_sectie, Nvl(sectie, Space(50)) As sectie, ;
			Nvl(id_lucrare, Cast(0 As I)) As id_lucrare, Nvl(nrord, Space(50)) As nrord, ;
			Nvl(id_responsabil, Cast(0 As I)) As id_responsabil, Nvl(nresp, Space(50)) As nresp, ;
			Nvl(id_ctr, Cast(0 As I)) As id_ctr, Nvl(contract, Space(50)) As contract, suma, suma_val, id_valuta, nume_val, curs, ;
			id_fact As id_factd, nrACT As pereched, ;
			explicatia, ;
			'Rata ' + Alltrim(Str(((m.gnAn * 12 + m.gnluna) - (an * 12 + luna) + 1))) + '/' + Alltrim(Str(((an_exp * 12 + luna_exp) - (an * 12 + luna) + 1))) + ' ' + Alltrim(Nvl(explicatia4, '')) As explicatia4, ;
			explicatia5, ;
			id_sucursala ;			
			From crsVenChelt ;
			Where !Empty(Nvl(suma, 0))
	Endif
	Use In (Select('crsVenChelt'))

	Select actactan
	Scan
		Gather Name m.loAct Fields Except scd, ascd, scc, ascc, id_partc, partc, id_partd, partd, id_sectie, sectie, id_lucrare, nrord, id_responsabil, nresp, ;
			id_ctr, contract, suma, suma_val, id_valuta, nume_val, curs, id_factc, perechec, id_factd, pereched, explicatia, explicatia4, explicatia5, id_sucursala
	Endscan
	If !Empty(Nvl(m.loAct.explicatia, ''))
		Update actactan Set explicatia = m.loAct.explicatia
	Endif


	Select .F. As ales, 0 As Cu_tva, Cast(0 As N(2)) As tipnota, T.* From actactan T Into Cursor tact Readwrite

	Use In (Select('actactan'))

	*** Verificare note contabile
	Select tact
	Go Top
	loForm = Createobject([frm_modific2007], m.pnIdSet, m.llNotaNoua)
	loForm.lb_titlu_alb_b121.Caption = Iif(m.pcCont = '471', 'Repunere cheltuieli in avans', Iif(m.pcCont = '472', 'Repunere venituri in avans', 'Subventii'))
	Select tact
	m.loForm.Show(1)

	If gnButon = 1
		Select tact
		Replace id_jtva_coloana With Null, proc_tva With 0 For Cu_tva = 0
		Select * From tact Into Cursor actactan Readwrite

		Select actactan
		Replace All id_util With gnIdUtil, id_set With m.pnIdSet
		Select actactan
		lnSucces  = OSCRIE_IN_FISIERE(0)
	Endif

	Use In (Select('tact'))
	Use In (Select('actactan'))


Endproc && repunere_cheltuieli_avans

********************************************
*** Editare set note definite de utilizator
********************************************
Define Class oxSet As Custom
	nIdSet = 0
	cXmlSets = ''
	cXmlRequest = ''
	cXmlNote = ''
	nIdSetNou = 99997 && Nota definita de utilizator

	Procedure Init
		Lparameters tnIdSet, tlNoLoad
		*** tlNoLoad: .T. nu se incarca xsets, xrequest, xnote (ex. la stergerea unui set nu este nevoie de incarcarea datelor)

		If Type('tnIdSet') = 'N'
			If !Empty(m.tnIdSet)
				This.nIdSet = m.tnIdSet
			Else
				This.nIdSet = This.nIdSetNou
			Endif
		Else
			This.nIdSet = This.nIdSetNou
		Endif

		*** Completez cXmlSets, cXmlRequest, cXmlNote
		If !m.tlNoLoad
			This.Load()
		Endif

	Endproc && Init

	*** schimb id_set in id_set_nou, astfel incat sa creez un set nou, in loc sa il actualizez pe cel vechi
	*** la salvarea unui set nou dintr-un set existent
	Procedure New
		This.nIdSet = This.nIdSetNou
	Endproc && New

	Procedure Delete
		Local llSucces
		Private pnIdSet

		pnIdSet = This.nIdSet

		lcSql = [begin pack_seturi.sterge_set(?pnIdSet); end;]
		llSucces = goExecutor.oExecuta(m.lcSql)
		Return m.llSucces
	Endproc

	Procedure Edit
		Local loFrmEditareSet As "frm_editare_set"
		Local llSucces, lcSql
		Private pnIdSet

		pnIdSet = This.nIdSet

		lcSql = [select label_item, id_item, id_fisier, fis_lista, camp_lista from xitems]
		llSucces = goExecutor.oExecuta(m.lcSql, [crsItems])
		If !m.llSucces
			Return m.llSucces
		Endif

		lcSql = [select categorie, id_categorie from xSetsCategorii where sters = 0 order by ordine]
		llSucces = goExecutor.oExecuta(m.lcSql, [crsCategorii])
		If !m.llSucces
			Return m.llSucces
		Endif

		This.Property2Cursor('cXmlRequest', 'crsRequest')
		This.Property2Cursor('cXmlSets', 'crsSet')

		If This.nIdSet = This.nIdSetNou
			Update crsSet Set nume_set = "Set nou " + Ttoc(Datetime()), id_set = 0, id_categorie = 0, categorie = ""
		Endif

		Select crsRequest
		loFrmEditareSet = Createobject("frm_editare_set", This)
		m.loFrmEditareSet.Show(1)
		llSucces = (m.gnButon = 1)

		Use In (Select('crsItems'))
		Use In (Select('crsCategorii'))
		Use In (Select('crsRequest'))
		Use In (Select('crsSet'))

		Return m.llSucces
	Endproc && Edit

	***************************************
	* Converteste un cursor in proprietate (ex: tact -> this.cXmlNote la salvarea unui model nou in nota fara predefinire)
	***************************************
	Procedure Cursor2Property
		Lparameters tcCursorName, tcProperty, tlNoSchema

		* tcCursorName: numele cursorului pentru conversia in xml
		* tcProperty: numele proprietatii: cxmlnote/cxmlsets/cxmlrequest; in functie de proprietate schimb numele nodului cursorului din xml in ceva fix, cunoscut in procedura din baza de date
		* tlNoSchema: daca xml-ul are nevoie de schema; in Oracle a dat eroare la parsarea xml cu schema; apelez fara schema in This.Save pentru salvarea xnote in baza de date

		Local lcCursorProp, lcCursorname, lcProperty, lcXML
		lcXML = ""
		lcCursorname = m.tcCursorName
		lcProperty = Alltrim(Lower(m.tcProperty))
		Do Case
			Case m.lcProperty = 'cxmlnote'
				lcCursorProp = "crsnote"
			Case m.lcProperty = 'cxmlsets'
				lcCursorProp = "crsset"
			Case m.lcProperty = 'cxmlrequest'
				lcCursorProp = "crsrequest"
		Endcase

		Cursortoxml(m.tcCursorName, 'lcXml', 1, 0 + 2 + 8, 0, Iif(m.tlNoSchema, "", "1"))

		If m.lcCursorname <> m.lcCursorProp
			lcXML = Strtran(m.lcXML, m.lcCursorname, m.lcCursorProp, 1, 10000, 1) && tact -> crsnote
		Endif
		This.&lcProperty = m.lcXML

	Endproc && Cursor2Property

	Procedure Property2Cursor
		Lparameters tcProperty, tcCursorName

		Local lcCursorname, lcProperty, lcXML
		lcCursorname = m.tcCursorName
		lcProperty = Alltrim(Lower(m.tcProperty))
		lcXML = This.&lcProperty

		Xmltocursor(m.lcXML, m.lcCursorname)
	Endproc && Property2Cursor

	***************************************
	* Citeste din baza de date informatiile despre xsets, xrequest, xnote si completeaza proprietatile clasei
	***************************************
	Procedure Load
		Private pnIdSet
		Local lcSql, llSucces
		pnIdSet = Iif(This.nIdSet <> 0, This.nIdSet, This.nIdSetNou)

		Text To m.lcSql Textmerge Noshow
		select s.id_set,
	       s.nr_set,
	       s.nume_set,
	       s.fix,
	       s.lista_note,
	       s.explicatia,
	       s.model,
	       s.formgest,
	       s.nu_sterg,
	       s.param1,
	       s.listare,
	       s.param2,
	       s.frm_date,
	       s.discount,
	       s.adaos,
	       s.factura,
	       s.id_selst,
	       s.id_seldr,
	       s.tip_doc,
	       s.tip_ctr,
	       s.expl_fixa,
	       s.aleg_cont,
	       s.frm_plata,
	       s.valuta,
	       s.compens,
	       s.id_tip_rul,
	       s.id_jnetax,
	       s.id_jtax,
	       s.tipjurnal,
	       s.id_jtaxn,
	       s.productie,
	       s.formproduc,
	       s.cursval,
	       s.id_categorie,
	       s.procedura_lans,
	       s.id_sucursala,
	       c.categorie
		  from xsets s left join xSetsCategorii c on s.id_categorie = c.id_categorie
		  where s.id_set = ?pnIdSet	
		Endtext

		llSucces = goExecutor.oExecuta(m.lcSql, [crsSet])
		If !m.llSucces
			Return m.llSucces
		Endif

		This.Cursor2Property("crsSet", "cXmlSets")
		Use In (Select('crsSet'))

		If This.nIdSet = 0
			Update crsSet Set nume_set = "Set nou " + Ttoc(Datetime()), id_set = 0, id_categorie = 0, categorie = ""
		Endif


		* Selectez din xrequest & xitems toate inregistrarile de pe id_set-ul curent, fara campurile de sume
		* Sumele se completeaza in xnote, nu in cererea de date
		Text To m.lcSql Textmerge Noshow
		select i.label_item,
		       s.nume_set,
		       r.valoare_default,
		       r.nr_item,
		       r.id_item,
		       r.id_set,
		       i.fis_lista,
		       i.id_fisier,
		       i.camp_lista,
		       i.x_init_val,
		       rpad(case
		              when i.fis_lista is not null then
		               pack_util.GetText(i.fis_lista,
		                                 i.id_fisier,
		                                 to_number(r.valoare_default),
		                                 replace(i.camp_lista, ',', ' || '' '' || '))
		              ELSE
		               r.valoare_default
		            end,
		            100,
		            ' ') as valoare_default_text
		  from xrequest r
		  join xsets s
		    on s.id_set = r.id_set
		  join xitems i
		    on i.id_item = r.id_item
		 where r.id_set = ?pnIdSet and 
		 	not ((lower(nvl(i.xinputmask, 'x')) like '%gnpa%' or 
	        lower(nvl(i.xinputmask, 'x')) like '%gnpcurs%' or
    	    lower(nvl(i.xinputmask, 'x')) like '%gnpval%') and i.id_item not in (21,22,23))
		 order by i.prioritate, r.nr_item
		Endtext

		llSucces = goExecutor.oExecuta(m.lcSql, [crsRequest])
		If !m.llSucces
			Return m.llSucces
		Endif

		This.Cursor2Property("crsRequest", "cXmlRequest")
		Use In (Select('crsRequest'))

		*** verific daca a fost deja completata This.cXmlNote pe INIT
		Text To m.lcSql Textmerge Noshow
		        SELECT decode(NVL(a.id_jtva_coloana, 0), 0, 0, 1) As Cu_tva, 
		           Cast(0 As Number(2)) As tipnota,
		             cast(0 as number(20)) as id_act,
		             cast(0 as number(2)) as luna,
		             cast(0 as number(4)) as an,
		             cast(0 as number(20)) as cod,
		             a.dataireg,
		             a.serie_act,
		             a.nract,
		             a.dataact,
		             a.explicatia,
		             a.xscd as scd,
		             a.xascd as ascd,
		             a.xscc as scc,
		             a.xascc as ascc,
		             a.suma,
		             a.pereched,
		             a.perechec,
		             a.suma_val,
		             a.id_valuta,
		             v.nume_val,
		             a.curs,
		             a.datascad,
		             0 AS neimpozab,
		             a.nnir,
		             cast(0 as number(5)) as id_util,
		             '' AS util,
		             sysdate as dataora,
		             cast(0 as number(5)) as id_utils,
		             '' AS utils,
		             sysdate as dataoras,
		             a.id_responsabil,
		             resp.denumire AS nresp,
		             a.id_venchelt,
		             venchelt.explicatie AS dst_chlt,
		             a.id_lucrare,
		             lucr.nrord,
		             a.id_ctr,
		             (case when ctr.numar is not null then ctr.numar || '/' else '' end) || TO_CHAR(ctr.data,'DD.MM.YYYY') as contract,
		             a.id_sectie,
		             sectii.sectie,
		             a.proc_tva,
		             a.id_set,
		             NVL(a.id_fact, 0) as id_fact,
		             a.id_partd,
		             part1.denumire AS partd,
		             a.id_partc,
		             part.denumire AS partc,
		             cast(0 as number(5)) as id_sucursala,
		             '' as sucursala,
		             a.id_fdoc,
		             fdoc.fel_document AS fdoc,
		             a.explicatia4,
		             a.explicatia5,
		             cast(0 as number(5)) as id_gestin,
		             '' AS gestin,
		             cast(0 as number(5)) as id_gestout,
		             '' AS gestout,
		             NVL(a.id_factd, 0) as id_factd,
		             NVL(a.id_factc, 0) as id_factc,
		             a.id_jtva_coloana,
		             jtva.denumire as explicatie_tva,
		             cast(0 AS NUMBER(1)) AS validat,
		             cast(0 as number(5)) as id_utilv,
		             '' as utilv,
		             SYSDATE AS dataorav,
		             NVL(doc.tva_incasare,0) as tva_incasare
		             from xnote a 
		          LEFT JOIN nom_fdoc fdoc ON a.id_fdoc = fdoc.id_fdoc
		          LEFT JOIN nom_parteneri part ON a.id_partc = part.id_part
		          LEFT JOIN nom_parteneri part1 ON a.id_partd = part1.id_part
		          LEFT JOIN vnom_venchel venchelt ON a.id_venchelt = venchelt.id_venchelt
		          LEFT JOIN nom_parteneri resp ON a.id_responsabil = resp.id_part
		          LEFT JOIN nom_sectii sectii ON a.id_sectie = sectii.id_sectie
		          LEFT JOIN vnom_lucrari lucr ON a.id_lucrare = lucr.id_lucrare
		          LEFT JOIN nom_valute v ON a.id_valuta = v.id_valuta
				  LEFT JOIN contracte ctr ON ctr.id_ctr = a.id_ctr          
		          LEFT JOIN jtva_coloane jtva ON a.id_jtva_coloana = jtva.id_jtva_coloana
		          LEFT JOIN documente doc on a.id_fact = doc.id_doc        	
				where a.id_set = ?pnIdSet
				order by nr_nota
		Endtext

		llSucces = goExecutor.oExecuta(m.lcSql, 'crsNote')

		If !m.llSucces
			Return m.llSucces
		Endif

		This.Cursor2Property("crsNote", "cXmlNote")
		Use In (Select('crsNote'))

		Return m.llSucces
	Endproc && Load

	Procedure Save
		Local lcSql, llSucces, lcXmlNote
		Private pcXmlNote, pcXmlRequest, pcXmlSets, pnIdSet

		pcXmlSets = This.cXmlSets
		pcXmlRequest = This.cXmlRequest
		pcXmlNote = ""

		* recreez xml note fara schema inline. pack_seturi.modifica_set dadea eroare cu schema inline
		Xmltocursor(This.cXmlNote, "cxmlnotetemp")
		Cursortoxml("cxmlnotetemp", 'pcXmlNote', 1, 0 + 2 + 8, 0, "")
		Use In (Select("cxmlnotetemp"))
		pcXmlNote = Strtran(m.pcXmlNote, "cxmlnotetemp", "crsnote", 1, 10000, 1) && crsnotetemp -> crsnote


		pnIdSet = Iif(This.nIdSet <> 0, This.nIdSet, This.nIdSetNou) && variabila privata declarata in oxSet.EditareSet()

		lcSql = [begin pack_seturi.modifica_set(?@m.pnIdSet, ?m.pcXmlSets, ?m.pcXmlNote, ?m.pcXmlRequest, ?gnIdUtil); end;]
		llSucces = goExecutor.oExecuta(m.lcSql)

		*** Pentru seturile noi se salveaza noul ID_SET in proprietatile clasei
		If m.llSucces
			This.nIdSet = m.pnIdSet
		Endif

		Return m.llSucces

	Endproc && Save

Enddefine && oSet
*******************************************************************
Procedure stornare_plinc
	Local loStornarePlInc, ldData, lnIdSet, lcCursorAct, lcCursorActan, lnSucces
	Private poRec, pnIdFact
	lnSucces = 1
	pnIdFact = 0
	lnIdSet = 10616
	ldData = Ttod(get_ora())
	If Month(m.ldData) <> gnluna Or Year(m.ldData) <> gnAn
		ldData = Gomonth(Date(gnAn, gnluna, 1), 1) - 1
	Endif
	poRec = Createobject('custom')
	With m.poRec
		.AddProperty('dataireg', m.ldData)
		.AddProperty('id_fdoc', 0)
		.AddProperty('fdoc', '')
		.AddProperty('nract', 0)
		.AddProperty('dataact', m.ldData)
		.AddProperty('cont', '')
		.AddProperty('tip_sold', '')
		.AddProperty('id_part', 0)
		.AddProperty('denumire', '')
		.AddProperty('datai', Date(gnAn, gnluna, 1))
		.AddProperty('dataf', m.ldData)
		.AddProperty('cod', 0)
		.AddProperty('cursor', '')
	Endwith

	Do Form frm_stornare_plinc Noshow Name m.loStornarePlInc Linked
	m.loStornarePlInc.Show(1)
	If gnButon = 1
		Select (m.poRec.Cursor)
		poRec.cod = cod

		Local loForm As [frm_modific2007]
		lcSql = [select a.*,a.suma as suma_orig,a.suma_val as suma_val_orig,0 as tipnota,decode(Nvl(id_jtva_coloana,0),0,0,1) as cu_tva ] + ;
			[from vact_tot a where a.cod = ] + Alltrim(Str(m.poRec.cod)) + [ order by a.id_act]
		lcCursor = Sys(2015)
		lcCursorModificare = [tact]
		lcCursorScriere = [actactan]
		If goExecutor.oExecuta(m.lcSql, m.lcCursor)
			Select .F. As ales, a.* From (m.lcCursor) a Into Cursor (m.lcCursorModificare) Readwrite

			Use In (Select(m.lcCursor))

			Update (m.lcCursorModificare) Set ;
				id_set = m.lnIdSet, ;
				id_util = gnIdUtil, ;
				dataireg = m.poRec.dataireg, ;
				dataact = m.poRec.dataact, ;
				serie_act = '', ;
				nrACT = m.poRec.nrACT, ;
				id_fdoc = m.poRec.id_fdoc, ;
				fdoc = m.poRec.fdoc, ;
				suma = (-1) * suma, ;
				suma_val = (-1) * suma_val

			* la notele de stornare 413 = 4111/401 = 403/ 404 = 405 nu trebuie sa am acelasi ID_FACT pe incasare/plata pentru ca apar in 413/403 doua inregistrari cu acelasi ID_FACT (+/-) si nu se pot inchide
			* generez alte ID_FACT
			Select (m.lcCursorModificare)
			Scan For scd = '413' Or Inlist(scc, '403', '405')
				pnIdFact = Nvl(id_fact, 0)
				If !Empty(m.pnIdFact)
					lnSucces = goExecutor.oSelect2Value("select seq_idfact.nextval from dual", @m.pnIdFact)
					If m.lnSucces > 0
						Replace id_fact With m.pnIdFact In (m.lcCursorModificare)
					Else
						amessagebox(goExecutor.cEroare, 0 + 48, _Screen.Caption)
						Exit
					Endif
				Endif
			Endscan

			Select (m.lcCursorModificare)
			Go Top

			loForm = Createobject([frm_modific2007], m.lnIdSet)
			loForm.lb_titlu_alb_b121.Caption = [Stornare plata / încasare]
			m.loForm.Show(1)

			If gnButon = 1
				Select * From (m.lcCursorModificare) Where suma <> 0 Into Cursor (m.lcCursorScriere) Readwrite
				Select (m.lcCursorScriere)
				OSCRIE_IN_FISIERE(0)
				Use In (m.lcCursorScriere)
			Endif
			Use In (m.lcCursorModificare)
		Endif
		Use In (m.poRec.Cursor)
	Endif
Endproc   