Mostrando entradas con la etiqueta SAP B1 - Informes. Mostrar todas las entradas
Mostrando entradas con la etiqueta SAP B1 - Informes. Mostrar todas las entradas

domingo, 26 de marzo de 2023

Inventarios - Lotes en Transferencias de Stock, Facturas. Etc. (Registro histórico)

Hola Amigos, les traigo una consulta que les puede ser muy util cuando requieren obtener los lotes afectados en uno o varios documentos, estos pueden ser una salida, una entrega, una factura, una devolución, una nota de crédito, etc.

Para eso les haré un ejemplo con las transferencias de stock:

SELECT T5.DocEntry, T5.DocNum, t5.DocDate, T5.UserSign, T5.Filler, T5.ToWhsCode,  T5.Comments  
                , T6.FromWhsCod, T6.LineNum, t6.LineStatus, t6.unitMsr, t6.Quantity, T1.ItemCode 
                , T6.WhsCode, T2.DistNumber, T0.Quantity as QDistNumber 
                FROM OWTR T5  
                inner join WTR1 T6 on T5.DocEntry = T6.DocEntry  
INNER JOIN OITL T1 ON T5.DocEntry = T1.ApplyEntry  
INNER JOIN ITL1 T0 ON T0.LogEntry = T1.LogEntry                
                INNER JOIN OBTN T2 ON T0.ItemCode = T2.ItemCode AND T0.SysNumber = T2.SysNumber                 
                where T5.DocDate > '20230126' and T5.CANCELED = 'N' And T1.ApplyType = 67 and T0.Quantity > 0 

Espero les ayude para sus informes, ¡saludos!.

jueves, 23 de junio de 2022

Bancos - Asociar facturas con su pago recibido

Me he topado un sin fin de ocasiones con la mala asociación de tablas en reportes que buscan unir las facturas de clientes con su pago recibido, por eso les dejo está consulta simple pero muy utilizada y que por lo mismo debemos asegurarnos este correcta:

FROM ORCT E
LEFT JOIN RCT2 T1 ON T1.DocNum=E.DocEntry
LEFT JOIN OINV T2 ON T2.DocEntry=T1.DocEntry
WHERE E."DocEntry"= {?DocKey@};

¡Saludos!

miércoles, 22 de junio de 2022

Gestión - Tiempos de timbrado en Integration Framework B1if

En esta consulta podremos ver los tiempos en que se genero el documento en SAP B1 y en el que el PAC (México) nos devolvió el timbrado con el Integration Framework.

SELECT T0.[DocNum], T0.CardName, T0.[DocEntry], T0.[CreateDate], T0.[CreateTS], T1.[CreateTS], T1.[U_B1SYS_FechaTimbr] , t1.ReportID, t2.U_NAME
FROM OINV T0 left JOIN ECM2 T1 ON T0.[DocEntry]= T1.[SrcObjAbs] AND  T0.[ObjType]= T1.[SrcObjType] 
INNER JOIN OUSR T2 ON T1.UserSign = T2.INTERNAL_K 
WHERE T0.[CreateDate]='20210512'
order by DocNum

¡Saludos!

Gestión - Tablas Query Manager, Búsquedas formateadas, Modelos de Autorización y Reportes/Layouts Crystal Report

Les comparto en esta publicación las 4 tablas generalmente más demandadas en los procesos de las compañías (ojo no en todas) que debería correr cualquier consultor que este migrando SAP B1 SQL a HANA, para de esta manera saber a lo que se está enfrentando en una o más bases de datos:
  1. Query Manager
  2. Busquedas Formateadas
  3. Modelos de Autorización
  4. Reportes y Layouts Crystal Report
Las siguientes consultas son el script básico, pueden adornarlas como a ustedes mejor les convenga:

Query Manager
select T0."CatName", T1."QName"  from OQCN T0
inner join OUQR T1 on T0."CategoryId" = T1."QCategory"
where CatName not in ('SAP_DASHBOARD_002_DAB012_QUERY','Sistema','KPI_MOBILE_HANA','KPI_MOBILE')
and CatName not like ('SAP_DASHBOARD_%')
Order by T0."CatName"
 
