Versión: v1.1 Autor: Jimmy Ricardo Sánchez Romero Fecha: 2025-10-09 Dependencias: [SIESA], [dbo].[t150_mc_bodegas], [dbo].[t152_mc_bodega_grupo_bodega],[dbo].[t284_co_ccosto],[dbo].[t441_movto_req_int], [dbo].[t440_docto_req_int],[dbo].[t121_mc_items_extensiones],[dbo].[t120_mc_items] Estado: Activa ✅
Consolidar la información de traslados internos recientes (últimos 20 días) entre bodegas del negocio IRCC,
CREATE OR ALTER VIEW [dbo].[v_bodegas_1]
AS
SELECT
CodBodegaOrigen,
CodBodegaDestino,
NumTraslado,
Posicion,
CodMaterial,
FechaCreacion,
FechaRecibo,
CantidadPedida,
CantidadPendiente,
UnidadMedida,
Traslados.Negocio,
TipoDocumento
FROM (
SELECT
-- Bodega origen del traslado
(SELECT f150_id
FROM [SIESA].[unoee_real1].[dbo].[t150_mc_bodegas]
WHERE f150_rowid = f440_rowid_bodega_sal) AS CodBodegaOrigen,
-- Bodega destino calculada con base en la unidad de negocio (UN)
(SELECT
CASE
WHEN f284_id_un = 2 THEN CONCAT(RTRIM(f150_id), '_PDV_EC')
WHEN f284_id_un = 3 THEN CONCAT(RTRIM(f150_id), '_PDV_CG')
WHEN f284_id_un = 4 THEN CONCAT(RTRIM(f150_id), '_PDV_BS')
WHEN f284_id_un = 12 THEN CONCAT(RTRIM(f150_id), '_PDV_VG')
WHEN f284_id_un = 15 THEN CONCAT(RTRIM(f150_id), '_PDV_EVOK')
WHEN f284_id_un = 17 THEN CONCAT(RTRIM(f150_id), '_PDV_NM')
END
FROM [SIESA].[unoee_real1].[dbo].[t150_mc_bodegas]
INNER JOIN [SIESA].[unoee_real1].[dbo].[t152_mc_bodega_grupo_bodega]
ON f152_rowid_bodega = f150_rowid
INNER JOIN [SIESA].[unoee_real1].[dbo].[t284_co_ccosto]
ON f284_id_co = f150_id_co
AND f150_id_cia = f284_id_cia
AND f152_id_cia = f150_id_cia
WHERE f150_rowid = f440_rowid_bodega_ent
AND f152_id_grupo_bodega = 'PDV'
AND f284_id_grupo_ccosto = 'GV'
AND f284_id_un IN (2,3,4,12,15,17)
) AS CodBodegaDestino,
-- Datos principales del traslado
f440_consec_docto AS NumTraslado,
ROW_NUMBER() OVER (PARTITION BY f440_consec_docto ORDER BY f441_rowid) AS Posicion,
f120_id AS CodMaterial,
f441_id_fecha AS FechaCreacion,
f441_fecha_entrega AS FechaRecibo,
f441_cant1_requerida AS CantidadPedida,
f441_cant1_requerida - f441_cant1_consumida AS CantidadPendiente,
f120_id_unidad_inventario AS UnidadMedida,
'IRCC' AS Negocio,
f440_id_tipo_docto AS TipoDocumento
FROM [SIESA].[unoee_real1].[dbo].[t441_movto_req_int]
INNER JOIN [SIESA].[unoee_real1].[dbo].[t440_docto_req_int]
ON f440_rowid = f441_rowid_docto_req_int
INNER JOIN [SIESA].[unoee_real1].[dbo].[t121_mc_items_extensiones]
ON f121_rowid = f441_rowid_item_ext
INNER JOIN [SIESA].[unoee_real1].[dbo].[t120_mc_items]
ON f120_rowid = f121_rowid_item
WHERE f441_ind_estado NOT IN (3, 9)
AND f440_id_tipo_docto = 'RTT' -- Tipo de documento: Requisición de traslado
AND f441_id_fecha >= GETDATE() - 20 -- Filtro: últimos 20 días
) Traslados
INNER JOIN [dbo].[bodegas] AS B
ON B.CodBodega = CodBodegaDestino
AND B.Negocio = Traslados.Negocio
WHERE I.[f120_id_cia] = 1
UNION ALL .....
| Esquema | Tablas principales |
|---|---|
| dbo | t150_mc_bodegas |
| dbo | t152_mc_bodega_grupo_bodega |
| dbo | t284_co_ccosto |
| dbo | t441_movto_req_int |
| dbo | t440_docto_req_int |
| dbo | t121_mc_items_extensiones |
| dbo | t120_mc_items |
Nota: esta estructura se repite en las tres instancias
[SIESA].[unoee_Real1][LEÑOS].[UnoeeRealLenos][SIESA].[unoeeRealPapajohns]| Columna | Tipo de dato | Descripción |
|---|---|---|
| CodBodegaOrigen | VARCHAR(5) | Código bodega origen |
| CodBodegaDestino | VARCHAR(15) | Código bodega destino |
| NumTraslado | INT | Número de causación |
| Posicion | BIGINT | |
| CodMaterial | INT | Código de item |
| FechaCreacion | DATETIME | Fecha de la creación del translado |
| FechaRecibo | DATETIME | Fecha que se recibe el producto |
| CantidadPedida | NUMERIC(28,4) | Cantidad solicitada |
| CantidadPendiente | NUMERIC(29,4) | Cantidad pendiente |
| UnidadMedida | CHAR(4) | Unidad de inventario |
| Negocio | VARCHAR(5) | Instancia del ERP |
| TipoDocumento | CHAR(3) | Tipo de documento causado |
| Versión | Fecha | Autor | Descripción |
|---|---|---|---|
| v1.0 | 2022-03-15 | Jimmy R. Sánchez | Creación inicial |
| v1.1 | 2025-10-09 | Jimmy R. Sánchez | Documentación formal |