LOCAL cResp, cCmd

campoStock = "(select stock from stock where iditem=item.id limit 1)"
campoCosto = "(select costavg from stock where iditem=item.id limit 1)"


cIdS = '0'
IF !EMPTY(oJs.cIdSalesman)	
	cIdS = ALLTRIM(TRANSFORM(oJs.cIdSalesman))
ENDIF

cCondSales = ' and aplica_pda '


IF oJs.filtrar_item 	
	IF oApp.sqlexec('select iditem from g_sales_item where idsalesman=?cIdS limit 10')>0
		cCondSales = ' and id in (select iditem from g_sales_item) ' 
	ENDIF
ENDIF


IF oApp.ghost_USAR_BODEGA=1
	campoStock = "(select cantidad from ghost.stockbod where iditem=item.id and idbodega="+oJs.cIdBodega+" limit 1)"
ENDIF


cTabla = 'item'
TEXT TO cCmd NOSHOW textmerge  
	SELECT 
		id+0 as id,
		name,note,noteunidad,
		lower(partnumber) as partnumber,
		lower(codigo2) as codigo2,
		price,priceb,pricec,priced,pricee,
		idbrand+0 as idbrand,
		idgrupo+0 as idgrupo,
		idprom+0 as idprom,
		unidadescaja,
		idItemProm+0 as iditemprom,
		BaseCant,PromCant,Base2,Prom2,act_prom2,descEsp,PromDesc,
		PorcDesc1,PorcDesc2,PorcDesc3,PorcDesc4,PorcDesc5,
		iva,
		idsupplier+0 as idsupplier,
		isservice,tipo,
		idcc+0 as idcc,
		idcp+0 as idcp,
		noesventa,
		<<campoCosto>> as costo,
		<<campoStock>> as stock,
		<<campoStock>> as stk00,
		<<campoStock>> as stk01,
		<<campoStock>> as stk02,
		<<campoStock>> as stk03,
		<<campoStock>> as stk04
	FROM item where !baja  <<cCondSales>>
ENDTEXT

*(select cantidad from stockbod where iditem=item.id and idbodega=00 limit 1)

*STRTOFILE (cCmd, '\temp\eddy_item.txt')

oApp.sqlexec(cCmd,cTabla)

oJs.android_up(cTabla)