Busquedas formateadas
Select CASE FormID when 133 then 'Factura Deudores' 
when 134 then  'Socio de Negocios'
when 804 then 'Catalogo de cuentas'
when 179 then 'Nota de Crédito' 
end FORM, ItemID,  QName
from CSHS a
inner join OUQR b on a.QueryId = b.IntrnalKey
 
Reportes y Layouts Crystal Report
select DocCode, DocName from RDOC
where Author not in ('System')
and TypeCode = 'RCRI'
 
Modelos de autorización
select a.Name 'Nombre Modelo', a.Remarks 'Descripción Modelo', c.Name as 'Nombre Etapa' , c.Remarks as 'Descripción Etapa'
,  e.U_NAME as  'Autorizador', c.MaxReqr as 'Autorizaciones requeridas', c.MaxRejReqr as 'Rechazos requeridos'
from OWTM a
inner join WTM2 b on a.WtmCode = b.WtmCode
inner join OWST c on b.WstCode = c.WstCode
inner join WST1 d on c.WstCode = d.WstCode
inner join OUSR e on d.UserID = e.USERID
where a.Active = 'Y'
order by [Nombre Modelo] , Autorizador,
[Nombre Modelo] , Autorizador 

¡Saludos!

martes, 21 de septiembre de 2021

Inventarios - Obtener el costo de artículo por Almacén en SAP

Hola de nuevo,

Les comparto como pueden obtener el costo de los artículos por almacén, esto nos ayuda bastante a la hora de detectar cuales no tienen costo, SAP en algunas de sus transacciones no no los permite según este configurado el sistema, como sabemos para darle un costo debemos usar la Revaloración de Inventario en el modulo de Inventarios.

SELECT distinct d.itemcode, c.ItemName, d.AvgPrice , d.WhsCode
from OITM c
inner join OITW d on c.ItemCode = d.ItemCode 
where d.WhsCode = 'CEDIS'

Espero les sirva. 

domingo, 25 de abril de 2021

Inventarios - Stock por lote y ubicación

Hola, después de no publicar un buen rato, les traigo algo que les ayudará mucho, un informe de Stock por Lote y Ubicación, ya que por almacén ya se los tenia desde el 2016 desde este Enlace.

Pero estando trabajando ahora con ubicaciones, requerí tenerlo por ubicaciones y aquí se los comparto:

SELECT OBTN.[DistNumber], 
       OBBQ.[OnHandQty],
   OBBQ.[ItemCode], 
   OBIN.[BinCode],
   OBIN.[AbsEntry],
   OBBQ.[WhsCode]  FROM OBBQ /* Esta tabla  como pueden ver es la importante aquí  */ 
       INNER JOIN OBTN 
   ON OBTN.[AbsEntry] = OBBQ.[SnBMDAbs]
       INNER JOIN OBIN ON OBIN.[AbsEntry] = OBBQ.[BinAbs]
       WHERE OBBQ.[OnHandQty] > 0 
   order by OBBQ.[ItemCode]

martes, 10 de diciembre de 2019

Inventario - Análisis de Artículos - PIVOTE

Hola!, buen día 😀... les dejo esta consulta con dos finalidades:
  1. Consultar en SAP la ultima entrada (fecha, total cantidad 1 año y cantidad ultima salida) y la ultima salida  (fecha, total cantidad 1 año y cantidad ultima salida) de los artículos.
  2. Conozcas a través de un ejercicio como funciona el Pivote en SQL Server, en este caso utilizo a los almacenes que están en una misma columna para que se abra cada almacén en una solo columna una por cada almacén, de esta forma evito repeticiones en el Item de mi consulta.
Espero les ayude bastante, hasta la próxima!.

