--Hash:7C00D4F861F91167BE2F3F02A3F42CA0
SET XACT_ABORT ON
BEGIN TRANSACTION;

GO

SET DATEFORMAT mdy;

--Validar que no existan scripts que no se hayan ejecutado
--//
IF EXISTS
(
	SELECT a.NumVersion + 1 AS HuecoInicio
	FROM ZiurVersiones a
	LEFT JOIN ZiurVersiones b ON a.NumVersion + 1 = b.NumVersion
	WHERE a.NumVersion>830 AND b.NumVersion IS NULL
	AND a.NumVersion + 1 < 914
)
RAISERROR('Error : hay un script que no se ejecuto , debe ejecutarlo manualmente.', 20, -1) with log
--//

--Colocar contenido de script diferencial aqui (Ziur.Database.publish.sql)

/*
 Plantilla de script anterior a la implementación							
--------------------------------------------------------------------------------------
 Este archivo contiene instrucciones de SQL que se ejecutarán antes del script de compilación	
 Use la sintaxis de SQLCMD para incluir un archivo en el script anterior a la implementación			
 Ejemplo:      :r .\miArchivo.sql								
 Use la sintaxis de SQLCMD para hacer referencia a una variable en el script anterior a la implementación		
 Ejemplo:      :setvar TableName miTabla							
               SELECT * FROM [$(TableName)]					
--------------------------------------------------------------------------------------
*/
GO

GO
PRINT N'Rename refactoring operation with key 39e323d1-a18d-4fb5-80bc-946c5930fd4b is skipped, element [dbo].[Radian_Encabezados].[Fecha] (SqlSimpleColumn) will not be renamed to XmlFecha';


GO
PRINT N'Rename refactoring operation with key 24ac2dce-152f-4c75-8570-d5ee322eb746 is skipped, element [dbo].[Radian_Encabezados].[NumDocumento] (SqlSimpleColumn) will not be renamed to XmlNumDocumento';


GO
PRINT N'Rename refactoring operation with key c2a1212d-8d40-4625-a993-71a98dabe481, 504b44ea-85ac-4e09-9fe1-4fee2967038d is skipped, element [dbo].[Radian_Encabezados].[IdProveedor] (SqlSimpleColumn) will not be renamed to XmlProveedor';


GO
PRINT N'Rename refactoring operation with key a1004f99-1a08-4c47-8144-6d2877e8d99f is skipped, element [dbo].[Radian_Encabezados].[CUFE] (SqlSimpleColumn) will not be renamed to XmlCUFE';


GO
PRINT N'Rename refactoring operation with key 7ac7e0d3-e9bb-4f26-b5c9-220a7828a902 is skipped, element [dbo].[Radian_Encabezados].[SenderNumIdentificacion] (SqlSimpleColumn) will not be renamed to XmlNumIdentificacion';


GO
PRINT N'Rename refactoring operation with key 2a0a27bb-57fa-465e-94ae-63f3657c6390 is skipped, element [dbo].[Radian_Encabezados].[SenderDV] (SqlSimpleColumn) will not be renamed to XmlDV';


GO
PRINT N'Rename refactoring operation with key edfcddf9-ad8b-4372-ab1b-3b1cc54b7096 is skipped, element [dbo].[Radian_Encabezados].[SenderNombres] (SqlSimpleColumn) will not be renamed to XmlNombres';


GO
PRINT N'Altering Table [dbo].[Empresas]...';


GO
ALTER TABLE [dbo].[Empresas]
    ADD [RdTokenDian]     NVARCHAR (500) NULL,
        [RdVersion]       SMALLINT       NULL,
        [RdIdProveedor]   INT            NULL,
        [RdTokenPassword] NVARCHAR (500) NULL;


GO
PRINT N'Creating Table [dbo].[Radian_Encabezados]...';


