dbo.LN_tickets_

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

15
Name Data Type Length Description
@p_accion varchar 20
@p_contraparte int 4
@p_gestion int 4
@p_servicio int 4
@p_cliente int 4
@p_userID int 4
@p_mensaje varchar 1000
@p_sector varchar 1
@p_estado_informe varchar 1
@p_informe int 4
@p_docID bigint 8
@p_id_ticket int 4
@p_desde datetime 8
@p_hasta datetime 8
@p_visible bit 1

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER PROCEDURE dbo.LN_tickets_ /* ADDTICKET - LISTBYCONTRA - ANSWERTICKET - SEARCHTICKETS*/
 @p_accion      varchar(20),
 @p_contraparte     int,
 @p_gestion       int,
    @p_servicio       int,
    @p_cliente      int,
    @p_userID           int,
    @p_mensaje          varchar(1000),
    @p_sector           varchar(1), /* IF FRONTEND = F IF BACKEND = B. SIRVE PARA ORDENAR A DERECHA O IZQUIERDA LOS MENSAJITOS*/
    @p_estado_informe   varchar(1) = NULL,
    @p_informe          int = NULL,
    @p_docID            bigint = NULL,
 @p_id_ticket        int = NULL,
    @p_desde            datetime = NULL,
    @p_hasta            datetime = NULL,
 @p_visible          bit = 1


AS
BEGIN

 SET NOCOUNT ON;

 if (@p_accion = 'ADDTICKET') 
    BEGIN
        INSERT INTO LN_tickets (cliente,servicio_contratado,contraparte,gestion,informe,estado_informe,doc_id,texto,userID,sector)
        values (@p_cliente,@p_servicio,@p_contraparte,@p_gestion,@p_informe,@p_estado_informe,@p_docID,@p_mensaje,@p_userID,@p_sector)
    END

 if (@p_accion = 'ANSWERTICKET') 
    BEGIN
        update LN_tickets set LN_tickets.isread = 1 ,LN_tickets.isanswered=1,LN_tickets.answered_by = @p_userID
        ,estado_informe=@p_estado_informe,fecha_leido=getdate(),fecha_respondido=getdate() 
         where LN_tickets.id_ticket=@p_id_ticket

        INSERT INTO LN_tickets (cliente,servicio_contratado,contraparte,gestion,informe,estado_informe,doc_id,texto,userID,sector)
        values (@p_cliente,@p_servicio,@p_contraparte,@p_gestion,@p_informe,@p_estado_informe,@p_docID,@p_mensaje,@p_userID,@p_sector)
    END

 if (@p_accion = 'LISTTICKETS')
    BEGIN
        SELECT * FROM LN_tickets
    END

    if (@p_accion = 'LISTBYCONTRA') 
    BEGIN
/*
select * from ln_gestiones where contraparte = 206961
declare @p_contraparte int = 206961
declare @p_gestion int = 208592
*/

        SELECT LN_tickets.texto,users.username,LN_tickets.created,sector,informes.informe,informes.estado_informe,ln_demo.contraparte,ln_demo.gestion,
  LN_tickets.servicio_contratado,ln_contrapartes.id_referencia,ln_contrapartes.country_code,clientes.nombre_cliente,informes.fecha_comprometida,
  LN_tipo_informes.nombre_tipo_informe,LN_tipo_informes.idTipoInforme,users.email
        FROM LN_tickets INNER JOIN LN_DEMO ON (LN_tickets.contraparte = ln_demo.contraparte and LN_tickets.gestion = ln_demo.gestion)
        inner join users on ln_tickets.userid = users.user_id
  inner join informes on ln_demo.informe = informes.informe 
  inner join LN_contrapartes on ln_demo.contraparte=ln_contrapartes.contraparte
  inner join clientes on LN_contrapartes.cliente=clientes.cliente
  inner join LN_tipo_informes on LN_tipo_informes.idTipoInforme=informes.id_tipo_informe
        where LN_tickets.contraparte=@p_contraparte and LN_tickets.gestion = @p_gestion
        order by LN_tickets.created asc


    END
 if (@p_accion = 'SEARCHTICKETS')
    BEGIN
        SELECT LN_tickets.texto,users.username,LN_tickets.created,sector,informes.informe,informes.estado_informe,ln_demo.contraparte,ln_demo.gestion,
  LN_tickets.servicio_contratado,ln_contrapartes.id_referencia,ln_contrapartes.country_code,clientes.nombre_cliente,informes.fecha_comprometida,
  LN_tipo_informes.nombre_tipo_informe,LN_tipo_informes.idTipoInforme,ANSWUid.username as Respondido_Por,LN_tickets.id_ticket,ln_contrapartes.hit_summary ,clientes.cliente,users.email,
        ln_demo.idTeam,LN_Teams.nombre,informes.proximo_llamado
        FROM LN_tickets 
        INNER JOIN LN_DEMO ON (LN_tickets.contraparte = ln_demo.contraparte and LN_tickets.gestion = ln_demo.gestion)
        inner join users on ln_tickets.userid = users.user_id
  inner join informes on ln_demo.informe = informes.informe 
  inner join LN_contrapartes on ln_demo.contraparte=ln_contrapartes.contraparte
  inner join clientes on LN_contrapartes.cliente=clientes.cliente
        inner join LN_Teams on ln_demo.idTeam=LN_Teams.id_team 
  inner join LN_tipo_informes on LN_tipo_informes.idTipoInforme=informes.id_tipo_informe
  left join users ANSWUid on ln_tickets.answered_by = ANSWUid.user_id
  where (LN_tickets.isread = 0 or LN_tickets.isanswered=0) and ln_tickets.servicio_contratado=@p_servicio
        and ln_demo.idTeam in (select id_team from LN_Team_Members where id_rol=1 and activo=1 and user_id = @p_userID) 
        order by LN_tickets.created asc




--select * from LN_Roles

    END

end

GO

Used By

No items found