Procedure actualizare_tva2007
	Private pnActAct,pnActIregPart,pnActNote,pcAnLuna1,pcAnLuna2,pnLunaI,pnAnI,pnLunaF,pnAnF
	Store 0 To pnActAct,pnActIregPart,pnActNote,pnLunaI,pnAnI,pnLunaF,pnAnF
	Store "" To pcAnLuna1, pcAnLuna2
	IF m.glLunaInchisa
		AMESSAGEBOX('Luna este inchisa! Operatia nu este permisa.',0+64,_screen.Caption)
		RETURN
	ENDIF 
	IF m.gnAn<>2007
		AMESSAGEBOX('Operatia este permisa doar pentru 2007!',0+64,_screen.Caption)
		RETURN
	ENDIF 

	loActTva = Createobject("frm_actualizare_tva")
	loActTva.Show(1)
	If gnButon = 1
		pnLunaI = Val(Substr(pcAnLuna1,1,2))
		pnAnI = Val(Substr(pcAnLuna1,3))
		pnLunaF = Val(Substr(pcAnLuna2,1,2))
		pnAnF = Val(Substr(pcAnLuna2,3))
		_Screen.MousePointer = 11
		lcSql = [begin actualizare_TVA2007(?pnActAct,?pnActIregPart,?pnActNote,?pnLunaI,?pnAnI,?pnLunaF,?pnAnF); end;]
		lnSucces = goExecutor.oExecute(lcSql)
		_Screen.MousePointer = 0
		If lnSucces < 0
			amessagebox(goExecutor.cEroare, 0+16, "Eroare")
		Else
			amessagebox("Inregistrarile au fost actualizate!" + Chr(13) + Chr(10) + ;
				"Trebuie sa dati refacere in registrele de vanzari si cumparari incepand cu luna "+Iif(pnAnI<=2006,[01],Substr(pcAnLuna1,1,2)) +"/2007!",0+64,"Info actualizare")
		Endif
	Endif
Endproc
************************************************************************************************************************
Procedure actualizare_solduri_valuta

	IF m.glLunaInchisa
		AMESSAGEBOX('Luna este inchisa! Operatia nu este permisa.',0+64,_screen.Caption)
		RETURN
	ENDIF 

	Local lnIdSet, llVerificAnalitic, llCompletareParteneri, lcContAles
	Local loHash
	Local lcSql, lcCursor, lnSucces, lcSelect, lcSchema, lcSql, lcSelect2, lcOrder, lcFiltru, lcFiltruOriginal, loActualizare

	lnIdSet = 90501
	llVerificAnalitic = .T.
	llCompletareParteneri = .T.

	&& valute
	*!* 08.05.2008
	*!*	lcSql = "select ID_VALUTA, NUME_VAL, 0000000.0000 as curs from vnom_valute where moneda_nationala = 0 order by nume_val"
	&& ultima zi din luna curenta pentru cursul valutar
	ldUltimaZi = Gomonth(Date(gnAn, gnLuna, 1),1) - 1

	TEXT TO lcSql textmerge noshow
select V.ID_VALUTA, V.NUME_VAL, CAST(NVL(C.CURS, 0) AS NUMBER(18,6)) as curs
  from vnom_valute V
  LEFT JOIN (SELECT ID_VALUTA, MAX(CURS) AS CURS
               FROM CURS
              WHERE TO_DATE('<<Dtos(ldUltimaZi)>>', 'YYYYMMDD') BETWEEN DATA AND DATA2
              GROUP BY ID_VALUTA) C ON V.ID_VALUTA = C.ID_VALUTA
 where V.moneda_nationala = 0
 order by V.nume_val
	ENDTEXT
	*!* 08.05.2008 ^

	lcCursor = "crsValute"
	lnSucces = goExecutor.oExecute(lcSql, lcCursor)
	If lnSucces < 0
		amessagebox(goExecutor.cEroare, 0+16, "Eroare")
	Endif

	*!*		SELECT * FROM crsValuteTemp INTO CURSOR crsValute READWRITE
	*!*		USE IN crsValuteTemp

	&& conturi cu inregistrari sau trezorerie
