
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_cat_catalogo_bodegas_itemDocumento]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[sel_cat_catalogo_bodegas_itemDocumento]
GO
CREATE PROCEDURE [dbo].[sel_cat_catalogo_bodegas_itemDocumento]
	@p_idDocumento as int
AS
BEGIN
SELECT [doc_itemDocumento].id as id_item,
       [doc_itemDocumento].id_catalogo as id_catalogo,
	   [doc_itemDocumento].id_bodega as id_bodega,
	   [doc_itemDocumento].cantidadPlaneado as cantidadPlaneada,
	   [doc_itemDocumento].cantidadEjecutado as cantidadEjecutada,
	   [doc_itemDocumento].valorUnitarioPlaneado as valorUnitarioPlaneado,
	   [doc_itemDocumento].valorUnitarioEjecutado as valorUnitarioEjecutado,
	   [cat_catalogo_bodega].existencia as existencia,
	   [gen_bodega].salidasEnRojo as permiteSalidasEnRojo
FROM [doc_itemDocumento] left join [cat_catalogo_bodega] on 
     [doc_itemDocumento].id_catalogo = [cat_catalogo_bodega].id_catalogo
	 left join [gen_bodega] on [gen_bodega].id = [doc_itemDocumento].id_bodega 
	 WHERE [doc_itemDocumento].id_documento=@p_idDocumento and 
     [doc_itemDocumento].active = 1
END