GO
CREATE TABLE [dbo].[Radian_Encabezados] (
    [IdEncab]                 INT             IDENTITY (1, 1) NOT NULL,
    [FechaProceso]            DATE            NOT NULL,
    [IdEmpresa]               INT             NULL,
    [XmlName]                 NVARCHAR (100)  NOT NULL,
    [XmlFull]                 NVARCHAR (MAX)  NOT NULL,
    [XmlFecha]                DATE            NOT NULL,
    [XmlNumDocumento]         NVARCHAR (255)  NOT NULL,
    [XmlProveedor]            NVARCHAR (255)  NOT NULL,
    [XmlCUFE]                 NVARCHAR (255)  NOT NULL,
    [XmlNumIdentificacion]    NVARCHAR (100)  NOT NULL,
    [XmlDV]                   NVARCHAR (100)  NOT NULL,
    [XmlNombres]              NVARCHAR (200)  NOT NULL,
    [XmlNumIdentificacionRec] NVARCHAR (100)  NOT NULL,
    [IdEvento]                INT             NULL,
    [Aprob_IdEvento]          INT             NULL,
    [IdRechazo]               INT             NULL,
    [RdIdEstadoDian]          INT             NULL,
    [RdFechaAutorizacion]     DATETIME        NULL,
    [RdUUID]                  NVARCHAR (100)  NULL,
    [RdMensRespuesta]         NVARCHAR (1000) NULL,
    [RdIdVersion]             SMALLINT        NULL,
    CONSTRAINT [PK_RadianEncab] PRIMARY KEY NONCLUSTERED ([IdEncab] ASC) WITH (FILLFACTOR = 90)
);


GO
PRINT N'Creating Table [dbo].[Radian_Eventos]...';


GO
CREATE TABLE [dbo].[Radian_Eventos] (
    [IdEvento]   INT            NOT NULL,
    [NomEvento]  NVARCHAR (200) NOT NULL,
    [CodigoDian] NVARCHAR (10)  NOT NULL,
    [EsActivo]   BIT            NOT NULL,
    CONSTRAINT [PK_Radian_Eventos] PRIMARY KEY NONCLUSTERED ([IdEvento] ASC) WITH (FILLFACTOR = 90)
);


GO
PRINT N'Creating Table [dbo].[Radian_Rechazos]...';


GO
CREATE TABLE [dbo].[Radian_Rechazos] (
    [IdRechazo]  INT            NOT NULL,
    [NomRechazo] NVARCHAR (200) NOT NULL,
    [CodigoDian] NVARCHAR (10)  NOT NULL,
    CONSTRAINT [PK_Radian_Rechazos] PRIMARY KEY NONCLUSTERED ([IdRechazo] ASC) WITH (FILLFACTOR = 90)
);


GO
PRINT N'Creating Default Constraint [dbo].[DF_Radian_Eventos_EsActivo]...';


GO
ALTER TABLE [dbo].[Radian_Eventos]
    ADD CONSTRAINT [DF_Radian_Eventos_EsActivo] DEFAULT ((-1)) FOR [EsActivo];


GO
PRINT N'Creating Foreign Key [dbo].[FK_Radian_Encabezados_Empresas]...';


GO
ALTER TABLE [dbo].[Radian_Encabezados] WITH NOCHECK
    ADD CONSTRAINT [FK_Radian_Encabezados_Empresas] FOREIGN KEY ([IdEmpresa]) REFERENCES [dbo].[Empresas] ([IdEmpresa]);


GO
PRINT N'Creating Foreign Key [dbo].[FK_Radian_Encabezados_Radian_Eventos]...';


GO
ALTER TABLE [dbo].[Radian_Encabezados] WITH NOCHECK
    ADD CONSTRAINT [FK_Radian_Encabezados_Radian_Eventos] FOREIGN KEY ([IdEvento]) REFERENCES [dbo].[Radian_Eventos] ([IdEvento]);


GO
PRINT N'Creating Foreign Key [dbo].[FK_Radian_Encabezados_Radian_Rechazos]...';


GO
ALTER TABLE [dbo].[Radian_Encabezados] WITH NOCHECK
    ADD CONSTRAINT [FK_Radian_Encabezados_Radian_Rechazos] FOREIGN KEY ([IdRechazo]) REFERENCES [dbo].[Radian_Rechazos] ([IdRechazo]);


GO
PRINT N'Creating Foreign Key [dbo].[FK_Empresas_FacturacionElectronica_Proveedores_RD]...';


GO
ALTER TABLE [dbo].[Empresas] WITH NOCHECK
    ADD CONSTRAINT [FK_Empresas_FacturacionElectronica_Proveedores_RD] FOREIGN KEY ([RdIdProveedor]) REFERENCES [dbo].[FacturacionElectronica_Proveedores] ([IdProveedor]);


GO
PRINT N'Refreshing View [dbo].[VClientes]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VClientes]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc_00]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc_00]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc_FP_00]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc_FP_00]';