select ItemCode, ItemName, OnHand, ItmsGrpNam,[Fecha de producción],[Ultima Entrada], [Cantidad Ultima Salida], [Total Salidas]
, [Cantidad Ultima Entrada], [Total Entradas], [Ultima Salida], [ALM1], [ALM2], [ALM3],[ALM4] 
from (
select a.ItemCode, a.ItemName, a.OnHand, b.ItmsGrpNam
, a.createDate as [Fecha de producción]
, (select MAX(createDate) from OINM where ItemCode = a.ItemCode and  TransType in (20,69,10000071)) as [Ultima Entrada]
, (select SUM(InQty) from OINM where ItemCode = a.ItemCode and  TransType in (20,69,10000071) and createDate = ( select MAX(createDate) from OINM where ItemCode = a.ItemCode and  TransType in (20,69,10000071)  ) ) as [Cantidad Ultima Entrada]
, (select SUM(InQty) from OINM where ItemCode = a.ItemCode and  TransType in (20,69,10000071) and createDate  between '20180101' and '20181231'  ) as [Total Entradas 2018]
, (select MAX(createDate) from OINM where ItemCode = a.ItemCode and  TransType in (60)) as [Ultima Salida]
, (select SUM(OutQty) from OINM where ItemCode = a.ItemCode and  TransType in (60) and createDate = ( select MAX(createDate) from OINM where ItemCode = a.ItemCode and  TransType in (60)  ) ) as [Cantidad Ultima Salida]
, (select SUM(OutQty) from OINM where ItemCode = a.ItemCode and  TransType in (60) and createDate between '20180101' and '20181231' ) as [Total Salidas 2018]
, c.OnHand [Stock en WHSE], a.BuyUnitMsr,a.InvntryUom, c.WhsCode
, CASE  
WHEN a.validFor = 'Y' and a.frozenFor = 'N' THEN 'Activo'
WHEN a.validFor = 'N' and a.frozenFor = 'Y' THEN 'Inactivo'
EnD as Activo
  from OITM a
inner join OITB b on a.ItmsGrpCod = b.ItmsGrpCod 
left join OITW c on a.ItemCode = c.ItemCode
and c.WhsCode in ('ALM1', 'ALM2', 'ALM3','ALM4') 
) consulta
PIVOT
(
AVG (consulta.[Stock en WHSE])
FOR WhsCode in ([ALM1], [ALM2], [ALM3],[ALM4])
)AS pvt

sábado, 7 de diciembre de 2019

Ventas - Ventas por cliente y articulo

Hola!, paso de forma muy rapída para compartirles esta consulta que me han solicitado mucho los agentes de ventas y que a ustedes les puede servir mucho de igual manera, saludos!.

select a.CardCode,
c.CardName,
a.DocDate,
DATEPART(month , a.DocDate) AS Periodo,
DATEPART(YEAR , a.DocDate) AS Año,
case a.DocSubType 
when 'DN' THEN 'Nota de débito'
when '--' THEN 'Factura'
END AS [Tipo de dcumento], 
a.DocNum,
a.DocEntry IrDocumento,
b.ItemCode,
case a.DocType When 'S' THEN b.dscription ELSE d.ItemName  END AS ItemName, 
b.Price,
case a.CANCELED
WHEN 'C' THEN case a.DocType When 'S' THEN -1 ELSE b.Quantity * -1  END
WHEN 'N' THEN case a.DocType When 'S' THEN 1 ELSE b.Quantity END
ELSE case a.DocType When 'S' THEN 1 ELSE b.Quantity END
END as Quantity,
case a.CANCELED WHEN 'C'
THEN case a.DocType When 'S'
 THEN case a.CurSource WHEN 'L' THEN  (b.Price * 1) * - 1 ELSE (b.Price * 1) * e.rate  * -1 END
ELSE case a.CurSource WHEN 'L' THEN  (b.Price * b.Quantity)  * -1 ELSE (b.Price * b.Quantity) * e.rate * -1 END
END
WHEN 'N' THEN
case a.DocType When 'S'
        THEN case a.CurSource WHEN 'L' THEN  (b.Price * 1)  ELSE (b.Price * 1) * e.rate END
ELSE          case a.CurSource WHEN 'L' THEN  (b.Price * b.Quantity)  ELSE (b.Price * b.Quantity) * e.rate END
END
ELSE
case a.DocType When 'S'
        THEN case a.CurSource WHEN 'L' THEN  (b.Price * 1)  ELSE (b.Price * 1) * e.rate END
ELSE          case a.CurSource WHEN 'L' THEN  (b.Price * b.Quantity)  ELSE (b.Price * b.Quantity) * e.rate END
END
END
AS [Total MXN],
case a.CANCELED WHEN 'C'
THEN case a.DocType When 'S'
 THEN
