-- =============================================
-- Author:		<Yonatan Gaete>
-- Create date: <06/10/2024>
-- Description:	<Cargar Reporte Bien Imprimible>
-- =============================================
ALTER PROCEDURE [dbo].[sp_conPlanillaBienes] 
(
	@idBien INT
)
AS
BEGIN
	SELECT 
		  B.[id]
		  ,B.[nombre]
		  ,B.[descripcion]
		  ,B.[numeroSerie]
		  ,B.[codigoBarra]
		  ,B.[codigoInterno]
		  ,B.[uniNeg]
		  ,ISNULL(UN.[descripcion], '') AS uninegDesc
		  ,B.[fechaCompra]
		  ,B.[costoCompra]
		  ,B.[vidaUtil]
		  ,B.[valorResidual]
		  ,B.[metodoDepreciacion]
		  ,CASE metodoDepreciacion WHEN 0 THEN 'Depreciacion Lineal' WHEN 1 THEN 'Depreciacion Acelerada' END AS depreciacionDesc
		  ,B.[grupo]
		  ,G.[nombre] AS grupoDesc
		  ,B.[subgrupo]
		  ,SG.[nombre] AS subGrupoDesc
		  ,B.[ubicacion]
		  ,ISNULL(U.[nombre], '') AS ubicacionDesc
		  ,B.[responsable]
		  ,ISNULL(R.[nombre], '') AS responsableDesc
		  ,B.[estado]
		  ,ISNULL(E.[nombre], '') AS estadoDesc
		  ,B.[fechaUltimaDepreciacion]
		  ,B.[manejaMantencion]
		  ,B.[permiteMovimiento]
		  ,B.[cuentaContable]
		  ,B.[rutCyV]
		  ,B.[tipoDocCyV]
		  ,B.[numDocCyV]
		  ,B.[codbus]
		  ,B.[orderCompra]
		  ,ISNULL(B.[departamento], 0) AS departamento
		  ,ISNULL(D.[descripcion], '') As departamentoDesc
		  ,B.deBaja
	FROM afiBienes B
	INNER JOIN afiGrupo G ON G.id = B.grupo
	INNER JOIN afiSubGrupo SG ON SG.id = B.subgrupo AND SG.idGrupo = B.grupo
	INNER JOIN conUnidadNegocio UN ON UN.idUniNeg = B.uniNeg
	INNER JOIN afiUbicaciones U ON U.id = B.ubicacion
	INNER JOIN afiResponsables R ON R.id = B.responsable
	INNER JOIN afiEstados E ON E.id = B.estado
	INNER JOIN remDepartamentos D ON D.idDepartamento = B.departamento
	WHERE B.id = @idBien
END