GO
PRINT N'Refreshing View [dbo].[VCruces_Origen]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VCruces_Origen]';


GO
PRINT N'Refreshing View [dbo].[VCruces_TodosDocs]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VCruces_TodosDocs]';


GO
PRINT N'Refreshing View [dbo].[vLibroAuxiliar_Mov]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[vLibroAuxiliar_Mov]';


GO
PRINT N'Refreshing View [dbo].[vLibroAuxiliar_Saldos_02]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[vLibroAuxiliar_Saldos_02]';


GO
PRINT N'Refreshing View [dbo].[VNomina_NE_Encabezados]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VNomina_NE_Encabezados]';


GO
PRINT N'Refreshing View [dbo].[VNominaContratos]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VNominaContratos]';


GO
PRINT N'Refreshing View [dbo].[VHistoriaClinica_Datos]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VHistoriaClinica_Datos]';


GO
PRINT N'Refreshing View [dbo].[VHistoriaClinica_Email]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VHistoriaClinica_Email]';


GO
PRINT N'Refreshing View [dbo].[VNominaCorte]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VNominaCorte]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc____TotPorCuentas_00]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc____TotPorCuentas_00]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc_FP____TotPorCuentas_00]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc_FP____TotPorCuentas_00]';


GO
PRINT N'Refreshing View [dbo].[VCostoPromedio_Cruces]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VCostoPromedio_Cruces]';


GO
PRINT N'Refreshing View [dbo].[VCruces_Agrup]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VCruces_Agrup]';


GO
PRINT N'Refreshing View [dbo].[VProduccion]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VProduccion]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc____TotPorCuentas_Fin]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc____TotPorCuentas_Fin]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc_FP____TotPorCuentas_Fin]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc_FP____TotPorCuentas_Fin]';


GO
PRINT N'Refreshing View [dbo].[VEncabezadosMov]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VEncabezadosMov]';


GO
PRINT N'Refreshing View [dbo].[VMovimientosFactElectronica]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VMovimientosFactElectronica]';


GO
PRINT N'Refreshing View [dbo].[VEncabezados]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VEncabezados]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc_01]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc_01]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc_FP_01]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc_FP_01]';


GO
PRINT N'Refreshing View [dbo].[VEncabezadosCont_Det]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VEncabezadosCont_Det]';


GO
PRINT N'Refreshing View [dbo].[VEncabezadosMov_Det]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VEncabezadosMov_Det]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc____TotRetes_Fin]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc____TotRetes_Fin]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc_01_01]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc_01_01]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc_FP____TotRetes_Fin]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc_FP____TotRetes_Fin]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc_FP_01_01]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc_FP_01_01]';


GO
PRINT N'Refreshing View [dbo].[VCierresDocsCont]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VCierresDocsCont]';


GO
PRINT N'Refreshing View [dbo].[VCierresDocs]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VCierresDocs]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc_02]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc_02]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc_FP_02]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc_FP_02]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc_03]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc_03]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc_FP_03]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc_FP_03]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc_Fin]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc_Fin]';


GO
PRINT N'Refreshing View [dbo].[VContabDoc_FP_Fin]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VContabDoc_FP_Fin]';


GO
PRINT N'Refreshing View [dbo].[VEncabezadoFactElectronica]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[VEncabezadoFactElectronica]';


GO
PRINT N'Refreshing Function [dbo].[ufnContabilizacion_FormasPago]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[ufnContabilizacion_FormasPago]';


GO
PRINT N'Refreshing Function [dbo].[ufnContabilizacion_Normal]...';


GO
PRINT N'Refreshing Procedure [dbo].[ActualizarAudit]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[ActualizarAudit]';


GO
PRINT N'Refreshing Procedure [dbo].[ContabilizarDoc_Validar]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[ContabilizarDoc_Validar]';


GO
PRINT N'Refreshing Procedure [dbo].[GenerarImptos]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GenerarImptos]';


GO
PRINT N'Refreshing Procedure [dbo].[GetArqueoCaja]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetArqueoCaja]';


GO
PRINT N'Refreshing Procedure [dbo].[GetComisiones]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetComisiones]';


GO
PRINT N'Refreshing Procedure [dbo].[GetConsecutivosFaltantes]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetConsecutivosFaltantes]';


