IF EXISTS (SELECT 1 FROM dbo.sysobjects WHERE ID = OBJECT_ID(N'[dbo].[sp_fco_baja_tablas]') 
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   DROP PROCEDURE dbo.sp_fco_baja_tablas
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE dbo.sp_fco_baja_tablas
(
    @vvc_tabla    varchar(30)
)
AS
BEGIN
    EXECUTE ('DROP TABLE ' + @vvc_tabla)

    EXECUTE ("DELETE fco_ala_datos_adi WHERE tabla = '" + @vvc_tabla + "'")
END
GO
GRANT EXECUTE ON sp_fco_baja_tablas TO Public
GO
IF EXISTS (SELECT 1 FROM dbo.sysobjects WHERE ID = OBJECT_ID(N'[dbo].[sp_fco_cambio_iss]') 
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   DROP PROCEDURE dbo.sp_fco_cambio_iss
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE dbo.sp_fco_cambio_iss
(
	@CIA  		char(4),
	@TABLA  	varchar(30),
	@COD_TRAB	char(10),
	@C03  		char(1),
	@C09  		char(1),
	@C10  		char(1),
	@C11  		char(1),
	@C12  		char(1),
	@C13  		char(1),
	@C14  		char(1),
	@C15  		char(1),
	@C16  		char(1),
	@C17  		char(1),
	@C18  		char(1),
	@C19  		char(1),
	@C20  		char(1),
	@C21  		char(1),
	@C22  		numeric(2,0),
  @C23            numeric(2,0),
  @C24            numeric(2,0),
  @C26            numeric(9,0),
  @C28            numeric(9,0),
  @C29            numeric(9,0),
  @C31            numeric(6,4),
  @C32            numeric(9,0),
  @C36            numeric(9,0),
  @C38            numeric(9,0)
)
/******************************************************************************************/
/*** Nombre:      sp_cambio_mf_iss	                            			***/
/*** Modulo:      ADAM V3. (Fiscal Colombiano)                                          ***/
/*** Descripcion: permite al usuario corregir las leves inconsistencias que             ***/
/***    ocasionalmente puedan presentarse en el reporte ISS             		***/
/***              o en el medio magnético        					***/
/******************************************************************************************/
AS
DECLARE	@sql  VARCHAR(2000)

BEGIN
	SELECT @sql = "UPDATE " + @TABLA +
     	" SET" +
	" C03='" + IsNull(@C03,"C") + "'," +
     	" C09='" + IsNull(@C09,"") + "'," +
     	" C10='" + IsNull(@C10,"") + "'," +
     	" C11='" + IsNull(@C11,"") + "'," +
     	" C12='" + IsNull(@C12,"") + "'," +
     	" C13='" + IsNull(@C13,"") + "'," +
     	" C14='" + IsNull(@C14,"") + "'," +
     	" C15='" + IsNull(@C15,"") + "'," +
     	" C16='" + IsNull(@C16,"") + "'," +
     	" C17='" + IsNull(@C17,"") + "'," +
     	" C18='" + IsNull(@C18,"") + "'," +
     	" C19='" + IsNull(@C19,"") + "'," +
     	" C20='" + IsNull(@C20,"") + "'," +
     	" C21='" + IsNull(@C21,"") + "'," +
     	" C22=" + IsNull(Convert(varchar,@C22),"0") + "," +
     	" C23=" + IsNull(Convert(varchar,@C23),"0") + "," +
     	" C24=" + IsNull(Convert(varchar,@C24),"0") + "," +
     	" C26=" + IsNull(Convert(varchar,@C26),"0") + "," +
     	" C28=" + IsNull(Convert(varchar,@C28),"0") + "," +
     	" C29=" + IsNull(Convert(varchar,@C29),"0") + "," +
     	" C31=" + IsNull(Convert(varchar,@C31),"0") + "," +
     	" C32=" + IsNull(Convert(varchar,@C32),"0") + "," +
     	" C36=" + IsNull(Convert(varchar,@C36),"0") + "," +
     	" C38=" + IsNull(Convert(varchar,@C38),"0") + 
    	" WHERE CIA='" + @CIA + "'" +
    	" AND COD_TRAB='" + @COD_TRAB + "'"

	EXECUTE (@sql)

     	IF @@ERROR <> 0 RAISERROR 13000 "Error al Actualizar la Tabla"
END

GO
GRANT EXECUTE ON sp_fco_cambio_iss TO Public
GO
IF EXISTS (SELECT 1 FROM dbo.sysobjects WHERE ID = OBJECT_ID(N'[dbo].[sp_fco_cambio_pension]') 
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   DROP PROCEDURE dbo.sp_fco_cambio_pension
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE dbo.sp_fco_cambio_pension
(
	@CIA  		char(4),
	@TABLA  	varchar(30),
	@COD_TRAB	char(10),
	@C11A  		char(4),
	@C13A  		char(1),
	@C13B  		char(1),
	@C13C  		char(1),
	@C13D  		char(1),
	@C13E  		char(1),
	@C13F  		char(1),
	@C13G  		char(1),
	@C13H  		char(1),
	@C13I  		char(1),
	@C13J  		char(1),
	@C13K  		char(1),
	@C13L  		char(1),
  @C14A           numeric(2,0),
  @C15A           numeric(9,0),
  @C17A           numeric(9,0),
  @C18A           numeric(9,4),
  @C19A           numeric(9,0),
  @C20A           numeric(9,0),
  @C20B           numeric(9,0),
  @C22A           numeric(9,0),
  @C23A           numeric(9,0)
)
/******************************************************************************************/
/*** Nombre:      sp_cambio_mf_pension                                             	***/
/*** Modulo:      ADAM V3. (Fiscal Colombiano)                                          ***/
/*** Descripcion: permite al usuario corregir las leves inconsistencias que             ***/
/***    ocasionalmente puedan presentarse en el reporte ALA Pensiones          		***/
/***              o en el medio magnético        					***/
/******************************************************************************************/
AS
DECLARE	@sql  VARCHAR(3000)

BEGIN
	SELECT @sql = "UPDATE " + @TABLA +
     	" SET" +
	" C11A='" + IsNull(@C11A,"C") + "'," +
     	" C13A='" + IsNull(@C13A,"") + "'," +
     	" C13B='" + IsNull(@C13B,"") + "'," +
     	" C13C='" + IsNull(@C13C,"") + "'," +
     	" C13D='" + IsNull(@C13D,"") + "'," +
     	" C13E='" + IsNull(@C13E,"") + "'," +
     	" C13F='" + IsNull(@C13F,"") + "'," +
     	" C13G='" + IsNull(@C13G,"") + "'," +
     	" C13H='" + IsNull(@C13H,"") + "'," +
     	" C13I='" + IsNull(@C13I,"") + "'," +
     	" C13J='" + IsNull(@C13J,"") + "'," +
     	" C13K='" + IsNull(@C13K,"") + "'," +
     	" C13L='" + IsNull(@C13L,"") + "'," +
        " C14A=" + IsNull(Convert(varchar,@C14A), '0') + "," +
        " C15A=" + IsNull(Convert(varchar,@C15A), '0') + "," +
        " C17A=" + IsNull(Convert(varchar,@C17A), '0') + "," +
        " C18A=" + IsNull(Convert(varchar,@C18A), '0') + "," +
        " C19A=" + IsNull(Convert(varchar,@C19A), '0') + "," +
        " C20A=" + IsNull(Convert(varchar,@C20A), '0') + "," +
        " C20B=" + IsNull(Convert(varchar,@C20B), '0') + "," +
        " C22A=" + IsNull(Convert(varchar,@C22A), '0') + "," +
        " C23A=" + IsNull(Convert(varchar,@C23A), '0') + 
    	" WHERE CIA='" + @CIA + "'" +
    	" AND COD_TRAB='" + @COD_TRAB + "'"


	EXECUTE (@sql)

     	IF @@ERROR <> 0 RAISERROR 13000 "Error al Actualizar la Tabla"
END


GO
GRANT EXECUTE ON sp_fco_cambio_pension TO Public
GO
IF EXISTS (SELECT 1 FROM dbo.sysobjects WHERE ID = OBJECT_ID(N'[dbo].[sp_fco_cambio_riesgos]') 
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   DROP PROCEDURE dbo.sp_fco_cambio_riesgos
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE dbo.sp_fco_cambio_riesgos
(
	@CIA  		char(4),
	@TABLA  	varchar(30),
	@COD_TRAB	char(10),
	@C11A  		char(4),
	@C13A  		char(1),
	@C13B  		char(1),
	@C13C  		char(1),
	@C13D  		char(1),
	@C13E  		char(1),
	@C13F  		char(1),
	@C13G  		char(1),
	@C13H  		char(1),
	@C13I  		char(1),
	@C13J  		char(1),
	@C13K  		numeric(2,0),
  @C14A           numeric(2,0),
  @C15A           numeric(9,0),
  @C17A           numeric(9,0),
	@C28A  		numeric(9,0),
	@C28B  		numeric(9,0),
  @C29A           numeric(9,0),
  @C30A           varchar(5),
  @C30B           varchar(5)
)
/******************************************************************************************/
/*** Nombre:      sp_cambio_mf_riesgos                                                	***/
/*** Modulo:      ADAM V3. (Fiscal Colombiano)                                          ***/
/*** Descripcion: permite al usuario corregir las leves inconsistencias que             ***/
/***    ocasionalmente puedan presentarse en el reporte ALA ARP             		***/
/***              o en el medio magnético        					***/
/******************************************************************************************/
AS
DECLARE	@sql  VARCHAR(2000), 
    @vvc_sql2 varchar(2000)

BEGIN
	SET @sql = 
        "UPDATE " + @TABLA + " SET" +
	" C11A='" + IsNull(@C11A,"C") + "'," +
     	" C13A='" + IsNull(@C13A,"") + "'," +
     	" C13B='" + IsNull(@C13B,"") + "'," +
     	" C13C='" + IsNull(@C13C,"") + "'," +
     	" C13D='" + IsNull(@C13D,"") + "'," +
     	" C13E='" + IsNull(@C13E,"") + "'," +
     	" C13F='" + IsNull(@C13F,"") + "'," +
     	" C13G='" + IsNull(@C13G,"") + "'," +
     	" C13H='" + IsNull(@C13H,"") + "'," +
     	" C13I='" + IsNull(@C13I,"") + "'," +
     	" C13J='" + IsNull(@C13J,"") + "'," +
     	" C13K=" + IsNull(convert(varchar,@C13K),"0") + ","

	SET @vvc_sql2 =
     	" C14A=" + IsNull(convert(varchar,@C14A),"0") + "," +
     	" C15A=" + IsNull(convert(varchar,@C15A),"0") + "," +
     	" C17A=" + IsNull(convert(varchar,@C17A),"0") + "," +
     	" C28A=" + IsNull(convert(varchar,@C28A),"0") + "," +
     	" C28B=" + IsNull(convert(varchar,@C28B),"0") + "," +
     	" C29A=" + IsNull(convert(varchar,@C29A),"0") + "," +
     	" C30A='" + IsNull(@C30A,"") + "'," +
     	" C30B='" + IsNull(@C30B,"") + "'" +
    	" WHERE CIA='" + @CIA + "'" +
    	" AND COD_TRAB='" + @COD_TRAB + "'" +
    	" AND C17A <> 0"

	EXECUTE (@sql + @vvc_sql2)

     	IF @@ERROR <> 0 RAISERROR 13000 "Error al Actualizar la Tabla"
END


GO
GRANT EXECUTE ON sp_fco_cambio_riesgos TO Public
GO
IF EXISTS (SELECT 1 FROM dbo.sysobjects WHERE ID = OBJECT_ID(N'[dbo].[sp_fco_cambio_salud]') 
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   DROP PROCEDURE dbo.sp_fco_cambio_salud
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE dbo.sp_fco_cambio_salud
(
    @CIA  	char(4),
    @TABLA      varchar(30),
    @COD_TRAB   char(10),
    @C11A  	char(4),
    @C13A  	char(1),
    @C13B  	char(1),
    @C13C  	char(1),
    @C13D  	char(1),
    @C13E  	char(1),
    @C13F  	char(1),
    @C13G  	char(1),
    @C13H  	char(1),
    @C13I  	char(1),
    @C13J  	char(1),
    @C14A       numeric(2,0),
    @C15A       numeric(9,0),
    @C17A       numeric(9,0),
    @C24A       numeric(9,0),
    @C25A  	varchar(10),
    @C25B       numeric(9,0),
    @C26A  	varchar(10),
    @C26B       numeric(9,0),
    @C27A       numeric(9,0)
)
/******************************************************************************************/
/*** Nombre:      sp_cambio_mf_salud                                                ***/
/*** Modulo:      ADAM V3. (Fiscal Colombiano)                                          ***/
/*** Descripcion: permite al usuario corregir las leves inconsistencias que             ***/
/***    	  ocasionalmente puedan presentarse en el reporte ALA Salud             ***/
/***              o en el medio magnético        					***/
/******************************************************************************************/
AS
DECLARE	@sql  VARCHAR(3000)

BEGIN
	SELECT @sql = "UPDATE " + @TABLA +
     	" SET" +
	" C11A='" + IsNull(@C11A,'C') + "'," +
     	" C13A='" + IsNull(@C13A,"") + "'," +
     	" C13B='" + IsNull(@C13B,"") + "'," +
     	" C13C='" + IsNull(@C13C,"") + "'," +
     	" C13D='" + IsNull(@C13D,"") + "'," +
     	" C13E='" + IsNull(@C13E,"") + "'," +
     	" C13F='" + IsNull(@C13F,"") + "'," +
     	" C13G='" + IsNull(@C13G,"") + "'," +
     	" C13H='" + IsNull(@C13H,"") + "'," +
     	" C13I='" + IsNull(@C13I,"") + "'," +
     	" C13J='" + IsNull(@C13J,"") + "'," +
        " C14A=" + IsNull(Convert(varchar,@C14A),'0') + "," +
        " C15A=" + IsNull(Convert(varchar,@C15A),'0') + "," +
        " C17A=" + IsNull(Convert(varchar,@C17A),'0') + "," +
        " C24A=" + IsNull(Convert(varchar,@C24A),'0') + "," +
     	" C25A='" + IsNull(@C25A,"") + "'," +
        " C25B=" + IsNull(Convert(varchar,@C25B),'0') + "," +
     	" C26A='" + IsNull(@C26A,"") + "'," +
        " C26B=" + IsNull(Convert(varchar,@C26B),'0') + "," +
        " C27A=" + IsNull(Convert(varchar,@C27A),'0') +
    	" WHERE CIA='" + @CIA + "'" +
    	" AND COD_TRAB='" + @COD_TRAB + "'"

	EXECUTE (@sql)

     	IF @@ERROR <> 0 RAISERROR 13000 "Error al Actualizar la Tabla"
END


GO
GRANT EXECUTE ON sp_fco_cambio_salud TO Public
GO
IF EXISTS (SELECT 1 FROM dbo.sysobjects WHERE ID = OBJECT_ID(N'[dbo].[sp_fco_cambio_vw_iss]') 
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   DROP PROCEDURE dbo.sp_fco_cambio_vw_iss
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE dbo.sp_fco_cambio_vw_iss
(
	@CIA  		char(4),
	@TABLA  	varchar(30),
	@COD_TRAB	char(10),
	@C10A  		char(4),
	@C11A  		char(1),
	@C11B  		char(1),
	@C11C  		char(1),
	@C11D  		numeric(2,0),
	@C11E  		numeric(2,0),
  @C12A           numeric(2,0),
	@C13A  		numeric(12,0),
  @C14A           numeric(10,0),
  @C14B           numeric(10,0),
  @C14C           numeric(10,0)
)
/******************************************************************************************/
/*** Nombre:      sp_cambio_mf_iss	                            			***/
/*** Modulo:      ADAM V3. (Fiscal Colombiano)                                          ***/
/*** Descripcion: permite al usuario corregir las leves inconsistencias que             ***/
/***    ocasionalmente puedan presentarse en el reporte ISS             		***/
/***              o en el medio magnético        					***/
/***  Revision: Abril 5 de 2002                                                         ***/
/******************************************************************************************/
AS
DECLARE	@sql  VARCHAR(1500)

BEGIN
	SELECT @sql = "UPDATE " + @TABLA +
     	" SET" +
	" C10A='" + IsNull(RTrim(@C10A),"C") + "'," +
     	" C11A='" + IsNull(@C11A,"") + "'," +
     	" C11B='" + IsNull(@C11B,"") + "'," +
     	" C11C='" + IsNull(@C11C,"") + "'," +
     	" C11D=" + IsNull(Convert(char,@C11D),"0") + "," +
     	" C11E=" + IsNull(Convert(char,@C11E),"0") + "," +
     	" C12A=" + IsNull(CONVERT(CHAR,@C12A),"0") + "," + 
     	" C13A=" + IsNull(CONVERT(CHAR,@C13A),"0") + "," +
     	" C14A=" + IsNull(CONVERT(CHAR,@C14A),"0") + "," +
     	" C14B=" + IsNull(CONVERT(CHAR,@C14B),"0") + "," +
     	" C14C=" + IsNull(CONVERT(CHAR,@C14C),"0") +
    	" WHERE CIA='" + @CIA + "'" +
    	" AND COD_TRAB='" + @COD_TRAB + "'"
	EXECUTE (@sql)

     	IF @@ERROR <> 0 RAISERROR 13000 "Error al Actualizar la Tabla"
END


GO
GRANT EXECUTE ON sp_fco_cambio_vw_iss TO Public
GO
