*!* 07.05.2010
*!* marius.mutu
*!* viz_stocuri - + codbare

PROCEDURE viz_stocuri
PARAMETERS tnTipGest,tcTipGest

LOCAL lnTipGest, lcFiltruInitial,lcTipGest, lcFiltruPermis
lcFiltruTipGest = ""
lcFiltruPermis = ""
lnTipGest = tnTipGest
lcTipGest = ""
IF EMPTY(tcTipGest)
	lcTipGest = []
ELSE
	lcTipGest = tcTipGest
ENDIF

lcFiltruInitial = [a.an=]+ Alltrim(Str(gnAn))+[ and a.luna=]+ Alltrim(Str(gnLuna))+;
	STRTRAN(gcCondSucursala,[id_sucursala],[a.id_sucursala])
IF !EMPTY(lnTipGest)
	lcFiltruTipGest = [ and a.nr_pag = ] + ALLTRIM(STR(lnTipGest))
ENDIF

IF EMPTY(gcGestPermis)
	lcFiltruPermis = [ and 1=2] 
else	
	lcFiltruPermis = [ and a.id_gestiune in (] + gcGestPermis + [)]
EndIf

lcFiltruInitial = lcFiltruInitial + lcFiltruTipGest + lcFiltruPermis

LOCAL lnStocObinv
lnStocObinv = 0
DO INAINTE_DE_STOC WITH gnAn, gnLuna, tnTipGest, lnStocObinv in oinainte_de.prg

PRIVATE postocuri,pcschema,pcselect,pcfiltru,pcorder
STORE '' TO postocuri

*!* 07.05.2010
pcschema=['nr_crt n(6),id_stoc n(20),an n(4),luna n(2),id_articol n(10),serie c(100),pret n(16,4),pretv n(16,4),'+]+;
	['tva n(16,4),tvav n(16,4),cants n(14,3),cant n(14,3),cante n(14,3),cont c(4),'+]+;
	['acont c(4),pretd n(16,4),dataora d,datain d,dataout d,proc_tvav n(5,2),'+]+;
	['id_gestiune n(5),codmat c(50),denumire c(100),um c(6),nr_pag n(2),nume_gestiune c(50),'+]+;
	['cgest c(20),um2 c(10),cant_bax n(9,4),grupa c(100),subgrupa c(100),id_valuta n(10), nume_val c(4),'+]+;
	['codmatf c(50), lot c(50), adata_expirare T,id_sucursala N(5),sucursala C(100),'+]+;
	['id_lucrare_rez N(10),nrord_rez C(50),id_part_rez N(10),part_rez C(100), codbare c(100),id_part N(10),furn_princ c(100), id_furnizor N(10), furnizor c(100), codnc8 C(20), greutate N(12,4), tara_origine C(100)']
	
pcselect=['select row_number() over (order by a.denumire) as nr_crt,a.id_stoc,a.an,a.luna,a.id_articol,a.serie,'+]+;
	['a.pret,a.pretv,a.tva,a.tvav,a.cants,a.cant,a.cante,a.cont,a.acont,a.pretd,a.dataora,'+]+;
	['a.datain,a.dataout,a.proc_tvav,'+]+;
	['a.id_gestiune,a.codmat,a.denumire,a.um,a.nr_pag,a.nume_gestiune,a.cgest,a.um2,a.cant_bax,a.grupa,a.subgrupa, a.id_valuta, a.nume_val, a.codmatf, a.lot, a.adata_expirare,'+]+;
	['a.id_sucursala,a.sucursala,'+]+;
	['a.id_lucrare_rez,a.nrord_rez,a.id_part_rez,a.part_rez, a.codbare,id_part,furn_princ, id_furnizor, furnizor, a.codnc8, a.greutate, a.tara_origine '+]+;
	['from vstoc a where 1=2']
*!* 07.05.2010 ^
pcfiltru = [1=2]
pcorder=[1]
llAfiseaza=.F.
_SCREEN.MOUSEPOINTER= 11
gencursor('postocuri','crsStocuri',pcselect,pcfiltru,pcschema,pcorder,llAfiseaza)
postocuri.ca_baza1.afisare()