GO
PRINT N'Refreshing Procedure [dbo].[GetDocsDiferencias]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetDocsDiferencias]';


GO
PRINT N'Refreshing Procedure [dbo].[GetEstadoCuenta]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetEstadoCuenta]';


GO
PRINT N'Refreshing Procedure [dbo].[GetImptoRetenciones]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetImptoRetenciones]';


GO
PRINT N'Refreshing Procedure [dbo].[GetInformeUGPP]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetInformeUGPP]';


GO
PRINT N'Refreshing Procedure [dbo].[GetInvKardexPorLote]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetInvKardexPorLote]';


GO
PRINT N'Refreshing Procedure [dbo].[GetKardexInventario]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetKardexInventario]';


GO
PRINT N'Refreshing Procedure [dbo].[GetKardexInventarioPorAgrupaciones]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetKardexInventarioPorAgrupaciones]';


GO
PRINT N'Refreshing Procedure [dbo].[GetLibroAuxiliar]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetLibroAuxiliar]';


GO
PRINT N'Refreshing Procedure [dbo].[GetMediosMagneticos]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetMediosMagneticos]';


GO
PRINT N'Refreshing Procedure [dbo].[GetPagoSeguridadSocial]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetPagoSeguridadSocial]';


GO
PRINT N'Refreshing Procedure [dbo].[GetVEncabezados]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetVEncabezados]';


GO
PRINT N'Refreshing Procedure [dbo].[Ziur_CrearClienteDeSistema]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[Ziur_CrearClienteDeSistema]';


GO
PRINT N'Refreshing Procedure [dbo].[ContabilizarDoc]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[ContabilizarDoc]';


GO
PRINT N'Refreshing Procedure [dbo].[CalcularCostoVenta]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[CalcularCostoVenta]';


GO
PRINT N'Refreshing Procedure [dbo].[GetDocsSinCruzar]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetDocsSinCruzar]';


GO
PRINT N'Refreshing Procedure [dbo].[GetVentasAgrupadoPorCliVend]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetVentasAgrupadoPorCliVend]';


GO
PRINT N'Refreshing Procedure [dbo].[GetDocumentosCierre]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetDocumentosCierre]';


GO
PRINT N'Refreshing Procedure [dbo].[GetLibroDiario]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetLibroDiario]';


GO
PRINT N'Refreshing Procedure [dbo].[GetNominaItemsProgramados]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetNominaItemsProgramados]';


GO
PRINT N'Refreshing Procedure [dbo].[ComisionesPorDoc]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[ComisionesPorDoc]';


GO
PRINT N'Refreshing Procedure [dbo].[GetVacaciones]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetVacaciones]';


GO
PRINT N'Refreshing Procedure [dbo].[GenerarCrucesCont]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GenerarCrucesCont]';


GO
PRINT N'Refreshing Procedure [dbo].[GetActivosFijosDet]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetActivosFijosDet]';


GO
PRINT N'Refreshing Procedure [dbo].[GetInformeRIPS]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetInformeRIPS]';


GO
PRINT N'Refreshing Procedure [dbo].[GetMovimientosFactElec]...';


GO
EXECUTE sp_refreshsqlmodule N'[dbo].[GetMovimientosFactElec]';


