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_id_balance | int | 4 | |
| @p_user_id | int | 4 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: LUIS J PRENAFETA
-- Create date: 03 AGOSTO 2018
-- Description: ASIGNA UN BALANCE CONTABLE EXISTENTE A UN DOC_ID DE LED, DEJANDO COMO
-- ELIMINADO EL BALANCE CONTABLE QUE SE ENCONTRABA EN ESTADO CARGA LED
-- Y ASIGNADO AL DOCUMENTO.
-- FINALMENTE PASA COMO VERIFICADO EL REGISTRO DE DOCUMENTO LED
-- =============================================
CREATE OR ALTER PROCEDURE dbo.LN_balances_reemplazar
-- Add the parameters for the stored procedure here
@p_doc_id int,
@p_id_balance int,
@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
DECLARE @usuario varchar(50)
select @usuario = first_name + ' ' + last_name
from users where user_id = @p_user_id
DECLARE @balance_previo int = null
select @balance_previo = id_externo
from LN_docs
where doc_id = @p_doc_id
and isnull(id_externo,0) <> @p_id_balance
if (@balance_previo is not null) begin
/* Si el balance que se esta tomando para reemplazo no tiene PDF, le asocia el PDF del cargado por el proveedor */
declare @url_subido varchar(100) = (select ruta_archivo from balances_contables where id_balance = @balance_previo)
declare @url_publicado varchar(100) = (select ruta_archivo from balances_contables where id_balance = @p_id_balance)
if (isnull(@url_publicado,'') = '')
BEGIN
update balances_contables set ruta_archivo = @url_subido where id_balance = @p_id_balance
END
update balances_contables set estado = 'ELIMINADO' ,
modified = GETDATE(), modified_by = @p_user_id
where id_balance = @balance_previo
declare @inicio date = null
declare @fin date = null
declare @periodo int = null
select @fin = fecha_balance, @periodo = periodo
from balances_contables
where id_balance = @p_id_balance
if (@fin is not null and @periodo > 0)
set @inicio = dateadd(day, 1, dateadd(month, (-1) * @periodo, @fin))
UPDATE LN_docs set estado_doc = 'V',
id_externo = @p_id_balance,
inicio_ejercicio = @inicio,
fin_ejercicio = @fin,
modified = GETDATE(), modified_by = @p_user_id,
verificado_backend = GETDATE(),
verificado_backend_por = @p_user_id,
doc_log = CONVERT(VARCHAR(MAX),doc_log) + CHAR(13)+CHAR(10) +
CONVERT(VARCHAR(10), GETDATE(),103) + ' ' + CONVERT(VARCHAR(5), GETDATE(), 14) + ' - Documento de balance verificado por ' + @usuario
WHERE doc_id = @p_doc_id
end
END
GO
GO
-- =============================================
-- Author: LUIS J PRENAFETA
-- Create date: 03 AGOSTO 2018
-- Description: ASIGNA UN BALANCE CONTABLE EXISTENTE A UN DOC_ID DE LED, DEJANDO COMO
-- ELIMINADO EL BALANCE CONTABLE QUE SE ENCONTRABA EN ESTADO CARGA LED
-- Y ASIGNADO AL DOCUMENTO.
-- FINALMENTE PASA COMO VERIFICADO EL REGISTRO DE DOCUMENTO LED
-- =============================================
CREATE OR ALTER PROCEDURE dbo.LN_balances_reemplazar
-- Add the parameters for the stored procedure here
@p_doc_id int,
@p_id_balance int,
@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
DECLARE @usuario varchar(50)
select @usuario = first_name + ' ' + last_name
from users where user_id = @p_user_id
DECLARE @balance_previo int = null
select @balance_previo = id_externo
from LN_docs
where doc_id = @p_doc_id
and isnull(id_externo,0) <> @p_id_balance
if (@balance_previo is not null) begin
/* Si el balance que se esta tomando para reemplazo no tiene PDF, le asocia el PDF del cargado por el proveedor */
declare @url_subido varchar(100) = (select ruta_archivo from balances_contables where id_balance = @balance_previo)
declare @url_publicado varchar(100) = (select ruta_archivo from balances_contables where id_balance = @p_id_balance)
if (isnull(@url_publicado,'') = '')
BEGIN
update balances_contables set ruta_archivo = @url_subido where id_balance = @p_id_balance
END
update balances_contables set estado = 'ELIMINADO' ,
modified = GETDATE(), modified_by = @p_user_id
where id_balance = @balance_previo
declare @inicio date = null
declare @fin date = null
declare @periodo int = null
select @fin = fecha_balance, @periodo = periodo
from balances_contables
where id_balance = @p_id_balance
if (@fin is not null and @periodo > 0)
set @inicio = dateadd(day, 1, dateadd(month, (-1) * @periodo, @fin))
UPDATE LN_docs set estado_doc = 'V',
id_externo = @p_id_balance,
inicio_ejercicio = @inicio,
fin_ejercicio = @fin,
modified = GETDATE(), modified_by = @p_user_id,
verificado_backend = GETDATE(),
verificado_backend_por = @p_user_id,
doc_log = CONVERT(VARCHAR(MAX),doc_log) + CHAR(13)+CHAR(10) +
CONVERT(VARCHAR(10), GETDATE(),103) + ' ' + CONVERT(VARCHAR(5), GETDATE(), 14) + ' - Documento de balance verificado por ' + @usuario
WHERE doc_id = @p_doc_id
end
END
GO
Depends On
3Used By
No items found