case a.CurSource WHEN 'C' THEN (b.Price * 1) * -1 ELSE (b.Price * 1) / e.rate * -1 END
ELSE
case a.CurSource WHEN 'C' THEN (b.Price * b.Quantity)  * -1 ELSE (b.Price * b.Quantity)  / e.rate* -1 END
END
WHEN 'N' THEN
case a.DocType When 'S'
 THEN
case a.CurSource WHEN 'C' THEN (b.Price * 1)  ELSE (b.Price * 1)  / e.rate END
ELSE
case a.CurSource WHEN 'C' THEN (b.Price * b.Quantity) ELSE (b.Price * b.Quantity) / e.rate END
END
ELSE
case a.DocType When 'S'
 THEN
case a.CurSource WHEN 'C' THEN (b.Price * 1)  ELSE (b.Price * 1)  / e.rate END
ELSE
case a.CurSource WHEN 'C' THEN (b.Price * b.Quantity) ELSE (b.Price * b.Quantity) / e.rate END
END
END
 AS [Total USD],
a.CANCELED,
a.Comments
from OINV a
inner join INV1 b on  a.docentry = b.docentry
inner join OCRD c on a.CardCode = c.CardCode
left join OITM d on b.ItemCode = d.ItemCode 
left join ORTT e on a.CreateDate = e.RateDate and e.Currency = 'USD'
where a.docdate between [%0]  and [%1]

UNION ALL

select a.CardCode,
c.CardName,
a.DocDate,
DATEPART(month , a.DocDate) AS Periodo,
DATEPART(YEAR , a.DocDate) AS Año,
case a.ObjType 
when 14 THEN 'Nota de Crédito'
END AS [Tipo de dcumento], 
a.DocNum,
a.DocEntry IrDocumento,
b.ItemCode,
case a.DocType When 'S' THEN b.dscription ELSE d.ItemName  END AS ItemName, 
b.Price,
case a.CANCELED
WHEN 'C' THEN case a.DocType When 'S' THEN 1 ELSE b.Quantity  END
WHEN 'N' THEN case a.DocType When 'S' THEN -1 ELSE b.Quantity * - 1 END
ELSE case a.DocType When 'S' THEN -1 ELSE b.Quantity * -1 END
END as Quantity,
case a.CANCELED WHEN 'C'
THEN case a.DocType When 'S'
 THEN case a.CurSource WHEN 'L' THEN  (b.Price * 1) ELSE (b.Price * 1) * e.rate   END
ELSE case a.CurSource WHEN 'L' THEN  (b.Price * b.Quantity)   ELSE (b.Price * b.Quantity) * e.rate  END
END
WHEN 'N' THEN
case a.DocType When 'S'
        THEN case a.CurSource WHEN 'L' THEN  (b.Price * 1) * -1 ELSE (b.Price * 1) * e.rate * -1 END
ELSE          case a.CurSource WHEN 'L' THEN  (b.Price * b.Quantity) * -1  ELSE (b.Price * b.Quantity) * e.rate * -1 END
END
ELSE
case a.DocType When 'S'
        THEN case a.CurSource WHEN 'L' THEN  (b.Price * 1) * -1  ELSE (b.Price * 1) * e.rate * -1 END
ELSE          case a.CurSource WHEN 'L' THEN  (b.Price * b.Quantity)  * -1 ELSE (b.Price * b.Quantity) * e.rate * -1 END
END
END
AS [Total MXN],
case a.CANCELED WHEN 'C'
THEN case a.DocType When 'S'
 THEN
case a.CurSource WHEN 'C' THEN (b.Price * 1)  ELSE (b.Price * 1) / e.rate  END
ELSE
case a.CurSource WHEN 'C' THEN (b.Price * b.Quantity)   ELSE (b.Price * b.Quantity)  / e.rate  END
END
WHEN 'N' THEN
case a.DocType When 'S'
 THEN
case a.CurSource WHEN 'C' THEN (b.Price * 1) * -1 ELSE (b.Price * 1)  / e.rate * -1 END
ELSE
case a.CurSource WHEN 'C' THEN (b.Price * b.Quantity) * -1 ELSE (b.Price * b.Quantity) / e.rate * -1 END
END
ELSE case a.DocType When 'S'
 THEN