GO
-- Refactoring step to update target server with deployed transaction logs
IF NOT EXISTS (SELECT OperationKey FROM [dbo].[__RefactorLog] WHERE OperationKey = '39e323d1-a18d-4fb5-80bc-946c5930fd4b')
INSERT INTO [dbo].[__RefactorLog] (OperationKey) values ('39e323d1-a18d-4fb5-80bc-946c5930fd4b')
IF NOT EXISTS (SELECT OperationKey FROM [dbo].[__RefactorLog] WHERE OperationKey = '24ac2dce-152f-4c75-8570-d5ee322eb746')
INSERT INTO [dbo].[__RefactorLog] (OperationKey) values ('24ac2dce-152f-4c75-8570-d5ee322eb746')
IF NOT EXISTS (SELECT OperationKey FROM [dbo].[__RefactorLog] WHERE OperationKey = 'c2a1212d-8d40-4625-a993-71a98dabe481')
INSERT INTO [dbo].[__RefactorLog] (OperationKey) values ('c2a1212d-8d40-4625-a993-71a98dabe481')
IF NOT EXISTS (SELECT OperationKey FROM [dbo].[__RefactorLog] WHERE OperationKey = 'a1004f99-1a08-4c47-8144-6d2877e8d99f')
INSERT INTO [dbo].[__RefactorLog] (OperationKey) values ('a1004f99-1a08-4c47-8144-6d2877e8d99f')
IF NOT EXISTS (SELECT OperationKey FROM [dbo].[__RefactorLog] WHERE OperationKey = '504b44ea-85ac-4e09-9fe1-4fee2967038d')
INSERT INTO [dbo].[__RefactorLog] (OperationKey) values ('504b44ea-85ac-4e09-9fe1-4fee2967038d')
IF NOT EXISTS (SELECT OperationKey FROM [dbo].[__RefactorLog] WHERE OperationKey = '7ac7e0d3-e9bb-4f26-b5c9-220a7828a902')
INSERT INTO [dbo].[__RefactorLog] (OperationKey) values ('7ac7e0d3-e9bb-4f26-b5c9-220a7828a902')
IF NOT EXISTS (SELECT OperationKey FROM [dbo].[__RefactorLog] WHERE OperationKey = '2a0a27bb-57fa-465e-94ae-63f3657c6390')
INSERT INTO [dbo].[__RefactorLog] (OperationKey) values ('2a0a27bb-57fa-465e-94ae-63f3657c6390')
IF NOT EXISTS (SELECT OperationKey FROM [dbo].[__RefactorLog] WHERE OperationKey = 'edfcddf9-ad8b-4372-ab1b-3b1cc54b7096')
INSERT INTO [dbo].[__RefactorLog] (OperationKey) values ('edfcddf9-ad8b-4372-ab1b-3b1cc54b7096')

GO

GO
	/*
	Plantilla de script posterior a la implementación							
	--------------------------------------------------------------------------------------
	 Este archivo contiene instrucciones de SQL que se anexarán al script de compilación.		
	 Use la sintaxis de SQLCMD para incluir un archivo en el script posterior a la implementación.			
	 Ejemplo:      :r .\miArchivo.sql								
	 Use la sintaxis de SQLCMD para hacer referencia a una variable en el script posterior a la implementación.		
	 Ejemplo:      :setvar TableName miTabla							
				   SELECT * FROM [$(TableName)]					
	--------------------------------------------------------------------------------------
	*/

	--Inclusion de nuevo operador ZiurOne
	--//
	IF NOT EXISTS (select * from FacturacionElectronica_TipoEnvio where IdTipoEnvio = 16)
	   insert into FacturacionElectronica_TipoEnvio (IdTipoEnvio, IdProveedor, NomEnvio, EsEnvioProd, IdTipoResol, UrlAPI) 
	   values (16,3,'ZiurOne Radian (Test)',0,3,'http://www.ziurone.com/api/ubl2.1')
GO

	IF (NOT EXISTS (select * from FacturacionElectronica_TipoEnvio where IdTipoEnvio = 17))
	   insert into FacturacionElectronica_TipoEnvio (IdTipoEnvio, IdProveedor, NomEnvio, EsEnvioProd, IdTipoResol, UrlAPI) 
	   values (17,3,'ZiurOne Radian (Producción)',1,3,'http://www.ziurone.com/api/ubl2.1')
GO
	--//

	--//Crear menu de find radian
	--//
	IF (NOT EXISTS(select * from Permisos_Interfaces where IdInterface = 667))
	insert into dbo.Permisos_Interfaces (IdInterface, NomInterface, EsActivo, NomClase, EsSistema, IdInterfaceParent)
	values(667,'Find Radian',1,'FindRadian',0,667)
