Query con las tablas OPCH,ODPO y OVPM

Hola buenas tardes, compañero
necesito realizar un reporte con las tablas de factura de proveedor, factura de anticipo y pagos efectuados

Pero necesito que igual me de el tipo de pago.

tengo el siguiente código pero no me da mas que puros de tipo proveedor

 SELECT 
 t1.DocNum 'Número de pago '
 ,case t1.DocType when 'C' then 'Cliente'
  when 'S' then 'Proveedor'
  when 'A' then 'Cuenta' else null end 'Tipo de pago'
 , t1.CardCode 'Codigo de prov'
 , t1.CardName 'Nombre de prov'
 ,T0.DocNum 'Número de fatura'
 ,fpi.OcrCode 'Departamento'
 ,fpi.OcrCode2 'Oficina'
 , t1.DocDate 'Fecha del contabilización'
 , t1.DocDueDate 'Fecha vencimiento'
 , t1.TaxDate 'Fecha documento'
 , case t1.DocCurr 
 when 'USD' then t1.TrsfrSumFC
 when 'MXP' then t1.TrsfrSum else
 t1.TrsfrSumFC end 'Monto del depósito'
 , t1.DocCurr 'Moneda del depósito'
 ,t1.TrsfrSumSy 'Monto del depósito en USD'
 ,t0.DocDate 'Fecha de factura'
 , Case t0.DocCur when 'USD' then t0.DocTotalFC-t0.VatSumFC
   when 'MXP' then t0.DocTotal-t0.VatSum
   else t0.DocTotalFC-t0.VatSumFC end 'Subtotal de factura'
 , t0.DocCur 'Moneda de factura'
 , Case t0.DocCur when 'USD' then t0.DocTotal-t0.VatSum
   when 'MXP' then t0.DocTotal-t0.VatSum
   else t0.DocTotal-t0.VatSum end 'Subtotal de factura en MXP'
 , Case t0.DocCur when 'USD' then t0.VatSumFC
    when 'MXP' then t0.VatSum
    else t0.VatSumFC end 'Impuesto'
 , Case t0.DocCur when 'USD' then t0.VatSum
    when 'MXP' then t0.VatSum
    else t0.VatSum end 'Impuesto en MXP'
 , Case t0.DocCur when 'USD' then t0.DocTotalFC
    when 'MXP' then t0.DocTotal
    else t0.DocTotalFC end 'Total Fact'
 , t0.Doctotal 'Total de Fact en MXP'
 , t0.DocTotalSy 'Total de Fact en USD'
 ,t0.U_CC_ProjectName 'Nombre del proyecto'
 ,t0.U_CC_ProjectCode 'Codigo del proyecto'
 ,t0.U_CC_AGCode 'Acuerdo global'
 FROM Odpo T0
 inner join dpo1 fpi on t0.DocEntry = fpi.DocEntry  
 inner JOIN OVPM T1 ON T1.DocEntry = T0.ReceiptNum
 where t1.Canceled='N' 
 group by t1.DocNum,t0.DocNum,T0.DocTotal,t1.Canceled,t1.DocDate,t1.DocCurr,t1.TrsfrSumFC,t1.TrsfrSum,t0.VatSum,t0.VatSumFC
 ,t0.DocTotalFC,t0.DocTotalSy,t1.TrsfrSumSy,t0.DocCur,t0.DocDate,t0.U_CC_ProjectName,t0.U_CC_ProjectCode,t0.U_CC_AGCode,t1.CardCode,
 t1.CardName,t1.DocDate,t1.DocDueDate,t1.TaxDate,fpi.OcrCode,fpi.OcrCode2,t1.DocType
  

 UNION ALL

 SELECT  
 t3.DocNum 'Número de pago '
 ,case t3.DocType when 'C' then 'Cliente'
  when 'S' then 'Proveedor'
  when 'A' then 'Cuenta' else null end 'Tipo de pago'
 , t3.CardCode 'Codigo de prov'
 , t3.CardName 'Nombre de prov'
  , t2.DocNum 'Número de fatura'
 , fp.OcrCode 'Departamento'
 , fp.OcrCode2 'Oficina'
 , t3.DocDate 'Fecha del contabilización'
 , t3.DocDueDate 'Fecha vencimiento'
 , t3.TaxDate 'Fecha documento'
 , case t3.DocCurr 
 when 'USD' then t3.TrsfrSumFC
 when 'MXP' then t3.TrsfrSum else
 t3.TrsfrSumFC end 'Monto del depósito'
 , t3.DocCurr 'Moneda del depósito'
 , t3.TrsfrSumSy 'Monto del depósito en USD'
 ,t2.DocDate 'Fecha de factura'
 , Case t2.DocCur when 'USD' then t2.DocTotalFC-t2.VatSumFC
   when 'MXP' then t2.DocTotal-t2.VatSum
   else t2.DocTotalFC-t2.VatSumFC end 'Subtotal de factura'
 , t2.DocCur 'Moneda de factura'
 , Case t2.DocCur when 'USD' then t2.DocTotal-t2.VatSum
   when 'MXP' then t2.DocTotal-t2.VatSum
   else t2.DocTotal-t2.VatSum end 'Subtotal de factura en MXP'
 , Case t2.DocCur when 'USD' then t2.VatSumFC
    when 'MXP' then t2.VatSum
    else t2.VatSumFC end 'Impuesto'
 , Case t2.DocCur when 'USD' then t2.VatSum
    when 'MXP' then t2.VatSum
    else t2.VatSum end 'Impuesto en MXP'
 , Case t2.DocCur when 'USD' then t2.DocTotalFC
    when 'MXP' then t2.DocTotal
    else t2.DocTotalFC end 'Total Fact'
  , t2.Doctotal 'Total de Fact en MXP'
 , t2.DocTotalSy 'Total de Fact en USD'
 , t2.U_CC_ProjectName 'Nombre del proyecto'
 , t2.U_CC_ProjectCode 'Codigo del proyecto'
 , t2.U_CC_AGCode 'Acuerdo global'
 FROM OPCH T2
 inner join pch1 fp on t2.DocEntry = fp.DocEntry  
 inner JOIN  OVPM T3 ON T3.DocEntry = T2.ReceiptNum 
 where t3.Canceled = 'N' 
  group by t3.DocNum,t2.DocNum,t2.DocTotal,t3.Canceled,t3.DocDate,t3.DocCurr,t3.TrsfrSumFC,t3.TrsfrSum,t2.VatSum,t2.VatSumFC
 ,t2.DocTotalFC,t2.DocTotalSy,t3.TrsfrSumSy,t2.DocCur,t2.DocDate,t2.Doctotal,t2.U_CC_ProjectName,t2.U_CC_ProjectCode,t2.U_CC_AGCode,
 t3.CardCode,t3.CardName, t3.DocDueDate,t3.TaxDate,fp.OcrCode,fp.OcrCode2,t3.DocType

