CREATE   PROCEDURE [dbo].[spInsertCartera]
@FechaPago VARCHAR(10),
@HoraPago VARCHAR(10),
@ValorCuota VARCHAR(30),
@IdContrato INT
AS
BEGIN TRANSACTION
		BEGIN TRY

		--INSERT INTO Bod.Cartera VALUES(@FechaPago,@HoraPago,@ValorCuota,@ValorCuota,'0',1,@IdContrato,0,1,'','','','')

		COMMIT TRANSACTION
		END TRY
BEGIN CATCH
ROLLBACK TRAN
DECLARE @ErrorMessage NVARCHAR(4000);
DECLARE @ErrorSeverity INT;
DECLARE @ErrorState INT;
	SELECT 
	@ErrorMessage = ERROR_MESSAGE(),
	@ErrorSeverity = ERROR_SEVERITY(),
	@ErrorState = ERROR_STATE();
	RAISERROR(
	@ErrorMessage, -- Message text.
	@ErrorSeverity, -- Severity.
	@ErrorState -- State.
	);
END CATCH
GO
/****** Object:  StoredProcedure [dbo].[spInsertClaseDoc]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 30/05/2024
-- Description:	Insertar Calse Documento
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertClaseDoc]
	-- Add the parameters for the stored procedure here
	@Nombre varchar(50) = null,
	@Descripcion varchar(50) = null

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
	-- Insert statements for procedure here
	INSERT INTO [dbo].[Clase_Doc]
           ([Nombre]
           ,[Descripcion])
     VALUES
           (@Nombre
           ,@Descripcion)

END
GO
/****** Object:  StoredProcedure [dbo].[spInsertClientes]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 23/09/2021
-- Description:	Insert Clientes
-- ================================================
CREATE   PROCEDURE [dbo].[spInsertClientes] 
	-- Add the parameters for the stored procedure here
	@TipoIdent int,
    @Identificacion nvarchar(20),
    @TipoCliente int,
    @Nombres varchar(125),
    @Apellidos varchar(125),
    @IdEmpresa int,
    @IdCiudad int,
    @Direccion varchar(125),
    @Movil varchar(20),
    @Telefono varchar(20),
	@Email varchar(125),
	@RazonSocial varchar(250)

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Clientes]
           ([TipoIdent]
           ,[Identificacion]
           ,[TipoCliente]
           ,[Nombres]
           ,[Apellidos]
           ,[IdEmpresa]
           ,[IdCiudad]
           ,[Direccion]
           ,[Movil]
           ,[Telefono]
		   ,[Email]
		   ,[RazonSocial])
     VALUES
           (@TipoIdent, 
           @Identificacion,
           @TipoCliente, 
           @Nombres, 
           @Apellidos, 
           @IdEmpresa, 
           @IdCiudad, 
           @Direccion, 
           @Movil, 
           @Telefono, 
		   @Email,
		   @RazonSocial)
END

GO
/****** Object:  StoredProcedure [dbo].[spInsertCompanias]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 11/04/20222
-- Description:	Insertar Compañias
-- ================================================
CREATE   PROCEDURE [dbo].[spInsertCompanias]
	-- Add the parameters for the stored procedure here
	@NombreCia varchar(50) = null,
    @Sucursal varchar(10) = null,
    @Direccion varchar(250) = null,
    @Telefono varchar(20) = null,
    @IdCiudad int = null,
    @Estado varchar(1) = null,
    @CodSyscom varchar(2) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Compania]
           ([NombreCia]
           ,[Sucursal]
           ,[Direccion]
           ,[Telefono]
           ,[IdCiudad]
           ,[Estado]
           ,[CodSyscom])
     VALUES
           (@NombreCia
           ,@Sucursal
           ,@Direccion
           ,@Telefono
           ,@IdCiudad
           ,@Estado
           ,@CodSyscom)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertConceptos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 09/02/2022
-- Description:	Insertar Conceptos
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertConceptos] 
	-- Add the parameters for the stored procedure here
	@CodSyscom varchar(4),
    @Concepto varchar(250),
    @Grupo varchar(20),
	@Valor decimal(18,2),
	@Porc_Descuento varchar(4),
	@IdConceptoPDF int,
	@ValorIva numeric(18,2),
	@RubroConcepto varchar(20)
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Concepto_Servicios]
           ([CodSyscom]
           ,[Concepto]
           ,[Grupo]
           ,[Valor]
           ,[Porc_Descuento]
           ,[IdConceptoPDF]
		   ,[ValorIva]
		   ,[RubroConcepto])
     VALUES
           (@CodSyscom
           ,@Concepto
           ,@Grupo
           ,@Valor
           ,@Porc_Descuento
		   ,@IdConceptoPDF
		   ,@ValorIva
		   ,@RubroConcepto)
END

GO
/****** Object:  StoredProcedure [dbo].[spInsertConductores]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 04/04/2022
-- Description:	Insertar Conductores
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertConductores] 
	-- Add the parameters for the stored procedure here
	@TipoIdent int = null,
    @Identificacion varchar(20) = null,
    @Nombres varchar(125) = null,
    @Apellidos varchar(125) = null,
    @IdCiudad int = null,
    @Direccion varchar(250) = null,
    @Telefono varchar(20) = null,
	@Movil varchar(20) = null,
    @Email varchar(250) = null,
    @Estado varchar(1) = null,
	@Liquidacion numeric(18,2) = null,
	@IdVehiculo int = null,
	@Compania int = null,
	@TipoConductor int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Conductores]
           ([TipoIdent]
           ,[Identificacion]
           ,[Nombres]
           ,[Apellidos]
           ,[IdCiudad]
           ,[Direccion]
           ,[Telefono]
		   ,[Movil]
           ,[Email]
           ,[Estado]
		   ,[Liquidacion]
		   ,[IdVehiculo]
		   ,[IdCia]
		   ,[TipoConductor])
    
	VALUES
           (@TipoIdent
           ,@Identificacion
           ,@Nombres
           ,@Apellidos
           ,@IdCiudad
           ,@Direccion
           ,@Telefono
		   ,@Movil
           ,@Email
           ,@Estado
		   ,@Liquidacion
		   ,@IdVehiculo
		   ,@Compania
		   ,@TipoConductor)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertCotArticulos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 27/10/2021
-- Description:	Insertar Cotizacion - Articulos
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertCotArticulos]
	-- Add the parameters for the stored procedure here
	@IdArticulo Int = null,
	@IdCotizacion Int = null,
	@Nombre varchar(125) = null,
    @Descripcion varchar(255) = null,
    @Cantidad varchar(10) = null,
	@IdSolicitud int = null,
	@CtrlEmpaque int = null,
	@Material int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Cotizacion_Articulos]
           ([IdArticulo]
		   ,[IdCotizacion]
           ,[Nombre]
           ,[Descripcion]
		   ,[Cantidad]
		   ,[IdSolicitud]
		   ,[Ctrl_Empaque]
		   ,[Material])
     
	 VALUES
           (@IdArticulo, 
		    @IdCotizacion, 
			@Nombre, 
			@Descripcion, 
			@Cantidad,
			@IdSolicitud,
			@CtrlEmpaque,
			@Material)
END



GO
/****** Object:  StoredProcedure [dbo].[spInsertCotBodegas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 07/03/2022
-- Description:	Guardar Cotizacion-Bodega
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertCotBodegas]
	-- Add the parameters for the stored procedure here
	@IdCotizacion int = null,
	@IdSolicitud int = null,
	@IdBodega int = null,
	@IdSucursal int = null,
	@Nombre varchar(125) = null,
	@Capacidad numeric(18,0) = null,
	@Ocupacion numeric(18,0) = null, 
	@Disponible numeric(18,0) = null,
	@Largo varchar(20) = null,
	@Ancho varchar(20) = null,
	@Alto varchar(20) = null,
	@Estado varchar(20) = null,
	@Codsyscom varchar(4) = null,
	@ValorBodega decimal(18,2) = null
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Cotizacion_Bodegas]
		([IdCotizacion]
		,[IdSolicitud]
		,[IdBodega]
		,[IdSucursal]
		,[Nombre]
		,[Capacidad]
		,[Ocupacion]
		,[Disponible]
		,[Largo]
		,[Ancho]
		,[Alto] 
		,[Estado]
		,[CodSyscom]
		,[ValorBodega])
		 
	VALUES (@IdCotizacion, 
			@IdSolicitud,
			@IdBodega, 
			@IdSucursal, 
			@Nombre, 
			@Capacidad, 
			@Ocupacion,
			@Disponible,
			@Largo, 
			@Ancho, 
			@Alto, 
			@Estado, 
			@CodSyscom,
			@ValorBodega)
	
END


GO
/****** Object:  StoredProcedure [dbo].[spInsertCotConceptos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 09/02/2022
-- Description:	Insertar Cotizacion - Conceptos
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertCotConceptos] 
	-- Add the parameters for the stored procedure here
	@IdCotizacion int = null,
    @IdServicio int = null,
    @CodSyscom varchar(4) = null,
    @Nombre varchar(125) = null,
    @Descripcion varchar(250) = null,
	@Valor_Servicio decimal(18,2) = null,
	@Valor_Negociado decimal(18,2) = null,
	@IdAsesor int = null,
	@ConcepPDF int = null,
	@Valor_Iva decimal(18,2) = null,
	@IdSolicitud int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Cotizacion_Conceptos]
           ([IdCotizacion]
           ,[IdServicio]
           ,[CodSyscom]
           ,[Nombre]
           ,[Descripcion]
           ,[Valor_Servicio]
           ,[Valor_Negociado]
           ,[IdAsesor]
		   ,[IdConceptoPDF]
		   ,[Valor_Iva]
		   ,[IdSolicitud])
     VALUES
           (@IdCotizacion, 
		    @IdServicio, 
			@CodSyscom, 
			@Nombre, 
			@Descripcion, 
			@Valor_Servicio, 
			@Valor_Negociado, 
			@IdAsesor, 
			@ConcepPDF, 
			@Valor_Iva,
			@IdSolicitud)
END

GO
/****** Object:  StoredProcedure [dbo].[spInsertCotDocumentos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 16/05/2024
-- Description:	Insertar Cotizacion Documentos
-- =============================================
CREATE PROCEDURE [dbo].[spInsertCotDocumentos]
	-- Add the parameters for the stored procedure here
	@IdCotizacion Int = null,
	@IdSolicitud int = null,
	@FechaDcto varchar(10) = null,
    @Documento varchar(MAX) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Cotizacion_Documentos]
           ([IdCotizacion]
           ,[IdSolicitud]
           ,[FechaDcto]
           ,[Documento])
     VALUES
           (@IdCotizacion
           ,@IdSolicitud
           ,@FechaDcto
           ,@Documento)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertCotEmpaques]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 26/04/2022
-- Description:	Insertar Cotizacion - Empaques
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertCotEmpaques]
	-- Add the parameters for the stored procedure here
	@IdMaterial Int = null,
	@IdCotizacion Int = null,
	@Nombre varchar(125) = null,
    @ValorCosto decimal(18,2) = null,
    @Cantidad decimal(18,2) = null,
	@IdSolicitud int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Cotizacion_Empaques]
           ([IdCotizacion]
           ,[IdMaterial]
           ,[Nombre]
           ,[ValorCosto]
		   ,[Cantidad]
		   ,[IdSolicitud])
     VALUES
           (@IdCotizacion, 
		    @IdMaterial, 
			@Nombre, 
			@ValorCosto, 
			@Cantidad,
			@IdSolicitud)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertCotizaciones]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Sergio Rendón Gómez
-- ALTER date: 27/10/2021
-- Description:	Insert Cotizacion
-- ================================================
CREATE PROCEDURE [dbo].[spInsertCotizaciones] 
	-- Add the parameters for the stored procedure here
	@IdCliente int = null, 
    @IdUsuario int = null, 
    @FechaCotizacion varchar(10) = null, 
    @Servicios int = null, 
    @Ciudad_Origen int = null, 
    @Direccion_Origen varchar(125) = null, 
    @Ciudad_Destino int = null, 
    @Direccion_Destino varchar(125) = null, 
    @Volumen varchar(50) = null, 
    @Arte int = null, 
    @Presencial varchar(1) = null,
	@FechaPresencial varchar(10) = null,
	@HoraPresencial varchar(8) = null,
    @Seguro int = null, 
    @Valor_Declarado varchar(20) = null, 
    @Porc_Liquidacion varchar(10) = null, 
    @IdFormaPago int = null, 
    @IdMetodoPago int = null, 
	@Almacenamiento varchar(1) = null,
    @Fecha_Recogida varchar(10) = null, 
    @Hora_Recogida varchar(8) = null, 
    @Fecha_Entrega varchar(10) = null, 
    @Hora_Entrega varchar(8) = null, 
    @Autorizado varchar(125) = null, 
    @Tipo_Ident_Autorizado int = null, 
    @Ident_Autorizado nvarchar(20) = null, 
    @Telefono_Autorizado varchar(10) = null, 
    @Medio_Comunicacion int = null, 
    @Medio_Servicio int = null, 
    @IdEstadoCot int = null, 
	@ValorCotizacion decimal(18, 2) = null,
    @Observacion varchar(MAX) = null,
	@IdSolicitud int = null,
	@TipoServ int = null,
	@MotivoPerdida int = null,
    @ObservaPerdida varchar(MAX) = null,
    @CuartoUtil int = null,
    @Exteriores int = null,
    @Tapizados int = null,
    @Sucursal int = null,
    @ObservaPago varchar(MAX) = null,
    @Fecha_Empaque varchar(10) = null,
    @Hora_Empaque varchar(8) = null,
    @Periodicidad int = null,
    @Ref_Personal varchar(125) = null,
    @Ref_Movil nchar(20) = null,
    @Ref_Direccion varchar(255) = null,
    @Ref_Correo varchar(125) = null,
	@IdBodega int = null,
	@BloqueoCot varchar(1) = null,
	@Poliza varchar(20) = null,
	@Barrio_Origen varchar(50) = null,
	@Barrio_Destino varchar(50) = null,
	@EmpaqueVenta int = null,
	@Serv_Inter int = null,
	@Flete_Inter varchar(50) = null,
	@Gastos_Inter int = null,
	@Vaduana_Inter varchar(50) = null,
	@Otros_Inter varchar(50) = null,
	@Aduana_Inter int = null,
	@Observa_Inter varchar(MAX) = null,
	@IdCia int = null,
	@ObservaEmpaque varchar(MAX) = null,
	@ObservaCliente varchar(MAX) = null,
	@IdEmpresa int = null,
	@RazonSocial varchar(250) = null,
	@NumOrden int = null,
	@ContactoEmpresa varchar(150) = null,
	@CorreoContacto varchar(250) = null,
	@FechaIniBod varchar(10) = null,
	@FechaFinBod varchar(10) = null,
	@ObservaBodega varchar(MAX) = null,
	@Cortesia varchar(1) = null,
	@FechaCortIni varchar(10) = null,
	@FechaCortFin varchar(10) = null,
	@FechaUltima varchar(10) = null,
	@Manifiesto int = null,
	@Remesa int = null,
	@Ctrl_Cotizacion int = null,
	@IdGestion int = null,
	@FechaProximo varchar(10) = null,
	@ContadorCorreo int = null,
	@AutorizaCortesia int = null, 
	@TteSalida int = null, 
	@Ocupacion numeric(18,0) = null, 
	@VrSugerido numeric(18,0) = null, 
	@VrNegociado numeric(18,0) = null,
	@ObservaInterna varchar(MAX) = null,
	@ValorVehiculo varchar(20) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	-- Declarar Variables
	DECLARE @IdCotizacion as int;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Cotizacion]
			([IdCliente]
			,[IdUsuario]
			,[IdSolicitud]
			,[FechaCotizacion]
			,[Servicios]
			,[Ciudad_Origen]
			,[Direccion_Origen]
			,[Ciudad_Destino]
			,[Direccion_Destino]
			,[Volumen]
			,[Arte]
			,[Presencial]
			,[FechaPresencial]
			,[HoraPresencial]
			,[Seguro]
			,[Valor_Declarado]
			,[Porc_Liquidacion]
			,[IdFormaPago]
			,[IdMetodoPago]
			,[Almacenamiento]
			,[Fecha_Recogida]
			,[Hora_Recogida]
			,[Fecha_Entrega]
			,[Hora_Entrega]
			,[Autorizado]
			,[Tipo_Ident_Autorizado]
			,[Ident_Autorizado]
			,[Telefono_Autorizado]
			,[Medio_Comunicacion]
			,[Medio_Servicio]
			,[IdEstadoCot]
			,[ValorCotizacion]
			,[Observacion]
			,[TipoServ]
			,[MotivoPerdida]
			,[ObservaPerdida] 
			,[CuartoUtil]
			,[Exteriores]
			,[Tapizados]
			,[Sucursal]
			,[ObservaPago]
			,[Fecha_Empaque]
			,[Hora_Empaque]
			,[Periodicidad] 
			,[Ref_Personal]
			,[Ref_Movil]
			,[Ref_Direccion]
			,[Ref_Correo]
			,[IdBodega]
			,[BloqueoCot]
			,[Poliza]
			,[Barrio_Origen]
			,[Barrio_Destino]
			,[EmpaqueVenta]
			,[Serv_Inter]
			,[Flete_Inter]
			,[Gastos_Inter]
			,[Vaduana_Inter]
			,[Otros_Inter]
			,[Aduana_Inter]
			,[Observa_Inter]
			,[IdCia]
			,[ObservaEmpaque]
			,[ObservaCliente]
			,[IdEmpresa]
			,[RazonSocial]
			,[NumOrden]
			,[ContactoEmpresa]
			,[CorreoContacto]
			,[FechaIniBod]
			,[FechaFinBod]
			,[ObservaBodega]
			,[Cortesia]
			,[FechaCortIni]
			,[FechaCortFin]
			,[FechaUltima]
			,[Manifiesto]
			,[Remesa]
			,[IdGestion]
			,[FechaProximo]
			,[Ctrl_Cotizacion]
			,[ContadorCorreo]
			,[AutorizaCortesia] 
			,[TteSalida]
			,[Ocupacion] 
			,[VrSugerido] 
			,[VrNegociado]
			,[ObservaInterna]
			,[Valor_Vehiculo])

     VALUES
			(@IdCliente, 
			@IdUsuario, 
			@IdSolicitud, 
			@FechaCotizacion, 
			@Servicios, 
			@Ciudad_Origen, 
			@Direccion_Origen, 
			@Ciudad_Destino, 
			@Direccion_Destino, 
			@Volumen, 
			@Arte, 
			@Presencial, 
			@FechaPresencial, 
			@HoraPresencial, 
			@Seguro, 
			@Valor_Declarado, 
			@Porc_Liquidacion, 
			@IdFormaPago, 
			@IdMetodoPago, 
			@Almacenamiento, 
			@Fecha_Recogida, 
			@Hora_Recogida, 
			@Fecha_Entrega, 
			@Hora_Entrega, 
			@Autorizado, 
			@Tipo_Ident_Autorizado, 
			@Ident_Autorizado,
			@Telefono_Autorizado,
			@Medio_Comunicacion, 
			@Medio_Servicio, 
			@IdEstadoCot, 
			@ValorCotizacion, 
			@Observacion,
			@TipoServ,
			@MotivoPerdida,
			@ObservaPerdida,
			@CuartoUtil,
			@Exteriores,
			@Tapizados,
			@Sucursal,
			@ObservaPago,
			@Fecha_Empaque,
			@Hora_Empaque,
			@Periodicidad,
			@Ref_Personal,
			@Ref_Movil,
			@Ref_Direccion,
			@Ref_Correo,
			@IdBodega,
			@BloqueoCot,
			@Poliza,
			@Barrio_Origen,
			@Barrio_Destino,
			@EmpaqueVenta,
			@Serv_Inter,
			@Flete_Inter,
			@Gastos_Inter,
			@Vaduana_Inter,
			@Otros_Inter,
			@Aduana_Inter,
			@Observa_Inter,
			@IdCia,
			@ObservaEmpaque,
			@ObservaCliente,
			@IdEmpresa,
			@RazonSocial,
			@NumOrden,
			@ContactoEmpresa,
			@CorreoContacto,
			@FechaIniBod,
			@FechaFinBod,
			@Observa_Inter,
			@Cortesia,
			@FechaCortIni,
			@FechaCortFin,
			@FechaUltima,
			@Manifiesto,
			@Remesa,
			@IdGestion,
			@FechaProximo,
			@Ctrl_Cotizacion,
			@ContadorCorreo,
			@AutorizaCortesia, 
			@TteSalida, 
			@Ocupacion, 
			@VrSugerido, 
			@VrNegociado,
			@ObservaInterna,
			@ValorVehiculo)

	SET @IdCotizacion = (SELECT MAX(IdCotizacion) FROM Cotizacion);
	
	-- Actualizar Registro de Llamadas
	UPDATE [dbo].[Reg_Llamadas] SET IdCotizacion = @IdCotizacion WHERE IdSolicitud = @IdSolicitud
	
	-- Actualiza el estado de las solicitudes y la pasa a gestionada --
	UPDATE [dbo].[Solicitudes]      SET Estado = '0' WHERE IdSolicitud = @IdSolicitud
	UPDATE [dbo].[Solicitud_Asesor] SET Estado = '0' WHERE IdSolicitud = @IdSolicitud

	-- Actualizar razon social y nit en clientes --
	UPDATE [dbo].[Clientes] SET RazonSocial     = @RazonSocial WHERE IdCliente = @IdCliente
	UPDATE [dbo].[Clientes] SET IdEmpresa       = @IdEmpresa WHERE IdCliente = @IdCliente
	UPDATE [dbo].[Empresas] SET ContactoEmpresa = @ContactoEmpresa, EmailContacto   = @CorreoContacto WHERE IdEmpresa = @IdEmpresa

	
	
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertCotMaterialesArticulo]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 27/10/2021
-- Description:	Insert Cotizacion Mat - Articulos
-- ================================================
CREATE   PROCEDURE [dbo].[spInsertCotMaterialesArticulo] 
	-- Add the parameters for the stored procedure here
	@IdCotizacion int = null,
	@IdCot_Articulo int = null,
	@IdMaterial int = null,
	@NombreMaterial varchar(125) = null,
	@IdArticulo int = null,
	@NombreArticulo varchar(125) = null,
	@Valor varchar(20) = null,
    @Cantidad decimal(18,2) = null,
	@IdSolicitud int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Cotizacion_MaterialesArticulo]
           ([IdCotizacion]
		   ,[IdCot_Articulo]
           ,[IdMaterial]
           ,[NombreMaterial]
           ,[IdArticulo]
           ,[NombreArticulo]
           ,[Valor]
           ,[Cantidad]
		   ,[IdSolicitud])
     VALUES
           (@IdCotizacion
		   ,@IdCot_Articulo
           ,@IdMaterial
		   ,@NombreMaterial
           ,@IdArticulo
		   ,@NombreArticulo
           ,@Valor
           ,@Cantidad
		   ,@IdSolicitud)

	-- Actualizar el Control de Empaque
	UPDATE [dbo].[Cotizacion_Articulos] SET Ctrl_Empaque = 1 where IdCotizacion = @IdCotizacion and IdCot_Articulo = @IdCot_Articulo

END


GO
/****** Object:  StoredProcedure [dbo].[spInsertCotRequisiciones]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 12/05/2022
-- Description: Registar Requisicion Cotizaicon
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertCotRequisiciones]
	-- Add the parameters for the stored procedure here
	@IdMaterial int,
    @IdCotizacion int,
    @Cantidad decimal(18,2),
    @ValorRequisicion decimal(18,2),
    @Clase varchar(1),
	@IdSolicitud int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets FROM
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Cotizacion_Requisicion]
           ([IdMaterial]
           ,[IdCotizacion]
           ,[Cantidad]
           ,[ValorRequisicion]
           ,[Clase]
		   ,[IdSolicitud])
	VALUES
		   (@IdMaterial 
           ,@IdCotizacion
           ,@Cantidad
           ,@ValorRequisicion
           ,@Clase
		   ,@IdSolicitud)	
END




GO
/****** Object:  StoredProcedure [dbo].[spInsertCotTotales]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 12/05/2022
-- Description: Registar Totales Cotizaicon
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertCotTotales]
	-- Add the parameters for the stored procedure here
	@IdConceptoPDF int = null,
    @IdCotizacion int,
	@ValorServicio decimal(18,0) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets FROM
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Cotizacion_Servicios]
		   ([IdConceptoPDF]
		   ,[IdCotizacion]
		   ,[ValorServicio])
	VALUES
		   (@IdConceptoPDF, @IdCotizacion, @ValorServicio)	
END


GO
/****** Object:  StoredProcedure [dbo].[spInsertDisponibilidad]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 01/10/2021
-- Description:	Insertar Disponibilidad
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertDisponibilidad]
	-- Add the parameters for the stored procedure here
	@IdVehiculo int,
	@Fecha_Ini varchar(10),
	@Fecha_Fin varchar(10),
	@Hora_Ini varchar(8),
	@Hora_Fin varchar(8)

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.

	SET NOCOUNT ON;
	
	declare @FechaIni as varchar(10)
	set @FechaIni=CONVERT(varchar,@Fecha_Ini,111)
	declare @FechaFin as varchar(10)
	set @FechaFin=CONVERT(varchar,@Fecha_Fin,111)
	declare @HoraIni as varchar(8)
	set @HoraIni=CONVERT(varchar,@Hora_Ini,108)
	declare @HoraFin as varchar(8)
	set @HoraFin=CONVERT(varchar,@Hora_Fin,108)

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Disponibilidad_Vehiculos]
           ([IdVehiculo]
           ,[Fecha_Ini]
           ,[Fecha_Fin]
           ,[Hora_Ini]
           ,[Hora_Fin])
     VALUES
           (@IdVehiculo,@Fecha_Ini, @Fecha_Fin, @Hora_Ini, @Hora_Fin)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertEmpresas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 05/07/2022
-- Description:	Insert Clientes Corporativos
-- ================================================
CREATE   PROCEDURE [dbo].[spInsertEmpresas] 
	-- Add the parameters for the stored procedure here
	@TipoIdent int = null,
    @TipoCliente int = null,
    @RazonSocial varchar(125) = null,
    @Nit varchar(20) = null,
    @IdCiudad int = null,
    @Movil varchar(20) = null,
    @Telefono varchar(20) = null,
    @Email varchar(250) = null,
    @Direccion varchar(250) = null,
	@ContactoEmpresa varchar(150) =  null,
	@EmailContacto varchar(250) =  null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Empresas]
           ([TipoIdent]
           ,[TipoCliente]
           ,[RazonSocial]
           ,[Nit]
           ,[IdCiudad]
           ,[Movil]
           ,[Telefono]
		   ,[Email]
		   ,[Direccion]
		   ,[ContactoEmpresa]
		   ,[EmailContacto])
     VALUES
           (@TipoIdent, 
           @TipoCliente, 
           @RazonSocial, 
           @Nit, 
           @IdCiudad, 
           @Movil, 
           @Telefono,
		   @Email,
		   @Direccion,
		   @ContactoEmpresa,
		   @EmailContacto)
END

GO
/****** Object:  StoredProcedure [dbo].[spInsertEventos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 31/01/2022
-- Description:	Guardar Eventos
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertEventos]
	-- Add the parameters for the stored procedure here
	@Nombre varchar(120),
	@Descripcion varchar(120),
	@Estado varchar(1)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Eventos]
		([Nombre]
		,[Descripcion]
		,[Estado])
		 
	VALUES(@Nombre, @Descripcion, @Estado);
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertFacturaCartera]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		JUAN ANDRES MARTINEZ
-- Create date: ENERO 2023
-- Description:	Insertar Factura Cartera
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertFacturaCartera]
@IdCartera INT,
@NumeroFactura VARCHAR(30),
@Archivo VARCHAR(MAX),
@Estado INT = NULL
AS
BEGIN TRANSACTION
		BEGIN TRY

		--IF(@Estado IS NULL)
		--BEGIN
		--	UPDATE Bod.Cartera SET Archivo = @Archivo, NumeroFactura = @NumeroFactura
		--	WHERE IdCartera = @IdCartera
		--END
		--ELSE
		--BEGIN
		--	UPDATE Bod.Cartera SET Archivo = @Archivo, NumeroFactura = @NumeroFactura, Estado = @Estado
		--	WHERE IdCartera = @IdCartera
		--END

		COMMIT TRANSACTION
		END TRY
BEGIN CATCH
ROLLBACK TRAN
DECLARE @ErrorMessage NVARCHAR(4000);
DECLARE @ErrorSeverity INT;
DECLARE @ErrorState INT;
	SELECT 
	@ErrorMessage = ERROR_MESSAGE(),
	@ErrorSeverity = ERROR_SEVERITY(),
	@ErrorState = ERROR_STATE();
	RAISERROR(
	@ErrorMessage, -- Message text.
	@ErrorSeverity, -- Severity.
	@ErrorState -- State.
	);
END CATCH
GO
/****** Object:  StoredProcedure [dbo].[spInsertHist_CotArticulos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 11/03/2024
-- Description:	Insertar Historico Cotizacion - Articulos
-- =============================================
CREATE PROCEDURE [dbo].[spInsertHist_CotArticulos]
	-- Add the parameters for the stored procedure here
	@IdArticulo Int = null,
	@IdCotizacion Int = null,
	@Nombre varchar(125) = null,
    @Descripcion varchar(255) = null,
    @Cantidad varchar(10) = null,
	@IdSolicitud int = null,
	@CtrlEmpaque int = null,
	@Material int = null,
	@CodVerificacion int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Hist_Cotizacion_Articulos]
           ([IdArticulo]
		   ,[IdCotizacion]
           ,[Nombre]
           ,[Descripcion]
		   ,[Cantidad]
		   ,[IdSolicitud]
		   ,[Ctrl_Empaque]
		   ,[Material]
		   ,[CodVerificacion])
     
	 VALUES
           (@IdArticulo, 
		    @IdCotizacion, 
			@Nombre, 
			@Descripcion, 
			@Cantidad,
			@IdSolicitud,
			@CtrlEmpaque,
			@Material,
			@CodVerificacion)
END



GO
/****** Object:  StoredProcedure [dbo].[spInsertHist_CotBodegas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 11/03/2024
-- Description:	Guardar Historico Cotizacion-Bodega
-- =============================================
CREATE PROCEDURE [dbo].[spInsertHist_CotBodegas]
	-- Add the parameters for the stored procedure here
	@IdCotizacion int = null,
	@IdSolicitud int = null,
	@IdBodega int = null,
	@IdSucursal int = null,
	@Nombre varchar(125) = null,
	@Capacidad numeric(18,0) = null,
	@Ocupacion numeric(18,0) = null, 
	@Disponible numeric(18,0) = null,
	@Largo varchar(20) = null,
	@Ancho varchar(20) = null,
	@Alto varchar(20) = null,
	@Estado varchar(20) = null,
	@Codsyscom varchar(4) = null,
	@ValorBodega decimal(18,2) = null,
	@CodVerificacion int = null
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Hist_Cotizacion_Bodegas]
		([IdCotizacion]
		,[IdSolicitud]
		,[IdBodega]
		,[IdSucursal]
		,[Nombre]
		,[Capacidad]
		,[Ocupacion]
		,[Disponible]
		,[Largo]
		,[Ancho]
		,[Alto] 
		,[Estado]
		,[CodSyscom]
		,[ValorBodega]
		,[CodVerificacion])
		 
	VALUES (@IdCotizacion, 
			@IdSolicitud,
			@IdBodega, 
			@IdSucursal, 
			@Nombre, 
			@Capacidad, 
			@Ocupacion,
			@Disponible,
			@Largo, 
			@Ancho, 
			@Alto, 
			@Estado, 
			@CodSyscom,
			@ValorBodega,
			@CodVerificacion)
	
END


GO
/****** Object:  StoredProcedure [dbo].[spInsertHist_CotConceptos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 11/03/2024
-- Description:	Insertar Historico Cotizacion - Conceptos
-- =============================================
CREATE PROCEDURE [dbo].[spInsertHist_CotConceptos] 
	-- Add the parameters for the stored procedure here
	@IdCotizacion int = null,
    @IdServicio int = null,
    @CodSyscom varchar(4) = null,
    @Nombre varchar(125) = null,
    @Descripcion varchar(250) = null,
	@Valor_Servicio decimal(18,2) = null,
	@Valor_Negociado decimal(18,2) = null,
	@IdAsesor int = null,
	@ConcepPDF int = null,
	@Valor_Iva decimal(18,2) = null,
	@IdSolicitud int = null,
	@CodVerificacion int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Hist_Cotizacion_Conceptos]
           ([IdCotizacion]
           ,[IdServicio]
           ,[CodSyscom]
           ,[Nombre]
           ,[Descripcion]
           ,[Valor_Servicio]
           ,[Valor_Negociado]
           ,[IdAsesor]
		   ,[IdConceptoPDF]
		   ,[Valor_Iva]
		   ,[IdSolicitud]
		   ,[CodVerificacion])
     VALUES
           (@IdCotizacion, 
		    @IdServicio, 
			@CodSyscom, 
			@Nombre, 
			@Descripcion, 
			@Valor_Servicio, 
			@Valor_Negociado, 
			@IdAsesor, 
			@ConcepPDF, 
			@Valor_Iva,
			@IdSolicitud,
			@CodVerificacion)
END

GO
/****** Object:  StoredProcedure [dbo].[spInsertHist_CotEmpaques]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 11/03/2024
-- Description:	Insertar Historico Cotizacion - Empaques
-- =============================================
CREATE PROCEDURE [dbo].[spInsertHist_CotEmpaques]
	-- Add the parameters for the stored procedure here
	@IdMaterial Int = null,
	@IdCotizacion Int = null,
	@Nombre varchar(125) = null,
    @ValorCosto decimal(18,2) = null,
    @Cantidad decimal(18,2) = null,
	@IdSolicitud int,
	@CodVerificacion int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Hist_Cotizacion_Empaques]
           ([IdCotizacion]
           ,[IdMaterial]
           ,[Nombre]
           ,[ValorCosto]
		   ,[Cantidad]
		   ,[IdSolicitud]
		   ,[CodVerificacion])
     VALUES
           (@IdCotizacion, 
		    @IdMaterial, 
			@Nombre, 
			@ValorCosto, 
			@Cantidad,
			@IdSolicitud,
			@CodVerificacion)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertHist_Cotizaciones]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- ALTER date: 11/03/2024
-- Description:	Insert Historico Cotizacion
-- ================================================
CREATE PROCEDURE [dbo].[spInsertHist_Cotizaciones] 
	-- Add the parameters for the stored procedure here
	@IdCotizacion int = null,
	@IdCliente int = null, 
    @IdUsuario int = null, 
    @FechaCotizacion varchar(10) = null, 
    @Servicios int = null, 
    @Ciudad_Origen int = null, 
    @Direccion_Origen varchar(125) = null, 
    @Ciudad_Destino int = null, 
    @Direccion_Destino varchar(125) = null, 
    @Volumen varchar(50) = null, 
    @Arte int = null, 
    @Presencial varchar(1) = null,
	@FechaPresencial varchar(10) = null,
	@HoraPresencial varchar(8) = null,
    @Seguro int = null, 
    @Valor_Declarado varchar(20) = null, 
    @Porc_Liquidacion varchar(10) = null, 
    @IdFormaPago int = null, 
    @IdMetodoPago int = null, 
	@Almacenamiento varchar(1) = null,
    @Fecha_Recogida varchar(10) = null, 
    @Hora_Recogida varchar(8) = null, 
    @Fecha_Entrega varchar(10) = null, 
    @Hora_Entrega varchar(8) = null, 
    @Autorizado varchar(125) = null, 
    @Tipo_Ident_Autorizado int = null, 
    @Ident_Autorizado nvarchar(20) = null, 
    @Telefono_Autorizado varchar(10) = null, 
    @Medio_Comunicacion int = null, 
    @Medio_Servicio int = null, 
    @IdEstadoCot int = null, 
	@ValorCotizacion decimal(18, 2) = null,
    @Observacion varchar(MAX) = null,
	@IdSolicitud int = null,
	@TipoServ int = null,
	@MotivoPerdida int = null,
    @ObservaPerdida varchar(MAX) = null,
    @CuartoUtil int = null,
    @Exteriores int = null,
    @Tapizados int = null,
    @Sucursal int = null,
    @ObservaPago varchar(MAX) = null,
    @Fecha_Empaque varchar(10) = null,
    @Hora_Empaque varchar(8) = null,
    @Periodicidad int = null,
    @Ref_Personal varchar(125) = null,
    @Ref_Movil nchar(20) = null,
    @Ref_Direccion varchar(255) = null,
    @Ref_Correo varchar(125) = null,
	@IdBodega int = null,
	@BloqueoCot varchar(1) = null,
	@Poliza varchar(20) = null,
	@Barrio_Origen varchar(50) = null,
	@Barrio_Destino varchar(50) = null,
	@EmpaqueVenta int = null,
	@Serv_Inter int = null,
	@Flete_Inter varchar(50) = null,
	@Gastos_Inter int = null,
	@Vaduana_Inter varchar(50) = null,
	@Otros_Inter varchar(50) = null,
	@Aduana_Inter int = null,
	@Observa_Inter varchar(MAX) = null,
	@IdCia int = null,
	@ObservaEmpaque varchar(MAX) = null,
	@ObservaCliente varchar(MAX) = null,
	@IdEmpresa int = null,
	@RazonSocial varchar(250) = null,
	@NumOrden int = null,
	@ContactoEmpresa varchar(150) = null,
	@CorreoContacto varchar(250) = null,
	@FechaIniBod varchar(10) = null,
	@FechaFinBod varchar(10) = null,
	@ObservaBodega varchar(MAX) = null,
	@Cortesia varchar(1) = null,
	@FechaCortIni varchar(10) = null,
	@FechaCortFin varchar(10) = null,
	@FechaUltima varchar(10) = null,
	@Manifiesto int = null,
	@Remesa int = null,
	@Ctrl_Cotizacion int = null,
	@IdGestion int = null,
	@FechaProximo varchar(10) = null,
	@ContadorCorreo int = null,
	@CodVerificacion int = null,
	@AutorizaCortesia int = null, 
	@TteSalida int = null, 
	@Ocupacion numeric(18,0) = null, 
	@VrSugerido numeric(18,0) = null, 
	@VrNegociado numeric(18,0) = null,
	@ObservaInterna varchar(MAX) = null,
	@CtrlEnvio int = null,
	@ValorVehiculo varchar(20) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Hist_Cotizacion]
			([IdCotizacion]
			,[IdCliente]
			,[IdUsuario]
			,[IdSolicitud]
			,[FechaCotizacion]
			,[Servicios]
			,[Ciudad_Origen]
			,[Direccion_Origen]
			,[Ciudad_Destino]
			,[Direccion_Destino]
			,[Volumen]
			,[Arte]
			,[Presencial]
			,[FechaPresencial]
			,[HoraPresencial]
			,[Seguro]
			,[Valor_Declarado]
			,[Porc_Liquidacion]
			,[IdFormaPago]
			,[IdMetodoPago]
			,[Almacenamiento]
			,[Fecha_Recogida]
			,[Hora_Recogida]
			,[Fecha_Entrega]
			,[Hora_Entrega]
			,[Autorizado]
			,[Tipo_Ident_Autorizado]
			,[Ident_Autorizado]
			,[Telefono_Autorizado]
			,[Medio_Comunicacion]
			,[Medio_Servicio]
			,[IdEstadoCot]
			,[ValorCotizacion]
			,[Observacion]
			,[TipoServ]
			,[MotivoPerdida]
			,[ObservaPerdida] 
			,[CuartoUtil]
			,[Exteriores]
			,[Tapizados]
			,[Sucursal]
			,[ObservaPago]
			,[Fecha_Empaque]
			,[Hora_Empaque]
			,[Periodicidad] 
			,[Ref_Personal]
			,[Ref_Movil]
			,[Ref_Direccion]
			,[Ref_Correo]
			,[IdBodega]
			,[BloqueoCot]
			,[Poliza]
			,[Barrio_Origen]
			,[Barrio_Destino]
			,[EmpaqueVenta]
			,[Serv_Inter]
			,[Flete_Inter]
			,[Gastos_Inter]
			,[Vaduana_Inter]
			,[Otros_Inter]
			,[Aduana_Inter]
			,[Observa_Inter]
			,[IdCia]
			,[ObservaEmpaque]
			,[ObservaCliente]
			,[IdEmpresa]
			,[RazonSocial]
			,[NumOrden]
			,[ContactoEmpresa]
			,[CorreoContacto]
			,[FechaIniBod]
			,[FechaFinBod]
			,[ObservaBodega]
			,[Cortesia]
			,[FechaCortIni]
			,[FechaCortFin]
			,[FechaUltima]
			,[Manifiesto]
			,[Remesa]
			,[IdGestion]
			,[FechaProximo]
			,[Ctrl_Cotizacion]
			,[ContadorCorreo]
			,[CodVerificacion]
			,[AutorizaCortesia] 
			,[TteSalida]
			,[Ocupacion] 
			,[VrSugerido] 
			,[VrNegociado]
			,[ObservaInterna]
			,[CtrlEnvio]
			,[Valor_Vehiculo])

     VALUES
			(@IdCotizacion
			,@IdCliente 
			,@IdUsuario 
			,@IdSolicitud 
			,@FechaCotizacion 
			,@Servicios 
			,@Ciudad_Origen 
			,@Direccion_Origen 
			,@Ciudad_Destino 
			,@Direccion_Destino 
			,@Volumen 
			,@Arte 
			,@Presencial 
			,@FechaPresencial 
			,@HoraPresencial 
			,@Seguro 
			,@Valor_Declarado 
			,@Porc_Liquidacion 
			,@IdFormaPago 
			,@IdMetodoPago 
			,@Almacenamiento 
			,@Fecha_Recogida 
			,@Hora_Recogida 
			,@Fecha_Entrega 
			,@Hora_Entrega 
			,@Autorizado 
			,@Tipo_Ident_Autorizado 
			,@Ident_Autorizado
			,@Telefono_Autorizado
			,@Medio_Comunicacion 
			,@Medio_Servicio 
			,@IdEstadoCot 
			,@ValorCotizacion 
			,@Observacion
			,@TipoServ
			,@MotivoPerdida
			,@ObservaPerdida
			,@CuartoUtil
			,@Exteriores
			,@Tapizados
			,@Sucursal
			,@ObservaPago
			,@Fecha_Empaque
			,@Hora_Empaque
			,@Periodicidad
			,@Ref_Personal
			,@Ref_Movil
			,@Ref_Direccion
			,@Ref_Correo
			,@IdBodega
			,@BloqueoCot
			,@Poliza
			,@Barrio_Origen
			,@Barrio_Destino
			,@EmpaqueVenta
			,@Serv_Inter
			,@Flete_Inter
			,@Gastos_Inter
			,@Vaduana_Inter
			,@Otros_Inter
			,@Aduana_Inter
			,@Observa_Inter
			,@IdCia
			,@ObservaEmpaque
			,@ObservaCliente
			,@IdEmpresa
			,@RazonSocial
			,@NumOrden
			,@ContactoEmpresa
			,@CorreoContacto
			,@FechaIniBod
			,@FechaFinBod
			,@Observa_Inter
			,@Cortesia
			,@FechaCortIni
			,@FechaCortFin
			,@FechaUltima
			,@Manifiesto
			,@Remesa
			,@IdGestion
			,@FechaProximo
			,@Ctrl_Cotizacion
			,@ContadorCorreo
			,@CodVerificacion
			,@AutorizaCortesia 
			,@TteSalida 
			,@Ocupacion 
			,@VrSugerido 
			,@VrNegociado
			,@ObservaInterna
			,@CtrlEnvio
			,@ValorVehiculo)


	UPDATE [dbo].[Cotizacion] SET CodVerificacion = @CodVerificacion WHERE IdCotizacion = @IdCotizacion
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertHist_CotMaterialesArticulo]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 11/03/2024
-- Description:	Insert historico Cotizacion Mat - Articulos
-- ================================================
CREATE PROCEDURE [dbo].[spInsertHist_CotMaterialesArticulo] 
	-- Add the parameters for the stored procedure here
	@IdCotizacion int = null,
	@IdHist_CotArticulo int = null,
	@IdMaterial int = null,
	@NombreMaterial varchar(125) = null,
	@IdArticulo int = null,
	@NombreArticulo varchar(125) = null,
	@Valor varchar(20) = null,
    @Cantidad decimal(18,2) = null,
	@IdSolicitud int = null,
	@CodVerificacion int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Hist_Cotizacion_MaterialesArticulo]
           ([IdCotizacion]
		   ,[IdHist_CotArticulo]
           ,[IdMaterial]
           ,[NombreMaterial]
           ,[IdArticulo]
           ,[NombreArticulo]
           ,[Valor]
           ,[Cantidad]
		   ,[IdSolicitud]
		   ,[CodVerificacion])
     VALUES
           (@IdCotizacion
		   ,@IdHist_CotArticulo
           ,@IdMaterial
		   ,@NombreMaterial
           ,@IdArticulo
		   ,@NombreArticulo
           ,@Valor
           ,@Cantidad
		   ,@IdSolicitud
		   ,@CodVerificacion)

	-- Actualizar el Control de Empaque
	UPDATE [dbo].[Hist_Cotizacion_Articulos] SET Ctrl_Empaque = 1 where IdCotizacion = @IdCotizacion and IdHist_CotArticulo = @IdHist_CotArticulo

END


GO
/****** Object:  StoredProcedure [dbo].[spInsertHist_CotRequisiciones]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 11/03/2024
-- Description: Registar Historico Requisicion Cotizaicon
-- =============================================
CREATE PROCEDURE [dbo].[spInsertHist_CotRequisiciones]
	-- Add the parameters for the stored procedure here
	@IdMaterial int = null,
    @IdCotizacion int = null,
    @Cantidad decimal(18,2) = null,
    @ValorRequisicion decimal(18,2) = null,
    @Clase varchar(1) = null,
	@IdSolicitud int = null,
	@CodVerificacion int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets FROM
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Hist_Cotizacion_Requisicion]
           ([IdMaterial]
           ,[IdCotizacion]
           ,[Cantidad]
           ,[ValorRequisicion]
           ,[Clase]
		   ,[IdSolicitud]
		   ,[CodVerificacion])
	VALUES
		   (@IdMaterial 
           ,@IdCotizacion
           ,@Cantidad
           ,@ValorRequisicion
           ,@Clase
		   ,@IdSolicitud
		   ,@CodVerificacion)	
END




GO
/****** Object:  StoredProcedure [dbo].[spInsertHistoricoLogPersonal]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 16/02/2023
-- Description:	Insertar Historico Log Personal
-- =============================================
CREATE PROCEDURE [dbo].[spInsertHistoricoLogPersonal]
	-- Add the parameters for the stored procedure here
	@IdPersonalLog int = null,
    @IdCotizacion int = null,
    @IdPersonal int = null,
    @IdEvento int = null,
    @RolPersonal int = null,
    @FechaHistorico varchar(20) = null,
    @AccionPersonal varchar(20) = null,
	@ValorRolPer numeric(18,0) = null,
	@Autorizacion int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Historico_LogPersonal]
           ([IdPersonalLog]
           ,[IdCotizacion]
           ,[IdPersonal]
           ,[IdEvento]
           ,[RolPersonal]
           ,[FechaHistorico]
           ,[AccionPersonal]
		   ,[ValorRolPer]
		   ,[Autorizacion])
     VALUES
           (@IdPersonalLog
           ,@IdCotizacion
           ,@IdPersonal
           ,@IdEvento
           ,@RolPersonal
           ,@FechaHistorico 
           ,@AccionPersonal
		   ,@ValorRolPer
		   ,@Autorizacion)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertHistoricoLogVehiculo]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 16/02/2023
-- Description:	Insertar Historico Log Vehiculo
-- =============================================
CREATE PROCEDURE [dbo].[spInsertHistoricoLogVehiculo]
	-- Add the parameters for the stored procedure here
	@IdVehiculosLog int = null,
    @IdCotizacion int = null, 
    @IdVehiculo int = null, 
    @IdEvento int = null, 
    @FechaHistorico varchar(10) = null, 
    @AccionVehiculo varchar(20) = null,
	@ValorRolVeh numeric(18,0) = null,
	@Autorizacion int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Historico_LogVehiculo]
           ([IdVehiculosLog]
           ,[IdCotizacion]
           ,[IdVehiculo]
           ,[IdEvento]
           ,[FechaHistorico]
           ,[AccionVehiculo]
		   ,[ValorRolVeh]
		   ,[Autorizacion])
     VALUES
           (@IdVehiculosLog
           ,@IdCotizacion 
           ,@IdVehiculo 
           ,@IdEvento 
           ,@FechaHistorico
           ,@AccionVehiculo
		   ,@ValorRolVeh
		   ,@Autorizacion)
END

GO
/****** Object:  StoredProcedure [dbo].[spInsertLogBodegas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 2024-02-21
-- Description: Insertar Logistica Bodegas
-- =============================================
CREATE PROCEDURE [dbo].[spInsertLogBodegas]
	-- Add the parameters for the stored procedure here
	@IdCotizacion int = null,
    @IdOrden int = null,
    @IdEvento int = null,
    @IdCiudadOrigen int = null,
    @IdCiudadDestino int = null,
	@IdCompania int = null,
    @FechaRecogida varchar(10) = null,
    @HoraRecogida varchar(8) = null,
    @FechaEntrega varchar(10) = null,
    @HoraEntrega varchar(8) = null,
    @Volumen varchar(50) = null,
    @ValorTransporte numeric(18,0) = null,
    @Reexpedicion numeric(18,0) = null,
    @IdVehiculo int = null,
    @Dias int = null,
    @ServicioBga int = null,
	@FechaDespacho varchar(10) = null,
	@CiaEncargada int = null,
	@CtrlCumplido int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Logistica_Bodega]
           ([IdCotizacion]
           ,[IdOrden]
           ,[IdEvento]
           ,[IdCiudadOrigen]
           ,[IdCiudadDestino]
		   ,[IdCompania]
           ,[FechaRecogida]
           ,[HoraRecogida]
           ,[FechaEntrega]
           ,[HoraEntrega]
           ,[Volumen]
           ,[ValorTransporte]
           ,[Reexpedicion]
           ,[IdVehiculo]
           ,[Dias]
           ,[ServicioBga]
		   ,[FechaDespacho]
		   ,[CiaEncargada]
		   ,[CtrlCumplido])
     VALUES
           (@IdCotizacion
           ,@IdOrden
           ,@IdEvento
           ,@IdCiudadOrigen
           ,@IdCiudadDestino
		   ,@IdCompania
           ,@FechaRecogida
           ,@HoraRecogida
           ,@FechaEntrega
           ,@HoraEntrega
           ,@Volumen
           ,@ValorTransporte
           ,@Reexpedicion
           ,@IdVehiculo
           ,@Dias
           ,@ServicioBga
		   ,@FechaDespacho
		   ,@CiaEncargada
		   ,@CtrlCumplido)
END


GO
/****** Object:  StoredProcedure [dbo].[spInsertLogPersonal]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 14/12/2022
-- Description:	Insertar Logistica - Personal
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertLogPersonal]
	-- Add the parameters for the stored procedure here
	@IdCotizacion int = null,
    @IdPersonal int = null,
    @Identificacion varchar(20) = null,
	@IdEvento int = null,
	@FechaIni varchar(10) = null,
	@HoraIni varchar(8) = null,
	@HoraFin varchar(8) = null,
	@Rol int = null,
	@CtrlPersonal int = null,
	@ValorRolPer numeric(18,0) = null,
	@Autorizacion int = null,
	@Servicio int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Logistica_Personal]
           ([IdCotizacion]
           ,[IdPersonal]
           ,[Identificacion]
           ,[IdEvento]
		   ,[FechaIni]
		   ,[HoraIni]
		   ,[HoraFin]
		   ,[Rol]
		   ,[CtrlPersonal]
		   ,[ValorRolPer]
		   ,[Autorizacion]
		   ,[Servicio])
     VALUES
           (@IdCotizacion
           ,@IdPersonal
           ,@Identificacion
           ,@IdEvento
		   ,@FechaIni
		   ,@HoraIni
		   ,@HoraFin
		   ,@Rol
		   ,@CtrlPersonal
		   ,@ValorRolPer
		   ,@Autorizacion
		   ,@Servicio)

	--Actualizar logSegimientos
	UPDATE [dbo].[Agenda] SET Personal = 0 WHERE IdEvento = @IdEvento and IdCotizacion = @IdCotizacion
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertLogSeguimientos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 21/12/2022
-- Description:	Insertar Logistica Seguimiento
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertLogSeguimientos]
	-- Add the parameters for the stored procedure here
	 @IdCotizacion int = null
    ,@IdOrdenServicio int = null
    ,@IdEvento int = null
    ,@IdVehiculo int = null
    ,@IdCompania int = null
    ,@IdActividad int = null
    ,@IdCiudadDestino int = null
	,@FechaServicio varchar(25) = null
    ,@Reporte1 varchar(max) = null
    ,@Reporte2 varchar(max) = null
    ,@Reporte3 varchar(max) = null
    ,@Reporte4 varchar(max) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Logistica_Seguimientos]
           ([IdCotizacion]
           ,[IdOrdenServicio]
           ,[IdEvento]
           ,[IdVehiculo]
           ,[IdCompania]
           ,[IdActividad]
           ,[IdCiudadDestino]
           ,[FechaServicio]
           ,[Reporte1]
           ,[Reporte2]
           ,[Reporte3]
           ,[Reporte4])
     VALUES
           (@IdCotizacion  
           ,@IdOrdenServicio  
           ,@IdEvento  
           ,@IdVehiculo  
           ,@IdCompania  
           ,@IdActividad  
           ,@IdCiudadDestino  
		   ,@FechaServicio
           ,@Reporte1  
           ,@Reporte2  
           ,@Reporte3  
           ,@Reporte4)

END


GO
/****** Object:  StoredProcedure [dbo].[spInsertLogTrafico]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 12/04/2022
-- Description:	Insert Control Trafico
-- ================================================
CREATE PROCEDURE [dbo].[spInsertLogTrafico]
	-- Add the parameters for the stored procedure here
	@IdVehiculo int = null,
	@IdCiudad int = null,
	@Fecha varchar(50) = null,
	@Manifiesto int = null,
	@IdCia int = null,
	@IdRuta int = null,
	@ValorFlete numeric(18,0) = null,
	@Flete_Conductor numeric(18,0) = null,
	@Flete_Socio numeric(18,0) = null,
	@Descuento_Socio numeric(18,0) = null,
	@Estado_Trafico int = null,
	@Flete_Locales numeric(18,0) = null,
	@Dcto_Oficina numeric(18,0) = null,
	@Descargue numeric(18,0) = null,
	@Papeleria numeric(18,0) = null,
	@Reexpedir numeric(18,0) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Logistica_Trafico]
			([IdVehiculo]
			,[IdCiudad]
			,[Fecha]
			,[Manifiesto]
			,[IdCia]
			,[IdRuta]
			,[ValorFlete]
			,[Flete_Conductor]
			,[Flete_Socio]
			,[Descuento_Socio]
			,[Estado_Trafico]
			,[Flete_Locales]
			,[Dcto_Oficina]
			,[Descargue]
			,[Papeleria]
			,[Reexpedir])

	VALUES
			(@IdVehiculo
			,@IdCiudad
			,@Fecha
			,@Manifiesto
			,@IdCia
			,@IdRuta
			,@ValorFlete
			,@Flete_Conductor
			,@Flete_Socio
			,@Descuento_Socio
			,@Estado_Trafico
			,@Flete_Locales
			,@Dcto_Oficina
			,@Descargue
			,@Papeleria
			,@Reexpedir)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertLogTraficoDetalles]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 05/04/2022
-- Description:	Update Logistica Trafico Detalles
-- ================================================
CREATE PROCEDURE [dbo].[spInsertLogTraficoDetalles]
	-- Add the parameters for the stored procedure here
	 @IdTrafico nchar(10) = null
    ,@IdCotizacion int = null
    ,@IdCliente int = null
	,@IdRuta_Detalle int = null
	,@KmRuta_Detalle numeric(18,2) = null
    ,@Manifiesto int = null
    ,@Direccion_Destino varchar(125) = null
    ,@Movil varchar(20) = null
    ,@Remesa varchar(50) = null
    ,@IdOrden int = null
    ,@ValorFactura numeric(18,0) = null
    ,@Abono numeric(18,0) = null
    ,@Saldo numeric(18,0) = null
    ,@Seguro numeric(18,0) = null
    ,@Bodega numeric(18,0) = null
    ,@Iva numeric(18,0) = null
    ,@Empaque numeric(18,0) = null
    ,@Montacargas numeric(18,0) = null
    ,@Otros numeric(18,0) = null
    ,@Servicio_Planta int = null
    ,@Recogida_Entrega numeric(18,0) = null
    ,@Recogida_Supern numeric(18,0) = null
    ,@Oficina numeric(18,0) = null
    ,@Reexpedicion numeric(18,0) = null
    ,@Veh_Reexpedicion int = null
    ,@Subtotal_Conductor numeric(18,0) = null
    ,@Cargue_Descargue numeric(18,0) = null
    ,@Papeleria_Socio numeric(18,0) = null
    ,@OficinaPrincipal numeric(18,0) = null
    ,@Subtotal_Socio numeric(18,0) = null
	,@IdEvento int = null
	,@CtrlManifiesto int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Logistica_TraficoDetalles]
           ([IdTrafico]
           ,[IdCotizacion]
           ,[IdCliente]
           ,[IdRuta_Detalle]
           ,[KmRuta_Detalle]
           ,[Manifiesto]
           ,[Direccion_Destino]
           ,[Movil]
           ,[Remesa]
           ,[IdOrden]
           ,[ValorFactura]
           ,[Abono]
           ,[Saldo]
           ,[Seguro]
           ,[Bodega]
           ,[Iva]
           ,[Empaque]
           ,[Montacargas]
           ,[Otros]
           ,[Servicio_Planta]
           ,[Recogida_Entrega]
           ,[Recogida_Supern]
           ,[Oficina]
           ,[Reexpedicion]
           ,[Veh_Reexpedicion]
           ,[Subtotal_Conductor]
           ,[Cargue_Descargue]
           ,[Papeleria_Socio]
           ,[OficinaPrincipal]
           ,[Subtotal_Socio]
		   ,[IdEvento]
		   ,[CtrlManifiesto])
     VALUES
           (@IdTrafico
           ,@IdCotizacion
           ,@IdCliente
           ,@IdRuta_Detalle
           ,@KmRuta_Detalle
           ,@Manifiesto
           ,@Direccion_Destino
           ,@Movil
           ,@Remesa
           ,@IdOrden
           ,@ValorFactura
           ,@Abono
           ,@Saldo
           ,@Seguro
           ,@Bodega
           ,@Iva
           ,@Empaque
           ,@Montacargas
           ,@Otros
           ,@Servicio_Planta
           ,@Recogida_Entrega
           ,@Recogida_Supern
           ,@Oficina
           ,@Reexpedicion
           ,@Veh_Reexpedicion
           ,@Subtotal_Conductor
           ,@Cargue_Descargue
           ,@Papeleria_Socio
           ,@OficinaPrincipal
           ,@Subtotal_Socio
		   ,@IdEvento
		   ,@CtrlManifiesto)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertLogVehiculos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 14/12/2022
-- Description:	Insertar Logistica - Vehiculos
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertLogVehiculos] 
	-- Add the parameters for the stored procedure here
	@IdCotizacion int = null,
    @IdVehiculo int = null,
    @Placa varchar(10) = null,
	@IdEvento int = null,
	@FechaIni varchar(10) = null,
	@HoraIni varchar(8) = null,
	@HoraFin varchar(8) = null,
	@Rol int = null,
	@Conductor int = null,
	@CedulaCond int = null,
	@RolConductor int = null,
	@ValorRolVeH numeric(18,0) = null,
	@Autorizacion int = null,
	@Servicio int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Logistica_Vehiculos]
           ([IdCotizacion]
           ,[IdVehiculo]
           ,[Placa]
           ,[IdEvento]
		   ,[FechaIni]
		   ,[HoraIni]
		   ,[HoraFin]
		   ,[Rol]
		   ,[ValorRolVeh]
		   ,[Autorizacion]
		   ,[Servicio])
    VALUES
           (@IdCotizacion
		   ,@IdVehiculo
		   ,@Placa
		   ,@IdEvento
		   ,@FechaIni
		   ,@HoraIni
		   ,@HoraFin
		   ,@Rol
		   ,@ValorRolVeh
		   ,@Autorizacion
		   ,@Servicio)

	--Actualizar Agenda
	UPDATE [dbo].[Agenda] SET Vehiculo = 0 Where IdEvento = @IdEvento and IdCotizacion = @IdCotizacion

	--Actualizar logSegimientos
	UPDATE [dbo].[Logistica_Seguimientos] SET IdVehiculo = @IdVehiculo Where IdEvento = @IdEvento and IdCotizacion = @IdCotizacion

	--Inserter Conductor en Personal
	INSERT INTO [dbo].[Logistica_Personal]
			([IdCotizacion]
           ,[IdPersonal]
           ,[Identificacion]
           ,[IdEvento]
		   ,[FechaIni]
		   ,[HoraIni]
		   ,[HoraFin]
		   ,[Rol]
		   ,[CtrlPersonal]
		   ,[ValorRolPer]
		   ,[Autorizacion]
		   ,[Servicio])

     VALUES
           (@IdCotizacion
           ,@Conductor
           ,@CedulaCond
           ,@IdEvento
		   ,@FechaIni
		   ,@HoraIni
		   ,@HoraFin
		   ,@RolConductor
		   ,1
		   ,0
		   ,0
		   ,@Servicio)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertMateriales]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 05/09/2021
-- Description:	Insertar Materiales
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertMateriales]
	-- Add the parameters for the stored procedure here
	@Nombre varchar(125),
    @Referencia varchar(10),
    @IdUnidad int,
    @ValorCosto varchar(20),
    @Proveedor int,
    @EstadoMat varchar(1),
    @CodSyscom varchar(50),
    @SubGrupo varchar(8),
	@Linea varchar(5),
	@Descripcion varchar(125)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Materiales]
           ([Nombre]
           ,[Referencia]
           ,[IdUnidad]
           ,[ValorCosto]
           ,[Proveedor]
           ,[EstadoMat]
           ,[CodSyscom]
           ,[SubGrupo]
		   ,[Linea]
		   ,[Descripcion])
     VALUES
           (@Nombre 
		   ,@Referencia
           ,@IdUnidad
           ,@ValorCosto
           ,@Proveedor
           ,@EstadoMat
           ,@CodSyscom
           ,@Subgrupo
		   ,@Linea
		   ,@Descripcion)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertMaterialesArticulos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 05/09/2021
-- Description:	Insertar Materiales-Articulos
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertMaterialesArticulos] 
	-- Add the parameters for the stored procedure here
	@IdMaterial Int=null,
	@IdArticulo Int=null,
	@Valor varchar(20)=null,
    @Cantidad decimal(18,2)=null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Materiales_Articulo]
           ([IdMaterial]
			,[IdArticulo]
			,[Valor]
			,[Cantidad])
     VALUES
           (@IdMaterial, @IdArticulo, @Valor, @Cantidad)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertNovedades]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 25-07-2023
-- Description:	Procedimiento para registrar novedades
-- =============================================
CREATE PROCEDURE [dbo].[spInsertNovedades] 
	-- Add the parameters for the stored procedure here
	@Descripcion varchar(255),
	@Estado varchar(1)
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
	INSERT INTO [dbo].[Novedades]
           ([Descripcion]
           ,[Estado])
     VALUES
           (@Descripcion,@Estado)
	
END

GO
/****** Object:  StoredProcedure [dbo].[spInsertOrdenServicio]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 14/03/2022
-- Description:	Insertar Orden Servicio
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertOrdenServicio]
	-- Add the parameters for the stored procedure here
	@NumOrden int,
    @FechaOrden varchar(10) = null,
    @HoraOrden varchar(8) = null,
    @EstadoOrden int = null,
    @IdCotizacion int = null,
	@BloqueoCot varchar(1) = null,
	@Compania int = null,
	@IdUsuario int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[OrdenServicio]
           ([NumOrden]
           ,[FechaOrden]
           ,[HoraOrden]
           ,[EstadoOrden]
           ,[IdCotizacion]
		   ,[NumInventario]
		   ,[IdUsuario]
		   ,[CtrlPostVenta])
     VALUES
           (@NumOrden
           ,@FechaOrden
           ,@HoraOrden
           ,@EstadoOrden
           ,@IdCotizacion
		   ,0
		   ,@IdUsuario
		   ,0)

	--Actualizar Cotizacion para bloqueo por generación de Orden de Mudanza
	UPDATE [dbo].[Cotizacion] 
		SET BloqueoCot = @BloqueoCot, 
			IdEstadoCot = '5'
	
		WHERE IdCotizacion = @IdCotizacion
END

GO
/****** Object:  StoredProcedure [dbo].[spInsertParametros]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 02/05/2023
-- Description:	Insert Parametros Basicos
-- =============================================
CREATE PROCEDURE [dbo].[spInsertParametros]
	-- Add the parameters for the stored procedure here
	@Nombre_Paramt varchar(125) = null,
	@Valor_Paramt numeric(18,2) = null,
    @Codigo_Paramt varchar(30) = null,
	@Descripcion varchar(250) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Parametros]
           ([Nombre_Paramt]
           ,[Valor_Paramt]
           ,[Codigo_Paramt]
		   ,[Descripcion])
    VALUES
           (@Nombre_Paramt
           ,@Valor_Paramt
           ,@Codigo_Paramt
		   ,@Descripcion)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertPerfiles]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:	Sergio Rendón Gómez
-- Create date: 02*08/2021
-- Description:	Procedimiento para guardar perfiles
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertPerfiles] 
	-- Add the parameters for the stored procedure here
	@Nombre varchar(120) = null, 
	@Estado varchar(1) = null, 
	@Descripcion varchar(255) = null,
	@Clase varchar(1) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
     INSERT INTO [dbo].[Perfiles]
           (Nombre
           ,Estado
           ,Descripcion
           ,Clase)
     
	 VALUES (@Nombre, @Estado, @Descripcion, @Clase);


END
GO
/****** Object:  StoredProcedure [dbo].[spInsertPermisos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 02/08/2021
-- Description:	Insertar Permiso
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertPermisos] 
	-- Add the parameters for the stored procedure here
	@IdPerfil Int,
	@IdModulo Int,
	@Registrar nchar(1),
	@Actualizar nchar(1),
	@Listar nchar(1),
	@Eliminar nchar(1)

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Permisos]
           ([IdPerfil]
           ,[IdModulo]
           ,[Registrar]
           ,[Actualizar]
           ,[Listar]
           ,[Eliminar])
     VALUES
           (@IdPerfil, @IdModulo, @Registrar, @Actualizar, @Listar, @Eliminar)

END





GO
/****** Object:  StoredProcedure [dbo].[spInsertPersonal]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 06/04/2022
-- Description:	Insertar Personal
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertPersonal] 
	-- Add the parameters for the stored procedure here
	@TipoIdent int = null,
    @Identificacion varchar(20) = null,
    @Nombres varchar(125) = null,
    @Apellidos varchar(125) = null,
    @IdCiudad int = null,
    @Direccion varchar(250) = null,
    @Telefono varchar(20) = null,
	@Movil varchar(20) = null,
    @Email varchar(250) = null,
    @Estado varchar(1) = null,
	@Compania int = null,
	@Cargo varchar(50) = null,
	@IdCargo varchar(5) = null,
	@TipoContrato int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Personal]
           ([TipoIdent]
           ,[Identificacion]
           ,[Nombres]
           ,[Apellidos]
           ,[IdCiudad]
           ,[Direccion]
           ,[Telefono]
		   ,[Movil]
           ,[Email]
           ,[Estado]
		   ,[IdCia]
		   ,[Cargo]
		   ,[IdCargo]
		   ,[TipoContrato])
    
	VALUES
           (@TipoIdent
           ,@Identificacion
           ,@Nombres
           ,@Apellidos
           ,@IdCiudad
           ,@Direccion
           ,@Telefono
		   ,@Movil
           ,@Email
           ,@Estado
		   ,@Compania
		   ,@Cargo
		   ,@IdCargo
		   ,@TipoContrato)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertPostVenta]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 2024-07-09
-- Description:	Insertar PostVenta
-- =============================================
CREATE  PROCEDURE [dbo].[spInsertPostVenta] 
	-- Add the parameters for the stored procedure here
	@IdOrdenServicio int = null,
    @IdCotizacion int = null,
    @IdCliente int = null,
    @FechaPostVenta varchar(10) = null,
    @HoraPostVenta varchar(8) = null,
    @Oficina1 int = null,
    @Oficina2 int = null,
    @ObservaOficina varchar(max) = null,
    @Operativo1 int = null,
    @Operativo2 int = null,
    @Operativo3 int = null,
    @Operativo4 int = null,
    @Operativo5 int = null,
    @Operativo6 int = null,
    @ObservaOperativo varchar(max) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[PostVenta]
           ([IdOrdenServicio]
           ,[IdCotizacion]
           ,[IdCliente]
           ,[FechaPostVenta]
           ,[HoraPostVenta]
           ,[Oficina1]
           ,[Oficina2]
           ,[ObservaOficina]
           ,[Operativo1]
           ,[Operativo2]
           ,[Operativo3]
           ,[Operativo4]
           ,[Operativo5]
           ,[Operativo6]
           ,[ObservaOperativo])
     VALUES
           ( @IdOrdenServicio 
            ,@IdCotizacion 
            ,@IdCliente 
            ,@FechaPostVenta
            ,@HoraPostVenta
            ,@Oficina1 
            ,@Oficina2 
            ,@ObservaOficina
            ,@Operativo1 
            ,@Operativo2 
            ,@Operativo3 
            ,@Operativo4 
            ,@Operativo5 
            ,@Operativo6 
            ,@ObservaOperativo)

	UPDATE [dbo].[OrdenServicio] SET CtrlPostVenta = 1 WHERE IdOrden = @IdOrdenServicio
	
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertPreoperacional]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 02/11/2021
-- Description:	Insertar Preventa
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertPreoperacional]
	-- Add the parameters for the stored procedure here
	@IdCotizacion int,
	@IdSolicitud int,
	@Fecha_Preventa varchar(10),
	@Hora_Preventa varchar(8),
	@IdAsesor int,
	@IdEstadoCot int,
	@Observaciones varchar(MAX),
	@Gestor int
AS

BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Preoperacional] 
           ([IdCotizacion]
		   ,[IdSolicitud]
           ,[Fecha_Preventa]
           ,[Hora_Preventa]
           ,[IdAsesor]
           ,[IdEstadoCot]
           ,[Observaciones]
		   ,[Gestor])
     VALUES
           (@IdCotizacion
		   ,@IdSolicitud
           ,@Fecha_Preventa
           ,@Hora_Preventa
           ,@IdAsesor
           ,@IdEstadoCot
           ,@Observaciones
		   ,@Gestor)

	IF @IdEstadoCot = 3
		BEGIN
			UPDATE [dbo].[Cotizacion] SET IdEstadoCot = @IdEstadoCot, FechaUltima = @Fecha_Preventa WHERE IdCotizacion = @IdCotizacion 
		END
	
	IF @IdEstadoCot = 4
		BEGIN
			UPDATE [dbo].[Cotizacion] SET IdEstadoCot = @IdEstadoCot, FechaUltima = @Fecha_Preventa WHERE IdCotizacion = @IdCotizacion 
		END
	
	IF @IdEstadoCot = 5
		BEGIN
			UPDATE [dbo].[Cotizacion] SET IdEstadoCot = @IdEstadoCot, FechaUltima = @Fecha_Preventa WHERE IdCotizacion = @IdCotizacion 
		END

END
GO
/****** Object:  StoredProcedure [dbo].[spInsertPropietarios]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 04/04/2022
-- Description:	Insertar Propietarios
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertPropietarios]
	-- Add the parameters for the stored procedure here
	@TipoIdent int = null,
    @Identificacion varchar(20) = null,
    @Nombres varchar(125) = null,
    @Apellidos varchar(125) = null,
    @IdCiudad int = null,
    @Direccion varchar(250) = null,
    @Telefono varchar(20) = null,
	@Movil varchar(20) = null,
    @Email varchar(250) = null,
    @Estado varchar(1) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Propietarios]

           ([TipoIdent]
           ,[Identificacion]
           ,[Nombres]
           ,[Apellidos]
           ,[IdCiudad]
           ,[Direccion]
           ,[Telefono]
		   ,[Movil]
           ,[Email]
           ,[Estado])
    
	VALUES
           (@TipoIdent
           ,@Identificacion
           ,@Nombres
           ,@Apellidos
           ,@IdCiudad
           ,@Direccion
           ,@Telefono
		   ,@Movil
           ,@Email
           ,@Estado)
END

GO
/****** Object:  StoredProcedure [dbo].[spInsertProveedores]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 04/04/2022
-- Description:	Insertar Proveedores
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertProveedores]
	-- Add the parameters for the stored procedure here
	@TipoIdent int = null,
    @Identificacion varchar(20) = null,
    @Nombres varchar(125) = null,
    @Apellidos varchar(125) = null,
    @IdCiudad int = null,
    @Direccion varchar(250) = null,
    @Telefono varchar(20) = null,
	@Movil varchar(20) = null,
    @Email varchar(250) = null,
    @Estado varchar(1) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Proveedores]

           ([TipoIdent]
           ,[Identificacion]
           ,[Nombres]
           ,[Apellidos]
           ,[IdCiudad]
           ,[Direccion]
           ,[Telefono]
		   ,[Movil]
           ,[Email]
           ,[Estado])
    
	VALUES
           (@TipoIdent
           ,@Identificacion
           ,@Nombres
           ,@Apellidos
           ,@IdCiudad
           ,@Direccion
           ,@Telefono
		   ,@Movil
           ,@Email
           ,@Estado)
END

GO
/****** Object:  StoredProcedure [dbo].[spInsertRangos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 02/05/2023
-- Description:	Insert Rangos
-- =============================================
CREATE PROCEDURE [dbo].[spInsertRangos]
	-- Add the parameters for the stored procedure here
	@LimiteInf int = null,
	@LimiteSup int = null,
    @VrRecogida numeric(18,0) = null,
    @VrSupern numeric(18,0) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Rangos]
           ([Limite_Inf]
           ,[Limite_Sup]
           ,[Vr_Recogida]
           ,[Vr_Supern])
     VALUES
           (@LimiteInf
           ,@LimiteSup
           ,@VrRecogida
           ,@VrSupern)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertRegLlamadas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 19/05/2023
-- Description:	Insert Registro Llamadas
-- =============================================
CREATE PROCEDURE [dbo].[spInsertRegLlamadas]
	-- Add the parameters for the stored procedure here
	@Fecha_Reg varchar(10) = null,
	@Nombres_Reg varchar(125) = null,
    @Apellidos_Reg varchar(125) = null,
    @Movil_Reg numeric(18,0) = null,
    @Motivo_Reg int = null,
    @IdUsuario int = null,
	@IdSolicitud int = null,
	@IdCotizacion int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Reg_Llamadas]
           ([Fecha_Reg]
		   ,[Nombres_Reg]
           ,[Apellidos_Reg]
           ,[Movil_Reg]
           ,[Motivo_Reg]
           ,[IdUsuario]
		   ,[IdSolicitud]
		   ,[IdCotizacion])
     VALUES
           (@Fecha_Reg
		   ,@Nombres_Reg
           ,@Apellidos_Reg
           ,@Movil_Reg
           ,@Motivo_Reg
           ,@IdUsuario
		   ,@IdSolicitud
		   ,@IdCotizacion)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertRestricciones]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 01/10/2021
-- Description:	Insertar Disponibilidad
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertRestricciones]
	-- Add the parameters for the stored procedure here
	@IdVehiculo int,
	@IdCiudad int,
	@Zona varchar(125),
	@Hora_Ini varchar(8),
	@Hora_Fin varchar(8),
	@Fecha_Ini varchar(10),
	@Fecha_Fin varchar(10)
	

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Restricciones_Vehiculos]
           ([IdVehiculo]
		   ,[IdCiudad]
           ,[Zona]
           ,[Hora_Ini]
           ,[Hora_Fin]
           ,[Fecha_Ini]
           ,[Fecha_Fin])
     VALUES
           (@IdVehiculo, @IdCiudad, @Zona, @Hora_Ini, @Hora_Fin, @Fecha_Ini, @Fecha_Fin)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertRoles]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 2021/09/13
-- Description:	Procedimiento para el registro de roles
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertRoles] 
	-- Add the parameters for the stored procedure here
	@IdPerfil int,
    @IdUsuario int,
    @Nombre varchar(125),
    @FechaIni varchar(10),
	@FechaFin varchar(10)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	-- Insert statements for procedure here
	
	INSERT INTO [dbo].[Roles]
           ([IdPerfil]
           ,[IdUsuario]
           ,[Nombre]
           ,[FechaIni]
           ,[FechaFin])
    VALUES (@IdPerfil, @IdUsuario, @Nombre, @FechaIni, @FechaFin);
          


END
GO
/****** Object:  StoredProcedure [dbo].[spInsertRutaPrecinto]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 16/05/2023
-- Description:	Insert Rutas Precintos
-- =============================================
CREATE PROCEDURE [dbo].[spInsertRutaPrecinto]
	-- Add the parameters for the stored procedure here
	@Opcion int,
	@Precinto int = null,
    @IdCia int = null,
    @IdTrafico int = null,
	@Item int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Consula todos los Tipo
		BEGIN
			INSERT INTO [dbo].[Ruta_Precintos]
				   ([Precinto]
				   ,[IdCia]
				   ,[IdTrafico]
				   ,[Item])

			VALUES
				   (@Precinto
				   ,@IdCia
				   ,@IdTrafico
				   ,@Item)
		END
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertRutas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 13/04/2023
-- Description:	Insert Rutas
-- =============================================
CREATE PROCEDURE [dbo].[spInsertRutas]
	-- Add the parameters for the stored procedure here
	@Opcion int,
	@Nombre_Ruta varchar(125) = null,
    @IdCiudadOrigen int = null,
    @IdCiudadDestino int = null,
    @Km_Ruta numeric(18,2) = null,
	@IdLocOri varchar(8) = null,
	@IdLocDes varchar(8) = null
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Consula todos los Tipo
		BEGIN
			INSERT INTO [dbo].[Rutas]
				   ([Nombre_Ruta]
				   ,[IdCiudadOrigen]
				   ,[IdCiudadDestino]
				   ,[Km_Ruta]
				   ,[IdLocOri]
				   ,[IdLocDes])

			VALUES
				   (@Nombre_Ruta
				   ,@IdCiudadOrigen
				   ,@IdCiudadDestino
				   ,@Km_Ruta
				   ,@IdLocOri
				   ,@IdLocDes)
		END

	
END

GO
/****** Object:  StoredProcedure [dbo].[spInsertSeguimiento]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 03/11/2021
-- Description:	Insertar Seguimiento
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertSeguimiento]
	-- Add the parameters for the stored procedure here
	@IdCotizacion int = null,
    @IdSolicitud int = null,
    @FechaSeguimiento varchar(10) = null,
    @HoraSeguimiento varchar(8) = null,
    @Asesor int = null,
    @IdEstadoCot int = null,
    @FechaProximo varchar(10) = null,
	@HoraProximo varchar(8) = null,
    @Gestion varchar(255) = null,
	@MotivoPerdida int = null,
    @ObservaPerdida varchar(MAX) = null,
	@ValorCotizacion decimal(18,2) = null,
	@IdGestion int = null,
	@CtrlRegistro int = null,
	@CtrlAgenda int = null,
	@CtrlConfirmacion int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	DECLARE @SeguimientoId int = null
	SELECT @SeguimientoId = max(IdSeguimiento) FROM [dbo].[Seguimientos] WHERE IdCotizacion = @IdCotizacion
	UPDATE [dbo].[Seguimientos] SET CtrlRegistro = 1 WHERE IdCotizacion = @IdCotizacion and IdSeguimiento = @SeguimientoId

	--Crear Nuevo Registro
	INSERT INTO [dbo].[Seguimientos]
           ([IdCotizacion]
           ,[IdSolicitud]
           ,[FechaSeguimiento]
           ,[HoraSeguimiento]
           ,[Asesor]
           ,[IdEstadoCot]
           ,[FechaProximo]
		   ,[HoraProximo]
           ,[Gestion]
		   ,[IdGestion]
		   ,[CtrlRegistro])
     VALUES
           (@IdCotizacion
           ,@IdSolicitud
           ,@FechaSeguimiento
           ,@HoraSeguimiento
           ,@Asesor
           ,@IdEstadoCot
           ,@FechaProximo
		   ,@HoraProximo
           ,@Gestion
		   ,@IdGestion
		   ,@CtrlRegistro)

	--Actualizar campos de la cotizacion cuando es rechazada
	UPDATE [dbo].[Cotizacion] 
		SET MotivoPerdida  = @MotivoPerdida, 
			ObservaPerdida = @ObservaPerdida,
			IdUsuario      = @Asesor,
			IdEstadoCot    = @IdEstadoCot
		
		WHERE IdCotizacion = @IdCotizacion

	--Actualizar Valor de la Cotizacion
	UPDATE [dbo].[Cotizacion] 
		SET ValorCotizacion = @ValorCotizacion, 
			FechaUltima     = @FechaSeguimiento,
			IdGestion       = @IdGestion,
			FechaProximo    = @FechaProximo

		WHERE IdCotizacion = @IdCotizacion

	-- Actualizar Control de Agendamiento en Agendas
	UPDATE [dbo].[Agenda]
		SET CtrlConfirmacion = @CtrlConfirmacion,
			CtrlAgenda       = @CtrlAgenda

		WHERE IdCotizacion = @IdCotizacion
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertServ_Radicado]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 27/05/2024
-- Description:	Crear Serv_Radicados
-- =============================================
CREATE PROCEDURE [dbo].[spInsertServ_Radicado]
	-- Add the parameters for the stored procedure here
	@IdCia int = null,
	@Compania varchar(3) = null,
	@Contador numeric(3,0) = null,
	@AnoRad numeric(2,0) = null,
	@EstadoRad varchar(1) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Serv_Radicado]
           ([IdCia]
           ,[Compania]
           ,[Contador]
           ,[AnoRad]
           ,[EstadoRad])
     VALUES
           (@IdCia
           ,@Compania
           ,@Contador
           ,@AnoRad
           ,@EstadoRad)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertServicioCliente]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 2024/05/22
-- Description:	Insertar Servicio Cliente
-- =============================================
CREATE PROCEDURE [dbo].[spInsertServicioCliente]
	-- Add the parameters for the stored procedure here
	@FechaServicio varchar(10) = null,
	@HoraServicio varchar(8) = null,
    @EstadoServicio int = null,
    @Movil varchar(20) = null,
    @Telefono varchar(20) = null,
    @TipoIdentidad int = null,
    @Identificacion varchar(20) = null,
	@Nombres varchar(125) = null,
	@Apellidos varchar(125) = null,
	@Email varchar(125) = null,
	@IdCliente int = null,
    @IdCotizacion int = null,
    @IdOrden int = null,
	@Compania int = null,
    @Motivo int = null,
    @ObservaServicio varchar(max) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[ServicioCliente]
			   ([FechaServicio]
			   ,[HoraServicio]
			   ,[EstadoServicio]
			   ,[Movil]
			   ,[Telefono]
			   ,[TipoIdentidad]
			   ,[Identificacion]
			   ,[Nombres]
			   ,[Apellidos]
			   ,[Email]
			   ,[IdCliente]
			   ,[IdCotizacion]
			   ,[IdOrden]
			   ,[Compania]
			   ,[Motivo]
			   ,[ObservaServicio])
     VALUES
           (@FechaServicio
		   ,@HoraServicio
           ,@EstadoServicio
           ,@Movil 
           ,@Telefono
		   ,@TipoIdentidad
           ,@Identificacion
		   ,@Nombres
		   ,@Apellidos
		   ,@Email
		   ,@IdCliente
           ,@IdCotizacion
           ,@IdOrden 
		   ,@Compania
           ,@Motivo
           ,@ObservaServicio)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertServicioClienteSeguimiento]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 30/05/2024
-- Description:	Insertar Seguimiento Serv Cliente
-- =============================================
CREATE  PROCEDURE [dbo].[spInsertServicioClienteSeguimiento]
-- Add the parameters for the stored procedure here
	@IdServicioCliente int,
	@FechaServ varchar(10) = null,
	@HoraServ varchar(8) = null,
	@GestorServ int = null,
	@EstadoServ int = null,
	@Observaciones varchar(MAX) = null
AS

BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[ServicioClienteSeguimiento]
           ([IdServicioCliente]
           ,[FechaServ]
           ,[HoraServ]
		   ,[GestorServ]
           ,[EstadoServ]
           ,[Observaciones])
     VALUES
           (@IdServicioCliente
           ,@FechaServ
           ,@HoraServ
		   ,@GestorServ
           ,@EstadoServ
           ,@Observaciones)

	UPDATE [dbo].[ServicioCliente] SET EstadoServicio = @EstadoServ WHERE IdServicioCliente = @IdServicioCliente
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertServicioPqrs]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 27/05/2024
-- Description:	Insertar Servicio Pqrs
-- =============================================
CREATE PROCEDURE [dbo].[spInsertServicioPqrs]
	-- Add the parameters for the stored procedure here
	@FechaRadicado varchar(10) = null,
	@HoraRadicado varchar(8) = null,
	@Radicado int = null,
    @CiaRadicado int = null,
	@AnoRadicado numeric(2,0) = null,
    @Recepcion int = null,
    @Clase int = null,
    @FechaReclamo varchar(10) = null,
    @HoraReclamo varchar(8) = null,
    @EstadoPqrs int = null,
    @FechaCierre varchar(10) = null,
    @Tiempo int = null,
    @Descripcion varchar(max) = null,
    @ClasePqrs int = null,
    @CausasOrigen int = null,
    @Responsable int = null,
	@IdSolicitud int = null,
    @IdCotizacion int = null,
    @IdOrden int = null,
    @IdCliente int = null,
	@CtrlCorreo int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	-- Declarar Variables
	DECLARE @IdServicioPqrs as int;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[ServicioPqrs]
			   ([FechaRadicado]
			   ,[HoraRadicado]
			   ,[Radicado]
			   ,[CiaRadicado]
			   ,[AnoRadicado]
			   ,[Recepcion]
			   ,[Clase]
			   ,[FechaReclamo]
			   ,[HoraReclamo]
			   ,[EstadoPqrs]
			   ,[FechaCierre]
			   ,[Tiempo]
			   ,[Descripcion]
			   ,[ClasePqrs]
			   ,[CausasOrigen]
			   ,[Responsable]
			   ,[IdSolicitud]
			   ,[IdCotizacion]
			   ,[IdOrden]
			   ,[IdCliente]
			   ,[CtrlCorreo])
     VALUES
           (@FechaRadicado
		   ,@HoraRadicado
		   ,@Radicado
           ,@CiaRadicado
		   ,@AnoRadicado
           ,@Recepcion
           ,@Clase
           ,@FechaReclamo 
		   ,@HoraReclamo
           ,@EstadoPqrs
           ,@FechaCierre
           ,@Tiempo 
           ,@Descripcion
           ,@ClasePqrs
           ,@CausasOrigen
           ,@Responsable
		   ,@IdSolicitud
           ,@IdCotizacion
           ,@IdOrden
           ,@IdCliente
		   ,@CtrlCorreo)

	--Extraer el ultimo registro
	SET @IdServicioPqrs = (SELECT MAX(IdServicioPqrs) FROM [dbo].[ServicioPqrs]); 

	--Actualizar PQRS Detalles
	-- UPDATE [dbo].[ServicioPqrsDetalle] SET IdServicioPqrs = @IdServicioPqrs WHERE IdCotizacion = @IdCotizacion

	--Actualizar Serv_Radicado
	UPDATE [dbo].[Serv_Radicado] SET Contador = @Radicado WHERE IdCia = @CiaRadicado and  AnoRad = @AnoRadicado
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertServicioPqrsDetalle]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 27/05/2024
-- Description:	Insertar Servicio Pqrs Detalle
-- =============================================
CREATE PROCEDURE [dbo].[spInsertServicioPqrsDetalle]
	@IdServicioPqrs INT = NULL,
    @IdSolicitud    INT = NULL,
    @IdCotizacion   INT = NULL,
    @IdArticulo     INT = NULL,
    @NombreArt      VARCHAR(125) = NULL,
    @ValorArt       NUMERIC(18,0) = 0,
	@Cantidad       INT = 0
AS
BEGIN

	SET NOCOUNT ON;

	INSERT INTO [dbo].[ServicioPqrsDetalle]
		(IdServicioPqrs, IdSolicitud, IdCotizacion, IdArticulo, NombreArt, ValorArt, Cantidad)
     VALUES
           (@IdServicioPqrs, @IdSolicitud, @IdCotizacion, @IdArticulo, @NombreArt, @ValorArt, @Cantidad)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertServicioPqrsSeguimiento]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 29/05/2024
-- Description:	Insertar Seguimiento PostVenta
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertServicioPqrsSeguimiento]
	-- Add the parameters for the stored procedure here
	@IdServicioPqrs int,
	@IdCotizacion int = null,
	@IdSolicitud int = null,
	@Fecha_Postventa varchar(10) = null,
	@Hora_Postventa varchar(8) = null,
	@IdAsesor int = null,
	@GestorPqrs int = null,
	@IdEstadoPqrs int = null,
	@Observaciones varchar(MAX) = null
AS

BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[ServicioPqrsSeguimiento]
           ([IdServicioPqrs]
		   ,[IdCotizacion]
		   ,[IdSolicitud]
           ,[Fecha_Postventa]
           ,[Hora_Postventa]
           ,[IdAsesor]
		   ,[GestorPqrs]
           ,[IdEstadoPqrs]
           ,[Observaciones])
     VALUES
           (@IdServicioPqrs
		   ,@IdCotizacion
		   ,@IdSolicitud
           ,@Fecha_Postventa
           ,@Hora_Postventa
           ,@IdAsesor
		   ,@GestorPqrs
           ,@IdEstadoPqrs
           ,@Observaciones)

	-- Actualizamos el estado en la tabla ServicioPqrs
	IF (
		SELECT EstadoPqrs 
		FROM ServicioPqrs 
		WHERE IdServicioPqrs = @IdServicioPqrs
	) <> @IdEstadoPqrs
	BEGIN 
		UPDATE ServicioPqrs
		SET EstadoPqrs = @IdEstadoPqrs
		WHERE IdServicioPqrs = @IdServicioPqrs
	END
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertServicios]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 02/09/2021
-- Description:	Insertar Servicio
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertServicios] 
	-- Add the parameters for the stored procedure here
	@Nombre varchar(125),
    @Descripcion varchar(255),
    @IdTipo int,
    @CodSyscom varchar(5)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Servicios]
           ([Nombre]
           ,[Descripcion]
           ,[IdTipo]
           ,[CodSyscom])
     VALUES
           (@Nombre, @Descripcion, @IdTipo, @CodSyscom)
END


GO
/****** Object:  StoredProcedure [dbo].[spInsertSolicitudAsesor]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 19/10/2021
-- Description:	Procedimiento almacenado para el registro del asesor solicitud
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertSolicitudAsesor] 
	-- Add the parameters for the stored procedure here
	 @IdAsesor int,
	 @IdSolicitud int,
	 @Estado varchar(1)=null,
	 @Observacion varchar(max)=null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	   
    INSERT INTO [dbo].[Solicitud_Asesor]
           ([IdAsesor]
           ,[IdSolicitud]
           ,[Estado]
           ,[Observacion])
     VALUES
           (@IdAsesor,@IdSolicitud,@Estado,@Observacion)

	
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertSolicitudes]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




-- =============================================
-- Author:		Sergio Rendón Gómez
-- ALTER date: 2021/10/12
-- Description:	Insertar Solicitudes 
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertSolicitudes]
	-- Add the parameters for the stored procedure here
	@Opcion int,
	@FechaServicio varchar(10) = null,
	@Nombre varchar(125) = null,
	@Apellido varchar(125) = null,
	@Telefono varchar(20) = null,
	@Movil varchar(20) = null,
	@Email varchar(120) = null,
	@IdCiudadOrigen int = null,
	@IdCiudadDestino int = null,
	@Observaciones varchar(MAX) = null,
	@Estado int = null,
	@IdServicio int = null,
	@Identificacion nvarchar(20) = null,
	@IdAsesor int = null,
	@IdCliente int = null,
	@OrigenNegocio int = null,
	@Registro int = null,
	@Ctrl_Solicitud int = null

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	-- Declarar Variables
	DECLARE @IdSolicitud as int;

	DECLARE @Existingdate as varchar(10)
	set @Existingdate=CONVERT(varchar,GETDATE(),23)

	DECLARE @Existingtime as varchar(8)
	Set @Existingtime=CONVERT(varchar,GETDATE(),108)
	
	IF @Opcion = 1  -- Crear solicitud por web
		BEGIN
			-- Crear Solicitudes
			INSERT INTO [dbo].[Solicitudes]
						([Fecha]
						,[Hora]
						,[FechaServicio]
						,[Nombre]
						,[Apellido]
						,[Telefono]
						,[Movil]
						,[Email]
						,[IdCiudadOrigen]
						,[IdCiudadDestino]
						,[Observaciones]
						,[Estado]
						,[IdServicio]
						,[Identificacion]
						,[IdAsesor]
						,[IdCliente]
						,[OrigenNegocio]
						,[Ctrl_Solicitud])
     
			VALUES (@Existingdate,
					@Existingtime,
					@FechaServicio,
					@Nombre,
					@Apellido,
					@Telefono,
					@Movil,
					@Email,
					@IdCiudadOrigen,
					@IdCiudadDestino,
					@Observaciones,
					@Estado,
					@IdServicio,
					@Identificacion,
					@IdAsesor,
					@IdCliente,
					@OrigenNegocio,
					@Ctrl_Solicitud) 

			SET @IdSolicitud = (SELECT MAX(IdSolicitud) FROM Solicitudes); 
			 
			-- Crear Solicitud vs Asesor
			INSERT INTO [dbo].[Solicitud_Asesor]
						([IdAsesor]
						,[IdSolicitud]
						,[Estado]
						,[Observacion])
	
			VALUES (@IdAsesor, @IdSolicitud,'1','-')


			-- Actualizar Solicitud en Registro Llamadas
			UPDATE [dbo].[Reg_Llamadas] SET IdSolicitud = @IdSolicitud WHERE IdReg_Llamada = @Registro
		END

	IF @Opcion = 2  -- Crear solicitud duplicada
		BEGIN
			-- Crear Solicitudes
			INSERT INTO [dbo].[Solicitudes]
						([Fecha]
						,[Hora]
						,[FechaServicio]
						,[Nombre]
						,[Apellido]
						,[Telefono]
						,[Movil]
						,[Email]
						,[IdCiudadOrigen]
						,[IdCiudadDestino]
						,[Observaciones]
						,[Estado]
						,[IdServicio]
						,[Identificacion]
						,[IdAsesor]
						,[IdCliente]
						,[OrigenNegocio]
						,[Ctrl_Solicitud])
     
			VALUES (@Existingdate,
					@Existingtime,
					@FechaServicio,
					@Nombre,
					@Apellido,
					@Telefono,
					@Movil,
					@Email,
					@IdCiudadOrigen,
					@IdCiudadDestino,
					@Observaciones,
					@Estado,
					@IdServicio,
					@Identificacion,
					@IdAsesor,
					@IdCliente,
					@OrigenNegocio,
					@Ctrl_Solicitud) 

			SET @IdSolicitud = (SELECT MAX(IdSolicitud) FROM Solicitudes); 
			 
			-- Crear Solicitud vs Asesor
			INSERT INTO [dbo].[Solicitud_Asesor]
						([IdAsesor]
						,[IdSolicitud]
						,[Estado]
						,[Observacion])
	
			VALUES (@IdAsesor, @IdSolicitud,'1','-')
		END
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertSoportePago]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 02/06/2022
-- Description: Registrar Soporte Pago
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertSoportePago] 
	-- Add the parameters for the stored procedure here
	@IdCotizacion int = null,
	@IdSolicitud int = null,
	@NumOrden int = null,
	@Soporte1 varchar(MAX) = null,
	@Soporte2 varchar(MAX) = null,
	@Soporte3 varchar(MAX) = null,
	@Soporte4 varchar(MAX) = null,
	@FecSoporte1 varchar(10) = null,
	@HorSoporte1 varchar(8) = null,
	@FecSoporte2 varchar(10) = null,
	@HorSoporte2 varchar(8) = null,
	@FecSoporte3 varchar(10) = null,
	@HorSoporte3 varchar(8) = null,
	@FecSoporte4 varchar(10) = null,
	@HorSoporte4 varchar(8) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[SoportePago]
           ([IdCotizacion]
           ,[IdSolicitud]
           ,[NumOrden]
           ,[Soporte1]
           ,[Soporte2]
           ,[Soporte3]
           ,[Soporte4]
		   ,[FecSoporte1]
		   ,[HorSoporte1]
		   ,[FecSoporte2]
		   ,[HorSoporte2]
		   ,[FecSoporte3]
		   ,[HorSoporte3]
		   ,[FecSoporte4]
		   ,[HorSoporte4])
     VALUES
           (@IdCotizacion,
			@IdSolicitud,
			@NumOrden,
			@Soporte1,
			@Soporte2,
			@Soporte3,
			@Soporte4,
			@FecSoporte1,
			@HorSoporte1,
			@FecSoporte2,
			@HorSoporte2,
			@FecSoporte3,
			@HorSoporte3,
			@FecSoporte4,
			@HorSoporte4)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertSucursales]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 20/09/2021
-- Description:	Insertar Sucursales
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertSucursales]
	-- Add the parameters for the stored procedure here
	@Nombre nvarchar(125),
	@Direccion nvarchar(125),
	@Telefono nvarchar(125),
	@Movil nvarchar(20),
	@IdResponsable int,
	@IdCiudad int

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Sucursales]
           ([Nombre]
           ,[Direccion]
           ,[Telefono]
           ,[Movil]
           ,[IdResponsable]
           ,[IdCiudad])
     VALUES
           (@Nombre, @Direccion, @Telefono, @Movil, @IdResponsable, @IdCiudad)
END


GO
/****** Object:  StoredProcedure [dbo].[spInsertTarifaRutas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 25/05/2023
-- Description:	Insertar Rutas Tarifa
-- =============================================
CREATE PROCEDURE [dbo].[spInsertTarifaRutas]
	-- Add the parameters for the stored procedure here
	@Origen_Ruta int = null,
    @Destino_Ruta int = null,
    @Descripcion varchar(250) = null,
	@Ubicacion int = null,
    @KmReal numeric(18,0) = null,
    @KmAjustado numeric(18,0) = null,
    @Tolerancia numeric(18,0) = null,
    @KmTotales numeric(18,0) = null,
    @Completo numeric(18,0) = null,
    @UnMedio numeric(18,0) = null,
    @UnTercio numeric(18,0) = null,
    @UnCuarto numeric(18,0) = null,
    @UnSeptimo numeric(18,0) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Tarifa_Rutas]
           ([Origen_Ruta]
           ,[Destino_Ruta]
           ,[Descripcion]
		   ,[Ubicacion]
           ,[KmReal]
           ,[KmAjustado]
           ,[Tolerancia]
           ,[KmTotales]
           ,[Completo]
           ,[UnMedio]
           ,[UnTercio]
           ,[UnCuarto]
           ,[UnSeptimo])
     VALUES
           (@Origen_Ruta 
           ,@Destino_Ruta
           ,@Descripcion
		   ,@Ubicacion
           ,@KmReal
           ,@KmAjustado
           ,@Tolerancia
           ,@KmTotales
           ,@Completo
           ,@UnMedio
           ,@UnTercio
           ,@UnCuarto
           ,@UnSeptimo)
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertTarifasBodegas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 11/03/2023
-- Description:	crear Tarifas Bodegas
-- =============================================
CREATE PROCEDURE [dbo].[spInsertTarifasBodegas]
	-- Add the parameters for the stored procedure here
	@Area numeric(18,0) = null,
    @ValorMetro numeric(18,2) = null,
    @Clase varchar(1) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Tarifas_Bodegas]
           ([Area]
           ,[ValorMetro]
           ,[Clase])
     VALUES
           (@Area
           ,@ValorMetro
           ,@Clase)
END


GO
/****** Object:  StoredProcedure [dbo].[spInsertTextos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 26/01/2022
-- Description:	Guardar Textos
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertTextos]
	-- Add the parameters for the stored procedure here
	@IdClaseDoc int,
	@Text1 varchar(MAX),
	@Text2 varchar(MAX),
	@Text3 varchar(MAX),
	@Text4 varchar(MAX)

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Textos]
		([IdClaseDoc]
		,[Text1]
		,[Text2]
		,[Text3]
		,[Text4])
		 
	VALUES(@IdClaseDoc, @Text1, @Text2, @Text3, @Text4);
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertTipo]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 01/09/2021
-- Description:	Insertar Tipo Servicio
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertTipo] 
	-- Add the parameters for the stored procedure here
	@IdTipo Int=null,
	@Nombre varchar(125),
	@CodSyscom varchar(4)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[TipoServicio]
           ([Nombre]
		   ,[CodSyscom])
     VALUES
           (@Nombre, @CodSyscom)

END

GO
/****** Object:  StoredProcedure [dbo].[spInsertUsuarios]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 09/08/2020
-- Description:	Crear usuarios
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertUsuarios] 
	-- Add the parameters for the stored procedure here
	@Nombres varchar(120) = null,
	@Apellidos varchar(120) = null,
    @TipoIdent int = null,
    @Identificacion as varchar(20) = null,
    @Email varchar(120) = null,
    @Movil varchar(20) = null,
	@IdArea int =null,
    @Estado varchar(1) = null,
    @Login varchar(20) = null,
    @Clave varchar(20) = null,
	@IdPerfil int = null,
	@NombrePerfil varchar(125) = null,
	@Contrasena varchar(20) = null,
	@Compania int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
   -- Insert statements for procedure here
    declare @IdUsuario as int;

    INSERT INTO [dbo].[Usuarios]
           ([Nombres]
           ,[Apellidos]
           ,[TipoIdent]
           ,[Identificacion]
           ,[Email]
           ,[Movil]
           ,[IdArea]
           ,[Estado]
           ,[Login]
           ,[Clave]
		   ,[Contrasena]
		   ,[IdCia])
     VALUES
           (@Nombres,
		    @Apellidos,
			@TipoIdent,
			@Identificacion,
			@Email,
			@Movil,
			@IdArea,
			@Estado,
			@Login,
			@Clave,
			@Contrasena,
			@Compania)

    set @IdUsuario = (SELECT MAX(IdUsuario) FROM Usuarios); 
	
	-- Borro la tabla de roles
	DELETE from Roles where IdUsuario = @IdUsuario 
	
	-- Registrando en la tabla de Roles
	INSERT INTO [dbo].[Roles]
           ([IdPerfil]
           ,[IdUsuario]
           ,[Nombre]
           ,[FechaIni]
           ,[FechaFin])
     VALUES
	       (@IdPerfil, 
		    @IdUsuario, 
			@NombrePerfil, 
			'9999/99/99', 
			'9999/99/99');
		   	
END
GO
/****** Object:  StoredProcedure [dbo].[spInsertVehiculos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 29/09/2021
-- Description:	Insert Vehiculos
-- =============================================
CREATE PROCEDURE [dbo].[spInsertVehiculos]
	-- Add the parameters for the stored procedure here
    @Placa varchar(10) = null,
    @TipoVehiculo int = null,
    @Modelo int = null,
	@Asignacion int = null,
	@IdCia int = null,
	@Afiliacion int = null,
    @IdPropietario int = null,
    @IdConductor int = null,
	@Largo numeric(18,2) = null,
	@Ancho numeric(18,2) = null,
	@Alto numeric(18,2) = null,
	@Volumen numeric(18,2) = null,
    @Capacidad numeric(18,2) = null,
    @PesoVacio numeric(18,2) = null,
	@PesoMaximo numeric(18,2) = null,
	@Combustible int = null,
	@Odometro int = null,
	@Estado varchar(1) = null,
    @Disponible int = null,
	@GrupoPro varchar(50) = null,
	@IdGrupoPro int = null,
    @Marca int = null,
	@Km_Gl numeric(18,2) = null,
	@Reserva numeric(18,2) = null,
	@Tpp numeric(18,2) = null,
	@Taux1 numeric(18,2) = null,
	@Taux2 numeric(18,2) = null,
	@Lleno numeric(18,2) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Vehiculos]
			([Placa]
			,[TipoVehiculo]
			,[Modelo]
			,[Asignacion]
			,[IdCia]
			,[Afiliacion]
			,[IdPropietario]
			,[IdConductor]
			,[Largo]
			,[Ancho]
			,[Alto]
			,[Volumen]
			,[PesoVacio]
			,[PesoMaximo]
			,[Capacidad]
			,[CtrlCombustible]
			,[Odometro]
			,[Estado]
			,[Disponible]
			,[GrupoPro]
			,[IdGrupoPro]
			,[Marca]
			,[Km_Gl]
			,[Reserva]
			,[Tpp]
			,[Taux1]
			,[Taux2]
			,[Lleno])
     VALUES
           ( @Placa
            ,@TipoVehiculo 
            ,@Modelo 
			,@Asignacion
			,@IdCia
			,@Afiliacion
            ,@IdPropietario 
            ,@IdConductor 
			,@Largo
			,@Ancho
			,@Alto
			,@Volumen
			,@PesoVacio
			,@PesoMaximo
            ,@Capacidad
			,@Combustible
			,@Odometro
            ,@Estado
            ,@Disponible
			,@GrupoPro
			,@IdGrupoPro
			,@Marca
			,@Km_Gl
			,@Reserva
			,@Tpp
			,@Taux1
			,@Taux2
			,@Lleno)

END




GO
/****** Object:  StoredProcedure [dbo].[spInsertVisitas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 04/11/2021
-- Description:	Insertar Visita Programacion
-- =============================================
CREATE   PROCEDURE [dbo].[spInsertVisitas]
	-- Add the parameters for the stored procedure here
	@IdCotizacion int, 
    @IdSolicitud int, 
    @FechaVisita varchar(10), 
    @HoraVisita varchar(8), 
    @AsesorVisita int, 
    @EstadoVisita int, 
    @Observacion varchar(255)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [dbo].[Cotizacion_Presencial]
           ([IdCotizacion]
           ,[IdSolicitud]
           ,[FechaVisita]
           ,[HoraVisita]
           ,[AsesorVisita]
           ,[EstadoVisita]
           ,[Observacion])
     VALUES
           (@IdCotizacion 
			,@IdSolicitud 
			,@FechaVisita 
			,@HoraVisita 
			,@AsesorVisita 
			,@EstadoVisita 
			,@Observacion)
END



GO
/****** Object:  StoredProcedure [dbo].[spUpdateAgendas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 05/05/2022
-- Description:	Actualizar Agendas
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateAgendas]
	-- Add the parameters for the stored procedure here
	@Opcion int,
	@IdEvento int = null,
	@title varchar(50) = null,
    @descripcion varchar(255) = null,
    @start varchar(30) = null,
    @color varchar(10) = null,
    @textColor varchar(10) = null,
    @end varchar(30) = null,
    @IdOrden int = null,
    @IdCotizacion int = null,
    @Vehiculo int = null,
    @Personal int = null,
	@Inventario int = null,
	@IdUsuario int = null,
	@Compania int = null,
	@FechaIni varchar(10) = null,
	@EstadoEvento int = null,
	@Servicio int = null,
	@FechaRecogida varchar(10) = null,
	@HoraRecogida varchar(8) = null,
	@FechaEntrega varchar(10) = null,
	@HoraEntrega varchar(8) = null,
	@CiudadOrigen int = null,
	@CiudadDestino int = null,
	@CiaEncargada int = null,
	@Requisicion int = null,
	@CtrlAgenda int = null,
	@CtrlConfirmacion int = null,
	@TipoServicioCot int = null,
	@Fecha_Ini varchar(10) = null,
	@Fecha_Fin varchar(10) = null,
	@MesAnterior int = null
AS

BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Actualizacion completa
		BEGIN
			UPDATE [dbo].[Agenda]

			SET  [title]           = @title
				,[descripcion]     = @descripcion
				,[start]           = @start
				,[color]           = @color
				,[textColor]       = @textColor
				,[end]             = @end
				,[IdOrden]         = @IdOrden
				,[IdCotizacion]    = @IdCotizacion
				,[Vehiculo]        = @Vehiculo
				,[Personal]        = @Personal
				,[IdUsuario]       = @IdUsuario
				,[IdCia]           = @Compania
				,[FechaIni]        = @FechaIni
				,[EstadoEvento]    = @EstadoEvento
				,[Servicio]        = @Servicio
				,[FechaRecogida]   = @FechaRecogida
				,[HoraRecogida]    = @HoraRecogida
				,[FechaEntrega]    = @FechaEntrega
				,[HoraEntrega]     = @HoraEntrega
				,[IdCiudadOrigen]  = @CiudadOrigen
				,[IdCiudadDestino] = @CiudadDestino
				,[CiaEncargada]    = @CiaEncargada
				,[CtrlAgenda]      = @CtrlAgenda
				,[CtrlConfirmacion]= @CtrlConfirmacion
				,[TipoServicioCot] = @TipoServicioCot 

			WHERE IdEvento = @IdEvento

			-- Actualizar Cotizacion 
			UPDATE [dbo].[OrdenServicio] 
				SET NumInventario  = @Inventario, 
					NumRequisicion = @Requisicion 
				WHERE IdOrden = @IdOrden
		END

	IF @Opcion = 2  -- Actualizacion completa
		BEGIN
			UPDATE [dbo].[Agenda]     SET [CtrlAgenda] = 3 WHERE FechaIni between @Fecha_Ini and @Fecha_Fin
			UPDATE [dbo].[TotalMeses] SET [Cerrado] = 0    WHERE IdMes = @MesAnterior   

		END
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateArticulos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 05/09/2021
-- Description:	Actualizar Tipo Servicio
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateArticulos] 
	-- Add the parameters for the stored procedure here
	@IdArticulo Int = null,
	@Nombre varchar(125) = null,
	@Descripcion varchar(255) = null,
	@Material int = null,
	@IdTipoArt int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Articulos]
		SET	 [Nombre]         = @Nombre
			,[Descripcion]    = @Descripcion
			,[Material]       = @Material
			,[IdTipoArticulo] = @IdTipoArt
	 
	WHERE IdArticulo = @IdArticulo
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdatebodCarSeguimiento]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:	     Juan Andres Martinez
-- Create date:  Enero 2023
-- Description:	 Actualizar Cartera Seguimiento
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdatebodCarSeguimiento]
	-- Add the parameters for the stored procedure here
	@IdSeguimiento int = null,
	@IdUsuario int = null,
	@IdContrato int = null,
	@IdCartera int = null,
	@IdCliente int = null,
	@DiasMora varchar(10) = null,
	@MesesMora varchar(10) = null,
	@TotalMora varchar(50) = null,
	@FechaSeguimiento varchar(10) = null,
	@Observacion varchar(max) = null,	
	@Formato int = null	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Bodegas_CarteraSeguimiento]
	  
	SET [IdUsuario]        = @IdUsuario
       ,[IdContrato]       = @IdContrato
       ,[IdCartera]        = @IdCartera
       ,[IdCliente]        = @IdCliente
       ,[DiasMora]         = @DiasMora
       ,[MesesMora]        = @MesesMora
       ,[TotalMora]        = @TotalMora
       ,[FechaSeguimiento] = @FechaSeguimiento
       ,[Observacion]      = @Observacion
       ,[Formato]          = @Formato

	WHERE IdSeguimiento   = @IdSeguimiento
END

GO
/****** Object:  StoredProcedure [dbo].[spUpdateBodCartera]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 05/10/2023
-- Description:	Actualizar Cartera
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateBodCartera] 
	-- Add the parameters for the stored procedure here
	 @Opcion int
	,@IdCartera int 
	,@FechaPago varchar(10) = null
    ,@HoraPago varchar(8) = null
    ,@Saldo numeric(18,0) = null
    ,@ValorCuota numeric(18,0) = null
    ,@PagoTotal numeric(18,0) = null
    ,@IdContrato int = null
    ,@Estado int = null
    ,@Intereses numeric(18,0) = null
    ,@Descuentos numeric(18,0) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Actualizacion completa
		BEGIN
			UPDATE [dbo].[Bodegas_Cartera]

				SET  [FechaPago]     = @FechaPago
					,[HoraPago]      = @HoraPago
					,[Saldo]         = @Saldo
					,[ValorCuota]    = @ValorCuota
					,[PagoTotal]     = @PagoTotal
					,[IdContrato]    = @IdContrato
					,[Estado]        = @Estado
					,[Intereses]     = @Intereses
					,[Descuentos]    = @Descuentos

				WHERE IdCartera = @IdCartera
		END

	IF @Opcion = 2  -- Actualizacion datos abono
		BEGIN
			UPDATE [dbo].[Bodegas_Cartera]

				SET  [Saldo]         = @Saldo
					,[PagoTotal]     = @PagoTotal
					,[IdContrato]    = @IdContrato
					,[Estado]        = @Estado
					,[Intereses]     = @Intereses
					,[Descuentos]    = @Descuentos

				WHERE IdCartera = @IdCartera
		END
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateBodContArticulos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 13/05/2025
-- Description:	update Contrato Articulos
-- ================================================
CREATE   PROCEDURE [dbo].[spUpdateBodContArticulos] 
	-- Add the parameters for the stored procedure here
	@IdCont_Articulo int, 
	@IdContrato int = null,
	@IdArticulo Int = null,
	@IdCotizacion Int = null,
	@Nombre varchar(125) = null,
    @Descripcion varchar(255) = null,
    @Cantidad varchar(10) = null,
	@EstadoArticulo varchar(2) = null,
	@Memorando varchar(50) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Bodegas_ContratoArticulos]
		SET [IdContrato]      = @IdContrato
			,[IdCotizacion]   = @IdCotizacion
			,[IdArticulo]     = @IdArticulo
			,[Nombre]         = @Nombre
			,[Descripcion]    = @Descripcion
			,[Cantidad]       = @Cantidad
			,[EstadoArticulo] = @EstadoArticulo
			,[Memorando]      = @Memorando

		WHERE IdCont_Articulo = @IdCont_Articulo and 
			  IdCotizacion    = @IdCotizacion
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateBodContBodegas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 18/01/2023
-- Description:	Actualizar Contratos bodegas
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateBodContBodegas]
	-- Add the parameters for the stored procedure here
	@IdCttBodega int, 
	@IdContrato int = null,
    @IdBodega int = null,
    @IdCotizacion int = null,
    @IdSucursal int = null,
    @Nombre varchar(125) = null,
    @Capacidad numeric(18, 0) = null,
    @Ocupacion numeric(18, 0) = null,
    @Disponible numeric(18, 0) = null,
    @Largo varchar(20) = null,
    @Ancho varchar(20) = null,
    @Alto varchar(20) = null,
    @Estado varchar(20) = null,
	@CodSyscom varchar(4) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Bodegas_ContratoBodegas]
		
		SET [IdContrato]   = @IdContrato
			,[IdBodega]    = @IdBodega
			,[IdCotizacion]= @IdCotizacion
			,[IdSucursal]  = @IdSucursal
			,[Nombre]      = @Nombre
			,[Capacidad]   = @Capacidad
			,[Ocupacion]   = @Ocupacion
			,[Disponible]  = @Disponible
			,[Largo]       = @Largo
			,[Ancho]       = @Ancho
			,[Alto]        = @Alto
			,[Estado]      = @Estado
			,[CodSyscom]   = @CodSyscom 
		
		WHERE IdCttBodega =  @IdCttBodega
END

GO
/****** Object:  StoredProcedure [dbo].[spUpdateBodContratoIPC]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 19/01/2024
-- Description:	update Contratos - Articulos
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateBodContratoIPC]
	-- Add the parameters for the stored procedure here
	@Opcion int,
	@IdAjuste int = null,
	@IdContrato int = null,
    @IdCartera int = null,
    @AjusteNumero int = null,
    @ValorBodega numeric(18,0) = null,
    @Ipc decimal(18,2) = null,
    @ValorAsegurado numeric(18,0) = null,
    @ValorIpc numeric(18,0) = null,
    @ValorSeguro numeric(18,0) = null,
    @ValorMensual numeric(18,0) = null,
    @Iva numeric(18,0) = null,
    @ValorTotal numeric(18,0) = null,
    @AplicaHasta varchar(10) = null,
    @CartaAviso varchar(10) = null,
	@DctoCarta varchar(max) = null,
	@CtrlCarta int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Actualizacion completa
		BEGIN
			UPDATE [dbo].[Bodegas_ContratoIPC]

				SET  [IdContrato]     = @IdContrato
					,[IdCartera]      = @IdCartera
					,[AjusteNumero]   = @AjusteNumero
					,[ValorBodega]    = @ValorBodega
					,[Ipc]            = @Ipc
					,[ValorAsegurado] = @ValorAsegurado
					,[ValorIpc]       = @ValorIpc
					,[ValorSeguro]    = @ValorSeguro
					,[ValorMensual]   = @ValorMensual
					,[Iva]            = @Iva
					,[ValorTotal]     = @ValorTotal
					,[AplicaHasta]    = @AplicaHasta
					,[CartaAviso]     = @CartaAviso
					,[DctoCarta]      = @DctoCarta
					,[CtrlCarta]      = @CtrlCarta

				 WHERE IdAjuste = @IdAjuste 
		END

	IF @Opcion = 2  -- Actualizacion Control y Dcto Carta
		BEGIN
			UPDATE [dbo].[Bodegas_ContratoIPC]

				SET  [DctoCarta] = @DctoCarta
					,[CtrlCarta] = @CtrlCarta

				 WHERE IdAjuste = @IdAjuste 
		END
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateBodContratos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 05/10/2022
-- Description:	Actualizar Contrato
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateBodContratos]
	-- Add the parameters for the stored procedure here
	 @Opcion int
	,@IdContrato int 
	,@NumeroContrato varchar(30) = null
    ,@FechaContrato varchar(10) = null
    ,@HoraContrato varchar(8) = null
    ,@FechaInicio varchar(10) = null
    ,@HoraInicio varchar(8) = null
    ,@FechaFin varchar(10) = null
    ,@HoraFin varchar(8) = null
    ,@IdCiudadOrigen int = null
    ,@IdSucursal int = null
    ,@IdCliente int = null
    ,@IdCotizacion int = null
    ,@IdOrdenServicio int = null
    ,@ValorContrato decimal(18, 0) = null
    ,@PorcentajeIVA decimal(18,2) = null
    ,@ValorIVA decimal(18, 0) = null
    ,@ValorDeclarado decimal(18, 0) = null
    ,@ValorPoliza decimal(18, 0) = null
    ,@IdPeriodicidad int = null
	,@MesesPeriodo int = null
    ,@ValorTotal decimal(18, 0) = null
    ,@EstadoContrato varchar(1) = null
    ,@Novedades varchar(10) = null
	,@PagoInicial varchar(1) = null
	,@CodigoEntrada varchar(50) = null
	,@CodigoSalida varchar(50) = null
	,@Bloqueo varchar(1) =  null
	,@Movimientos int = null
	,@ControlContrato int = null
	,@IdCartera int = null
	,@IdCia int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Actualizacion completa
	BEGIN
		SET @CodigoEntrada = (SELECT IdEntrada FROM Bodegas_CodigoEntrada WHERE CodEntrada = @CodigoEntrada AND IdContrato = @IdContrato)
		SET @CodigoSalida = (SELECT IdSalida FROM Bodegas_CodigoSalida WHERE CodSalida = @CodigoSalida AND IdContrato = @IdContrato)
		
		UPDATE 
			[dbo].[Bodegas_Contratos]
		SET 
			[NumeroContrato]  = @NumeroContrato
			,[FechaContrato]   = @FechaContrato
			,[HoraContrato]    = @HoraContrato
			,[FechaInicio]     = @FechaInicio
			,[HoraInicio]      = @HoraInicio
			,[FechaFin]        = @FechaFin
			,[HoraFin]         = @HoraFin
			,[IdCiudadOrigen]  = @IdCiudadOrigen
			,[IdSucursal]      = @IdSucursal
			,[IdCliente]       = @IdCliente
			,[IdCotizacion]    = @IdCotizacion
			,[IdOrdenServicio] = @IdOrdenServicio
			,[ValorContrato]   = @ValorContrato
			,[PorcentajeIVA]   = @PorcentajeIVA
			,[ValorIVA]        = @ValorIVA
			,[ValorDeclarado]  = @ValorDeclarado
			,[ValorPoliza]     = @ValorPoliza
			,[IdPeriodicidad]  = @IdPeriodicidad
			,[MesesPeriodo]    = @MesesPeriodo
			,[ValorTotal]      = @ValorTotal
			,[EstadoContrato]  = @EstadoContrato
			,[Novedades]       = @Novedades
			,[PagoInicial]     = @PagoInicial
			,[CodigoEntrada]   = @CodigoEntrada
			,[CodigoSalida]    = @CodigoSalida
			,[Bloqueo]         = @Bloqueo
			,[Movimientos]     = @Movimientos
			,[ControlContrato] = @ControlContrato
			,[IdCartera]       = @IdCartera
			,[IdCia]           = @IdCia
		WHERE 
			IdContrato = @IdContrato

		--UPDATE [dbo].[Cotizacion_Conceptos] SET Valor_Negociado = @ValorContrato WHERE IdCotizacion = @IdCotizacion and IdServicio = 17;
	END

	IF @Opcion = 2  -- Actualizacion campo bloqueo
		BEGIN
			UPDATE [dbo].[Bodegas_Contratos] SET [Bloqueo] = @Bloqueo WHERE  IdContrato = @IdContrato and IdCotizacion = @IdCotizacion
		END

	IF @Opcion = 3  -- Actualizacion Campos Contrato
		BEGIN
			UPDATE [dbo].[Bodegas_Contratos] 
				
				SET	[NumeroContrato]  = @NumeroContrato,
					[IdOrdenServicio] = @IdOrdenServicio
			
				WHERE  IdContrato = @IdContrato and IdCotizacion = @IdCotizacion
		END

	IF @Opcion = 4  -- Actualizacion campo Control
		BEGIN
			UPDATE [dbo].[Bodegas_Contratos] SET [ControlContrato] = 1, [Bloqueo] = 'S' WHERE  IdContrato = @IdContrato and IdCotizacion = @IdCotizacion
		END

	IF @Opcion = 5  -- Actualizacion Pago Inicial
		BEGIN
			UPDATE [dbo].[Bodegas_Contratos] SET [PagoInicial] = @PagoInicial WHERE  IdContrato = @IdContrato and IdCotizacion = @IdCotizacion
		END

END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateBodegas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:	     Sergio Rendón Gómez
-- Create date:  24/09/2021
-- Description:	 Actualizar Bodega
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateBodegas]
	-- Add the parameters for the stored procedure here
	@Opcion int,
	@IdBodega int = null,
	@IdSucursal int = null,
	@Nombre varchar(125) = null,
	@Capacidad numeric(18,2) = null,
	@IdUnidad int = null,
	@Largo numeric(18,2) = null,
	@Ancho numeric(18,2) = null,
	@Alto numeric(18,2) = null,
	@Estado varchar(2) = null,
	@Disponible numeric(18,2) = null,
	@CodSyscom varchar(4) = null,
	@ValorBodega decimal(18,2) = null,
	@Ocupacion numeric(18,2) = null,
	@CapacidadFinal numeric(18,2) = null,
	@IdTarifaBodega int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Actualizacion completa
		BEGIN
			UPDATE [dbo].[Bodegas]
				SET [IdSucursal]     = @IdSucursal	
				   ,[Nombre]         = @Nombre
				   ,[Capacidad]      = @Capacidad
				   ,[IdUnidad]       = @IdUnidad
				   ,[Largo]          = @Largo
				   ,[Ancho]          = @Ancho
				   ,[Alto]           = @Alto
				   ,[Estado]         = @Estado
				   ,[Disponible]     = @Disponible
				   ,[CodSyscom]      = @CodSyscom
				   ,[ValorBodega]    = @ValorBodega
				   ,[Ocupacion]      = @Ocupacion
				   ,[CapacidadFinal] = @CapacidadFinal
				   ,[IdTarifaBodega] = @IdTarifaBodega

				WHERE IdBodega = @IdBodega
		END

	IF @Opcion = 2  -- Actualizacion completa
		BEGIN
			UPDATE [dbo].[Bodegas] 
				SET  [ValorBodega]    = @ValorBodega 
					,[Capacidad]      = @Capacidad
					,[IdTarifaBodega] = @IdTarifaBodega

				WHERE IdBodega = @IdBodega
		END
END

GO
/****** Object:  StoredProcedure [dbo].[spUpdateBodEstadoCuentas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 15/01/2023
-- Description:	Actualizar Estado de Cuentas
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateBodEstadoCuentas]
	-- Add the parameters for the stored procedure here
	@IdCuenta int = null,
	@IdContrato int = null,
    @IdCartera int = null,
    @IdCliente int = null,
    @Desde varchar(10) = null,
    @Hasta varchar(10) = null,
    @ValorBodega numeric(18,0) = null,
    @ValorSeguro numeric(18,0) = null,
    @ValorIva numeric(18,0) = null,
    @ValorBaseCuenta numeric(18,0) = null,
    @ValorIpcCuenta numeric(18,0) = null,
    @ValorIvaCuenta numeric(18,0) = null,
    @MesesMora int = null,
    @VrSancionCuenta numeric(18,0) = null,
    @VrDeudaMes numeric(18,0) = null,
    @VrAbonoDeuda numeric(18,0) = null,
    @VrSaldoDeuda numeric(18,0) = null,
    @VrDeudaAcumulada numeric(18,0) = null,
    @CtrlPago int = null,
    @CtrlCuota int = null,
	@PorcentajeIpc numeric(18, 2) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Bodegas_EstadoCuentas]

	   SET [IdContrato]       = @IdContrato
		  ,[IdCartera]        = @IdCartera
		  ,[IdCliente]        = @IdCliente
		  ,[Desde]            = @Desde
		  ,[Hasta]            = @Hasta
		  ,[ValorBodega]      = @ValorBodega
		  ,[ValorSeguro]      = @ValorSeguro
		  ,[ValorIva]         = @ValorIva
		  ,[ValorBaseCuenta]  = @ValorBaseCuenta
		  ,[ValorIpcCuenta]   = @ValorIpcCuenta
		  ,[ValorIvaCuenta]   = @ValorIvaCuenta
		  ,[MesesMora]        = @MesesMora
		  ,[VrSancionCuenta]  = @VrSancionCuenta
		  ,[VrDeudaMes]       = @VrDeudaMes
		  ,[VrAbonoDeuda]     = @VrAbonoDeuda
		  ,[VrSaldoDeuda]     = @VrSaldoDeuda
		  ,[VrDeudaAcumulada] = @VrDeudaAcumulada
		  ,[CtrlPago]         = @CtrlPago
		  ,[CtrlCuota]        = @CtrlCuota
		  ,[PorcentajeIpc]    = @PorcentajeIpc
	 
	 WHERE IdCuenta = @IdCuenta
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateBodIPC]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 2023-12-20
-- Description:	Guardar Bodega IPC
-- ===============================================
CREATE PROCEDURE [dbo].[spUpdateBodIPC] 
	-- Add the parameters for the stored procedure here
	@IdIPC int, 
	@Valor decimal(18,2) = null,
    @Ano int = null,
    @Puntos decimal(18,2) = null,
    @EstadoIPC int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Bodegas_IPC]

		SET [Valor]      = @Valor
			,[Ano]       = @Ano
			,[Puntos]    = @Puntos
			,[EstadoIPC] = @EstadoIPC

		WHERE IdIPC = @IdIPC
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateBodKardex]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 16/03/2023
-- Description:	update Kardex
-- ================================================
CREATE   PROCEDURE [dbo].[spUpdateBodKardex] 
	-- Add the parameters for the stored procedure here
	@Opcion int,
	@IdKardex int,
	@IdCont_Articulo int = null, 
	@IdContrato int = null,
	@IdCotizacion Int = null,
    @Cantidad varchar(10) = null,
	@Revisado int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Actualizacion Cantidad de Articulos
		BEGIN
			UPDATE [dbo].[Bodegas_KardexArticulos]
				SET [IdCont_Articulo] = @IdCont_Articulo
					,[IdContrato]     = @IdContrato
					,[IdCotizacion]   = @IdCotizacion
					,[Cantidad]       = @Cantidad
					,[Revisado]       = @Revisado

				WHERE IdKardex = @IdKardex 

			-- Actualizar contratos-Articulos
			UPDATE [dbo].[Bodegas_ContratoArticulos] SET Cantidad = @Cantidad WHERE IdCont_Articulo = @IdCont_Articulo and IdContrato = @IdContrato
		END

	IF @Opcion = 2  -- Actualizacion De revisión de articulo
		BEGIN
			UPDATE [dbo].[Bodegas_KardexArticulos]
				SET [IdContrato]    = @IdContrato
					,[IdCotizacion] = @IdCotizacion
					,[Revisado]     = @Revisado

				WHERE IdKardex = @IdKardex 

			-- Actualizar contratos-Articulos
			UPDATE [dbo].[Bodegas_ContratoArticulos] SET Cantidad = @Cantidad WHERE IdCont_Articulo = @IdCont_Articulo and IdContrato = @IdContrato
		END
END

GO
/****** Object:  StoredProcedure [dbo].[spUpdateCarteraCerrado]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:	     Juan Andres Martinez
-- Create date:  Enero 2023
-- Description:	 Actualizar Cartera Cerrado
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateCarteraCerrado]
@IdContrato INT
AS
--UPDATE CA
--	SET CA.Inactivo = 1
--FROM Bod.Cartera AS CA
--JOIN Bod.Contratos AS C ON CA.IdContrato = C.IdContrato
--WHERE C.IdContrato = @IdContrato
GO
/****** Object:  StoredProcedure [dbo].[spUpdateCarteraTarifas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:	     Juan Andres Martinez
-- Create date:  Enero 2023
-- Description:	 Actualizar Cartera Tarifas
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateCarteraTarifas]
@IdCartera INT,
@Saldo VARCHAR(30),
@PagoTotal VARCHAR(30),
@ValCuota VARCHAR(30),
@Estado INT
AS
--UPDATE Bod.Cartera SET Saldo = @Saldo, PagoTotal = @PagoTotal, ValorCuota = @ValCuota, Estado = @Estado
--WHERE 
--	Bod.Cartera.IdCartera = @IdCartera
GO
/****** Object:  StoredProcedure [dbo].[spUpdateClientes]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 23/09/2021
-- Description:	Update Clientes
-- ================================================
CREATE   PROCEDURE [dbo].[spUpdateClientes] 
	-- Add the parameters for the stored procedure here
	@IdCliente int,
	@TipoIdent int,
    @Identificacion nvarchar(20),
    @TipoCliente int,
    @Nombres varchar(125),
    @Apellidos varchar(125),
    @IdEmpresa varchar(125),
    @IdCiudad int,
    @Direccion varchar(125),
    @Movil varchar(20),
    @Telefono varchar(20),
	@Email varchar(125),
	@RazonSocial varchar(250)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Clientes]

	SET [TipoIdent]		  = @TipoIdent
		,[Identificacion] = @Identificacion
		,[TipoCliente]	  = @TipoCliente
		,[Nombres]		  = @Nombres
		,[Apellidos]	  = @Apellidos
		,[IdEmpresa]	  = @IdEmpresa
		,[IdCiudad]		  = @IdCiudad
		,[Direccion]	  = @Direccion
		,[Movil]		  = @Movil
	    ,[Telefono]		  = @Telefono
		,[Email]		  = @Email
		,[RazonSocial]	  = @RazonSocial

	 WHERE IdCliente = @IdCliente
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateCompanias]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 11/04/20222
-- Description:	Update Compañias
-- ================================================
CREATE   PROCEDURE [dbo].[spUpdateCompanias]
	-- Add the parameters for the stored procedure here
	@IdCia int = null,
	@NombreCia varchar(50) = null,
    @Sucursal varchar(10) = null,
    @Direccion varchar(250) = null,
    @Telefono varchar(20) = null,
    @IdCiudad int = null,
    @Estado varchar(1) = null,
    @CodSyscom varchar(2) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Compania]
		SET [NombreCia] = @NombreCia
		    ,[Sucursal]  = @Sucursal
		    ,[Direccion] = @Direccion
		    ,[Telefono]  = @Telefono
		    ,[IdCiudad]  = @IdCiudad
		    ,[Estado]    = @Estado
		    ,[CodSyscom] = @CodSyscom
	 
		WHERE IdCia   = @IdCia
END

GO
/****** Object:  StoredProcedure [dbo].[spUpdateConceptos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 09/02/2022
-- Description:	Actualizar Conceptos
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateConceptos]
	-- Add the parameters for the stored procedure here
	@IdConceptoServ int,
	@CodSyscom varchar(4),
    @Concepto varchar(250),
    @Grupo varchar(20),
	@Valor decimal(18,2),
	@Porc_Descuento varchar(4),
	@IdConceptoPDF int,
	@ValorIva decimal(18,2),
	@RubroConcepto varchar(20)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Concepto_Servicios]
		SET [CodSyscom]       = @CodSyscom
			,[Concepto]       = @Concepto
			,[Grupo]          = @Grupo
			,[Valor]          = @Valor
			,[Porc_Descuento] = @Porc_Descuento
			,[IdConceptoPDF]  = @IdConceptoPDF
			,[ValorIva]       = @ValorIva
			,[RubroConcepto]  = @RubroConcepto
		
		WHERE IdConceptoServ = @IdConceptoServ
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateConductores]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 04/04/2022
-- Description:	Actualizar Conductores
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateConductores] 
	-- Add the parameters for the stored procedure here
	@IdConductor int = null,
	@TipoIdent int = null,
    @Identificacion varchar(20) = null,
    @Nombres varchar(125) = null,
    @Apellidos varchar(125) = null,
    @IdCiudad int = null,
    @Direccion varchar(250) = null,
    @Telefono varchar(20) = null,
	@Movil varchar(20) = null,
    @Email varchar(250) = null,
    @Estado varchar(1) = null,
	@Liquidacion numeric(18,2) = null,
	@IdVehiculo int = null,
	@Compania int = null,
	@TipoConductor int = null,
	@IdGrupo varchar(4) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Conductores]
	
	SET [TipoIdent]      = @TipoIdent
       ,[Identificacion] = @Identificacion
       ,[Nombres]        = @Nombres
       ,[Apellidos]      = @Apellidos
       ,[IdCiudad]       = @IdCiudad
       ,[Direccion]      = @Direccion
       ,[Telefono]       = @Telefono
	   ,[Movil]          = @Movil
       ,[Email]          = @Email
       ,[Estado]         = @Estado
	   ,[Liquidacion]    = @Liquidacion
	   ,[IdVehiculo]     = @IdVehiculo
	   ,[IdCia]          = @Compania
	   ,[TipoConductor]  = @TipoConductor
 
	WHERE IdConductor   = @IdConductor
END

GO
/****** Object:  StoredProcedure [dbo].[spUpdateCotArticulos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 23/05/2023
-- Description:	update Cotizacion articulos
-- ================================================
CREATE PROCEDURE [dbo].[spUpdateCotArticulos] 
	-- Add the parameters for the stored procedure here
	@IdCot_Articulo int = null, 
	@IdCotizacion int = null, 
	@Cantidad varchar(10) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Cotizacion_Articulos]
		SET [Cantidad] = @Cantidad
		WHERE  IdCot_Articulo = @IdCot_Articulo and IdCotizacion = @IdCotizacion
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateCotBodegas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 25/03/2025
-- Description:	Actualizar Cotizacion bodegas
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateCotBodegas]
	@Opcion int, 
    @IdCotizacion int = null,
    @Estado varchar(20) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1 --Actualizar Estado Cotizacion-Bodegas
		BEGIN 
			--Actualizar Estado Cotizacion-Bodegas
			UPDATE [dbo].[Cotizacion_Bodegas] SET Estado = @Estado FROM [dbo].[Cotizacion_Bodegas] as CBG WHERE CBG.IdCotizacion = @IdCotizacion
		
			--Actualizar Estado Contrato-Bodegas
			--UPDATE [Bod].[Contratos_Bodegas] 
			--	SET Estado = CBG.Estado
			--	FROM [Bod].[Contratos_Bodegas] as CTB, (SELECT * FROM [dbo].[Cotizacion_Bodegas] WHERE IdCotizacion = @IdCotizacion) as CBG
			--	WHERE CTB.IdBodega = CBG.IdBodega

			--Actualizar Estado Bodegas
			UPDATE [dbo].[Bodegas] 
				SET Estado = CBG.Estado
				FROM [dbo].[Bodegas] as BDG, (SELECT * FROM [dbo].[Cotizacion_Bodegas] WHERE IdCotizacion = @IdCotizacion) as CBG
				WHERE BDG.IdBodega = CBG.IdBodega
		END
	
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateCotClientes]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 19/05/2022
-- Description:	Update Clientes en Cotizacion
-- ================================================
CREATE   PROCEDURE [dbo].[spUpdateCotClientes] 
	-- Add the parameters for the stored procedure here
	@IdCliente int,
	@IdCotizacion int
    
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Cotizacion] SET IdCliente = @IdCliente WHERE IdCotizacion = @IdCotizacion
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateCotDocumentos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 16/05/2024
-- Description: Update Cotizacion Documentos
-- ==================================================
CREATE PROCEDURE [dbo].[spUpdateCotDocumentos] 
	-- Add the parameters for the stored procedure here
	@IdCotDocumento Int = null,
	@IdCotizacion Int = null,
	@IdSolicitud int = null,
	@FechaDcto varchar(10) = null,
    @Documento varchar(MAX) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Cotizacion_Documentos]

		SET [IdCotizacion] = @IdCotizacion
			,[IdSolicitud] = @IdSolicitud
			,[FechaDcto]   = @FechaDcto
			,[Documento]   = @Documento
 
		WHERE IdCotDocumento = @IdCotDocumento
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateCotizaciones]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Sergio Rendón Gómez
-- ALTER date: 25/01/2021
-- Description:	Update Cotizaciones
-- ================================================
CREATE PROCEDURE [dbo].[spUpdateCotizaciones]
	-- Add the parameters for the stored procedure here
	@Opcion int,
	@IdCotizacion int = null,
	@IdCliente int = null,
    @IdUsuario int = null,
    @IdSolicitud int = null,
    @FechaCotizacion varchar(10) = null,
    @Servicios int = null,
    @Ciudad_Origen int = null,
    @Direccion_Origen varchar(125) = null,
    @Ciudad_Destino int = null,
    @Direccion_Destino varchar(125) = null,
    @Volumen varchar(50) = null,
    @Arte int = null,
    @Presencial varchar(1) = null,
    @FechaPresencial varchar(10) = null,
    @HoraPresencial varchar(8) = null,
    @Seguro int = null,
    @Valor_Declarado varchar(20) = null,
    @Porc_Liquidacion varchar(10) = null,
    @IdFormaPago int = null,
    @IdMetodoPago int = null,
    @Almacenamiento varchar(1) = null,
    @Fecha_Recogida varchar(10) = null,
    @Hora_Recogida varchar(8) = null,
    @Fecha_Entrega varchar(10) = null,
    @Hora_Entrega varchar(8) = null,
    @Autorizado varchar(125) = null,
    @Tipo_Ident_Autorizado int = null,
    @Ident_Autorizado nvarchar(20) = null,
    @Telefono_Autorizado varchar(10) = null,
    @Medio_Comunicacion int = null,
    @Medio_Servicio int = null,
    @IdEstadoCot int = null,
    @ValorCotizacion decimal(18, 2) = null,
    @Observacion varchar(255) = null,
	@TipoServ int = null,
	@MotivoPerdida int = null,
    @ObservaPerdida varchar(MAX) = null,
    @CuartoUtil int = null,
    @Exteriores int = null,
    @Tapizados int = null,
    @Sucursal int = null,
    @ObservaPago varchar(MAX) = null,
    @Fecha_Empaque varchar(10) = null,
    @Hora_Empaque varchar(8) = null,
    @Periodicidad int = null,
    @Ref_Personal varchar(125) = null,
    @Ref_Movil nchar(20) = null,
    @Ref_Direccion varchar(255) = null,
    @Ref_Correo varchar(125) = null,
	@IdBodega int = null,
	@BloqueoCot varchar(1) = null,
	@Poliza varchar(20) = null,
	@Barrio_Origen varchar(50) = null,
	@Barrio_Destino varchar(50) = null,
	@EmpaqueVenta int = null,
	@Serv_Inter int = null,
	@Flete_Inter varchar(50) = null,
	@Gastos_Inter int = null,
	@Vaduana_Inter varchar(50) = null,
	@Otros_Inter varchar(50) = null,
	@Aduana_Inter int = null,
	@Observa_Inter varchar(MAX) = null,
	@IdCia int = null,
	@ObservaEmpaque varchar(MAX) = null,
	@ObservaCliente varchar(MAX) = null,
	@IdEmpresa int = null,
	@RazonSocial varchar(125) = null,
	@NumOrden int = null,
	@ContactoEmpresa varchar(150) = null,
	@CorreoContacto varchar(250) = null,
	@FechaIniBod varchar(10) = null,
	@FechaFinBod varchar(10) = null,
	@ObservaBodega varchar(MAX) = null,
	@Cortesia varchar(1) = null,
	@FechaCortIni varchar(10) = null,
	@FechaCortFin varchar(10) = null,
	@FechaUltima varchar(10) = null,
	@Manifiesto int = null,
	@Remesa int = null,
	@Ctrl_Cotizacion int = null,
	@ContadorCorreo int = null,
	@CodVerifica int = null,
	@AutorizaCortesia int = null, 
	@TteSalida int = null, 
	@Ocupacion numeric(18,0) = null, 
	@VrSugerido numeric(18,0) = null, 
	@VrNegociado numeric(18,0) = null,
	@ObservaInterna varchar(MAX) = null,
	@ValorVehiculo varchar(20) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Consula todos los Tipo
		BEGIN
			UPDATE [dbo].[Cotizacion]
			   SET [IdCliente]             = @IdCliente
				  ,[IdUsuario]             = @IdUsuario 
				  ,[IdSolicitud]           = @IdSolicitud
				  ,[FechaCotizacion]       = @FechaCotizacion 
				  ,[Servicios]             = @Servicios
				  ,[Ciudad_Origen]         = @Ciudad_Origen
				  ,[Direccion_Origen]      = @Direccion_Origen
				  ,[Ciudad_Destino]        = @Ciudad_Destino
				  ,[Direccion_Destino]     = @Direccion_Destino
				  ,[Volumen]               = @Volumen
				  ,[Arte]                  = @Arte
				  ,[Presencial]            = @Presencial
				  ,[FechaPresencial]       = @FechaPresencial
				  ,[HoraPresencial]        = @HoraPresencial
				  ,[Seguro]                = @Seguro
				  ,[Valor_Declarado]       = @Valor_Declarado
				  ,[Porc_Liquidacion]      = @Porc_Liquidacion
				  ,[IdFormaPago]           = @IdFormaPago  
				  ,[IdMetodoPago]          = @IdMetodoPago 
				  ,[Almacenamiento]        = @Almacenamiento
				  ,[Fecha_Recogida]        = @Fecha_Recogida
				  ,[Hora_Recogida]         = @Hora_Recogida
				  ,[Fecha_Entrega]         = @Fecha_Entrega
				  ,[Hora_Entrega]          = @Hora_Entrega
				  ,[Autorizado]            = @Autorizado
				  ,[Tipo_Ident_Autorizado] = @Tipo_Ident_Autorizado
				  ,[Ident_Autorizado]      = @Ident_Autorizado
				  ,[Telefono_Autorizado]   = @Telefono_Autorizado
				  ,[Medio_Comunicacion]    = @Medio_Comunicacion
				  ,[Medio_Servicio]        = @Medio_Servicio
				  ,[IdEstadoCot]           = @IdEstadoCot
				  ,[ValorCotizacion]       = @ValorCotizacion
				  ,[Observacion]           = @Observacion
				  ,[TipoServ]			   = @TipoServ
				  ,[MotivoPerdida]         = @MotivoPerdida
				  ,[ObservaPerdida]        = @ObservaPerdida
				  ,[CuartoUtil]            = @CuartoUtil
				  ,[Exteriores]            = @Exteriores
				  ,[Tapizados]             = @Tapizados
				  ,[Sucursal]              = @Sucursal
				  ,[ObservaPago]           = @ObservaPago
				  ,[Fecha_Empaque]         = @Fecha_Empaque
				  ,[Hora_Empaque]          = @Hora_Empaque
				  ,[Periodicidad]          = @Periodicidad
				  ,[Ref_Personal]          = @Ref_Personal
				  ,[Ref_Movil]             = @Ref_Movil
				  ,[Ref_Direccion]         = @Ref_Direccion
				  ,[Ref_Correo]            = @Ref_Correo
				  ,[IdBodega]              = @IdBodega
				  ,[BloqueoCot]            = @BloqueoCot
				  ,[Poliza]                = @Poliza
				  ,[Barrio_Origen]         = @Barrio_Origen
				  ,[Barrio_Destino]        = @Barrio_Destino
				  ,[EmpaqueVenta]          = @EmpaqueVenta
				  ,[Serv_Inter]            = @Serv_Inter
				  ,[Flete_Inter]           = @Flete_Inter
				  ,[Gastos_Inter]          = @Gastos_Inter
				  ,[Vaduana_Inter]         = @Vaduana_Inter
				  ,[Otros_Inter]           = @Otros_Inter
				  ,[Aduana_Inter]          = @Aduana_Inter
				  ,[Observa_Inter]         = @Observa_Inter
				  ,[IdCia]                 = @IdCia
				  ,[ObservaEmpaque]        = @ObservaEmpaque
				  ,[ObservaCliente]        = @ObservaCliente
				  ,[IdEmpresa]             = @IdEmpresa
				  ,[RazonSocial]           = @RazonSocial
				  ,[NumOrden]              = @NumOrden
				  ,[ContactoEmpresa]       = @ContactoEmpresa
				  ,[CorreoContacto]        = @CorreoContacto
				  ,[FechaIniBod]           = @FechaIniBod
				  ,[FechaFinBod]           = @FechaFinBod
				  ,[ObservaBodega]         = @ObservaBodega
				  ,[Cortesia]              = @Cortesia
				  ,[FechaCortIni]          = @FechaCortIni
				  ,[FechaCortFin]          = @FechaCortFin
				  ,[FechaUltima]           = @FechaUltima
				  ,[Manifiesto]            = @Manifiesto
				  ,[Remesa]                = @Remesa
				  ,[AutorizaCortesia]      = @AutorizaCortesia
				  ,[TteSalida]             = @TteSalida
				  ,[Ocupacion]             = @Ocupacion
				  ,[VrSugerido]            = @VrSugerido
				  ,[VrNegociado]		   = @VrNegociado
				  ,[ObservaInterna]        = @ObservaInterna
				  ,[Valor_Vehiculo]        = @ValorVehiculo
		  
			WHERE IdCotizacion = @IdCotizacion

			-- Actualizar razon social y nit en clientes --
			UPDATE [dbo].[Clientes] SET RazonSocial     = @RazonSocial WHERE IdCliente = @IdCliente
			UPDATE [dbo].[Clientes] SET IdEmpresa       = @IdEmpresa WHERE IdCliente = @IdCliente
			UPDATE [dbo].[Empresas] SET ContactoEmpresa = @ContactoEmpresa, EmailContacto = @CorreoContacto WHERE IdEmpresa = @IdEmpresa
		END

	IF @Opcion = 2  -- Actualizar control de nuevos
		BEGIN
			UPDATE [dbo].[Cotizacion]
				
				SET Ctrl_Cotizacion = @Ctrl_Cotizacion
				
				WHERE IdUsuario = @IdUsuario
		END

	IF @Opcion = 3  -- Actualizar Fechas Recogida y Entrega
		BEGIN
			UPDATE [dbo].[Cotizacion]
			   SET [Fecha_Recogida] = @Fecha_Recogida
				  ,[Hora_Recogida]  = @Hora_Recogida
				  ,[Fecha_Entrega]  = @Fecha_Entrega
				  ,[Hora_Entrega]   = @Hora_Entrega
				
			   WHERE IdCotizacion = @IdCotizacion
		END

	IF @Opcion = 4  -- Actualizar Contador de Correo
		BEGIN
			UPDATE [dbo].[Cotizacion]      SET [ContadorCorreo] = @ContadorCorreo                  WHERE IdCotizacion = @IdCotizacion
			UPDATE [dbo].[Hist_Cotizacion] SET [CtrlEnvio] = 1, [ContadorCorreo] = @ContadorCorreo WHERE IdCotizacion = @IdCotizacion and CodVerificacion = @CodVerifica
		END
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateCotMaterialesArticulo]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 13/05/2025
-- Description:	update Cotizacion Mat - articulos
-- ================================================
CREATE   PROCEDURE [dbo].[spUpdateCotMaterialesArticulo] 
	-- Add the parameters for the stored procedure here
	@IdCot_MatArt int, 
	@IdCotizacion int, 
	@Cantidad decimal(18,2) 
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Cotizacion_MaterialesArticulo]
		SET [Cantidad] = @Cantidad
		WHERE  IdCot_MatArt = @IdCot_MatArt and IdCotizacion = @IdCotizacion
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateEmpresas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 05/07/2022
-- Description:	Update Clientes Corporativos
-- ================================================
CREATE   PROCEDURE [dbo].[spUpdateEmpresas] 
	-- Add the parameters for the stored procedure here
	@IdEmpresa int,
	@TipoIdent int = null,
    @TipoCliente int = null,
    @RazonSocial varchar(125) = null,
    @Nit varchar(20) = null,
    @IdCiudad int = null,
    @Movil varchar(20) = null,
    @Telefono varchar(20) = null,
    @Email varchar(250) = null,
    @Direccion varchar(250) = null,
	@ContactoEmpresa varchar(150) =  null,
	@EmailContacto varchar(250) =  null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Empresas]
	SET [TipoIdent]	       = @TipoIdent
		,[TipoCliente]     = @TipoCliente
		,[RazonSocial]     = @RazonSocial
		,[Nit]		       = @Nit
		,[IdCiudad]	       = @IdCiudad
		,[Movil]	       = @Movil
	    ,[Telefono]	       = @Telefono
	    ,[Email]   	       = @Email
		,[Direccion]       = @Direccion
		,[ContactoEmpresa] = @ContactoEmpresa
		,[EmailContacto]   = @EmailContacto

	 WHERE IdEmpresa = @IdEmpresa
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateEstadosCuenta]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Fabian Esteban Becerra Gonzalez
-- Create date: 19/12/2024
-- Description:	Actualizar los estados de cuenta del contrato ( Se ejecuta cada vez que se entra al modulo de cartera )
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateEstadosCuenta] 
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	BEGIN TRAN
	BEGIN TRY
		WHILE 1 = 1
		BEGIN 
			-- Obtenemos los registros de estados de cuenta pendientes.
			-- 
			-- Esta consulta esta hecha para obtener los registros que tienen
			-- el estado de cuenta incompleto.
			SELECT 
				BEC.*
			INTO 
				TmpEstadosCuenta
			FROM 
				Bodegas_Contratos AS BC
			INNER JOIN 
				Bodegas_EstadoCuentas AS BEC ON BEC.IdContrato = BC.IdContrato
			WHERE 
				BC.Novedades NOT IN (4, 5)
				AND BEC.IdCuenta = (
					SELECT TOP 1 IdCuenta 
					FROM Bodegas_EstadoCuentas
					WHERE IdContrato = BC.IdContrato
					ORDER BY Hasta DESC
				)
				AND Hasta < CAST(GETDATE() AS DATE)

			-- Si no hay registros terminamos la ejecucion.
			IF NOT EXISTS (SELECT 1 FROM TmpEstadosCuenta)
			BEGIN 
				DROP TABLE TmpEstadosCuenta;
				BREAK;
			END

			-- Insertamos el siguiente estado de cuenta pendiente a los obtenidos anteriormente.
			INSERT INTO Bodegas_EstadoCuentas (
				IdContrato, IdCartera
				,IdCliente, Desde
				,Hasta, ValorBodega
				,ValorSeguro, ValorIva 
				,ValorBaseCuenta, ValorIpcCuenta
				,ValorIvaCuenta, MesesMora
				,VrSancionCuenta, VrDeudaMes
				,VrAbonoDeuda, VrSaldoDeuda
				,VrDeudaAcumulada, CtrlPago
				,CtrlCuota, PorcentajeIpc
			)
			SELECT
				EC.IdContrato,
				EC.IdCartera,
				EC.IdCliente,
				CAST(DATEADD(DAY, 1, CAST(EC.Hasta AS DATE)) AS VARCHAR) AS Desde,
				CAST(DATEADD(DAY, 30, CAST(EC.Hasta AS DATE)) AS VARCHAR) AS Hasta,
				EC.ValorBodega,
				EC.ValorSeguro,
				EC.ValorIva,
				EC.ValorBaseCuenta,
				(
					CASE
						WHEN 
							YEAR(CAST((SELECT FechaContrato FROM Bodegas_Contratos WHERE IdContrato = EC.IdContrato) AS DATE)) < YEAR(CAST(EC.Hasta AS DATE))  
							THEN CAST(ValorBodega * ((SELECT ValorTotal FROM Bodegas_IPC WHERE Ano = YEAR(GETDATE()) AND EstadoIPC = 1) / 100) AS FLOAT )
						ELSE 0
					END
				) AS ValorIpcCuenta,
				EC.ValorIva AS ValorIvaCuenta,
				0 AS MesesMora,
				0 AS VrSancionCuenta,
				(
					EC.ValorBaseCuenta 
					+ (
						CASE
							WHEN 
								YEAR(CAST((SELECT FechaContrato FROM Bodegas_Contratos WHERE IdContrato = EC.IdContrato) AS DATE)) < YEAR(CAST(EC.Hasta AS DATE))  
								THEN CAST(ValorBodega * ((SELECT ValorTotal FROM Bodegas_IPC WHERE Ano = YEAR(GETDATE()) AND EstadoIPC = 1) / 100) AS FLOAT )
							ELSE 0
						END
					)
					+ EC.ValorIva
				) AS ValorDeudaMes,
				0 AS VrAbonoDeuda,
				0 AS VrSaldoDeuda,
				0 AS VrDeudaAcumulada,
				0 AS CtrlPago,
				(EC.CtrlCuota + 1) AS CtrlCuota,
				(SELECT ValorTotal FROM Bodegas_IPC WHERE Ano = YEAR(GETDATE()) AND EstadoIPC = 1) AS PorcentajeIpc
			FROM 
				TmpEstadosCuenta AS EC
		
			-- Eliminamos la tabla temporal.
			DROP TABLE TmpEstadosCuenta
		END

		-- Actualizamos los meses en mora y la sancion por mora.
		--
		-- Obtenemos los registros de estado de cuenta que no esten al dia. 
		SELECT 
			BEC.*
		INTO 
			TmpEstadosCuenta
		FROM 
			Bodegas_Contratos AS BC
		INNER JOIN 
			Bodegas_EstadoCuentas AS BEC ON BEC.IdContrato = BC.IdContrato
		WHERE 
			BC.Novedades NOT IN (4, 5)
			AND CtrlPago = 0
			AND Hasta < CAST(GETDATE() AS DATE)
		ORDER BY 
			BEC.IdContrato
	
		-- Actualizamos los meses en mora y sancion por mora.
		UPDATE 
			Bodegas_EstadoCuentas
		SET 
			MesesMora = DATEDIFF(MONTH, EC.Desde, GETDATE()),	
			VrSancionCuenta = CAST((
				CASE
					WHEN EC.VrSaldoDeuda = 0 THEN EC.ValorBaseCuenta 
					ELSE EC.VrSaldoDeuda
				END 
			) * 1.5 / 100 AS FLOAT) * DATEDIFF(MONTH, EC.Desde, GETDATE())

		FROM 
			Bodegas_EstadoCuentas AS BE
		INNER JOIN 
			TmpEstadosCuenta AS EC ON BE.IdCuenta = EC.IdCuenta
		WHERE 
			BE.IdCuenta = EC.IdCuenta;

		-- Actualizamos el valor de la deuda.
		UPDATE 
			Bodegas_EstadoCuentas
		SET 
			VrDeudaMes = (EC.ValorBaseCuenta + EC.ValorIpcCuenta + EC.ValorIvaCuenta + BE.VrSancionCuenta)
		FROM 
			Bodegas_EstadoCuentas AS BE
		INNER JOIN 
			TmpEstadosCuenta AS EC ON BE.IdCuenta = EC.IdCuenta
		WHERE 
			BE.IdCuenta = EC.IdCuenta;

		-- Eliminamos la tabla temporal.
		DROP TABLE TmpEstadosCuenta

		SELECT 1 AS success, '' AS [message]
		
		COMMIT TRAN
	END TRY 

	BEGIN CATCH
		
		ROLLBACK TRAN
		SELECT 0 AS success, ERROR_MESSAGE() AS [message]
		
	END CATCH

END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateHist_CotArticulos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 11/03/2024
-- Description:	update Historico Cotizacion articulos
-- ================================================
CREATE PROCEDURE [dbo].[spUpdateHist_CotArticulos] 
	-- Add the parameters for the stored procedure here
	@IdHist_CotArticulo int = null, 
	@IdCotizacion int = null, 
	@Cantidad varchar(10) = null,
	@CodVerificacion int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Hist_Cotizacion_Articulos]
		SET [Cantidad] = @Cantidad
		WHERE  IdHist_CotArticulo = @IdHist_CotArticulo and IdCotizacion = @IdCotizacion and CodVerificacion = @CodVerificacion
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateHist_CotBodegas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 11/03/2024
-- Description:	Actualizar Cotizacion bodegas
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateHist_CotBodegas]
	@Opcion int, 
    @IdCotizacion int = null,
    @Estado varchar(20) = null,
	@CodVerificacion int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1 --Actualizar Estado Cotizacion-Bodegas
		BEGIN 
			--Actualizar Estado Cotizacion-Bodegas
			UPDATE [dbo].[Hist_Cotizacion_Bodegas] 
				SET Estado = @Estado 
				FROM [dbo].[Hist_Cotizacion_Bodegas] as CBG WHERE CBG.IdCotizacion = @IdCotizacion and CBG.CodVerificacion = @CodVerificacion
			
		END
	
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateHist_Cotizaciones]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Sergio Rendón Gómez
-- ALTER date: 11/03/2024
-- Description:	Update Historico Cotizaciones
-- ================================================
CREATE PROCEDURE [dbo].[spUpdateHist_Cotizaciones]
	-- Add the parameters for the stored procedure here
	@Opcion int,
	@IdCotizacion int = null,
	@IdCliente int = null,
    @IdUsuario int = null,
    @IdSolicitud int = null,
    @FechaCotizacion varchar(10) = null,
    @Servicios int = null,
    @Ciudad_Origen int = null,
    @Direccion_Origen varchar(125) = null,
    @Ciudad_Destino int = null,
    @Direccion_Destino varchar(125) = null,
    @Volumen varchar(50) = null,
    @Arte int = null,
    @Presencial varchar(1) = null,
    @FechaPresencial varchar(10) = null,
    @HoraPresencial varchar(8) = null,
    @Seguro int = null,
    @Valor_Declarado varchar(20) = null,
    @Porc_Liquidacion varchar(10) = null,
    @IdFormaPago int = null,
    @IdMetodoPago int = null,
    @Almacenamiento varchar(1) = null,
    @Fecha_Recogida varchar(10) = null,
    @Hora_Recogida varchar(8) = null,
    @Fecha_Entrega varchar(10) = null,
    @Hora_Entrega varchar(8) = null,
    @Autorizado varchar(125) = null,
    @Tipo_Ident_Autorizado int = null,
    @Ident_Autorizado nvarchar(20) = null,
    @Telefono_Autorizado varchar(10) = null,
    @Medio_Comunicacion int = null,
    @Medio_Servicio int = null,
    @IdEstadoCot int = null,
    @ValorCotizacion decimal(18, 2) = null,
    @Observacion varchar(255) = null,
	@TipoServ int = null,
	@MotivoPerdida int = null,
    @ObservaPerdida varchar(MAX) = null,
    @CuartoUtil int = null,
    @Exteriores int = null,
    @Tapizados int = null,
    @Sucursal int = null,
    @ObservaPago varchar(MAX) = null,
    @Fecha_Empaque varchar(10) = null,
    @Hora_Empaque varchar(8) = null,
    @Periodicidad int = null,
    @Ref_Personal varchar(125) = null,
    @Ref_Movil nchar(20) = null,
    @Ref_Direccion varchar(255) = null,
    @Ref_Correo varchar(125) = null,
	@IdBodega int = null,
	@BloqueoCot varchar(1) = null,
	@Poliza varchar(20) = null,
	@Barrio_Origen varchar(50) = null,
	@Barrio_Destino varchar(50) = null,
	@EmpaqueVenta int = null,
	@Serv_Inter int = null,
	@Flete_Inter varchar(50) = null,
	@Gastos_Inter int = null,
	@Vaduana_Inter varchar(50) = null,
	@Otros_Inter varchar(50) = null,
	@Aduana_Inter int = null,
	@Observa_Inter varchar(MAX) = null,
	@IdCia int = null,
	@ObservaEmpaque varchar(MAX) = null,
	@ObservaCliente varchar(MAX) = null,
	@IdEmpresa int = null,
	@RazonSocial varchar(125) = null,
	@NumOrden int = null,
	@ContactoEmpresa varchar(150) = null,
	@CorreoContacto varchar(250) = null,
	@FechaIniBod varchar(10) = null,
	@FechaFinBod varchar(10) = null,
	@ObservaBodega varchar(MAX) = null,
	@Cortesia varchar(1) = null,
	@FechaCortIni varchar(10) = null,
	@FechaCortFin varchar(10) = null,
	@FechaUltima varchar(10) = null,
	@Manifiesto int = null,
	@Remesa int = null,
	@FechaProximo varchar(10) = null,
	@IdGestion int = null, 
	@Ctrl_Cotizacion int = null,
	@ContadorCorreo int = null,
	@CodVerificacion int = null,
	@AutorizaCortesia int = null, 
	@TteSalida int = null, 
	@Ocupacion numeric(18,0) = null, 
	@VrSugerido numeric(18,0) = null, 
	@VrNegociado numeric(18,0) = null,
	@ObservaInterna varchar(MAX) = null,
	@ValorVehiculo varchar(20) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Consula todos los Tipo
		BEGIN
			UPDATE [dbo].[Hist_Cotizacion]
			   SET [IdCotizacion]          = @IdCotizacion
				  ,[IdCliente]             = @IdCliente
				  ,[IdUsuario]             = @IdUsuario 
				  ,[IdSolicitud]           = @IdSolicitud
				  ,[FechaCotizacion]       = @FechaCotizacion 
				  ,[Servicios]             = @Servicios
				  ,[Ciudad_Origen]         = @Ciudad_Origen
				  ,[Direccion_Origen]      = @Direccion_Origen
				  ,[Ciudad_Destino]        = @Ciudad_Destino
				  ,[Direccion_Destino]     = @Direccion_Destino
				  ,[Volumen]               = @Volumen
				  ,[Arte]                  = @Arte
				  ,[Presencial]            = @Presencial
				  ,[FechaPresencial]       = @FechaPresencial
				  ,[HoraPresencial]        = @HoraPresencial
				  ,[Seguro]                = @Seguro
				  ,[Valor_Declarado]       = @Valor_Declarado
				  ,[Porc_Liquidacion]      = @Porc_Liquidacion
				  ,[IdFormaPago]           = @IdFormaPago  
				  ,[IdMetodoPago]          = @IdMetodoPago 
				  ,[Almacenamiento]        = @Almacenamiento
				  ,[Fecha_Recogida]        = @Fecha_Recogida
				  ,[Hora_Recogida]         = @Hora_Recogida
				  ,[Fecha_Entrega]         = @Fecha_Entrega
				  ,[Hora_Entrega]          = @Hora_Entrega
				  ,[Autorizado]            = @Autorizado
				  ,[Tipo_Ident_Autorizado] = @Tipo_Ident_Autorizado
				  ,[Ident_Autorizado]      = @Ident_Autorizado
				  ,[Telefono_Autorizado]   = @Telefono_Autorizado
				  ,[Medio_Comunicacion]    = @Medio_Comunicacion
				  ,[Medio_Servicio]        = @Medio_Servicio
				  ,[IdEstadoCot]           = @IdEstadoCot
				  ,[ValorCotizacion]       = @ValorCotizacion
				  ,[Observacion]           = @Observacion
				  ,[TipoServ]			   = @TipoServ
				  ,[MotivoPerdida]         = @MotivoPerdida
				  ,[ObservaPerdida]        = @ObservaPerdida
				  ,[CuartoUtil]            = @CuartoUtil
				  ,[Exteriores]            = @Exteriores
				  ,[Tapizados]             = @Tapizados
				  ,[Sucursal]              = @Sucursal
				  ,[ObservaPago]           = @ObservaPago
				  ,[Fecha_Empaque]         = @Fecha_Empaque
				  ,[Hora_Empaque]          = @Hora_Empaque
				  ,[Periodicidad]          = @Periodicidad
				  ,[Ref_Personal]          = @Ref_Personal
				  ,[Ref_Movil]             = @Ref_Movil
				  ,[Ref_Direccion]         = @Ref_Direccion
				  ,[Ref_Correo]            = @Ref_Correo
				  ,[IdBodega]              = @IdBodega
				  ,[BloqueoCot]            = @BloqueoCot
				  ,[Poliza]                = @Poliza
				  ,[Barrio_Origen]         = @Barrio_Origen
				  ,[Barrio_Destino]        = @Barrio_Destino
				  ,[EmpaqueVenta]          = @EmpaqueVenta
				  ,[Serv_Inter]            = @Serv_Inter
				  ,[Flete_Inter]           = @Flete_Inter
				  ,[Gastos_Inter]          = @Gastos_Inter
				  ,[Vaduana_Inter]         = @Vaduana_Inter
				  ,[Otros_Inter]           = @Otros_Inter
				  ,[Aduana_Inter]          = @Aduana_Inter
				  ,[Observa_Inter]         = @Observa_Inter
				  ,[IdCia]                 = @IdCia
				  ,[ObservaEmpaque]        = @ObservaEmpaque
				  ,[ObservaCliente]        = @ObservaCliente
				  ,[IdEmpresa]             = @IdEmpresa
				  ,[RazonSocial]           = @RazonSocial
				  ,[NumOrden]              = @NumOrden
				  ,[ContactoEmpresa]       = @ContactoEmpresa
				  ,[CorreoContacto]        = @CorreoContacto
				  ,[FechaIniBod]           = @FechaIniBod
				  ,[FechaFinBod]           = @FechaFinBod
				  ,[ObservaBodega]         = @ObservaBodega
				  ,[Cortesia]              = @Cortesia
				  ,[FechaCortIni]          = @FechaCortIni
				  ,[FechaCortFin]          = @FechaCortFin
				  ,[FechaUltima]           = @FechaUltima
				  ,[Manifiesto]            = @Manifiesto
				  ,[Remesa]                = @Remesa
				  ,[IdGestion]             = @IdGestion
				  ,[FechaProximo]          = @FechaProximo
				  ,[Ctrl_Cotizacion]       = @Ctrl_Cotizacion
				  ,[ContadorCorreo]        = @ContadorCorreo
				  ,[CodVerificacion]       = @CodVerificacion
				  ,[AutorizaCortesia]      = @AutorizaCortesia
				  ,[TteSalida]             = @TteSalida
				  ,[Ocupacion]             = @Ocupacion
				  ,[VrSugerido]            = @VrSugerido
				  ,[VrNegociado]		   = @VrNegociado
				  ,[ObservaInterna]        = @ObservaInterna
				  ,[Valor_Vehiculo]        = @ValorVehiculo
		  
			WHERE IdCotizacion    = @IdCotizacion and
				  CodVerificacion = @CodVerificacion 

			UPDATE [dbo].[Cotizacion] SET CodVerificacion = @CodVerificacion WHERE IdCotizacion = @IdCotizacion

		END

	IF @Opcion = 2  -- Actualizar control de nuevos
		BEGIN
			UPDATE [dbo].[Hist_Cotizacion]
				
				SET Ctrl_Cotizacion = @Ctrl_Cotizacion
				
				WHERE IdUsuario = @IdUsuario
		END

	IF @Opcion = 3  -- Actualizar Fechas Recogida y Entrega
		BEGIN
			UPDATE [dbo].[Hist_Cotizacion]
			   SET [Fecha_Recogida] = @Fecha_Recogida
				  ,[Hora_Recogida]  = @Hora_Recogida
				  ,[Fecha_Entrega]  = @Fecha_Entrega
				  ,[Hora_Entrega]   = @Hora_Entrega
				
			   WHERE IdCotizacion    = @IdCotizacion and
					 CodVerificacion = @CodVerificacion
		END

	IF @Opcion = 4  -- Actualizar Contador de Correo
		BEGIN
			UPDATE [dbo].[Hist_Cotizacion]
			   SET [ContadorCorreo] = @ContadorCorreo
				
			   WHERE IdCotizacion    = @IdCotizacion and
					 CodVerificacion = @CodVerificacion
		END
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateHist_CotMaterialesArticulo]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 11/03/2024
-- Description:	update Historico Cotizacion Mat - articulos
-- ================================================
CREATE PROCEDURE [dbo].[spUpdateHist_CotMaterialesArticulo] 
	-- Add the parameters for the stored procedure here
	@IdHist_CotMatArt int = null, 
	@IdCotizacion int = null, 
	@Cantidad decimal(18,2) = null,
	@CodVerificacion int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Hist_Cotizacion_MaterialesArticulo]
		SET [Cantidad] = @Cantidad
		WHERE  IdHist_CotMatArt = @IdHist_CotMatArt and IdCotizacion = @IdCotizacion and CodVerificacion = @CodVerificacion
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateLogBodegas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 2024-02-21
-- Description:Update Logistica Bodegas
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateLogBodegas]
	-- Add the parameters for the stored procedure here
	@Opcion int, 
	@IdLogBodega int = null,
	@IdCotizacion int = null,
    @IdOrden int = null,
    @IdEvento int = null,
    @IdCiudadOrigen int = null,
    @IdCiudadDestino int = null,
	@IdCompania int = null,
    @FechaRecogida varchar(10) = null,
    @HoraRecogida varchar(8) = null,
    @FechaEntrega varchar(10) = null,
    @HoraEntrega varchar(8) = null,
    @Volumen varchar(50) = null,
    @ValorTransporte numeric(18,0) = null,
    @Reexpedicion numeric(18,0) = null,
    @IdVehiculo int = null,
    @Dias int = null,
    @ServicioBga int = null,
    @FechaDespacho varchar(10) = null,
	@CiaEncargada int = null,
	@CtrlCumplido int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Actualizacion completa
		BEGIN
			UPDATE [dbo].[Logistica_Bodega]

				  SET [IdCotizacion]    = @IdCotizacion 
					 ,[IdOrden]         = @IdOrden 
					 ,[IdEvento]        = @IdEvento 
					 ,[IdCiudadOrigen]  = @IdCiudadOrigen 
					 ,[IdCiudadDestino] = @IdCiudadDestino 
					 ,[IdCompania]      = @IdCompania
					 ,[FechaRecogida]   = @FechaRecogida 
					 ,[HoraRecogida]    = @HoraRecogida 
					 ,[FechaEntrega]    = @FechaEntrega 
					 ,[HoraEntrega]     = @HoraEntrega 
					 ,[Volumen]         = @Volumen 
					 ,[ValorTransporte] = @ValorTransporte 
					 ,[Reexpedicion]    = @Reexpedicion 
					 ,[IdVehiculo]      = @IdVehiculo 
					 ,[Dias]            = @Dias 
					 ,[ServicioBga]     = @ServicioBga 
					 ,[FechaDespacho]   = @FechaDespacho
					 ,[CiaEncargada]    = @CiaEncargada
					 ,[CtrlCumplido]    = @CtrlCumplido

				 WHERE IdLogBodega = @IdLogBodega
		END

	IF @Opcion = 2  -- Actualizacion completa
		BEGIN
			UPDATE [dbo].[Logistica_Bodega]

				 SET [IdCotizacion]  = @IdCotizacion 
					,[IdEvento]      = @IdEvento 
					,[Dias]          = @Dias 
					,[FechaDespacho] = @FechaDespacho
					,[CtrlCumplido]  = @CtrlCumplido

				 WHERE IdLogBodega = @IdLogBodega
		END
END

GO
/****** Object:  StoredProcedure [dbo].[spUpdateLogPersonal]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 06/07/2024
-- Description:Update Logistica Bodegas
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateLogPersonal]
	-- Add the parameters for the stored procedure here
	@Opcion int, 
	@IdPersonalLog int = null,
	@IdCotizacion int = null,
    @IdPersonal int = null,
    @Identificacion varchar(20) = null,
    @IdEvento int = null,
    @FechaIni varchar(10) = null,
    @HoraIni varchar(8) = null,
    @HoraFin varchar(8) = null,
    @Rol int = null,
    @CtrlPersonal int = null,
    @ValorRolPer numeric(18,0) = null,
    @Autorizacion int = null,
    @Servicio int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Actualizacion completa
		BEGIN
			UPDATE [dbo].[Logistica_Personal]

				  SET  [IdCotizacion]   = @IdCotizacion
					  ,[IdPersonal]     = @IdPersonal
					  ,[Identificacion] = @Identificacion
					  ,[IdEvento]       = @IdEvento
					  ,[FechaIni]       = @FechaIni
					  ,[HoraIni]        = @HoraIni
					  ,[HoraFin]        = @HoraFin
					  ,[Rol]            = @Rol
					  ,[CtrlPersonal]   = @CtrlPersonal
					  ,[ValorRolPer]    = @ValorRolPer
					  ,[Autorizacion]   = @Autorizacion
					  ,[Servicio]       = @Servicio

				 WHERE IdPersonalLog = @IdPersonalLog
		END

	IF @Opcion = 2  -- Actualizacion completa
		BEGIN
			DECLARE
			@FechaActual varchar(10) = CONVERT (date, SYSDATETIME())

			UPDATE [dbo].[Logistica_Personal]

				 SET [IdCotizacion] = @IdCotizacion 
					,[IdEvento]     = @IdEvento 
					,[ValorRolPer]  = @ValorRolPer
					,[Autorizacion] = @Autorizacion

				 WHERE IdPersonalLog = @IdPersonalLog

			--Insertar codigo nuevo
			INSERT INTO [dbo].[LogPersonal_Autorizacion]
					([Codigo]
					,[NomAutorizar]
					,[FechaAutorizar]
					,[IdEvento]
					,[IdCotizacion])
			 VALUES
				   (@Autorizacion
				   ,'OPRR'
				   ,@FechaActual
				   ,@IdEvento
				   ,@IdCotizacion)
		END
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateLogSeguimientos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 21/12/2022
-- Description:	Update Logistica Seguimientos
-- ================================================
CREATE   PROCEDURE [dbo].[spUpdateLogSeguimientos]
	-- Add the parameters for the stored procedure here
	 @IdLogSeguimiento int
	,@IdCotizacion int = null
    ,@IdOrdenServicio int = null
    ,@IdEvento int = null
    ,@IdVehiculo int = null
    ,@IdCompania int = null
    ,@IdActividad int = null
    ,@IdCiudadDestino int = null
	,@FechaServicio varchar(25) = null
    ,@Reporte1 varchar(max) = null
    ,@Reporte2 varchar(max) = null
    ,@Reporte3 varchar(max) = null
    ,@Reporte4 varchar(max) = null
	,@FechaServ varchar(10) = null
	,@HoraServ varchar(8) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Logistica_Seguimientos]

	SET  [IdCotizacion]    = @IdCotizacion
        ,[IdOrdenServicio] = @IdOrdenServicio
        ,[IdEvento]        = @IdEvento
        ,[IdVehiculo]      = @IdVehiculo
        ,[IdCompania]      = @IdCompania
        ,[IdActividad]     = @IdActividad
        ,[IdCiudadDestino] = @IdCiudadDestino
        ,[FechaServicio]   = @FechaServicio
        ,[Reporte1]        = @Reporte1
        ,[Reporte2]        = @Reporte2
        ,[Reporte3]        = @Reporte3
        ,[Reporte4]        = @Reporte4

	WHERE IdLogSeguimiento =  @IdLogSeguimiento
	
END

GO
/****** Object:  StoredProcedure [dbo].[spUpdateLogTrafico]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 12/04/2022
-- Description:	Update Control Trafico
-- ================================================
CREATE PROCEDURE [dbo].[spUpdateLogTrafico] 
	-- Add the parameters for the stored procedure here
	@Opcion int,
	@IdTrafico int,
	@IdVehiculo int = null,
	@IdCiudad int = null,
	@Fecha varchar(50) = null,
	@Manifiesto int = null,
	@IdCia int = null,
	@IdRuta int = null,
	@ValorFlete numeric(18,0) = null,
	@Flete_Conductor numeric(18,0) = null,
	@Flete_Socio numeric(18,0) = null,
	@Descuento_Socio numeric(18,0) = null,
	@Estado_Trafico int = null,
	@Flete_Locales numeric(18,0) = null,
	@Dcto_Oficina numeric(18,0) = null,
	@Descargue numeric(18,0) = null,
	@Papeleria numeric(18,0) = null,
	@Reexpedir numeric(18,0) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Actualizacion completa
		BEGIN
			UPDATE [dbo].[Logistica_Trafico]

				SET [IdVehiculo]      = @IdVehiculo
					,[IdCiudad]        = @IdCiudad
					,[Fecha]           = @Fecha
					,[Manifiesto]      = @Manifiesto
					,[IdCia]           = @IdCia
					,[IdRuta]          = @IdRuta
					,[ValorFlete]      = @ValorFlete
					,[Flete_Conductor] = @Flete_Conductor
					,[Flete_Socio]     = @Flete_Socio
					,[Descuento_Socio] = @Descuento_Socio
					,[Estado_Trafico]  = @Estado_Trafico
					,[Flete_Locales]   = @Flete_Locales
					,[Dcto_Oficina]    = @Dcto_Oficina
					,[Descargue]       = @Descargue
					,[Papeleria]       = @Papeleria
					,[Reexpedir]       = @Reexpedir

				WHERE IdTrafico = @IdTrafico
		END

	IF @Opcion = 2  -- Actualizacion Ruta
		BEGIN
			UPDATE [dbo].[Logistica_Trafico] SET [IdRuta] = @IdRuta WHERE IdTrafico = @IdTrafico
		END

	IF @Opcion = 3  -- Actualizacion Manifiesto
		BEGIN
			UPDATE [dbo].[Logistica_Trafico] SET [Manifiesto] = @Manifiesto WHERE IdTrafico = @IdTrafico
			UPDATE [dbo].[Logistica_TraficoDetalles] SET [Manifiesto] = @Manifiesto WHERE IdTrafico = @IdTrafico
		END

	
	IF @Opcion = 4  -- Actualizacion Estado
		BEGIN
			UPDATE [dbo].[Logistica_Trafico] SET Estado_Trafico = @Estado_Trafico  WHERE IdTrafico = @IdTrafico
		END
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateLogTraficoDetalles]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 05/04/2022
-- Description:	Update Logistica Trafico Detalles
-- ================================================
CREATE PROCEDURE [dbo].[spUpdateLogTraficoDetalles]
	-- Add the parameters for the stored procedure here
	 @Opcion int
	,@IdDetalle_Trafico int
	,@IdTrafico nchar(10) = null
    ,@IdCotizacion int = null
    ,@IdCliente int = null
	,@IdRuta_Detalle int = null
	,@KmRuta_Detalle numeric(18,2) = null
    ,@Manifiesto int = null
    ,@Direccion_Destino varchar(125) = null
    ,@Movil varchar(20) = null
    ,@Remesa varchar(50) = null
    ,@IdOrden int = null
    ,@ValorFactura numeric(18,0) = null
    ,@Abono numeric(18,0) = null
    ,@Saldo numeric(18,0) = null
    ,@Seguro numeric(18,0) = null
    ,@Bodega numeric(18,0) = null
    ,@Iva numeric(18,0) = null
    ,@Empaque numeric(18,0) = null
    ,@Montacargas numeric(18,0) = null
    ,@Otros numeric(18,0) = null
    ,@Servicio_Planta int = null
    ,@Recogida_Entrega numeric(18,0) = null
    ,@Recogida_Supern numeric(18,0) = null
    ,@Oficina numeric(18,0) = null
    ,@Reexpedicion numeric(18,0) = null
    ,@Veh_Reexpedicion int = null
    ,@Cargue_Descargue numeric(18,0) = null
    ,@Papeleria_Socio numeric(18,0) = null
    ,@OficinaPrincipal numeric(18,0) = null
    ,@Subtotal_Conductor numeric(18,0) = null
    ,@Subtotal_Socio numeric(18,0) = null
	,@IdEvento int = null
	,@CtrlManifiesto int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Actualizacion completa
		BEGIN
			UPDATE [dbo].[Logistica_TraficoDetalles]
 
				SET  [IdTrafico]          = @IdTrafico
					,[IdCotizacion]       = @IdCotizacion
					,[IdCliente]          = @IdCliente
					,[IdRuta_Detalle]     = @IdRuta_Detalle
					,[KmRuta_Detalle]     = @KmRuta_Detalle
					,[Manifiesto]         = @Manifiesto
					,[Direccion_Destino]  = @Direccion_Destino
					,[Movil]              = @Movil
					,[Remesa]             = @Remesa
					,[IdOrden]            = @IdOrden
					,[ValorFactura]       = @ValorFactura
					,[Abono]              = @Abono
					,[Saldo]              = @Saldo
					,[Seguro]             = @Seguro
					,[Bodega]             = @Bodega
					,[Iva]                = @Iva
					,[Empaque]            = @Empaque
					,[Montacargas]        = @Montacargas
					,[Otros]              = @Otros
					,[Servicio_Planta]    = @Servicio_Planta
					,[Recogida_Entrega]   = @Recogida_Entrega
					,[Recogida_Supern]    = @Recogida_Supern
					,[Oficina]            = @Oficina
					,[Reexpedicion]       = @Reexpedicion
					,[Veh_Reexpedicion]   = @Veh_Reexpedicion
					,[Cargue_Descargue]   = @Cargue_Descargue
					,[Papeleria_Socio]    = @Papeleria_Socio
					,[OficinaPrincipal]   = @OficinaPrincipal
					,[Subtotal_Conductor] = @Subtotal_Conductor
					,[Subtotal_Socio]     = @Subtotal_Socio
					,[IdEvento]           = @IdEvento
					,[CtrlManifiesto]     = @CtrlManifiesto
 
				WHERE IdDetalle_Trafico = @IdDetalle_Trafico
		END

	IF @Opcion = 2  -- Actualizacion remesa
		BEGIN
			UPDATE [dbo].[Logistica_TraficoDetalles] SET [Remesa] = @Remesa WHERE IdDetalle_Trafico = @IdDetalle_Trafico
			UPDATE [dbo].[Cotizacion] SET [Remesa] = @Remesa, [Manifiesto] = @Manifiesto    WHERE IdCotizacion = @IdCotizacion
			UPDATE [dbo].[Agenda] SET [NumRemesa] = @Remesa, [NumManifiesto] = @Manifiesto WHERE IdEvento = @IdEvento
		END
	
	
	IF @Opcion = 3  -- Actualizacion Manifiesto
		BEGIN
			UPDATE [dbo].[Cotizacion] SET [Manifiesto] = @Manifiesto WHERE IdCotizacion = @IdCotizacion
			UPDATE [dbo].[Agenda] SET [NumManifiesto] = @Manifiesto WHERE IdEvento = @IdEvento
		END

	IF @Opcion = 4  -- Actualizacion Estado
		BEGIN
			UPDATE [dbo].[Logistica_Trafico] SET Estado_Trafico = 3  WHERE IdTrafico = @IdTrafico
		END

	IF @Opcion = 5  -- Actualizar Control Manifiesto
		BEGIN
			UPDATE [dbo].[Logistica_TraficoDetalles] SET [CtrlManifiesto] = @CtrlManifiesto WHERE IdDetalle_Trafico = @IdDetalle_Trafico
		END

END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateMateriales]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 06/09/2021
-- Description:	Actualizar Materiales
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateMateriales] 
	-- Add the parameters for the stored procedure here
	@IdMaterial Int,
	@Nombre varchar(125),
    @Referencia varchar(10),
    @IdUnidad int,
    @ValorCosto varchar(20),
    @Proveedor int,
    @EstadoMat varchar(1),
    @CodSyscom varchar(50),
    @SubGrupo varchar(8),
	@Linea varchar(5),
	@Descripcion varchar(125)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Materiales]
    
	SET [Nombre]     = @Nombre
       ,[Referencia] = @Referencia
       ,[IdUnidad]   = @IdUnidad
       ,[ValorCosto] = @ValorCosto
       ,[Proveedor]  = @Proveedor
       ,[EstadoMat]  = @EstadoMat
       ,[CodSyscom]  = @CodSyscom
       ,[SubGrupo]   = @SubGrupo
       ,[Linea]      = @Linea
	   ,[Descripcion]= @Descripcion

	WHERE IdMaterial = @IdMaterial
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateMaterialesArticulos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 06/09/2021
-- Description:	Actualizar Materiales-Articulos
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateMaterialesArticulos]
	-- Add the parameters for the stored procedure here
	@IdMatArticulo int = null,
	@IdMaterial Int = null,
	@IdArticulo Int = null,
	@Valor varchar(20) = null,
    @Cantidad decimal(18,2) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Materiales_Articulo]

		SET [IdMaterial] = @IdMaterial
		   ,[IdArticulo] = @IdArticulo
		   ,[Valor]      = @Valor
		   ,[Cantidad]   = @Cantidad

		WHERE IdMatArticulo = @IdMatArticulo
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateNovedades]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 18-07-2023
-- Description:	Procedimiento para actualizar las novedades
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateNovedades] 
	-- Add the parameters for the stored procedure here
   @IdNovedad int,
   @Descripcion varchar(255),
   @Estado varchar(1)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	   	
	UPDATE [dbo].[Novedades]
		SET [Descripcion] = @Descripcion
			,[Estado] = @Estado
		WHERE IdNovedad=@IdNovedad

END

GO
/****** Object:  StoredProcedure [dbo].[spUpdateOrdenServicio]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 14/03/2022
-- Description:	Actualizar Orden Servicio
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateOrdenServicio]
	-- Add the parameters for the stored procedure here
	@Opcion int,
	@IdOrden int = null,
	@NumOrden int = null,
    @FechaOrden varchar(10) = null,
    @HoraOrden varchar(8) = null,
    @EstadoOrden int = null,
    @IdCotizacion int = null,
	@Compania int = null,
	@IdUsuario int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Actualizacion completa
		BEGIN
			UPDATE [dbo].[OrdenServicio]

				SET [NumOrden]        = @NumOrden
					,[FechaOrden]     = @FechaOrden
					,[HoraOrden]      = @HoraOrden
					,[EstadoOrden]    = @EstadoOrden
					,[IdCotizacion]   = @IdCotizacion
					,[Compania]       = @Compania
					,[NumInventario]  = 0
					,[IdUsuario]      = @IdUsuario
					,[NumRequisicion] = 0
 
				WHERE IdOrden = @IdOrden

			-- Actualizar Cotizacion 
			UPDATE [dbo].[Cotizacion] 
				SET NumOrden    = @NumOrden,
					BloqueoCot  = 'S', 
					IdEstadoCot = '5'
				WHERE IdCotizacion = @IdCotizacion
		END

	IF @Opcion = 2  -- Actualizar Estado
		BEGIN
			UPDATE [dbo].[OrdenServicio] SET [EstadoOrden]   = @EstadoOrden WHERE IdOrden = @IdOrden
		END

END



GO
/****** Object:  StoredProcedure [dbo].[spUpdateParametros]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 02/05/2023
-- Description:	Actualizar Parametros Basicos
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateParametros]
	-- Add the parameters for the stored procedure here
	@IdParametro int = null,
	@Nombre_Paramt varchar(125) = null,
	@Valor_Paramt numeric(18,2) = null,
    @Codigo_Paramt varchar(30) = null,
	@Descripcion varchar(250) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Parametros]
		
		SET [Nombre_Paramt] = @Nombre_Paramt,
			[Valor_Paramt]  = @Valor_Paramt,
			[Codigo_Paramt] = @Codigo_Paramt,
			[Descripcion]   = @Descripcion
		
		WHERE IdParametro = @IdParametro 
END

GO
/****** Object:  StoredProcedure [dbo].[spUpdatePerfiles]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 02/08/2021
-- Description:	Actualizacion de perfiles
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdatePerfiles] 
	-- Add the parameters for the stored procedure here
	@IdPerfil int,
	@Nombre varchar(120) = null,
	@Estado varchar(1) = null, 
	@Descripcion varchar(255) = null,
	@Clase varchar(1) = null
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	UPDATE [dbo].[Perfiles]
	  
	SET 
	    Nombre      = @Nombre	
	   ,Estado      = @Estado
	   ,Descripcion = @Descripcion
	   ,Clase       = @Clase
	   
	WHERE IdPerfil = @IdPerfil

END
GO
/****** Object:  StoredProcedure [dbo].[spUpdatePermisos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 02/08/2021
-- Description:	Actualizar Permisos
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdatePermisos] 
	-- Add the parameters for the stored procedure here
	@IdPermiso Int,
	@IdPerfil Int,
	@IdModulo Int,
	@Registrar nchar(1),
	@Actualizar nchar(1),
	@Listar nchar(1),
	@Eliminar nchar(1)

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	
	 
		UPDATE [dbo].[Permisos]
		SET [IdPerfil]  = @IdPerfil
		   ,[IdModulo]  = @IdModulo
		   ,[Registrar] = @Registrar
		   ,[Actualizar]= @Actualizar
		   ,[Listar]    = @Listar
		   ,[Eliminar]  = @Eliminar
		WHERE IdPermiso = @IdPermiso
	 
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdatePersonal]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 06/04/2022
-- Description:	Actualizar Personal
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdatePersonal]
	-- Add the parameters for the stored procedure here
	@IdPersonal int = null,
	@TipoIdent int = null,
    @Identificacion varchar(20) = null,
    @Nombres varchar(125) = null,
    @Apellidos varchar(125) = null,
    @IdCiudad int = null,
    @Direccion varchar(250) = null,
    @Telefono varchar(20) = null,
	@Movil varchar(20) = null,
    @Email varchar(250) = null,
    @Estado varchar(1) = null,
	@Compania int = null,
	@Cargo varchar(50) = null,
	@IdCargo varchar(5) = null,
	@TipoContrato int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Personal]
	
	SET [TipoIdent]     = @TipoIdent
      ,[Identificacion] = @Identificacion
      ,[Nombres]        = @Nombres
      ,[Apellidos]      = @Apellidos
      ,[IdCiudad]       = @IdCiudad
      ,[Direccion]      = @Direccion
      ,[Telefono]       = @Telefono
	  ,[Movil]          = @Movil
      ,[Email]          = @Email
      ,[Estado]         = @Estado
      ,[IdCia]          = @Compania
	  ,[Cargo]          = @Cargo
	  ,[IdCargo]        = @IdCargo
	  ,[TipoContrato]   = @TipoContrato
 
	WHERE IdPersonal   = @IdPersonal
END

GO
/****** Object:  StoredProcedure [dbo].[spUpdatePropietarios]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 04/04/2022
-- Description:	Actualizar Propietarios
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdatePropietarios] 
	-- Add the parameters for the stored procedure here
	@IdPropietario int = null,
	@TipoIdent int = null,
    @Identificacion varchar(20) = null,
    @Nombres varchar(125) = null,
    @Apellidos varchar(125) = null,
    @IdCiudad int = null,
    @Direccion varchar(250) = null,
    @Telefono varchar(20) = null,
	@Movil varchar(20) = null,
    @Email varchar(250) = null,
    @Estado varchar(1) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Propietarios]
	
	SET [TipoIdent]     = @TipoIdent
      ,[Identificacion] = @Identificacion
      ,[Nombres]        = @Nombres
      ,[Apellidos]      = @Apellidos
      ,[IdCiudad]       = @IdCiudad
      ,[Direccion]      = @Direccion
      ,[Telefono]       = @Telefono
	  ,[Movil]          = @Movil
      ,[Email]          = @Email
      ,[Estado]         = @Estado
 
	WHERE IdPropietario   = @IdPropietario
END

GO
/****** Object:  StoredProcedure [dbo].[spUpdateProveedores]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 04/04/2022
-- Description:	Actualizar Proveedores
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateProveedores] 
	-- Add the parameters for the stored procedure here
	@IdProveedor int = null,
	@TipoIdent int = null,
    @Identificacion varchar(20) = null,
    @Nombres varchar(125) = null,
    @Apellidos varchar(125) = null,
    @IdCiudad int = null,
    @Direccion varchar(250) = null,
    @Telefono varchar(20) = null,
	@Movil varchar(20) = null,
    @Email varchar(250) = null,
    @Estado varchar(1) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Proveedores]
	
		SET [TipoIdent]       = @TipoIdent
			,[Identificacion] = @Identificacion
			,[Nombres]        = @Nombres
			,[Apellidos]      = @Apellidos
			,[IdCiudad]       = @IdCiudad
			,[Direccion]      = @Direccion
			,[Telefono]       = @Telefono
			,[Movil]          = @Movil
			,[Email]          = @Email
			,[Estado]         = @Estado
 
		WHERE IdProveedor   = @IdProveedor
END

GO
/****** Object:  StoredProcedure [dbo].[spUpdateRadicados]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Fabian Esteban Becerra Gonzalez
-- Create date: 04/02/2025
-- Description:	Actualiza los consecutivos y años de los radicados de las compañias.
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateRadicados] 

AS
BEGIN
	
	IF NOT EXISTS (
		SELECT 1 
		FROM Serv_Radicado 
		WHERE AnoRad = RIGHT(YEAR(GETDATE()), 2)
	)
	UPDATE 
		Serv_Radicado
	SET 
		Contador = 0,
		AnoRad = RIGHT(YEAR(GETDATE()), 2)

END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateRangos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 02/05/2023
-- Description:	Actualizar Rangos
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateRangos]
	-- Add the parameters for the stored procedure here
	@IdRango int = null,
	@LimiteInf int = null,
	@LimiteSup int = null,
    @VrRecogida numeric(18,0) = null,
    @VrSupern numeric(18,0) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Rangos]

		SET [Limite_Inf]   = @LimiteInf
			,[Limite_Sup]  = @LimiteSup
			,[Vr_Recogida] = @VrRecogida
			,[Vr_Supern]   = @VrSupern
			,[Descripcion] = 0

		WHERE IdRango = @IdRango
END


GO
/****** Object:  StoredProcedure [dbo].[spUpdateRutas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 13/04/2023
-- Description:	Update Rutas
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateRutas]
	-- Add the parameters for the stored procedure here
	@Opcion int,
	@IdRutas int,
	@Nombre_Ruta varchar(125) = null,
    @IdCiudadOrigen int = null,
    @IdCiudadDestino int = null,
    @Km_Ruta numeric(18,2) = null,
	@IdLocOri varchar(8) = null,
	@IdLocDes varchar(8) = null,
	@CodSyscom varchar(4) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Consula todos los Tipo
		BEGIN
			UPDATE [dbo].[Rutas]
				SET  [Nombre_Ruta]	   = @Nombre_Ruta
					,[IdCiudadOrigen]  = @IdCiudadOrigen
					,[IdCiudadDestino] = @IdCiudadDestino
					,[Km_Ruta]	       = @Km_Ruta
					,[IdLocOri]        = @IdLocOri
					,[IdLocDes]	       = @IdLocDes
					,[CodSyscom]       = @CodSyscom

				WHERE IdRutas = @IdRutas
		END

	IF @Opcion = 2  -- Consula todos los Tipo
		BEGIN
			UPDATE [dbo].[Rutas]
				SET  [Nombre_Ruta]	   = @Nombre_Ruta
					,[IdCiudadOrigen]  = @IdCiudadOrigen
					,[IdCiudadDestino] = @IdCiudadDestino
					,[Km_Ruta]	       = @Km_Ruta
					,[IdLocOri]        = @IdLocOri
					,[IdLocDes]	       = @IdLocDes
					,[CodSyscom]       = @CodSyscom

				WHERE IdRutas = @IdRutas

			--Insertar registro en Rutas Contador
			INSERT INTO [dbo].[Ruta_Contador] ([IdRutas], [Caracter]) VALUES  (@IdRutas, 'C')
		END
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateServ_Radicado]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 27/05/2024
-- Description:	Update Serv_Radicados
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateServ_Radicado]
	-- Add the parameters for the stored procedure here
	@IdRadicado int,
	@IdCia int = null,
	@Compania varchar(3) = null,
	@Contador numeric(3,0) = null,
	@AnoRad numeric(2,0) = null,
	@EstadoRad varchar(1) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Serv_Radicado]

		SET [IdCia]     = @IdCia 
		   ,[Compania]  = @Compania
		   ,[Contador]  = @Contador
		   ,[AnoRad]    = @AnoRad
	 	   ,[EstadoRad] = @EstadoRad
		
		WHERE IdRadicado = @IdRadicado
END



GO
/****** Object:  StoredProcedure [dbo].[spUpdateServicioCliente]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 2024/05/22
-- Description:	Insertar Servicio Cliente
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateServicioCliente]
	-- Add the parameters for the stored procedure here
	@IdServicioCliente int = null,
	@FechaServicio varchar(10) = null,
	@HoraServicio varchar(8) = null,
    @EstadoServicio varchar(1) = null,
    @Movil varchar(20) = null,
    @Telefono varchar(20) = null,
    @TipoIdentidad int = null,
    @Identificacion varchar(20) = null,
	@Nombres varchar(125) = null,
	@Apellidos varchar(125) = null,
	@Email varchar(125) = null,
	@IdCliente int = null,
    @IdCotizacion int = null,
    @IdOrden int = null,
	@Compania int = null,
    @Motivo int = null,
    @ObservaServicio varchar(max) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	UPDATE [dbo].[ServicioCliente]
	   SET [FechaServicio]   = @FechaServicio 
		  ,[HoraServicio]    = @HoraServicio
		  ,[EstadoServicio]  = @EstadoServicio
		  ,[Movil]           = @Movil
		  ,[Telefono]        = @Telefono
		  ,[TipoIdentidad]   = @TipoIdentidad 
		  ,[Identificacion]  = @Identificacion 
		  ,[Nombres]         = @Nombres
		  ,[Apellidos]       = @Apellidos
		  ,[Email]           = @Email
		  ,[IdCliente]       = @IdCliente 
		  ,[IdCotizacion]    = @IdCotizacion 
		  ,[IdOrden]         = @IdOrden 
		  ,[Compania]        = @Compania
		  ,[Motivo]          = @Motivo 
		  ,[ObservaServicio] = @ObservaServicio

	 WHERE IdServicioCliente = @IdServicioCliente
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateServicioPqrs]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 27/05/2024
-- Description:	Actualizar Servicio Pqrs
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateServicioPqrs]
	-- Add the parameters for the stored procedure here
	@Opcion int,
	@IdServicioPqrs int,
	@FechaRadicado varchar(10) = null,
	@HoraRadicado varchar(8) = null,
	@Radicado int = null,
    @CiaRadicado int = null,
	@AnoRadicado numeric(2,0) = null,
    @Recepcion int = null,
    @Clase int = null,
    @FechaReclamo varchar(10) = null,
    @HoraReclamo varchar(10) = null,
    @EstadoPqrs int = null,
    @FechaCierre varchar(10) = null,
    @Tiempo int = null,
    @Descripcion varchar(max) = null,
    @ClasePqrs int = null,
    @CausasOrigen int = null,
    @Responsable int = null,
	@IdSolicitud int = null,
    @IdCotizacion int = null,
    @IdOrden int = null,
    @IdCliente int = null,
	@CtrlCorreo int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Actualizacion completa
		BEGIN
			UPDATE [dbo].[ServicioPqrs]
			   SET [FechaRadicado] = @FechaRadicado
				  ,[HoraRadicado]  = @HoraRadicado
				  ,[Radicado]      = @Radicado
				  ,[CiaRadicado]   = @CiaRadicado
				  ,[AnoRadicado]   = @AnoRadicado
				  ,[Recepcion]     = @Recepcion
				  ,[Clase]         = @Clase
				  ,[FechaReclamo]  = @FechaReclamo
				  ,[HoraReclamo]   = @HoraReclamo
				  ,[EstadoPqrs]    = @EstadoPqrs
				  ,[FechaCierre]   = @FechaCierre
				  ,[Tiempo]        = @Tiempo
				  ,[Descripcion]   = @Descripcion
				  ,[ClasePqrs]     = @ClasePqrs
				  ,[CausasOrigen]  = @CausasOrigen
				  ,[Responsable]   = @Responsable
				  ,[IdSolicitud]   = @IdSolicitud
				  ,[IdCotizacion]  = @IdCotizacion
				  ,[IdOrden]       = @IdOrden
				  ,[IdCliente]     = @IdCliente
				  ,[CtrlCorreo]    = @CtrlCorreo

			 WHERE IdServicioPqrs = @IdServicioPqrs
		END

	IF @Opcion = 2  -- Actualizar Estado
		BEGIN
			UPDATE [dbo].[ServicioPqrs] SET CtrlCorreo = @CtrlCorreo WHERE IdServicioPqrs = @IdServicioPqrs
		END
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateServicioPqrsDetalle]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 27/05/2024
-- Description:	Actualziar Servicio Pqrs Detalle
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateServicioPqrsDetalle]
	-- Add the parameters for the stored procedure here
	@IdServicioDetalle int,
	@IdServicioPqrs int = null,
    @IdSolicitud int = null,
    @IdCotizacion int = null,
    @IdArticulo int = null,
    @NombreArt varchar(125) = null,
    @ValorArt numeric(18,0) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[ServicioPqrsDetalle]

	   SET [IdServicioPqrs] = @IdServicioPqrs
		  ,[IdSolicitud]    = @IdSolicitud
		  ,[IdCotizacion]   = @IdCotizacion
		  ,[IdArticulo]     = @IdArticulo
		  ,[NombreArt]      = @NombreArt
		  ,[ValorArt]       = @ValorArt

		WHERE IdServicioDetalle = @IdServicioDetalle
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateServicios]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 02/09/2021
-- Description:	Actualizar Servicio
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateServicios]
	-- Add the parameters for the stored procedure here
	@IdServicio Int,
	@Nombre varchar(125),
    @Descripcion varchar(255),
    @IdTipo int,
    @CodSyscom varchar(5)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Servicios]
    SET [Nombre]       = @Nombre
        ,[Descripcion] = @Descripcion
        ,[IdTipo]      = @IdTipo
        ,[CodSyscom]   = @CodSyscom
	WHERE IdServicio   = @IdServicio
END

GO
/****** Object:  StoredProcedure [dbo].[spUpdateSolicitudes]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez.
-- ALTER date: 2023/08/29
-- Description:	Actualizar solicitudes
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateSolicitudes] 
	-- Add the parameters for the stored procedure here
	@Opcion int,
	@IdSolicitud int = null,         
	@FechaServicio varchar(10) = null,
	@Telefono varchar(20) = null,
	@Email varchar(120) = null,
	@IdCiudadOrigen int = null,
	@IdCiudadDestino int = null,
	@Observaciones varchar(max) = null,
	@Estado int = null,
	@IdServicio int = null,
	@Identificacion nvarchar(20) = null,
	@Ctrl_Solicitud int = null,
	@IdAsesor int = null
	 
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @Opcion = 1  -- Consula todos los Tipo
		BEGIN
			declare @Existingdate as varchar(10)
			set @Existingdate=CONVERT(varchar,GETDATE(),23)

			declare @Existingtime as varchar(8)
			Set @Existingtime=CONVERT(varchar,GETDATE(),108)

			UPDATE [dbo].[Solicitudes]
			   SET [Fecha]           = @Existingdate,
				   [Hora]            = @Existingtime,
				   [FechaServicio]   = @FechaServicio,
				   [Telefono]        = @Telefono,
				   [Email]           = @Email,
				   [IdCiudadOrigen]  = @IdCiudadOrigen,
				   [IdCiudadDestino] = @IdCiudadDestino, 
				   [Observaciones]   = @Observaciones,
				   [Estado]          = @Estado, 
				   [IdServicio]      = @IdServicio,
				   [Identificacion]  = @Identificacion

			 WHERE IdSolicitud=@IdSolicitud
		END
	
	IF @Opcion = 2  -- Consula todos los Tipo
		BEGIN
			UPDATE [dbo].[Solicitudes] 
				
				SET Ctrl_Solicitud = @Ctrl_Solicitud 
				
				WHERE IdAsesor = @IdAsesor
		END
 

END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateSoportePago]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 02/06/2022
-- Description:	Actualizar Soporte Pago
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateSoportePago]
	-- Add the parameters for the stored procedure here
	@IdSoportePago int,
	@IdCotizacion int = null,
	@IdSolicitud int = null,
	@NumOrden int = null,
	@Soporte1 varchar(MAX) = null,
	@Soporte2 varchar(MAX) = null,
	@Soporte3 varchar(MAX) = null,
	@Soporte4 varchar(MAX) = null,
	@FecSoporte1 varchar(10) = null,
	@HorSoporte1 varchar(8) = null,
	@FecSoporte2 varchar(10) = null,
	@HorSoporte2 varchar(8) = null,
	@FecSoporte3 varchar(10) = null,
	@HorSoporte3 varchar(8) = null,
	@FecSoporte4 varchar(10) = null,
	@HorSoporte4 varchar(8) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[SoportePago]

		SET IdCotizacion = @IdCotizacion
			,IdSolicitud = @IdSolicitud
			,NumOrden    = @NumOrden
			,Soporte1    = @Soporte1
			,Soporte2    = @Soporte2
			,Soporte3    = @Soporte3
			,Soporte4    = @Soporte4
			,FecSoporte1 = @FecSoporte1
			,HorSoporte1 = @HorSoporte1
			,FecSoporte2 = @FecSoporte2
			,HorSoporte2 = @HorSoporte2
			,FecSoporte3 = @FecSoporte3
			,HorSoporte3 = @HorSoporte3
			,FecSoporte4 = @FecSoporte4
			,HorSoporte4 = @HorSoporte4
	
	WHERE IdSoportePago = @IdSoportePago
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateSucursales]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 20/09/2021
-- Description:	Update Sucursales
-- ================================================
CREATE   PROCEDURE [dbo].[spUpdateSucursales]
	-- Add the parameters for the stored procedure here
	@IdSucursal int,
	@Nombre nvarchar(125),
	@Direccion nvarchar(125),
	@Telefono nvarchar(125),
	@Movil nvarchar(20),
	@IdResponsable int,
	@IdCiudad int

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
		UPDATE [dbo].[Sucursales]
		SET  [Nombre]		 = @Nombre
			,[Direccion]	 = @Direccion
			,[Telefono]		 = @Telefono
			,[Movil]		 = @Movil
			,[IdResponsable] = @IdResponsable
			,[IdCiudad]		 = @IdCiudad
		WHERE IdSucursal = @IdSucursal

END

GO
/****** Object:  StoredProcedure [dbo].[spUpdateTarifaRutas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 25/05/2023
-- Description:	Actualizar Rutas Tarifa
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateTarifaRutas]
	-- Add the parameters for the stored procedure here
	@IdTarifa int = null,
	@Origen_Ruta int = null,
    @Destino_Ruta int = null,
    @Descripcion varchar(250) = null,
	@Ubicacion int = null,
    @KmReal numeric(18,0) = null,
    @KmAjustado numeric(18,0) = null,
    @Tolerancia numeric(18,0) = null,
    @KmTotales numeric(18,0) = null,
    @Completo numeric(18,0) = null,
    @UnMedio numeric(18,0) = null,
    @UnTercio numeric(18,0) = null,
    @UnCuarto numeric(18,0) = null,
    @UnSeptimo numeric(18,0) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Tarifa_Rutas]
		SET [Origen_Ruta]   = @Origen_Ruta
			,[Destino_Ruta] = @Destino_Ruta
			,[Descripcion]  = @Descripcion
			,[Ubicacion]    = @Ubicacion
			,[KmReal]       = @KmReal
			,[KmAjustado]   = @KmAjustado
			,[Tolerancia]   = @Tolerancia
			,[KmTotales]    = @KmTotales
			,[Completo]     = @Completo
			,[UnMedio]      = @UnMedio
			,[UnTercio]     = @UnTercio
			,[UnCuarto]     = @UnCuarto
			,[UnSeptimo]    = @UnSeptimo
 
		WHERE IdTarifa = @IdTarifa
END

GO
/****** Object:  StoredProcedure [dbo].[spUpdateTarifasBodegas]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 11/03/2023
-- Description:	Actualziar Tarifas Bodegas
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateTarifasBodegas]
	-- Add the parameters for the stored procedure here
	@IdTarifaBodega int,
	@Area numeric(18,0) = null,
    @ValorMetro numeric(18,2) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Tarifas_Bodegas]
		SET  [Area]       = @Area
			,[ValorMetro] = @ValorMetro
 
		WHERE IdTarifaBodega = @IdTarifaBodega
END


GO
/****** Object:  StoredProcedure [dbo].[spUpdateTemporales]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 12/04/2022
-- Description:	Actualizar Archivos Temporales
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateTemporales] 
	-- Add the parameters for the stored procedure here
	@IdCotizacion int,
	@IdSolicitud int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Cotizacion_Articulos]          SET IdCotizacion = @IdCotizacion Where IdCotizacion = '0' and IdSolicitud = @IdSolicitud
	UPDATE [dbo].[Cotizacion_MaterialesArticulo] SET IdCotizacion = @IdCotizacion Where IdCotizacion = '0' and IdSolicitud = @IdSolicitud
	UPDATE [dbo].[Cotizacion_Conceptos]          SET IdCotizacion = @IdCotizacion Where IdCotizacion = '0' and IdSolicitud = @IdSolicitud
	UPDATE [dbo].[Cotizacion_Empaques]           SET IdCotizacion = @IdCotizacion Where IdCotizacion = '0' and IdSolicitud = @IdSolicitud
	UPDATE [dbo].[Cotizacion_Requisicion]        SET IdCotizacion = @IdCotizacion Where IdCotizacion = '0' and IdSolicitud = @IdSolicitud
	UPDATE [dbo].[Cotizacion_Bodegas]            SET IdCotizacion = @IdCotizacion Where IdCotizacion = '0' and IdSolicitud = @IdSolicitud
	UPDATE [dbo].[Seguimientos]                  SET IdCotizacion = @IdCotizacion Where IdCotizacion = '0' and IdSolicitud = @IdSolicitud
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateTextos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:	     Sergio Rendón Gómez
-- Create date:  26/01/2022
-- Description:	 Actualizar Textos
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateTextos] 
	-- Add the parameters for the stored procedure here
		@IdTexto int,
		@IdClaseDoc int,
		@Text1 varchar(MAX),
		@Text2 varchar(MAX),
		@Text3 varchar(MAX),
		@Text4 varchar(MAX)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Textos]
	  
	SET 
	   [IdClaseDoc] = @IdClaseDoc	
	   ,[Text1]     = @Text1
	   ,[Text2]     = @Text2
	   ,[Text3]     = @Text3
	   ,[Text4]     = @Text4
	   
	WHERE IdTexto   = @IdTexto
END
GO
/****** Object:  StoredProcedure [dbo].[spUpdateTipo]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 01/09/2021
-- Description:	Actualizar Tipo Servicio
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateTipo]
	-- Add the parameters for the stored procedure here
	@IdTipo Int=null,
	@Nombre varchar(125),
	@CodSyscom varchar(4)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	
	UPDATE [dbo].[TipoServicio]
	SET	[Nombre]      = @Nombre
	   ,[CodSyscom]   = @CodSyscom
	WHERE IdTipo = @IdTipo
END

GO
/****** Object:  StoredProcedure [dbo].[spUpdateUsuarios]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 09/08/2021
-- Description:	Procedimiento almacenado para la actualizacion de datos de usuarios
-- =============================================
CREATE   PROCEDURE [dbo].[spUpdateUsuarios] 
	-- Add the parameters for the stored procedure here
	@IdUsuario int,
	@Nombres varchar(120) = null,
	@Apellidos varchar(120) = null,
    @TipoIdent int = null,
    @Identificacion varchar(20) = null,
    @Email varchar(120) = null,
    @Movil varchar(20)=null,
	@IdArea int = null,
    @Estado varchar(1) = null,
    @Login varchar(20) = null,
    @Clave varchar(20) = null,
	@IdPerfil int = null,
	@NombrePerfil varchar(125) = null,
	@Contrasena varchar(20) = null,
	@Compania int = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [dbo].[Usuarios]
		SET [Nombres]        = @Nombres,
		    [Apellidos]      = @Apellidos,
		    [TipoIdent]      = @TipoIdent,
		    [Identificacion] = @Identificacion,
		    [Email]          = @Email,
		    [Movil]          = @Movil,
		    [IdArea]         = @IdArea,
		    [Estado]         = @Estado,
		    [Login]          = @Login,
		    [Clave]          = @Clave,
			[Contrasena]     = @Contrasena,
			[IdCia]          = @Compania

		WHERE IdUsuario =  @IdUsuario;

		 --Borrar el rol del usuario
		 DELETE from Roles where IdUsuario = @IdUsuario;

		-- Registrando en la tabla de Roles
		INSERT INTO [dbo].[Roles]
			([IdPerfil]
			,[IdUsuario]
			,[Nombre]
			,[FechaIni]
			,[FechaFin])
		VALUES
			(@IdPerfil,
			 @IdUsuario, 
			 @NombrePerfil, 
			 '9999/99/99', 
			 '9999/99/99');
END

GO
/****** Object:  StoredProcedure [dbo].[spUpdateVehiculos]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Sergio Rendón Gómez
-- Create date: 29/09/2021
-- Description:	Update Vehiculos
-- =============================================
CREATE PROCEDURE [dbo].[spUpdateVehiculos]
	-- Add the parameters for the stored procedure here
	@IdVehiculo int = null,
    @Placa varchar(10) = null,
    @TipoVehiculo int = null,
    @Modelo int = null,
	@Asignacion int = null,
	@IdCia int = null,
	@Afiliacion int = null,
    @IdPropietario int = null,
    @IdConductor int = null,
	@Largo numeric(18,2) = null,
	@Ancho numeric(18,2) = null,
	@Alto numeric(18,2) = null,
	@Volumen numeric(18,2) = null,
    @Capacidad numeric(18,2) = null,
    @PesoVacio numeric(18,2) = null,
	@PesoMaximo numeric(18,2) = null,
	@Combustible int = null,
	@Odometro int = null,
	@Estado varchar(1) = null,
    @Disponible int = null,
	@GrupoPro varchar(50) = null,
	@IdGrupoPro int = null,
    @Marca int = null,
	@Km_Gl numeric(18,2) = null,
	@Reserva numeric(18,2) = null,
	@Tpp numeric(18,2) = null,
	@Taux1 numeric(18,2) = null,
	@Taux2 numeric(18,2) = null,
	@Lleno numeric(18,2) = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE	
		[dbo].[Vehiculos]
	SET  
		[Placa]		      = @Placa,
		[TipoVehiculo]    = @TipoVehiculo,
		[Modelo]		  = @Modelo, 
		[Asignacion]      = @Asignacion,
		[IdCia]           = @IdCia,
		[Afiliacion]	  = @Afiliacion,
		[IdPropietario]   = @IdPropietario, 
		[IdConductor]	  = @IdConductor,
		[Largo]           = @Largo,
		[Ancho]           = @Ancho,
		[Alto]            = @Alto,
		[Volumen]         = @Volumen,
		[PesoVacio]       = @PesoVacio,
		[PesoMaximo]      = @PesoMaximo,
		[Capacidad]       = @Capacidad,
		[CtrlCombustible] = @Combustible,
		[Odometro]        = @Odometro,
		[Estado]		  = @Estado,
		[Disponible]	  = @Disponible, 
		[GrupoPro]        = @GrupoPro,
		[IdGrupoPro]      = @IdGrupoPro,
		[Marca]		      = @Marca,
		[Km_Gl]           = @Km_Gl,
		[Reserva]         = @Reserva,
		[Tpp]             = @Tpp,
		[Taux1]           = @Taux1, 
		[Taux2]           = @Taux2,
		[Lleno]           = @Lleno
	WHERE 
		IdVehiculo = @IdVehiculo
END

GO
/****** Object:  StoredProcedure [dbo].[spUpsertTipoDanio]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Fabian Esteban Becerra G.
-- Create date: 25/11/2024
-- Description:	Crear y modificar un tipo de daño.
-- =============================================

CREATE PROCEDURE [dbo].[spUpsertTipoDanio]
	@IdTipoDanioPqrs INT = NULL,
	@Nombre VARCHAR(30),
	@Descripcion VARCHAR(100),
	@Inactivo BIT
AS
BEGIN
	SET NOCOUNT ON;

	BEGIN TRAN
	BEGIN TRY
		
		IF @IdTipoDanioPqrs IS NULL
		BEGIN 
			INSERT INTO Serv_TipoDanioPqrs
				(Nombre, Descripcion)
			VALUES 
				(@Nombre, @Descripcion)

			SET @IdTipoDanioPqrs = SCOPE_IDENTITY()
		END
		ELSE 
		BEGIN
			UPDATE 
				Serv_TipoDanioPqrs
			SET 
				Nombre = @Nombre,
				Descripcion = @Descripcion,
				Inactivo = @Inactivo
			WHERE 
				IdTipoDanioPqrs = @IdTipoDanioPqrs
		END

		SELECT
			1 AS success,
			CONCAT('Operacion exitosa: Tipo de daño ', @Nombre, ' ', ' registrado correctamente.') AS [message]

		COMMIT TRAN
	END TRY

	BEGIN CATCH
		ROLLBACK TRANSACTION

		DECLARE 
			@ErrorMessage NVARCHAR(4000) = ERROR_MESSAGE()
        
		SELECT
			0 AS success,
			@ErrorMessage AS [message]

	END CATCH
END
GO
/****** Object:  StoredProcedure [dbo].[updateBodegasAnularCerrarContrato]    Script Date: 04/02/2025 11:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Fabian Esteban Becerra G.
-- Create date: 17/12/2024
-- Description:	Actualiza las bodegas cuando se anula o cierrra el contrato.
-- =============================================
CREATE PROCEDURE [dbo].[updateBodegasAnularCerrarContrato] 
	@IdContrato INT
AS
BEGIN
	
	IF EXISTS 
	(
		SELECT 1 
		FROM Bodegas_Contratos 
		WHERE IdContrato = @IdContrato
			AND Novedades IN (4, 5)
	)
	BEGIN
		UPDATE 
			B
		SET 
			B.Disponible     = (B.Disponible + BCB.Ocupacion),
			B.CapacidadFinal = (B.Disponible + BCB.Ocupacion),
			B.Ocupacion      = (B.Ocupacion - BCB.Ocupacion),
			B.Estado = 1
		FROM 
			Bodegas_ContratoBodegas AS BCB
		LEFT JOIN 
			Bodegas AS B ON B.IdBodega = BCB.IdBodega
		WHERE 
			BCB.IdContrato = @IdContrato
	END

END
GO