case a.CurSource WHEN 'C' THEN (b.Price * 1) * -1 ELSE (b.Price * 1)  / e.rate * -1 END
ELSE
case a.CurSource WHEN 'C' THEN (b.Price * b.Quantity) * -1 ELSE (b.Price * b.Quantity) / e.rate * -1 END
END
END
 AS [Total USD],
--d.ItemName, 
--b.Price,
--b.Quantity * -1,
--case a.CurSource WHEN 'L' THEN  b.Price * b.Quantity * -1 ELSE (b.Price * b.Quantity * -1) * e.rate END AS [Total MXN],
--case a.CurSource WHEN 'C' THEN (b.Price * b.Quantity * -1) / e.rate ELSE (b.Price * b.Quantity * -1) END AS [Total USD],
a.CANCELED,
a.Comments
from ORIN a
--left join RIN1 e on a.Docentry = e.BaseEntry
inner join RIN1 b on  a.docentry = b.docentry
inner join OCRD c on a.CardCode = c.CardCode
left join OITM d on b.ItemCode = d.ItemCode 
left join ORTT e on a.CreateDate = e.RateDate and e.Currency = 'USD'
where a.docdate between [%0]  and [%1]

jueves, 19 de septiembre de 2019

Compras - Partidas abiertas por Item

Para los que nos preguntemos que material de nuestros pedidos aún no están en los almacenes, pueden resolver esa inquietud con esta consulta que aquí les dejo, contempla las OC que van directamente a almacén y las OC que pasan previamente por una factura para después iniciar la o las entradas al almacén.

Saludos!.

Select a.docdate, a.DocNum, a.CardCode, a.CardName, b.ItemCode, b.Dscription
, b.WhsCode, b.Quantity, b.InvntSttus,  b.LineStatus, b.OpenQty, d.SlpName as [Comprador]
, (select DocNum from OPRQ where DocEntry =  (select Top 1 T1.BaseEntry from POR1 T1 inner join OPOR T0 on T0.DocEntry = T1.DocEntry
  where T0.Segment = 0 and T1.BaseEntry is not null and T0.DocNum = a.DocNum)) as SC
,(select ReqName from OPRQ where DocEntry =  (select Top 1 T1.BaseEntry from POR1 T1 inner join OPOR T0 on T0.DocEntry = T1.DocEntry
  where T0.Segment = 0 and T1.BaseEntry is not null and T0.DocNum = a.DocNum)) as Solicitante
from OPOR a
inner join POR1 b on a.DocEntry = b.DocEntry
inner join OITM c on b.ItemCode = c.ItemCode
inner join OSLP d on a.SlpCode = d.SlpCode
and b.InvntSttus = 'O' and b.TargetType in (20,-1)
and a.CANCELED = 'N'
and c.frozenFor = 'N'
and c.validFor = 'Y'
and c.InvntItem = 'Y'
and a.DocStatus <> 'C'

union all

select a.docdate, a.DocNum, a.CardCode, a.CardName, b.ItemCode, b.Dscription
, b.WhsCode, b.Quantity, d.InvntSttus, b.LineStatus, d.OpenQty, f.SlpName as [Comprador]
 ,   (select DocNum from OPRQ where DocEntry = (select Top 1 b.BaseEntry from POR1 b inner join OPOR a on a.DocEntry = b.DocEntry
  where a.Segment = 0 and b.BaseEntry is not null and a.DocNum = (select distinct DocNum from OPOR where DocEntry = d.BaseEntry and d.BaseType = 22))) as SC
 ,   (select ReqName from OPRQ where DocEntry = (select Top 1 b.BaseEntry from POR1 b inner join OPOR a on a.DocEntry = b.DocEntry
  where a.Segment = 0 and b.BaseEntry is not null and a.DocNum = (select distinct DocNum from OPOR where DocEntry = d.BaseEntry and d.BaseType = 22))) as Solicitante
