Buenas tardes estimado he creado un query donde me refleje la antiguedad de saldos, pero me he topado con el inconveniente de no poder restar las Notas de Credito, Anticipos de Clientes y Asientos contables realizados a algunos clientes el query que tengo es el siguiente:
select
'0.No Vencido' as Grupo,
T0.DocDate,
t0.DocDueDate,
DATEDIFF(day,t0.docduedate, getdate()) as Dias,
T0.CardCode,
T0.CardName,
T0.DocTotal,
T0.PaidToDate,
T0.DocTotal-T0.PaidToDate AS Saldo
from OINV T0
WHERE --T0.DocDate > '2017-01-01'
--AND
T0.PaidToDate != T0.DocTotal
AND T0.DocDueDate > GETDATE()
union all
select
'0-30' as Grupo,
T0.DocDate,
t0.DocDueDate,
DATEDIFF(day,t0.docduedate, getdate()) as Dias,
T0.CardCode,
T0.CardName,
T0.DocTotal,
T0.PaidToDate,
T0.DocTotal-T0.PaidToDate AS Saldo,
T1.Balance
from OINV T0
LEFT OUTER JOIN OCRD T1 ON T1.CardCode = T0.CardCode
Where/* T0.DocDate > '2017-01-01' and T0.CardCode='C00080' AND*/
T0.PaidToDate != T0.DocTotal AND DATEDIFF(day,T0.DocDueDate, getdate()) >= 0 and DATEDIFF(day,T0.DocDueDate, getdate()) <= 30 and T1.CardType ='C'