Hola!, ¿como están?... hoy les comparto una consulta con la cual podrán generar infinidad de reportes ya sean masivos o individuales para cada uno de sus proveedores, por ejemplo desde un Crystal Report.
Esta consulta tiene la información necesaria para poder aprovecharla de la mejor manera que ustedes decidan, si algo les hiciera falta no duden colocarlo en los comentarios.
SELECT T5.Street, T5.StreetNo, T5.Block, T5.City, T5.County, UPPER(t6.Name) as State
, UPPER(T7.Name) as Country, T5.ZipCode, convert(varchar,T1.[DocDate],103) as Fecha, T1.DocEntry, T1.[DocNum] as Pago, T3.[DocNum] as Provision
, CASE when t3.isIns = 'Y' then 'OC(s) ' +
ISNULL ((SELECT STUFF
((SELECT distinct ',' + CAST(DocNum AS VARCHAR(15))
FROM OPOR a
inner join POR1 b on a.DocEntry = b.DocEntry
WHERE b.TrgetEntry = t3.DocEntry
and a.CANCELED ='N' FOR XML PATH('')), 1, 1, '')), ' - ')
else
t3.[FolioPref] + '-' + CAST(T3.[FolioNum] as VARCHAR (15)) end as Factura
, T1.[CardCode] as [Codigo Proveedor]
, T1.[CardName] as [Nombre Proveedor], T9.E_mail, 'OP' as [Operacion Terminada]
, case t1.DocCurr when 'USD' then t3.DocTotalFC when 'MXN' Then t3.DocTotal end as [Monto Factura]
, case t1.DocCurr when 'USD' then AppliedFC when 'MXN' Then SumApplied end as [Monto Pagado]
, t1.DocCurr as 'Moneda'
, CASE when t3.isIns = 'Y' then '' else t3.NumAtCard end as UUID, convert(varchar,T1.TrsfrDate,103) as TrsfrDate
, CONVERT(varchar,convert(money,case t1.DocCurr when 'USD' then TrsfrSumFC when 'MXN' then T1.TrsfrSum end), 1) as [Monto Transferencia]
, T8.AcctName
FROM [dbo].[OVPM] T1 INNER JOIN VPM2 T2 ON T1.DocEntry = T2.DocNum
INNER JOIN OPCH T3 ON T2.DocEntry = T3.DocEntry
INNER JOIN OCRD T4 ON T4.CardCode = T1.CardCode
LEFT JOIN CRD1 T5 ON T5.CardCode = T4.CardCode and T5.AdresType = 'B'
LEFT JOIN OCST T6 ON T6.Code = T5.State
LEFT JOIN OCRY T7 ON t7.Code = T5.Country
LEFT JOIN OACT T8 on T8.AcctCode = T1.TrsfrAcct
LEFT JOIN OCRD T9 on T9.CardCode = T1.CardCode
WHERE T1.[CreateDate] between [%0] and [%1]
and T1.Canceled = 'N'
No hay comentarios:
Publicar un comentario