*!* 08.05.2008
*!* selecta sumele din balanta_parteneri si pentru 542 (trebuia doar pentru 5124, 5314)
*!* acum se poate face reevaluarea pentru toate conturile cu balanta de parteneri, nu numai pentru clasa 5
*!*		lcSql = "select cont, explicatie, fel_cont,cu_inregistrari from config_cont_ireg where cu_inregistrari = 1 or SUBSTR(cont,1,1) = '5' order by cont"
	lcSql = "select cont, explicatie, fel_cont,cu_inregistrari from config_cont_ireg order by cont"
*!* 09.05.2008 ^
	lcCursor = "crsConturi"
	lnSucces = goExecutor.oExecute(lcSql, lcCursor)
	If lnSucces < 0
		amessagebox(goExecutor.cEroare, 0+16, "Eroare")
	Endif


	&& cursor gol cu facturi
	Private poireg_parteneri, pobalanta_parteneri
	Store '' To poireg_parteneri, pobalanta_parteneri


	lcSchema = [an n(4), luna n(2), ales N(1), id_fact n(20), id_part n(20), cont c(4), acont c(4), ID_VALUTA N(5), ] + ;
		[PRECDEB N(20,4),PRECCRED N(20,4),PRECVALDEB N(20,4),PRECVALCRED N(20,4), ] + ;
		[debit n(20,4),credit n(20,4),valdebit n(20,4), valcredit n(20,4), ] + ;
		[nract N(20),DATAACT D,DATAIREG D,DATASCAD D,CURS N(18,6), ] + ;
		[NUME C(100), NUME_VAL C(10), ] + ;
		[CURSBNR N(18,6), SOLDVAL n(20,4), SOLDLEI n(20,4), DIFERENTA N(20,4), proc_tva n(10,4), id_jtva_coloana i]

	lcSelect = [SELECT AN, LUNA, 1 as ales, ID_FACT, ID_PART, CONT, ACONT, ID_VALUTA, ] +;
		[PRECDEB, PRECCRED, PRECVALDEB, PRECVALCRED, ] +;
		[DEBIT, CREDIT, VALDEBIT, VALCREDIT, ] +;
		[NRACT, DATAACT, DATAIREG, DATASCAD, CURS, ] +;
		[NUME, NUME_VAL, ] + ;
		[000000.000000 as cursbnr, 000000000.0000 as soldval, 000000000.0000 as soldlei, 000000000.0000 as diferenta, proc_tva, id_jtva_coloana ] + ;
		[ FROM VIREG_PARTENERI]

	lcSelect2 = [SELECT AN, LUNA, 1 as ales, 0 AS ID_FACT, ID_PART, CONT, ACONT, ID_VALUTA, ] +;
		[PRECDEB, PRECCRED, PRECVALDEB, PRECVALCRED, ] +;
		[DEBIT, CREDIT, VALDEBIT, VALCREDIT, ] +;
		[0 AS NRACT, TO_DATE('', 'YYYYMMDD') AS DATAACT, TO_DATE('', 'YYYYMMDD') AS DATAIREG, TO_DATE('', 'YYYYMMDD') AS DATASCAD, 000000.0000 AS CURS, ] +;
		[NUME, NUME_VAL, ] + ;
		[000000.0000 as cursbnr, 000000000.0000 as soldval, 000000000.0000 as soldlei, 000000000.0000 as diferenta, 0000.0000 as proc_tva, 0000000000 as id_jtva_coloana ] + ;
		[ FROM VBALANTA_PARTENERI]

	lcOrder = [dataact]
	lcFiltru = [1=2]
	lcFiltruOriginal = [an = ?gnAn and luna = ?gnLuna and (precvaldeb + valdebit - precvalcred - valcredit <> 0)]
	loHash = GetHash()
	loHash.SetValue('cNume', 'poireg_parteneri')
	loHash.SetValue('cAlias', 'crsFacturi')
	loHash.SetValue('cSelect', lcSelect)
	loHash.SetValue('cFiltru', lcFiltru)
	loHash.SetValue('cSchema', lcSchema)
	loHash.SetValue('cOrder', lcOrder)
	loHash.SetValue('lAfisare', .F.)
	*!*	loHash.SetValue('cGroup', '' )
	loHash.SetValue('lModParam', .T.)
	loHash.SetValue('cFiltruOriginal', lcFiltruOriginal)

	&& cursor adapter pentru inregistrari parteneri
	gencursor_hash(loHash)
	poireg_parteneri.ca_baza1.afisare()

	&& cursor adapter pentru balanta parteneri
	loHash.SetValue('cNume', 'pobalanta_parteneri')
	loHash.SetValue('cSelect', lcSelect2)
	gencursor_hash(loHash)

	*!* formular calcul diferente - creeaza cursorul crsActTemp
	*!*		SELECT crsValute
	loActualizare = Createobject("frm_actualizare_facturi_valuta")
	loActualizare.Show(1)

	*!*		lcCursor = "crsActTemp"
	*!*		IF gnButon = 1

	*!*			SELECT crsFacturi
	*!*			LOCATE
	*!*			lcContAles = ALLTRIM(CONT)
	*!*			SELECT crsConturi
	*!*			LOCATE FOR ALLTRIM(CONT) == lcContAles
	*!*			IF FOUND()
	*!*				lnFelCont = fel_cont
	*!*			ELSE
	*!*				lnFelCont = 0
	*!*			ENDIF

	*!*
	*!*			SELECT an, luna, ID_FACT, ID_PART AS ID_PARTD, NUME AS PARTD, ID_PART AS ID_PARTC, NUME AS PARTC, ;
	*!*				SPACE(4) as scd, acont AS ascd, SPACE(4) as scc, acont AS ascc, diferenta AS SUMA, ;
	*!*				nract AS pereched, ID_FACT AS id_factd, ;
	*!*				nract AS perechec, ID_FACT AS id_factc, ;
	*!*				cursBNR AS CURS, nume_val, id_valuta, ;
	*!*				PADR('DIFERENTE REEVALUARE;' + ALLTRIM(TRANSFORM(CURS)) + ';' + ALLTRIM(TRANSFORM(CURSBNR)), 50, ' ') as explicatia, ;
	*!*				PADR(ALLTRIM(TRANSFORM(CURS)), 50, ' ') AS EXPLICATIA4 ;
	*!*				FROM crsFacturi ;
	*!*				WHERE diferenta <> 0 ;
	*!*				INTO CURSOR crsActTemp ;
	*!*				READWRITE

	*!*			IF _TALLY > 0

	*!*				SELECT crsActTemp
	*!*				REPLACE ALL SCD WITH lcContAles, SCC WITH "765 ", ascc WITH '', ID_PARTC WITH 0, PARTC WITH '', PERECHEC WITH 0 ;
	*!*				FOR (SUMA>0 AND lnFelCont = 0) OR (SUMA<0 AND lnFelCont = 0)

	*!*				REPLACE ALL SCD WITH "665 ", ascd WITH '', SCC WITH lcContAles, ID_PARTD WITH 0, PARTD WITH '', PERECHED WITH 0 ;
	*!*				FOR (SUMA<0 AND lnFelCont = 0) OR (SUMA>0 AND lnFelCont = 1)
	*!*
	*!*				REPLACE ALL EXPLICATIA WITH STRTRAN(EXPLICATIA, 'REEVALUARE', 'FAVORABILE') FOR SCC = '765'
	*!*				REPLACE ALL EXPLICATIA WITH STRTRAN(EXPLICATIA, 'REEVALUARE', 'NEFAVORABILE') FOR SCD = '665'

	*!*				REPLACE ALL SUMA WITH ABS(SUMA)


	*!*				lnSucces = scrie_nota_import(lnIdSet, llVerificAnalitic, llCompletareParteneri, "crsActTemp")
	*!*			ENDIF
	*!*		ENDIF


	If Used('crsValute')
		Use In crsValute
	Endif
	If Used('crsConturi')
		Use In crsConturi
	Endif
	If Used('crsFacturi')
		Use In crsFacturi
	Endif
Endproc && actualizare_solduri_valuta