GO

	IF (NOT EXISTS(select * from Permisos_InterfacesPorUsuario where IdInterface = 667))
	begin
		insert into dbo.Permisos_InterfacesPorUsuario (IdUsuario, IdInterface, EsConsultar, EsInsertar, EsActualizar, EsEliminar, EsConsultarDenegar, EsInsertarDenegar, EsActualizarDenegar, EsEliminarDenegar)
		values (2,667,1,1,1,1,0,0,0,0)

		insert into dbo.Permisos_InterfacesPorUsuario (IdUsuario, IdInterface, EsConsultar, EsInsertar, EsActualizar, EsEliminar, EsConsultarDenegar, EsInsertarDenegar, EsActualizarDenegar, EsEliminarDenegar)
		values (22,667,1,1,1,1,0,0,0,0)

		insert into dbo.Permisos_InterfacesPorUsuario (IdUsuario, IdInterface, EsConsultar, EsInsertar, EsActualizar, EsEliminar, EsConsultarDenegar, EsInsertarDenegar, EsActualizarDenegar, EsEliminarDenegar)
		values (-103,667,1,1,1,1,0,0,0,0)

		insert into dbo.Permisos_InterfacesPorUsuario (IdUsuario, IdInterface, EsConsultar, EsInsertar, EsActualizar, EsEliminar, EsConsultarDenegar, EsInsertarDenegar, EsActualizarDenegar, EsEliminarDenegar)
		values (-104,667,1,1,1,1,0,0,0,0)

		insert into dbo.Permisos_InterfacesPorUsuario (IdUsuario, IdInterface, EsConsultar, EsInsertar, EsActualizar, EsEliminar, EsConsultarDenegar, EsInsertarDenegar, EsActualizarDenegar, EsEliminarDenegar)
		values (-105,667,1,1,1,1,0,0,0,0)

		insert into dbo.Permisos_InterfacesPorUsuario (IdUsuario, IdInterface, EsConsultar, EsInsertar, EsActualizar, EsEliminar, EsConsultarDenegar, EsInsertarDenegar, EsActualizarDenegar, EsEliminarDenegar)
		values (-106,667,1,1,1,1,0,0,0,0)

		insert into dbo.Permisos_InterfacesPorUsuario (IdUsuario, IdInterface, EsConsultar, EsInsertar, EsActualizar, EsEliminar, EsConsultarDenegar, EsInsertarDenegar, EsActualizarDenegar, EsEliminarDenegar)
		values (-107,667,1,1,1,1,0,0,0,0)
	end
GO

	IF (NOT EXISTS(SELECT * FROM Menu WHERE IdMenu = 911391))
	INSERT INTO [dbo].[Menu]
				([IdMenu]
			   ,[NumPantalla]
			   ,[NomMenu]
			   ,[EsGrupo]
			   ,[IdMenuPadre]
			   ,[Orden]
			   ,[AyudaTexto]
			   ,[Opcion]
			   ,[NomForm]
			   ,[IdImageNormal]
			   ,[IdImageMouseOver]
			   ,[IdImageMouseDown]
			   ,[IdImageMouseDrag]
			   ,[IdInterface]
			   ,[EsActivo]
			   ,[xxxRevisado])
	VALUES
	(911391,1,'Buscar Radian',1,10035,1,'Buscar Radian',1,'FindRadian',11104,11104,11104,11104,667,0,0)
GO

	--Inclusion de eventos de radian
	--//
	IF NOT EXISTS(select * from Radian_Eventos where IdEvento = 1)
	   INSERT INTO [Radian_Eventos] ([IdEvento] ,[NomEvento] ,[CodigoDian], [EsActivo])
	   VALUES(1, 'Acuse de recibo de Factura Electrónica de Venta','030',1)

	IF NOT EXISTS(select * from Radian_Eventos where IdEvento = 2)
	   INSERT INTO [Radian_Eventos] ([IdEvento] ,[NomEvento] ,[CodigoDian], [EsActivo])
	   VALUES(2, 'Reclamo de la Factura Electrónica de Venta','031',1)

	IF NOT EXISTS(select * from Radian_Eventos where IdEvento = 3)
	   INSERT INTO [Radian_Eventos] ([IdEvento] ,[NomEvento] ,[CodigoDian], [EsActivo])
	   VALUES(3, 'Recibo del bien y/o prestación del servicio','032',1)

	IF NOT EXISTS(select * from Radian_Eventos where IdEvento = 4)
	   INSERT INTO [Radian_Eventos] ([IdEvento] ,[NomEvento] ,[CodigoDian], [EsActivo])
	   VALUES(4, 'Aceptación expresa','033',1)

	IF NOT EXISTS(select * from Radian_Eventos where IdEvento = 5)
	   INSERT INTO [Radian_Eventos] ([IdEvento] ,[NomEvento] ,[CodigoDian], [EsActivo])
	   VALUES(5, 'Aceptación Tácita','034',0)

	IF NOT EXISTS(select * from Radian_Eventos where IdEvento = 6)
	   INSERT INTO [Radian_Eventos] ([IdEvento] ,[NomEvento] ,[CodigoDian], [EsActivo])
	   VALUES(6, 'Documento validado por la DIAN','02',0)

	IF NOT EXISTS(select * from Radian_Eventos where IdEvento = 7)
	   INSERT INTO [Radian_Eventos] ([IdEvento] ,[NomEvento] ,[CodigoDian], [EsActivo])
	   VALUES(7, 'Documento rechazado por la DIAN','04',0)

	IF NOT EXISTS(select * from Radian_Eventos where IdEvento = 990200)
	   INSERT INTO [Radian_Eventos] ([IdEvento] ,[NomEvento] ,[CodigoDian], [EsActivo])
	   VALUES(990200, 'Acuse+Recibo+Aceptación','ZR',1)

	IF NOT EXISTS(select * from Radian_Eventos where IdEvento = 990300)
	   INSERT INTO [Radian_Eventos] ([IdEvento] ,[NomEvento] ,[CodigoDian], [EsActivo])
	   VALUES(990300, 'Acuse+Recibo+Reclamo','ZR',1)
	   