from OPOR a
inner join POR1 b on a.DocEntry = b.DocEntry
inner join OPCH c on b.TrgetEntry = c.DocEntry
inner join PCH1 d on c.DocEntry = d.DocEntry
inner join OITM e on b.ItemCode = e.ItemCode
inner join OSLP f on a.SlpCode = f.SlpCode
and d.InvntSttus = 'O' and b.TargetType in (18,-1)
and e.frozenFor = 'N'
and e.validFor = 'Y'
and e.InvntItem = 'Y'
and d.BaseLine = b.LineNum and d.ItemCode = b.ItemCode
and a.CANCELED = 'N'

martes, 10 de septiembre de 2019

Tesorería - Pagos efectuados

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'

miércoles, 4 de septiembre de 2019

Compras - Ultimo precio de compra

Para conocer el ultimo precio de compra de un articulo o servicio posiblemente habrán muchas maneras, la mas fácil es la siguiente consulta hacia la tabla de los Datos Maestros de Artículo: 

SELECT T1.[LastPurPrc] FROM OITM T1 Where T1.ItemCode = 'XxXxX'

Pero la consulta anterior no nos permite saber cuando fue la fecha de esa ultima compra, ni tampoco quien fue el proveedor por poner solo unos ejemplos, para estos casos les dejo la siguiente consulta.

select distinct * from (
select b.DocDate, b.CardCode, b.CardName, a.ItemCode, a.Dscription, a.Price from PCH1 a
inner join OPCH b on a.DocEntry = b.DocEntry
where a.ItemCode = 'XxXxX'
and b.CANCELED = 'N'
) tabla
inner join (select e.ItemCode , MAX(f.docdate) docdate from PCH1 e
inner join OPCH f on e.DocEntry = f.DocEntry and e.ItemCode = 'XxXxX') and f.CANCELED = 'N' group by e.ItemCode) tabla2
on tabla.ItemCode = tabla2.ItemCode and tabla.DocDate = tabla2.docdate
order by  tabla.ItemCode, tabla.docdate


Nota: Si este Item se repite, es por que en la misma fecha hubo compras con diferentes precios o diferentes proveedores.


Espero les sirva, saludos!.

miércoles, 28 de agosto de 2019

Producción - Costo de fabricación Con BOM (Lista de Materiales)

Que tal?, como han estado?, les comparto una consulta que puede ser de utilidad, en la cual podrán ver los costos que esta generando su producción.

Para este ejemplo en particular ya se encuentran la lista de materiales de los productos a producir cargada (La mejor practica), lista que se consume a diario a través de un almacén ficticio destinado para el consumo de la producción, el cual tendrían que colocar en las XxXx que están en negritas.

Por lo que al final esta consulta les dará detalles de los movimientos (Entradas, Transferencias y Salidas) de los materiales consumidos por día en un rango de fechas.

select Case TransType
when 60 then 'Salida'
when 59 then 'Entrada'
when 67 then 'Transferencia' end as [Movimiento], a.Currency
, a.DocDate, BASE_REF as [No. Documento], c.filler as [From Whse], c.ToWhsCode as [To Whse], a.Warehouse
, d.DocNum as [OF], case d.Type when 'S' then 'Estandár'
when 'D' then 'Desmonte'
when 'P' then 'Especial' End as [Tipo OF], d.PlannedQty, d.Uom, d.ItemCode as [Codigo Producto], e.ItemName
, a.ItemCode as [Codigo Material], a.Dscription, a.InQty, a.OutQty * -1 as [OutQty]
, CASE TransType
when 60 then g.unitMsr
when 59 then f.unitMsr
when 67 then h.unitMsr
end as [UM]
, case a.currency when 'USD' then a.Price * a.Rate
  when 'MXN' then a.Price end as Price
