Buenas tardes estoy tratando de hacer un query pero no se como relacionar la tabla de pagos orct para que muestra el pago parcial o completo de la factura
Existe alguna persona que me pueda orientar
De antemanos Muchas Gracias
SELECT
DISTINCT(T0.DocNum) as 'Numero de Pedido',
T0.DocDate as 'Fecha de Pedido',
Case
When T0.DocStatus = 'O' and T0.Canceled = 'N' Then 'Abierto'
When T0.DocStatus = 'C' and T0.Canceled = 'N' Then 'Cerrado'
When T0.DocStatus = 'C' and T0.Canceled = 'Y' Then 'Cancelado'
else
''
end as 'Estatus de Pedido',
(T0.Doctotal-T0.vatsum) as 'Importe s/iva MXN OV',
T0.CardCode as 'Codigo Cliente',
T0.CardName as 'Nombre Cliente',
T3.DocNum as 'Numero de Entrega',
(T3.Doctotal-T3.vatsum) as 'Importe s/iva MXN ENT',
T5.DocNum as 'Numero de Factura',
T5.DocDate as 'Fecha de Factura',
(T5.Doctotal-T5.vatsum) as 'Importe s/iva MXN ENT'
FROM ORDR T0
INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry
LEFT JOIN DLN1 T2 ON T1.DocEntry = T2.BaseEntry
AND T1.LineNum = T2.BaseLine
AND T1.ObjType = T2.BaseType
LEFT JOIN ODLN T3 ON T2.DocEntry = T3.DocEntry
LEFT JOIN INV1 T4 ON (T2.DocEntry = T4.BaseEntry AND T2.LineNum = T4.BaseLine AND T2.ObjType = T4.BaseType)
OR
(T1.DocEntry = T4.BaseEntry AND T1.LineNum = T4.BaseLine AND T1.ObjType = T4.BaseType)
LEFT JOIN OINV T5 ON T4.DocEntry = T5.DocEntry
WHERE 1 = 1
and T1.TargetType<>14
AND T0.[DocDate] >='04-05-2022' AND T0.[DocDate] <= '04-05-2022'
ORDER BY T0.DocNum