USE [FastMoneyPro_Remit]
GO
/****** Object:  StoredProcedure [dbo].[proc_notification]    Script Date: 7/4/2019 11:35:48 AM ******/
DROP PROCEDURE [dbo].[proc_notification]
GO
/****** Object:  StoredProcedure [dbo].[proc_notification]    Script Date: 7/4/2019 11:35:48 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[proc_notification]
	@user VARCHAR(50)
AS
    SET NOCOUNT ON;
    SET XACT_ABORT ON;
    BEGIN
		IF (SELECT dbo.FNAHasRight(@User,'90100000') )='N'
			RETURN
		DECLARE @NotificationList table([count] INT,Msg VARCHAR(100), Msg1 VARCHAR(50),Link VARCHAR(100)) 

		INSERT INTO @NotificationList
        SELECT COUNT('A') AS [count] , CAST(COUNT('A') AS VARCHAR) + ' Modification Request(s) pending' AS [msg],
			  'Approve Modify Txn(s)' AS Msg1,'/Remit/Transaction/ApproveModification/List.aspx' AS [link]
        FROM    tranModifyLog TL WITH ( NOLOCK )
        WHERE   TL.status = 'ModificationRequest'
        UNION ALL
        SELECT  COUNT('A') AS [count] ,CAST(COUNT('A') AS VARCHAR) + ' Cancel Request(s) pending' AS [msg], 'Approve Cancel Txn(s)' AS Msg1,
                '/Remit/Transaction/Cancel/ApproveReqUnapprovedTxn.aspx' AS [link]
        FROM    vwRemitTran trn WITH ( NOLOCK )
                INNER JOIN tranCancelrequest A WITH ( NOLOCK ) ON A.controlNo = trn.controlNo
        WHERE   trn.tranStatus = 'CancelRequest'
                AND A.cancelStatus = 'CancelRequest'
        UNION ALL
        SELECT  COUNT('A') AS [count] ,
                CAST(COUNT('A') AS VARCHAR) + ' Blocked Transaction(s)' AS [msg], 'Approve Blocked Txn(s)' AS Msg1,
                '/Remit/Transaction/BlockTransaction/List.aspx' AS [link]
        FROM    remitTran trn WITH ( NOLOCK )
        WHERE   trn.tranStatus = 'Block'
        UNION ALL
        SELECT  COUNT('A') AS [count] ,CAST(COUNT('A') AS VARCHAR) + ' Locked Transaction(s)' AS [msg], 'Release Locked Txn(s)' AS Msg1,
                '/Remit/Transaction/UnlockTransaction/List.aspx' AS [link]
        FROM    remitTran trn WITH ( NOLOCK )
        WHERE   trn.tranStatus = 'Lock'
              --  AND trn.tranType = 'D'
        UNION ALL
        SELECT  COUNT('A') AS [count] ,
                CAST(COUNT('A') AS VARCHAR) + ' Txn(s) Pending For Approval' AS [msg], 'Approve Txn(s)' AS Msg1,
                '/Remit/Transaction/Approve/Manage.aspx' AS [link]
        FROM    dbo.remitTran
        WHERE   tranStatus = 'Hold'
                AND payStatus = 'Unpaid'
                AND approvedBy IS NULL
              --  AND tranType = 'D'
        UNION ALL
        SELECT  COUNT('A') AS [count] ,
                CAST(COUNT('A') AS VARCHAR) + ' Txn(s) Pending For Approval(Int''l)' AS [msg], 'Approve International Txn(s)' AS Msg1,
                '/Remit/Transaction/ApproveTxn/holdTxnList.aspx?country=SOUTH KOREA' AS [link]
        FROM    dbo.remitTranTemp
        WHERE   tranStatus IN ( 'Hold', 'Compliance Hold', 'OFAC Hold', 'OFAC/Compliance Hold' )
                AND payStatus = 'Unpaid'
                AND approvedBy IS NULL
                AND tranType = 'I'
		UNION ALL
		 SELECT  COUNT('A') AS [count] ,
                CAST(COUNT('A') AS VARCHAR) + ' &nbsp; Online  Txn(s) Pending For Approval(Int''l)' AS [msg], 'Approve International Txn(s)' AS Msg1,
                '/Remit/Transaction/ApproveTxn/holdOnlineTxnList.aspx?country=SOUTH KOREA' AS [link]
        FROM    dbo.remitTranTemp
        WHERE   tranStatus IN ( 'Hold', 'Compliance Hold', 'OFAC Hold', 'OFAC/Compliance Hold' )
                AND payStatus = 'Unpaid'
                AND approvedBy IS NULL
                AND (tranType = 'O' AND isOnlineTxn='Y');

		SELECT * FROM @NotificationList WHERE [count] > 0
    END;

GO