,  a.CalcPrice
, Case TransType
when 60 then  (a.OutQty * a.CalcPrice) * -1
when 59 then  (a.InQty * a.CalcPrice)
when 67 then
case c.ToWhsCode
when 'XxXx' then (a.InQty * a.CalcPrice)
else (a.OutQty * a.CalcPrice) * -1  end end as [Total MXN]
, Case TransType
when 60 then (a.OutQty * a.CalcPrice) * -1  / b.Rate
when 59 then (a.InQty * a.CalcPrice) / b.Rate
when 67 then
case c.ToWhsCode
when 'XxXx' then  (a.InQty * a.CalcPrice)  / b.Rate
else (a.OutQty * a.CalcPrice) * -1 / b.Rate end end as [Total USD]
, a.Comments, a.JrnlMemo
from OINM a Inner join ORTT b on a.DocDate = b.RateDate
left join OWTR c on c.DocEntry = a.CreatedBy
left join OWOR d on d.DocEntry = a.AppObjAbs and a.ApplObj = 202
left join OITM e on e.ItemCode = d.ItemCode
left join IGN1 f on f.DocEntry = a.CreatedBy and a.ItemCode = f.ItemCode and a.DocLineNum = f.LineNum
left join IGE1 g on g.DocEntry = a.CreatedBy and a.ItemCode = g.ItemCode and a.DocLineNum = g.LineNum
left join WTR1 h on h.DocEntry = a.CreatedBy and a.ItemCode = h.ItemCode and a.DocLineNum = h.LineNum
where TransType in (67,60,59)
and a.DocDate >= [%0]
and  a.DocDate <= [%1]
and (a.Warehouse = XxXx)
and b.Currency = 'USD'
order by DocDate

viernes, 5 de julio de 2019

Compras - Mercadería en transito

Les dejo una consulta que puede serles de mucha utilidad, en ella podrán ver las facturas reserva que no presentan aún entradas al almacén, solo deberán colocar en donde existe la condición de cuenta (remarcado en negro) sus cuentas contables de mercadería en transito, esta debe cuadrar contra la del balance.

Saludos!.

select t0.DocStatus, T0.CreateDate, t0.DocDate,T0.DocNum, T0.CardCode, T0.CardName, T1.ItemCode, T1.Dscription, t1.AcctCode, t2.acctname
, t1.Price, t1.Currency, T1.Quantity as [Cantidad Solicitada], T1.LineTotal  as [LineTotal]
,  T1.LineTotal / (select T10.Rate from ORTT T10 where T10.Currency = 'USD' and T10.RateDate = T0.DocDate)  as [LineTotal USD]
,T1.Quantity - isnull(( select SUM(T10.Quantity) from PDN1 T10 inner join OPDN T11 on T10.DocEntry = t11.DocEntry
where    T10.ItemCode = t1.ItemCode and T11.CANCELED = 'N' and t10.BaseEntry = t1.DocEntry and T10.BaseLine = T1.LineNum ),0) as [Cantidad en Transito]
, CASE T0.DocCur when 'MXN' THEN T1.Price * (T1.Quantity - isnull(( select SUM(T10.Quantity) from PDN1 T10 inner join OPDN T11 on T10.DocEntry = t11.DocEntry
where    T10.ItemCode = t1.ItemCode and T11.CANCELED = 'N' and t10.BaseEntry = t1.DocEntry and T10.BaseLine = T1.LineNum ),0))
                 when 'USD' THEN  T1.Price * (T1.Quantity - isnull(( select SUM(T10.Quantity) from PDN1 T10 inner join OPDN T11 on T10.DocEntry = t11.DocEntry
where    T10.ItemCode = t1.ItemCode and T11.CANCELED = 'N' and t10.BaseEntry = t1.DocEntry and T10.BaseLine = T1.LineNum ),0)) * (select T10.Rate from ORTT T10 where T10.Currency = 'USD' and T10.RateDate = T0.DocDate)
                 End as [LineTotal en Transito]
, CASE T0.DocCur when 'MXN' THEN T1.Price * (T1.Quantity - isnull(( select SUM(T10.Quantity) from PDN1 T10 inner join OPDN T11 on T10.DocEntry = t11.DocEntry
where    T10.ItemCode = t1.ItemCode and T11.CANCELED = 'N' and t10.BaseEntry = t1.DocEntry and T10.BaseLine = T1.LineNum ),0)) / (select T10.Rate from ORTT T10 where T10.Currency = 'USD' and T10.RateDate = T0.DocDate)
                 when 'USD' THEN  T1.Price * (T1.Quantity - isnull(( select SUM(T10.Quantity) from PDN1 T10 inner join OPDN T11 on T10.DocEntry = t11.DocEntry
where    T10.ItemCode = t1.ItemCode and T11.CANCELED = 'N' and t10.BaseEntry = t1.DocEntry and T10.BaseLine = T1.LineNum ),0))
                 End as [LineTotal en Transito USD]
