LOCAL cResp, cCmd, cIdUser,cItemGrupo,cPatron, cFecha,cUnidad
DECLARE aParam [1]

oApp.explode(oJs.cParam,@aParam,'|')

cRuc   = aParam[1]
cClave = aParam[2]

cResp = '{'



TEXT TO cmd noshow
	SELECT 
		 i.id as iditem,
		 i.name as detalle,
		 i.partnumber as codigo, 
		(SELECT stock    FROM stock WHERE iditem=i.id ) as cant_total,
		(SELECT costavg  FROM stock WHERE iditem=i.id ) as costo,
		(SELECT cantidad FROM stockbod WHERE idbodega=2 AND iditem=i.id ) as cant_01,
		(SELECT cantidad FROM stockbod WHERE idbodega=3 AND iditem=i.id ) as cant_02,
		(SELECT cantidad FROM stockbod WHERE idbodega=4 AND iditem=i.id ) as cant_03,
		(SELECT cantidad FROM stockbod WHERE idbodega=5 AND iditem=i.id ) as cant_04,
		(SELECT cantidad FROM stockbod WHERE idbodega=6 AND iditem=i.id ) as cant_05
	FROM item as i where i.idbrand in (select id from brand where ruc='@ruc')
ENDTEXT

cmd = STRTRAN(cmd,'@ruc',cRuc)

*STRTOFILE(cmd, '\eddy.txt')

cItemGrupo = ""	

IF oApp.sqlexec(cmd,'curItems')>0
	cItemGrupo = 'itemsgrupo:['
	SELECT curItems
	SCAN all
		IF LEN(cItemGrupo)>12
			cItemGrupo = cItemGrupo +  ','
		ENDIF
		
		
		cItemGrupo = cItemGrupo +  '['
		cItemGrupo = cItemGrupo + oJs.cll(curItems.iditem)
		cItemGrupo = cItemGrupo + oJs.cll(curItems.codigo)
		cItemGrupo = cItemGrupo + oJs.cll(curItems.detalle)
		cItemGrupo = cItemGrupo + oJs.cll(curItems.cant_total)
		cItemGrupo = cItemGrupo + oJs.cll(curItems.costo)
		cItemGrupo = cItemGrupo + oJs.cll(curItems.cant_01)
		cItemGrupo = cItemGrupo + oJs.cll(curItems.cant_02)
		cItemGrupo = cItemGrupo + oJs.cll(curItems.cant_03)
		cItemGrupo = cItemGrupo + oJs.cll(curItems.cant_04)
		cItemGrupo = cItemGrupo + oJs.cll(curItems.cant_05,.t.)
		cItemGrupo = cItemGrupo +  ']'
	ENDSCAN
	cItemGrupo = cItemGrupo + ']'
ENDIF

cResp = cResp  +cItemGrupo + '}'

*MESSAGEBOX(cResp)

cCmd = 'json/set_respuesta.php?id='+oJs.cIdCmd+'&resp='+cResp

*STRTOFILE(cCmd , '\eddy.txt')

oApp.runLink(cCmd)
