LOCAL cResp, cCmd

cIdS = oJs.cIdSalesman

cTabla = 'customer'


IF oJs.all_cust
	TEXT TO cCmd NOSHOW TEXTMERGE
	SELECT
	c.id+0 as id,		
	c.ruc,		
	c.name,		
	c.comercio,		
	c.address,		
	c.city,		
	c.email,		
	c.phone,		
	c.pvp,		
	c.codigo,		
	c.opcionpvp,		
	c.idsalesman+0 as idsalesman,		
	c.idzona+0 as idzona,		
	c.note as notas ,		
	c.secuencia ,		
	c.openaccount as cupo,		
	c.tipo as tipocliente,		
	c.diascredito,		
	1 as idvisita,		
	if(TRIM(c.horavisita)="","12:00:00",c.horavisita) as horavisita,		
	c.latitud ,		
	c.longitud  	
	FROM customer as c 
	where c.state=1 or c.id=0
	ENDTEXT
	
ELSE
	TEXT TO cCmd NOSHOW TEXTMERGE
	SELECT
	c.id+0 as id,		
	c.ruc,		
	c.name,		
	c.comercio,		
	c.address,		
	c.city,		
	c.email,		
	c.phone,		
	c.pvp,		
	c.codigo,		
	c.opcionpvp,		
	c.idsalesman+0 as idsalesman,		
	c.idzona+0 as idzona,		
	c.note as notas ,		
	c.secuencia ,		
	c.openaccount as cupo,		
	c.tipo as tipocliente,		
	c.diascredito,		
	vc.idvisitas+0 as idvisita,		
	if(TRIM(c.horavisita)="","12:00:00",c.horavisita) as horavisita,		
	c.latitud ,		
	c.longitud  	
	FROM customer as c 
	inner join visitascustomer as vc on c.id=vc.idcustomer 
	where (c.state=1 and vc.idsalesman = <<cIdS>>) or c.id=0 
	ENDTEXT
ENDIF

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

oApp.sqlexec(cCmd,cTabla)

oJs.android_up(cTabla)
