*!* 27.02.2012
*!* marius.mutu
*!* verificare inainte_de in functie de optiune 0 = VERIFICARE, 1 = NU SE VERIFICA, 2 = INTREBARE UTILIZATOR

*!*	14.07.2017
*!*	marius.mutu
*!*	INAINTE_DE_STOC
*!*	adaugat parametru tcListaIdGestiuni (optional) pentru verificarea unei liste de gestiuni la adaugare inventar

*******************************************
* PROCEDURE INAINTE( tcProc, tcCont )
* Data/ora : 10/27/04, 11:30:19
* autor : liana.macinic
* descriere:

****** PARAMETER BLOCK **************
* Parametri : 2
* Parameter 1: numele procedurii de pe server
* Parameter 2: contul
*
*******************************************

*!*	do inainte WITH "IREG_parteneri",lcContPart in oinainte_de.prg

Procedure INAINTE( tcProc, tcCont, tcVMesaj, tcVTip, tcExceptii, tcCoresp, tnLuna, tnAn )
	Local lcProc, lcCont, lcMesaj, lcTip, llProgress, lnLuna, lnAn

	*!* 27.02.2012
	If Type('gnVerificareInainte') <> 'N'
		Local gnVerificareInainte
		gnVerificareInainte = 0
	Endif

	*** FARA VERIFICARE
	If gnVerificareInainte = 1
		Wait Window 'Nu se verifica corelatiile...' Nowait
		Return
	Endif

	*** INTREBARE UTILIZATOR
	If gnVerificareInainte = 2
		lnOptiune = xmenu("\<Fara verificare corelatii;\-;\<Verificare corelatii")
		If m.lnOptiune = 1
			Wait Window 'Nu se verifica corelatiile...' Nowait
			Return
		Endif
	Endif
	*!* 27.02.2012 ^

	If Empty(tnLuna)
		lnLuna = gnLuna
	Else
		lnLuna = tnLuna
	Endif

	If Empty(tnAn)
		lnAn = gnAn
	Else
		lnAn = tnAn
	Endif

	*!*	IF !EMPTY(tcCont) AND tcCont = '4118'
	*!*		DEBUG
	*!*		SUSPEND
	*!*	ENDIF

	lcProc = "INAINTE_DE_" + Alltrim(tcProc)

	If Empty(tcCont)
		lcCont = ""
	Else
		lcCont = [, '] + Alltrim(tcCont) + [']
	Endif

	*---le-am bagat pentru lista conturilor corespondente (vanz)
	If !Empty(tcExceptii)
		lcCont = lcCont + [,] + tcExceptii
	Endif

	If !Empty(tcCoresp)
		lcCont = lcCont + [,] + tcCoresp
	Endif
	*---le-am bagat pentru lista conturilor corespondente

	If Empty(tcVMesaj)
		llProgress = .T.
	Else
		llProgress = .F.
	Endif

	lcSql = [select PACK_INAINTE_DE.] + lcProc + [(] + Alltrim(Str(lnAn)) + [,] + Alltrim(Str(lnLuna)) + [,?gnIdSucursala] + lcCont + [) AS VALOARE FROM DUAL]&&[select * from ] + gcS + [.calendar]
	lcCursor = [crsRezultate]
	lnSucces = goExecutor.oExecute(lcSql, lcCursor, llProgress)

	If lnSucces < 0
		aMessagebox(goExecutor.cEroare, 0 + 16, "Eroare")
	Else
		Select crsRezultate
		If !Empty(valoare) And !Isnull(valoare)
			lcMasaj = crsRezultate.valoare

			If 'VANZ2007' $ Upper(lcProc) Or 'CUMP2007' $ Upper(lcProc)
				aMessagebox(lcMasaj, 0 + 48, 'Diferente')
			Else

				lnOccurs = Occurs(crlf, lcMasaj)
				For i = 1 To lnOccurs
					lcString = Strextract(lcMasaj, ':', crlf, i)
					If Substr(lcString, 1, 1) = "<" && diferente intre suma analiticelor si sintetice
						lcString1 = Substr(lcString, 2, Len(lcString) - 2)
					Else
						lcString1 = Transform(Val(Strtran(lcString, ' ', '')), '999 999 999 999 999.9999')
					Endif
					lcMasaj = Strtran(lcMasaj, lcString, " " + Alltrim(lcString1))
				Endfor

				If Substr(valoare, 2, 2) == Chr(13) + Chr(10)
					lcTip = Substr(valoare, 1, 1)
					lcMesaj = Substr(lcMasaj, 4)
				Else
					lcTip = ""
					lcMesaj = lcMasaj
				Endif

				If Empty(tcVMesaj)
					lcMasaj = Substr(lcMasaj, 4)
					If !Empty(lcMasaj)
						aMessagebox(lcMasaj, 0 + 48, 'Diferente ' + STRTRAN(STRTRAN(TRANSFORM(m.lcCont), [,], []), ['], [],1,2))
						*!*							ooo = CREATEOBJECT('frm_inainte_de')
						*!*							ooo.cMesaj = lcMasaj
						*!*							ooo.edit1.HEIGHT = lnOccurs*20
						*!*							ooo.HEIGHT = 54 + lnOccurs*20
						*!*							ooo.AUTOCENTER = .T.
						*!*							ooo.SHOW()

						*!*							RELEASE ooo
					Endif
				Else
					If !Empty(tcVTip)
						&tcVTip = lcTip
					Endif
					&tcVMesaj = lcMesaj
				Endif
			Endif && 'VANZ2007'$UPPER(lcProc) OR 'CUMP2007'$UPPER(lcProc)
		Endif && !EMPTY(valoare) AND !ISNULL(valoare)

		goExecutor.oReset()
		Use In crsRezultate
	Endif
Endproc

**********************sfarsit procedura INAINTE*******************

* PROCEDURE test_ireg( tcCont, tnActiv )
* Date : 02.11.2004, 16:05:34
* author : catalin.neagu
* description:

****** PARAMETER BLOCK **************
* Parameters : 2
* Parameter 1:
* Parameter 2:
*
******************************************* INCEPUT:test_ireg *******************************************
Procedure test_ireg( tcCont, tlActiv, tnLuna, tnAn )

	Local lcCont, lnActiv, lnLuna, lnAn
	lnActiv = 0
	If tlActiv
		lnActiv = 1
	Endif
	If Empty(tnLuna)
		lnLuna = gnLuna
	Else
		lnLuna = tnLuna
	Endif

	If Empty(tnAn)
		lnAn = gnAn
	Else
		lnAn = tnAn
	Endif

	lcCont = Alltrim(tcCont)
	lcSql = [select PACK_INAINTE_DE.TEST_INREGISTRARI(] + Alltrim(Str(lnAn)) + [,] + Alltrim(Str(lnLuna)) + [,?gnIdSucursala,'] + lcCont + [',] + Alltrim(Str(lnActiv)) + [) AS VALOARE FROM DUAL]&&[select * from ] + gcS + [.calendar]
	*!*		STRTOFILE(lcSql,'c:\inaintedetest.txt')
	lcCursor = [crsRezultate]
	lnSucces = goExecutor.oExecute(lcSql, lcCursor)

	If lnSucces < 0
		aMessagebox(goExecutor.cEroare, 0 + 16, "Eroare")
	Else

		Select crsRezultate
		If !Empty(valoare) And !Isnull(valoare)
			valoare = Alltrim(valoare)
			lcOcurr = Occurs('*', valoare)
			lcValoare = Iif(Substr(valoare, 1, 1) = '*', '', '*') + valoare
			Dimension laMesaje(lcOcurr)
			For i = 1 To lcOcurr
				laMesaje[i] = Strextract(lcValoare, '*', '*', i)
			Endfor
		Endif .
		*!*	PUBLIC ARRAY lam(1,3)

		If Type('laMesaje') # "U"
			otree = Createobject('teste_ireg', @laMesaje, lcCont, lnActiv)
			otree.Show(1)
			Release otree
		Endif
		goExecutor.oReset()
		Use In crsRezultate
	Endif

Endproc
******************************************* SFARSIT: test_ireg *******************************************


* PROCEDURE test_casa( tcCont, tnActiv )
* Date : 25.05.2005, 10:16:34
* author : georgiana.voicu
* description:

****** PARAMETER BLOCK **************
* Parameters : 2
* Parameter 1:
* Parameter 2:
*
******************************************* INCEPUT:test_casa *******************************************
Procedure test_casa
	Lparameters tcCont
	Private pcContTestCasa
	pcContTestCasa = Alltrim(tcCont)
	
	
	*!* 27.02.2012
	If Type('gnVerificareInainte') <> 'N'
		Local gnVerificareInainte
		gnVerificareInainte = 0
	Endif

	*** FARA VERIFICARE
	If gnVerificareInainte = 1
		Wait Window 'Nu se verifica corelatiile...' Nowait
		Return
	Endif

	*** INTREBARE UTILIZATOR
	If gnVerificareInainte = 2
		lnOptiune = xmenu("\<Fara test casa;\-;\<Test casa")
		If m.lnOptiune = 1
			Wait Window 'Nu se face test casa...' Nowait
			Return
		Endif
	Endif
	*!* 27.02.2012 ^
		
	lcSql = [select PACK_INAINTE_DE.TEST_CASA(?gnAn,?gnLuna,?pcContTestCasa,?gnIdSucursala) AS VALOARE FROM DUAL]
	lcCursor = [crsRezultate]
	*!*		lt1 = Datetime()
	lnSucces = goExecutor.oExecute(lcSql, lcCursor)
	*!*		lt2 = Datetime()
	If lnSucces < 0
		aMessagebox(goExecutor.cEroare, 0 + 16, "Eroare")
	Else
		*!*		MessageBox(Ttoc(lt1,3)+Chr(13)+Chr(10)+Ttoc(lt2,3)+Chr(13)+Chr(10)+Ttoc(lt3,3)+Chr(13)+Chr(10)+Ttoc(lt4,3)+Chr(13)+Chr(10))
		Select crsRezultate
		If !Empty(valoare) And !Isnull(valoare)
			valoare = Alltrim(valoare)
			lcOcurr = Occurs('*', valoare)
			lcValoare = Iif(Substr(valoare, 1, 1) = '*', '', '*') + valoare
			*!*	modificare	v 2.0.124
			*!*			Strtofile(Strtran(lcValoare,[*],Chr(13)+Chr(10)),[C:\2.txt])
			If Type('goLog') = 'O'
				goLog.Log(Strtran(lcValoare, [*], Chr(13) + Chr(10)))
			Endif
			*!*	modificare	v 2.0.124	^
			Dimension laMesaje(lcOcurr)
			For i = 1 To lcOcurr
				laMesaje[i] = Strextract(lcValoare, '*', '*', i)
			Endfor
		Endif

		If Type('laMesaje') # "U"
			otree = Createobject('teste_ireg', @laMesaje)
			otree.Lb_titlu_alb_b121.Caption = [TEST CASA]
			otree.Show(1)
			Release otree
		Endif
		goExecutor.oReset()

		If Used('crsRezultate')
			Use In crsRezultate
		Endif
	Endif
	Release pcContTestCasa
Endproc
******************************************* SFARSIT: test_casa *******************************************

******************************************* INCEPUT: verific_stoc_cu_balanta *******************************************
Procedure verific_stoc_cu_balanta
	Parameters tcCont, tnOptiune

	Local lcCont, lnOptiune, lnOccurs, lcValoare, i
	i = 1

	lnOptiune = tnOptiune
	lcCont = Alltrim(tcCont)


	*!*	lcSql = [select PACK_INAINTE_DE.INAINTE_DE_STOC(']+lcCont+[',?gnAn,?gnLuna,]+ALLTRIM(STR(lnOptiune))+[,?gnIdSucursala) AS VALOARE FROM DUAL]
	lcSql = [select pack_inainte_de.inainte_de_stoc('] + lcCont + [',] + Alltrim(Str(gnAn)) + "," + Alltrim(Str(gnLuna)) + "," + ;
		+ Iif(Isnull(gnIdSucursala), "null", Alltrim(Str(gnIdSucursala))) + "," + Alltrim(Str(lnOptiune)) + ") as valoare from dual"
	*STRTOFILE(lcsql,'c:\pack_inainte_destoc.txt')
	lcCursor = [crsRezultate]
	lnSucces = goExecutor.oExecute(lcSql, lcCursor)

	If lnSucces < 0
		aMessagebox(goExecutor.cEroare, 0 + 16, "Eroare")
	Else

		Select crsRezultate
		lcValoare = Alltrim(valoare)
		*STRTOFILE(lcValoare+CHR(13)+'Apare de :'+STR(OCCURS(CHR(10),lcValoare)),'c:\valoare.txt')

		lcStr = Strextract(lcValoare, ' = ', '  ', i)
		lcStr = Alltrim(lcStr)

		Do While !Empty(lcStr)
			lcStr = Strextract(lcValoare, ' = ', '  ', i)&& extrag elem i
			lcStr = Alltrim(Strtran(lcStr, ' ', '') )&& in caz ca este formatat ii scoate spatiile libere
			lcValoare = Strtran(lcValoare, ' ' + lcStr + '  ', ' ' + Alltrim(Transform(Val(lcStr), '999 999 999 999 999.99')) + '  ')
			i = i + 1
			lcStr = Strextract(lcValoare, ' = ', '  ', i)
			*lcStr=ALLTRIM(STRTRAN(lcStr,' ','') )
		Enddo
		lnOccurs = Occurs(Chr(10), lcValoare)
		ooo = Createobject('frm_inainte_de')
		ooo.cMesaj = lcValoare
		**ooo.width = 550
		ooo.edit1.Height = lnOccurs * 20
		ooo.Height = 54 + lnOccurs * 20
		ooo.AutoCenter = .T.
		ooo.Show()

		Release ooo
		Use In crsRezultate
	Endif

Endproc
******************************************* SFARSIT: verific_stoc_cu_balanta *******************************************

************************
*** Verifica stocul cantitativ si valoric al lunii curente fata de luna precedenta
************************
Procedure INAINTE_DE_STOC
	Parameters tnAn, tnLuna, tnTipGest, tnStocObinv, tcListaIdGestiuni

	Local lcCursor, lcSql, lnSucces, lcSelect, lcValoare
	Local lcIdGestiune, lnGestiune, lnGestiuni, lnIdGestiune, lcSeparator, lcListaIdGestiuni
	lcValoare = ''
	lcSeparator = '|'
	lcSelect = Select()

	If Empty(Nvl(tcListaIdGestiuni, ''))
		lcListaIdGestiuni = 'null'
	ELSE
		&& elimin separatorul de lista, daca apare la sfarsit. considera ca este un element 
		lcListaIdGestiuni = IIF(RIGHT(ALLTRIM(m.tcListaIdGestiuni),1) = m.lcSeparator, LEFT(ALLTRIM(m.tcListaIdGestiuni), LEN(ALLTRIM(m.tcListaIdGestiuni)) - 1), ALLTRIM(m.tcListaIdGestiuni))
		&& elimin "" sau ''
		lcListaIdGestiuni = STRTRAN(STRTRAN(m.lcListaIdGestiuni, ["], []), ['], [])
	Endif

	lnGestiuni = Getwordcount(m.lcListaIdGestiuni, '|')
	For lnGestiune = 1 To m.lnGestiuni
		lcIdGestiune = Getwordnum(m.lcListaIdGestiuni, m.lnGestiune, '|')
		
		Wait Window 'Verificare stoc precedent ... ' + ;
			IIF(m.lcIdGestiune <> 'null', m.lcIdGestiune, 'toate gestiunile') + ;
			IIF(m.tnTipGest = 2, ' tip materii prime/materiale', ;
			IIF(m.tnTipGest = 3, ' tip obiecte inventar', ;
			IIF(m.tnTipGest = 4, ' tip produse', ;
			IIF(m.tnTipGest = 5, ' tip marfa pret achizitie', ;
			IIF(m.tnTipGest = 6, ' tip marfa pret vanzare', ;
			IIF(m.tnTipGest = 7, ' tip marfa pret achizitie*','')))))) NOWAIT 
		
		lnIdGestiune = Iif(LOWER(m.lcIdGestiune) = 'null', Null, Int(Val(m.lcIdGestiune)))

		lcSql = "select pack_inainte_de.inainte_de_stoc(" + Alltrim(Str(tnAn)) + "," + Alltrim(Str(tnLuna)) + "," + ;
			Alltrim(Str(tnTipGest)) + "," + Alltrim(Str(tnStocObinv)) + "," + Iif(Isnull(gnIdSucursala), "null", Alltrim(Str(gnIdSucursala))) + "," + Iif(Empty(Nvl(m.lnIdGestiune, '')), "null", Alltrim(Str(lnIdGestiune))) + ") as valoare from dual"
		lcCursor = [crsRezultate]
		lnSucces = goExecutor.oExecute(lcSql, lcCursor)

		If lnSucces < 0
			aMessagebox(goExecutor.cEroare, 0 + 16, "Eroare")
		ELSE
			Select crsRezultate
			IF !EMPTY(ALLTRIM(Nvl(valoare, '')))
				lcValoare = lcValoare + ALLTRIM(Nvl(valoare, '')) + Chr(13) + Chr(10)
			ENDIF 	
		Endif
		Use In (Select('crsRezultate'))
	Endfor

	If !Empty(m.lcValoare)
		aMessagebox(m.lcValoare, 0 + 48, "Verificare")
	ENDIF
	
	Select (m.lcSelect)
	Return m.lcValoare
Endproc && INAINTE_DE_STOC