Estimado Javier,
Esta parte no entendí tengo el siguiente código pero no me da mas que puros de tipo proveedor
La pregunta es ¿Le haces pagos a Clientes? o deseas ver y analizar los pagos recibidos de clientes? si es asi eso está en otra tabla ORCT de pagos recibidos.

Lo que necesito es información de pagos efectuados de proveedor
de un pago efectuado la lista de facturas que contiene ese pago para ello tengo que conectar las tres tablas
fact de proveedor y anticipo proveedor

los siguientes datos


y de las facturas tambien necesitaría información que están dentro pero no los muestra el pago

Hola ya pude mostrar los pagos con facturas proveedor y anticipo
Pero no me salen los pagos a cuentas como podría agregarlas les comparto la consulta

SELECT distinct T0.[DocNum] as ‘Numero de pago’
,case t0.DocType when ‘C’ then ‘Cliente’
when ‘S’ then ‘Proveedor’
when ‘A’ then ‘Cuenta’ else null end ‘Tipo de pago’
, t0.DocDate ‘Fecha del contabilización’
, t0.DocDueDate ‘Fecha vencimiento’
, t0.TaxDate ‘Fecha documento’
, T0.[CardCode] ‘Código de prov’
, T0.[CardName] ‘Nombre de proveedor’
, case t0.DocCurr
when ‘USD’ then t0.TrsfrSumFC
when ‘MXP’ then t0.TrsfrSum else
t0.TrsfrSumFC end ‘Monto del deposito’
, t0.DocCurr ‘Moneda del deposito’
, t0.TrsfrSumSy ‘Monto del deposito en USD’
, T4.[DocNum] as ‘Factura’
, b.OcrCode ‘Departamento Fact’
, b.OcrCode2 ‘Oficina fact’
, t4.DocDate ‘Fecha de factura’
, Case t4.DocCur when ‘USD’ then t4.DocTotalFC-t4.VatSumFC
when ‘MXP’ then t4.DocTotal-t4.VatSum
else t4.DocTotalFC-t4.VatSumFC end ‘Subtotal de factura’
, t4.DocCur ‘Moneda de factura’
, Case t4.DocCur when ‘USD’ then t4.DocTotal-t4.VatSum
when ‘MXP’ then t4.DocTotal-t4.VatSum
else t4.DocTotal-t4.VatSum end ‘Subtotal de factura en MXP’
, Case t4.DocCur when ‘USD’ then t4.VatSumFC
when ‘MXP’ then t4.VatSum
else t4.VatSumFC end ‘Impuesto fact’
, Case t4.DocCur when ‘USD’ then t4.VatSum
when ‘MXP’ then t4.VatSum
else t4.VatSum end ‘Impuesto en MXP fact’
, Case t4.DocCur when ‘USD’ then t4.DocTotalFC
when ‘MXP’ then t4.DocTotal
else t4.DocTotalFC end ‘Total Fact’
, t4.PaidToDate ‘Pago total fact’
, t4.Doctotal ‘Total de Fact en MXP’
, t4.DocTotalSy ‘Total de Fact en USD’
, t4.U_CC_ProjectName ‘Nombre del proyecto fct’
, t4.U_CC_ProjectCode ‘Codigo del proyecto fct’
, t4.U_CC_AGCode ‘Acuerdo global fct’
, T3.[DocNum] as ‘Factura Anticipo’
, a.OcrCode ‘Departamento Ant’
, a.OcrCode2 ‘Oficina atc’
, t3.DocDate ‘Fecha de factura atc’
, Case t3.DocCur when ‘USD’ then t3.DocTotalFC-t3.VatSumFC
when ‘MXP’ then t3.DocTotal-t3.VatSum
else t3.DocTotalFC-t3.VatSumFC end ‘Subtotal de factura atc’
, t3.DocCur ‘Moneda de factura atc’
, Case t3.DocCur when ‘USD’ then t3.DocTotal-t3.VatSum
when ‘MXP’ then t3.DocTotal-t3.VatSum
else t3.DocTotal-t3.VatSum end ‘Subtotal de factura en MXP atc’
, Case t3.DocCur when ‘USD’ then t3.VatSumFC
when ‘MXP’ then t3.VatSum
else t3.VatSumFC end ‘Impuesto atc’
, Case t3.DocCur when ‘USD’ then t3.VatSum
when ‘MXP’ then t3.VatSum
else t3.VatSum end ‘Impuesto en MXP atc’
, Case t3.DocCur when ‘USD’ then t3.DocTotalFC
when ‘MXP’ then t3.DocTotal
else t3.DocTotalFC end ‘Total Fact atc’
, t3.PaidToDate ‘Pago total atc’
, t3.Doctotal ‘Total de Fact en MXP atc’
, t3.DocTotalSy ‘Total de Fact en USD atc’
,t3.U_CC_ProjectName ‘Nombre del proyecto atc’
,t3.U_CC_ProjectCode ‘Codigo del proyecto atc’
,t3.U_CC_AGCode ‘Acuerdo global atc’
FROM
[dbo].[OVPM] T0
INNER JOIN VPM2 T1 ON T0.[DocEntry] = T1.[DocNum]
LEFT JOIN ODPO T3 ON T1. [DocEntry] = T3. [DocEntry]
left join dpo1 a on T3. [DocEntry] = a.DocEntry
LEFT JOIN OPCH T4 ON T1. [DocEntry]=T4. [DocEntry]
left join PCH1 b on T4. [DocEntry] = b.DocEntry
left join OJDT t5 on t0.TransId = t5.Number
WHERE T0.[Canceled] = ‘N’
order by T0.[DocNum]

1 me gusta

Javier, no se si ya hallas resuelto tu problema, pero te comento que si cambiar el inner join en

INNER JOIN VPM2 T1 ON T0.[DocEntry] = T1.[DocNum]

por left outer join

LEFT OUTER JOIN VPM2 T1 ON T0.[DocEntry] = T1.[DocNum]

podrás ver también los pagos a cuenta. Lo que pasa es que con el inner join solo muestras los registros de la tabla OVPM que se encuentran en la VPM2, pero los pagos a cuenta nunca estarán en la tabla VPM2, ya que esta guarda las facturas pagadas.

Espero esto te ayude.
Saludos.

2 Me gusta

Muchas gracias, si lo resolví de la forma que me indicas
Saludos