DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspCuenta]
GO
DROP PROCEDURE [dbo].[paWcfSeLisTm_TraEspTempCargarDetCons]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspCuenta]    Script Date: 23/08/2024 10:53:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Cesar Fernando Carre?o 
-- Create date: 04/01/2024
-- Description:	Metodo para tarifa cuenta
-- =============================================
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspCuenta]	
	@Operacion varchar(10),
	@IdTarifa varchar(5),
	@TipDoc varchar(5),
	@IdCuenta varchar(20),
	@ClaseTarif Varchar(5),
	@CdCueOtr varchar(20),		
	@AntIdTarifa varchar(5),
	@AntTipDoc varchar(5),
	@AntIdCuenta varchar(20),
	@AntClaseTarif Varchar(5),
	@AntCdCueOtr varchar(20)
AS
begin
    SET @IdTarifa = CASE WHEN @IdTarifa = null THEN '' ELSE @IdTarifa END;
    SET @TipDoc = CASE WHEN @TipDoc = null THEN '' ELSE @TipDoc END;
    SET @IdCuenta = CASE WHEN @IdCuenta = null THEN '' ELSE @IdCuenta END;
    SET @ClaseTarif = CASE WHEN @ClaseTarif = null THEN '' ELSE @ClaseTarif END;
    SET @CdCueOtr = CASE WHEN @CdCueOtr = null THEN '' ELSE @CdCueOtr END;
    
    SET @AntIdTarifa = CASE WHEN @AntIdTarifa = null THEN '' ELSE @AntIdTarifa END;
    SET @AntTipDoc = CASE WHEN @AntTipDoc = null THEN '' ELSE @AntTipDoc END;
    SET @AntIdCuenta = CASE WHEN @AntIdCuenta = null THEN '' ELSE @AntIdCuenta END;
    SET @AntClaseTarif = CASE WHEN @AntClaseTarif = null THEN '' ELSE @AntClaseTarif END;
    SET @AntCdCueOtr = CASE WHEN @AntCdCueOtr = null THEN '' ELSE @AntCdCueOtr END;

	IF(@Operacion = 'GUARDAR')
	BEGIN		
		--select 'gua' 'gua'
		INSERT INTO [dbo].[TarifCuentas] (
			[IdTarifa],
			[TipDoc],
			[IdCuenta],
			[ClaseTarif],
			[CdCueOtr]
		)
        VALUES (
			@IdTarifa,
            @TipDoc,
            @IdCuenta,
            @ClaseTarif,
            @CdCueOtr
		)        				
	END

	IF(@Operacion = 'EDITAR')
	BEGIN		
		UPDATE 
			[dbo].[TarifCuentas]
		SET 
			[IdTarifa] = @IdTarifa,
			[TipDoc] = @TipDoc,
			[IdCuenta] = @IdCuenta,
			[ClaseTarif] = @ClaseTarif,
			[CdCueOtr] = @CdCueOtr
		WHERE 
			IdTarifa = @AntIdTarifa 
			AND TipDoc = @AntTipDoc 
			AND IdCuenta = @AntIdCuenta 
			AND ClaseTarif = @AntClaseTarif 
			AND ISNULL(CdCueOtr, '') = ISNULL(@AntCdCueOtr, '');
	END

	IF(@Operacion = 'ELIMINAR')
	BEGIN
		--select 'elei' 'elil'
		DELETE FROM 
			[dbo].[TarifCuentas]
		WHERE 
			IdTarifa = @AntIdTarifa 
			AND TipDoc = @AntTipDoc 
			AND IdCuenta = @AntIdCuenta 
			AND ClaseTarif = @AntClaseTarif 
			AND CdCueOtr = @AntCdCueOtr
	END
	
end

BEGIN
	--tabla para mostrar los datos de clases de tarifa 
	select IdDoc, TipoDoc 
	from Sys_TiposDoc 
	where IdDoc in ('FC1', 'OPE', 'DF1', 'DF2', 'DFC', 'DFO', 'DOE', 'FCR', 'FCE', 'DFE') AND Inactivo = 0;

	--Mostrar las clases de tarifa
	select IdClase, NomClase 
	from ClaseTar 
	where IdClase in ('ICA', 'BOM', 'IAT', 'RET', 'RTC') AND Inactivo = 0;

	--Mostrar Codigos De Tarifa
	select IdTarifa, Tarifa, Simbolo, Descripcion 
	from TablaPor 
	where IdClase in ('ICA', 'BOM', 'IAT', 'RET', 'RTC') AND Inactivo = 0;

	--Mostrar Tabla Cuentas
	select IdCuenta, NomCuenta 
	from PUC 
	where Movimiento = 1 and Inactivo = 0;

	--Datos ya guardados
	select * 
	from TarifCuentas 
	where ClaseTarif in ('ICA', 'BOM', 'IAT', 'RET', 'RTC') AND TipDoc in ('FC1', 'OPE', 'DF1', 'DF2', 'DFC', 'DFO', 'DOE', 'FCR', 'FCE', 'DFE')
END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTm_TraEspTempCargarDetCons]    Script Date: 24/08/2024 10:07:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Cesar Fernando Carre?o 
-- Create date: 04/01/2024
-- Description:	Metodo para cargar tabla temporal 
-- =============================================
CREATE PROCEDURE [dbo].[paWcfSeLisTm_TraEspTempCargarDetCons]	
	@Usuario varchar(20)
AS
	set @Usuario = (
		select 'CCD' + IdEstacion as Estacion 
		from adm_Usuarios 
		where IdUsuario = @Usuario
	)
BEGIN
	select 
		[TipDoc],
		[Causacion],
		[IdCia],
		[Item],
		[IdConcepto],
		[Descripcion],
		[TipoConc],
		[VrDebito],
		[VrCredito],
		[CdCuenta],
		[NitTercero],
		[RazonSocial],
		[CdCCosto],
		[CCosto],
		[CdSubCos],
		[SubCosto],
		[pVehiculo],
		[NumVeh],
		[ClaseMat],
		[TipoAfiVehic],
		[VrBase],
		[TarifBase],
		[Referencia],
		[TipDocRef],
		[DocRef],
		[TipFac],
		[Factura],
		[IdCiaFac],
		[ItemFac],
		[FecVence],
		[EstadoReg],
		[TipoLiq],
		[NumLiquida],
		[CiaLiquida],
		[VrAbonado] 
	from 
		tm_TraEsDetConc 
	where 
		TmNumero = @Usuario
	 
	DELETE FROM [dbo].[tm_TraEsDetConc]
	WHERE TmNumero = @Usuario

END