GO
	--//


	--Inclusion de rechazos de radian
	--//
	IF NOT EXISTS(select * from Radian_Rechazos where IdRechazo = 1)
	   INSERT INTO [Radian_Rechazos] (IdRechazo, NomRechazo, CodigoDian)
	   VALUES(1, 'Documento con inconsistencias','01')

	IF NOT EXISTS(select * from Radian_Rechazos where IdRechazo = 2)
	   INSERT INTO [Radian_Rechazos] (IdRechazo, NomRechazo, CodigoDian)
	   VALUES(2, 'Mercancía no entregada totalmente','02')

	IF NOT EXISTS(select * from Radian_Rechazos where IdRechazo = 3)
	   INSERT INTO [Radian_Rechazos] (IdRechazo, NomRechazo, CodigoDian)
	   VALUES(3, 'Mercancía no entregada parcialmente','03')

	IF NOT EXISTS(select * from Radian_Rechazos where IdRechazo = 4)
	   INSERT INTO [Radian_Rechazos] (IdRechazo, NomRechazo, CodigoDian)
	   VALUES(4, 'Servicio no prestado','04')
GO
	--//

	--Inclusion de videos
	--//
	UPDATE Permisos_Interfaces SET VideoURL = 'https://youtu.be/lp-8HFdEHJ4' WHERE IdInterface = 520
	UPDATE Permisos_Interfaces SET VideoURL = 'https://youtu.be/X8z9OX5XZ1k' WHERE IdInterface = 521
	UPDATE Permisos_Interfaces SET VideoURL = 'https://youtu.be/0RZSmudFqbQ' WHERE IdInterface = 594
	UPDATE Permisos_Interfaces SET VideoURL = 'https://youtu.be/nnPJJZNFnBs' WHERE IdInterface = 595
	UPDATE Permisos_Interfaces SET VideoURL = 'https://youtu.be/IEPFPDHZvfU' WHERE IdInterface = 600
	UPDATE Permisos_Interfaces SET VideoURL = 'https://youtu.be/AMkYgSDlYNg' WHERE IdInterface = 601
	UPDATE Permisos_Interfaces SET VideoURL = 'https://youtu.be/kmFJqXdwPfg' WHERE IdInterface = 604
	UPDATE Permisos_Interfaces SET VideoURL = 'https://youtu.be/y9q21EK8WDg' WHERE IdInterface = 605
GO
	--//
GO

GO
PRINT N'Checking existing data against newly created constraints';


GO
ALTER TABLE [dbo].[Radian_Encabezados] WITH CHECK CHECK CONSTRAINT [FK_Radian_Encabezados_Empresas];

ALTER TABLE [dbo].[Radian_Encabezados] WITH CHECK CHECK CONSTRAINT [FK_Radian_Encabezados_Radian_Eventos];

ALTER TABLE [dbo].[Radian_Encabezados] WITH CHECK CHECK CONSTRAINT [FK_Radian_Encabezados_Radian_Rechazos];

ALTER TABLE [dbo].[Empresas] WITH CHECK CHECK CONSTRAINT [FK_Empresas_FacturacionElectronica_Proveedores_RD];


GO
PRINT N'Update complete.';

--Actualizar datos de la version
INSERT INTO ZiurVersiones (IdVersion, NumVersion, Descripcion)
VALUES (324,914,'Modificacion Radian y Doc Soporte ZiurOne')
GO

COMMIT
GO