, (select SUM(T10.linetotal) from PCH1 T10 where T10.DocEntry = T0.DocEntry)   as [Sub Total Fact]
, (select SUM(T10.LineTotal) / (select T10.Rate from ORTT T10 where T10.Currency = 'USD' and T10.RateDate = T0.DocDate) from PCH1 T10 where T10.DocEntry = T0.DocEntry) as [Sub Total Fact USD]
, T0.VatSum as [IVA Fact]
, CASE T0.DocCur when 'MXN' THEN T0.VatSum / (select T10.Rate from ORTT T10 where T10.Currency = 'USD' and T10.RateDate = T0.DocDate)
                 when 'USD' THEN  T0.VatSumFC
                 End as [IVA USD Fact]
, T0.[DocTotal] as [Total Fact]
, CASE T0.DocCur when 'MXN' THEN T0.[DocTotal] / (select T10.Rate from ORTT T10 where T10.Currency = 'USD' and T10.RateDate = T0.DocDate)
                 when 'USD' THEN  T0.[DocTotalFC]
                 End as [Total Fact USD]
from OPCH T0
INNER JOIN PCH1 T1 on T0.DocEntry = T1.DocEntry
INNER JOIN OACT T2 on T1.AcctCode = T2.AcctCode
where T0.isIns = 'Y'
and T1.InvntSttus = 'O'
and T1.TargetType in (20,-1)
and T0.CANCELED in ('C','N')
and T1.AcctCode in ('XXXXXX')
order by DocDate


jueves, 14 de febrero de 2019

Gestión - Autorizador por Modelo de Autorización en SAP

¿Necesitas saber quienes autorizan los modelos de autorización activos?, esta sencilla consulta te arroja esa información:

select a.Name 'Nombre Modelo', a.Remarks 'Descripción Modelo', c.Name as 'Nombre Etapa' , c.Remarks as 'Descripción Etapa'
,  e.U_NAME as  'Autorizador', c.MaxReqr as 'Autorizaciones requeridas', c.MaxRejReqr as 'Rechazos requeridos'
from OWTM a
inner join WTM2 b on a.WtmCode = b.WtmCode
inner join OWST c on b.WstCode = c.WstCode
inner join WST1 d on c.WstCode = d.WstCode
inner join OUSR e on d.UserID = e.USERID
where a.Active = 'Y'
order by 
[Nombre Modelo] , Autorizador

Si además quieres saber los autores de cada Modelo de Autorización, ocupa también esta Query:

select a.Name as 'Nombre Modelo', a.Remarks as 'Descripción Modelo'
, e.U_NAME as 'Autor'
from OWTM a
inner join WTM1 b on a.WtmCode = b.WtmCode
inner join OUSR e on b.UserID = e.USERID
where a.Active = 'Y'
order by [autor], [Nombre Modelo]

jueves, 4 de agosto de 2016

Inventarios - Auditoría de Stock Por Lote y Almacén

Les mostrare a continuación como podemos obtener una consulta de stock de artículos por Lote, esto por que me encontré que al querer consultar las tablas RSRN, RBTN, RITL o SBDR  para realizar una consulta personalizada con estos datos, resulta que no existen 😮, seguro a mas de uno nos ha pasado, por lo que me di a la tarea de encontrar estos datos, a continuación les dejo la consulta:

select b.ItemName, a.ItemCode, a.WhsCode, a.BatchNum
, b.SalUnitMsr
, a.Quantity
, a.ExpDate,  a.PrdDate, a.InDate, a.CreateDate
, c.U_GroupName
from OIBT a
inner join OITM b on a.ItemCode = b.ItemCode
inner join OITB c on c.ItmsGrpCod = b.ItmsGrpCod

La tabla en negritas es la importante aquí, las demás son opcionales dependiendo sus necesidades pueden ir agregando o quitando, Ojo no confundir esta consulta con la de Producción de lotes, para eso esta la vista OITL e ITL1.

Cualquier duda o comentario, no dudes en publicarlo.
Saludos!.