LOCAL loStocuri
loStocuri=CREATEOBJECT('frm_stocuri')
_SCREEN.MOUSEPOINTER= 0
loStocuri.ntipgest = lnTipGest
PRIVATE pcListTipGest
pcListTipGest = []
lnOptgrValue = IIF(loStocuri.ntipgest<>0,IIF(loStocuri.ntipgest=6,2,IIF(loStocuri.ntipgest=7,4,1)),3)
WITH loStocuri
	.Lb_titlu_alb_b121.CAPTION = [STOCURI] + IIF(!EMPTY(lcTipGest),[ / ] + lcTipGest,[])
	.cFiltruInitial = lcFiltruInitial
	.optgrup.VALUE = lnOptgrValue
	IF lnOptgrValue = 1
		.optgrup.option2.VISIBLE = .F.
		.optgrup.option3.VISIBLE = .F.
		.optgrup.option4.VISIBLE = .F.
	ENDIF
	IF lnOptgrValue = 2
		.optgrup.option1.VISIBLE = .F.
		.optgrup.option3.VISIBLE = .F.
		.optgrup.option4.VISIBLE = .F.
	ENDIF
	IF lnOptgrValue = 4
		.optgrup.option1.VISIBLE = .F.
		.optgrup.option2.VISIBLE = .F.
		.optgrup.option3.VISIBLE = .F.
	ENDIF	
	.optgrup.ENABLED = IIF(.ntipgest<>0,.F.,.T.)
	IF .But_modifica1.VISIBLE
		.But_modifica1.VISIBLE = IIF(.ntipgest<>0,.T.,.F.)
	ENDIF
ENDWITH
loStocuri.SHOW(1)
RELEASE postocuri

ENDPROC && viz_stocuri
************************************************************************************************
PROCEDURE viz_stocuri_pretv
PARAMETERS tnTipGest,tcTipGest

LOCAL lnTipGest, lcFiltruInitial,lcTipGest, lcFiltruPermis
lcFiltruTipGest = ""
lcFiltruPermis = ""
lnTipGest = tnTipGest
lcTipGest = ""
IF EMPTY(tcTipGest)
	lcTipGest = []
ELSE
	lcTipGest = tcTipGest
ENDIF

lcFiltruInitial = [a.an=]+ Alltrim(Str(gnAn))+[ and a.luna=]+ Alltrim(Str(gnLuna))+;
	STRTRAN(gcCondSucursala,[id_sucursala],[a.id_sucursala])
IF !EMPTY(lnTipGest)
	lcFiltruTipGest = [ and a.nr_pag = ] + ALLTRIM(STR(lnTipGest))
ENDIF

IF EMPTY(gcGestPermis)
	lcFiltruPermis = [ and 1=2] 
else	
	lcFiltruPermis = [ and a.id_gestiune in (] + gcGestPermis + [)]
EndIf

lcFiltruInitial = lcFiltruInitial + lcFiltruTipGest + lcFiltruPermis

LOCAL lnStocObinv
lnStocObinv = 0
DO INAINTE_DE_STOC WITH gnAn, gnLuna, tnTipGest, lnStocObinv in oinainte_de.prg

PRIVATE postocuri,pcschema,pcselect,pcfiltru,pcorder
STORE '' TO postocuri

pcschema=['nr_crt n(6),an n(4),luna n(2),id_articol n(10),serie c(100),pretv n(16,4),'+]+;
	['tvav n(16,4),cants n(14,3),cant n(14,3),cante n(14,3),cont c(4),'+]+;
	['acont c(4),dataora d,datain d,dataout d,proc_tvav n(5,2),'+]+;
	['id_gestiune n(5),codmat c(50),denumire c(100),'+]+;
	['um c(6),nr_pag n(2),nume_gestiune c(50),cgest c(20),um2 c(10),cant_bax n(9,4),grupa c(100),'+]+;
	['subgrupa c(100), codmatf c(50), lot c(50), adata_expirare T,id_sucursala n(5),sucursala c(100),'+]+;
	['id_lucrare_rez N(10),nrord_rez C(50),id_part_rez N(10),part_rez C(100),id_part n(10),furn_princ c(100), id_furnizor N(10), furnizor c(100), codnc8 C(20), greutate N(12,4), tara_origine C(100)']	
