LOCAL cResp, cCmd

cTabla = 'cxc'

cCond = "A.Balance != 0 AND !M.void AND !M.agrupado "
ccIdS = ' '
IF !EMPTY(oJs.cParam)
	ccIdS = "and cust.idsalesman="+ALLTRIM(oJs.cParam)
ENDIF


TEXT TO cCmd NOSHOW	TEXTMERGE 

	SELECT	A.reference as referencia,
		  	CAST(A.Date as char) as fecha, 
			CAST(A.Due as char) as vence,
			CAST(ROUND(A.Total,2) as char) as total, 
			CAST(ROUND(A.Balance,2) as char) as saldo, 
			CAST(A.Cuota as char) as cuota,
			M.idcustomer+0 as idcustomer,
			M.idsalesman+0 as idsalesman,
			A.id+0 as idCuota,
			M.idinvoice+0 as idinvoice,
			M.idcc+0 as idcc,
			M.idcp+0 as idcp
	FROM AccountCus AS M INNER JOIN AccountCusCuota AS A on M.id = a.idaccountcus 
			LEFT JOIN Accountype      AS C on A.IdAccountype = C.Id 
			LEFT JOIN invoice         AS I on M.idinvoice = i.id 
			LEFT JOIN Customer        AS Cust on M.IdCustomer = Cust.Id 
			LEFT JOIN Salesman        AS Sales on Cust.IdSalesman = Sales.id
	WHERE  <<cCond>> <<ccIdS>> 
	ORDER BY M.idcustomer, A.date, A.reference, A.Cuota 
ENDTEXT

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

oApp.sqlexec(cCmd,cTabla)

oJs.android_up(cTabla)
