CREATE OR ALTER PROCEDURE [dbo].[_obtenerIdEstadoDocumentoXOrdenUltimoCatalogo] 
		@p_dataObjectJSON NVARCHAR(MAX), -- [ { "id": 0, "orden": 0 } ]
		@p_idUsuario AS INT,
		@p_eid AS VARCHAR(10)
	AS
BEGIN
	SELECT top 1 est.id
	FROM OPENJSON(@p_dataObjectJSON)
	WITH (
		id INT,
		orden INT
	  ) jsonObject
	  INNER JOIN cat_catalogo cat
	ON cat.id = jsonObject.id
	  INNER JOIN doc_estadoTipoDocumento est
	ON est.estadoTipoDocumento_codigo = cat.catalogo_codigo
	WHERE
	  cat.active = 1 AND 
	  est.active = 1 AND 
	  (cat.catalogo_codigo <> '' OR cat.catalogo_codigo is not null) AND
	  (est.estadoTipoDocumento_codigo <> '' OR est.estadoTipoDocumento_codigo is not null)
	ORDER BY jsonObject.orden DESC
END