pcselect=['select row_number() over (order by a.denumire) as nr_crt,a.an,a.luna,a.id_articol,a.serie,'+]+;
	['a.pretv,a.tvav,a.cants,'+]+;
	['a.cant,a.cante,a.cont,a.acont,a.dataora,'+]+;
	['a.datain,a.dataout,a.proc_tvav,'+]+;
	['a.id_gestiune,a.codmat,a.denumire,a.um,a.nr_pag,a.nume_gestiune,a.cgest,a.um2,a.cant_bax,a.grupa,'+]+;
	['a.subgrupa, a.codmatf, a.lot, a.adata_expirare,a.id_sucursala,a.sucursala,'+]+;
	['a.id_lucrare_rez,a.nrord_rez,a.id_part_rez,a.part_rez,a.id_part,a.furn_princ, a.id_furnizor, a.furnizor, a.codnc8, a.greutate, a.tara_origine '+]+;	
	[' from ]+ gcS+[.vstoc_pretv a where 1=2']

pcfiltru = [1=2]
pcorder=[1]
llAfiseaza=.F.
_SCREEN.MOUSEPOINTER= 11
gencursor('postocuri','crsStocuri',pcselect,pcfiltru,pcschema,pcorder,llAfiseaza)
postocuri.ca_baza1.afisare()

LOCAL loStocuri
loStocuri=CREATEOBJECT('frm_stocuri_pretv')
_SCREEN.MOUSEPOINTER= 0
loStocuri.ntipgest = lnTipGest
PRIVATE pcListTipGest
pcListTipGest = []
WITH loStocuri
	.Lb_titlu_alb_b121.CAPTION = [STOCURI] + IIF(!EMPTY(lcTipGest),[ / ] + lcTipGest,[])
	.cFiltruInitial = lcFiltruInitial
ENDWITH
loStocuri.SHOW(1)
RELEASE postocuri

ENDPROC && viz_stocuri_pretv
************************************************************************************************
PROCEDURE viz_stocuri_obinv
PARAMETERS tnTipGest,tcTipGest, tlInFolosinta

LOCAL lnTipGest, lcFiltruInitial,lcTipGest, lcFiltruPermis
lcFiltruTipGest = ""
lcFiltruPermis = ""
lnTipGest = tnTipGest
lcTipGest = ""

IF EMPTY(tcTipGest)
	lcTipGest = []
ELSE
	lcTipGest = tcTipGest
ENDIF

lcFiltruInitial = [a.an=]+ Alltrim(Str(gnAn))+[ and a.luna=]+ Alltrim(Str(gnLuna))+;
	STRTRAN(gcCondSucursala,[id_sucursala],[a.id_sucursala])
*!* 05.06.2008
*!* nu este nevoie de nr_pag in vstoc_obinv
*!*	IF !EMPTY(lnTipGest)
*!*		lcFiltruTipGest = [ and a.nr_pag = ] + ALLTRIM(STR(lnTipGest))
*!*	ENDIF
*!* 05.06.2008 ^

IF EMPTY(gcGestPermis)
	lcFiltruPermis = [ and 1=2] 
else	
	lcFiltruPermis = [ and a.id_gestiune in (] + gcGestPermis + [)]
EndIf

lcFiltruInitial = lcFiltruInitial + lcFiltruTipGest + lcFiltruPermis

LOCAL lnStocObinv
lnStocObinv = 1
DO INAINTE_DE_STOC WITH gnAn, gnLuna, tnTipGest, lnStocObinv in oinainte_de.prg


PRIVATE postocuri
Local lcSelect, lcFiltru, lcSchema, lcOrder, llAfiseaza,  lcGroup, llModParam, lcFiltruOriginal
STORE '' TO postocuri

IF tlInFolosinta
	lcSchema = [nr_crt n(6),id_stoc n(20),an n(4),luna n(2),id_articol n(10),serie c(100), lot c(20), pret n(16,4),cants n(14,3),cant n(14,3),cante n(14,3),cont c(4), ]+;
		[acont c(4),pretd n(16,4),dataora d,datain d,dataout d, ]+;
		[id_gestiune n(5),codmat c(50),denumire c(100),id_responsabil n(10),nresp c(30), ]+;
		[um c(6),cgest c(20),datapif d,dnf N(5),dns_luni n(10),nume_gestiune c(50), ]+;
		[marca N(10), id_meseria N(5), meserie C(64), id_formatia N(5), formatia C(64), dataang D, datalic D, ]+;
		[id_grupa N(5), grupa C(100), id_subgrupa N(5), subgrupa C(100), ]+;
		[um2 c(10),cant_bax n(9,4),id_sucursala N(5),sucursala C(100), furn_princ C(100), codnc8 C(20), greutate N(12,4), tara_origine C(100)]
