LOCAL cResp, cCmd

cIdS = ''
IF !EMPTY(oJs.cParam)
*!*		IF oApp.sqlexec('select idsalesman from user where id='+oJs.cParam,'curS')>0
*!*			cIdS = curS.idsalesman
*!*		ENDIF
	
	cIdS = TRANSFORM(oJs.cParam)
ENDIF



cTabla = 'customer'

cond = IIF(EMPTY(cIdS), "", " and idsalesman = "+cIdS)

TEXT TO cCmd NOSHOW TEXTMERGE 
	SELECT 
		id+0 as id,
		ruc,
		name,
		comercio,
		address,
		city,
		email,
		phone,
		pvp,
		codigo,
		opcionpvp,
		idsalesman+0 as idsalesman,
		idzona+0 as idzona,
		note as notas ,
		secuencia ,
		openaccount as cupo,
		tipo as tipocliente,
		diascredito,
		idvisitas+0 as idvisita,
		if(TRIM(horavisita)="","12:00:00",horavisita) as horavisita,
		latitud ,
		longitud  
	FROM customer WHERE state=1 <<cond>> 
ENDTEXT

oApp.sqlexec(cCmd,cTabla)


oJs.json_up(cTabla)
