Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
3| Name | Data Type | Length | Description |
|---|---|---|---|
| @p_doc_id | int | 4 | |
| @p_texto_rechazo | varchar | 500 | |
| @p_user_id | int | 4 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: LUIS J. PRENAFETA
-- Create date: 06 AGOSTO 2018
-- Description: RECHAZA LA CARGA DE UN BALANCE LED SUBIDO POR UN PROVEEDOR, DEJANDO
-- EL DOCUMENTO EN ESTADO 'R'. AL REGISTRO DE BALANCES_CONTABLES ASOCIADO
-- LO PASA AL ESTADO 'ELIMINADO'.
-- =============================================
CREATE OR ALTER PROCEDURE dbo.LN_balances_rechazar
-- Add the parameters for the stored procedure here
@p_doc_id int,
@p_texto_rechazo varchar(500),
@p_user_id 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
if (@p_doc_id is not null) begin
declare @id_balance int = null
declare @ident varchar(50)
declare @fecha date = null
declare @periodo int = null
DECLARE @usuario varchar(50)
select @usuario = first_name + ' ' + last_name
from users where user_id = @p_user_id
select @ident = padrones.identificacion,
@id_balance = balances_contables.id_balance,
@fecha = balances_contables.fecha_balance,
@periodo = balances_contables.periodo
FROM LN_docs
inner join LN_tipos_doc on LN_docs.tipo_doc = LN_tipos_doc.tipo_doc
inner join LN_contrapartes on LN_docs.contraparte = LN_contrapartes.contraparte
inner join padrones on LN_contrapartes.id_padron = padrones.id_padron
inner join identificadores on padrones.identificador = identificadores.identificador
inner join country on identificadores.country_code = country.country_code
inner join clientes on LN_docs.cliente = clientes.cliente
inner join balances_contables on LN_docs.id_externo = balances_contables.id_balance
where LN_docs.doc_id = @p_doc_id
/* Marcamos como eliminado el balance contable asociado al documento */
if (@id_balance > 0) begin
UPDATE balances_contables SET estado = 'ELIMINADO'
WHERE id_balance = @id_balance
end
/* El documento LED queda rechazado */
declare @inicio date = null
if (@fecha is not null and @periodo > 0)
set @inicio = dateadd(day, 1, dateadd(month, (-1) * @periodo, @fecha))
UPDATE LN_docs set estado_doc = 'R',
/*inicio_ejercicio = @inicio,
fin_ejercicio = @fecha,*/
modified = GETDATE(), modified_by = @p_user_id,
rechazado = GETDATE(),
rechazado_por = @p_user_id,
texto_rechazo = @p_texto_rechazo,
doc_log = CONVERT(VARCHAR(MAX),doc_log) + CHAR(13)+CHAR(10) +
CONVERT(VARCHAR(10), GETDATE(),103) + ' ' + CONVERT(VARCHAR(5), GETDATE(), 14) + ' - Documento de balance rechazado por ' + @usuario
WHERE doc_id = @p_doc_id
end
END
GO
GO
-- =============================================
-- Author: LUIS J. PRENAFETA
-- Create date: 06 AGOSTO 2018
-- Description: RECHAZA LA CARGA DE UN BALANCE LED SUBIDO POR UN PROVEEDOR, DEJANDO
-- EL DOCUMENTO EN ESTADO 'R'. AL REGISTRO DE BALANCES_CONTABLES ASOCIADO
-- LO PASA AL ESTADO 'ELIMINADO'.
-- =============================================
CREATE OR ALTER PROCEDURE dbo.LN_balances_rechazar
-- Add the parameters for the stored procedure here
@p_doc_id int,
@p_texto_rechazo varchar(500),
@p_user_id 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
if (@p_doc_id is not null) begin
declare @id_balance int = null
declare @ident varchar(50)
declare @fecha date = null
declare @periodo int = null
DECLARE @usuario varchar(50)
select @usuario = first_name + ' ' + last_name
from users where user_id = @p_user_id
select @ident = padrones.identificacion,
@id_balance = balances_contables.id_balance,
@fecha = balances_contables.fecha_balance,
@periodo = balances_contables.periodo
FROM LN_docs
inner join LN_tipos_doc on LN_docs.tipo_doc = LN_tipos_doc.tipo_doc
inner join LN_contrapartes on LN_docs.contraparte = LN_contrapartes.contraparte
inner join padrones on LN_contrapartes.id_padron = padrones.id_padron
inner join identificadores on padrones.identificador = identificadores.identificador
inner join country on identificadores.country_code = country.country_code
inner join clientes on LN_docs.cliente = clientes.cliente
inner join balances_contables on LN_docs.id_externo = balances_contables.id_balance
where LN_docs.doc_id = @p_doc_id
/* Marcamos como eliminado el balance contable asociado al documento */
if (@id_balance > 0) begin
UPDATE balances_contables SET estado = 'ELIMINADO'
WHERE id_balance = @id_balance
end
/* El documento LED queda rechazado */
declare @inicio date = null
if (@fecha is not null and @periodo > 0)
set @inicio = dateadd(day, 1, dateadd(month, (-1) * @periodo, @fecha))
UPDATE LN_docs set estado_doc = 'R',
/*inicio_ejercicio = @inicio,
fin_ejercicio = @fecha,*/
modified = GETDATE(), modified_by = @p_user_id,
rechazado = GETDATE(),
rechazado_por = @p_user_id,
texto_rechazo = @p_texto_rechazo,
doc_log = CONVERT(VARCHAR(MAX),doc_log) + CHAR(13)+CHAR(10) +
CONVERT(VARCHAR(10), GETDATE(),103) + ' ' + CONVERT(VARCHAR(5), GETDATE(), 14) + ' - Documento de balance rechazado por ' + @usuario
WHERE doc_id = @p_doc_id
end
END
GO
Depends On
9Used By
No items found