ELSE
	lcschema = [nr_crt n(6),id_stoc n(20),an n(4),luna n(2),id_articol n(10),serie c(100),lot c(20),pret n(16,4),cants n(14,3),cant n(14,3),cante n(14,3),cont c(4), ]+;
		[acont c(4),pretd n(16,4),dataora d,datain d,dataout d, ]+;
		[id_gestiune n(5),codmat c(50),denumire c(100),id_responsabil n(10),nresp c(30), ]+;
		[um c(6),cgest c(20),datapif d,dns_luni n(10),nume_gestiune c(50), ]+;
		[um2 c(10),cant_bax n(9,4),grupa c(100),subgrupa c(100),id_sucursala N(5),sucursala C(100), furn_princ C(100), codnc8 C(20), greutate N(12,4), tara_origine C(100)]
ENDIF

IF tlInFolosinta
	lcselect = [select row_number() over (order by denumire) as nr_crt, ]+;
		[id_stoc, an, luna, id_articol, serie, lot,pret, cants, ]+;
		[cant, cante, cont, acont, pretd, dataora, datain, dataout, id_gestiune, ]+;
		[codmat, denumire, id_responsabil, nresp, ]+;
		[um, cgest, datapif, dnf, dns_luni, nume_gestiune, ]+;
		[marca, id_meseria, meseria, id_formatia, formatia, dataang, datalic, ]+;
		[id_grupa, grupa, id_subgrupa, subgrupa, um2, cant_bax,id_sucursala,sucursala,furn_princ, codnc8, greutate, tara_origine ]+;
		[ from vstoc_obinv_sal a]

ELSE
	lcselect = [select row_number() over (order by denumire) as nr_crt,id_stoc,an,luna,id_articol,serie,lot,pret,cants, ]+;
		[cant,cante,cont,acont,pretd,dataora,datain,dataout,id_gestiune,codmat,denumire,id_responsabil,nresp, ]+;
		[um,cgest,datapif,dns_luni,nume_gestiune,um2,cant_bax,grupa,subgrupa,id_sucursala,sucursala,furn_princ, codnc8, greutate, tara_origine ]+;
		[ from vstoc_obinv a]
ENDIF

lcFiltru = [1=2]
lcOrder = [1]
lcgroup = []
llAfiseaza=.F.
lcFiltruOriginal = []
llModParam = .T.
_SCREEN.MOUSEPOINTER= 11

gencursor('postocuri','crsStocuri', lcSelect, lcFiltru, lcSchema, lcOrder, llAfiseaza,  lcGroup, llModParam, lcFiltruOriginal)
postocuri.ca_baza1.afisare()
_SCREEN.MOUSEPOINTER= 0

PRIVATE pcListTipGest
LOCAL loStocuri
pcListTipGest = []
loStocuri=CREATEOBJECT('frm_stocuri_obinv',tlInFolosinta)
loStocuri.ntipgest = lnTipGest
lnOptgrValue = IIF(lnTipGest<>0,IIF(lnTipGest=6,2,1),3)
WITH loStocuri
	.Lb_titlu_alb_b121.CAPTION = [STOCURI / OBIECTE DE INVENTAR AFLATE IN FOLOSINTA]
	.cFiltruInitial = lcFiltruInitial
	.optgrup.VALUE = lnOptgrValue
	IF lnOptgrValue = 1
		.optgrup.option2.VISIBLE = .F.
		.optgrup.option3.VISIBLE = .F.
	ENDIF
	IF lnOptgrValue = 2
		.optgrup.option1.VISIBLE = .F.
		.optgrup.option3.VISIBLE = .F.
	ENDIF
	.optgrup.ENABLED = IIF(.ntipgest<>0,.F.,.T.)
	IF .But_modifica1.VISIBLE
		.But_modifica1.VISIBLE = IIF(.ntipgest<>0,.T.,.F.)
	ENDIF
ENDWITH
loStocuri.SHOW(1)
RELEASE postocuri

ENDPROC && viz_stocuri_obinv



