USE [FastMoneyPro_Remit]
GO
/****** Object:  StoredProcedure [dbo].[proc_dropDownList]    Script Date: 7/4/2019 11:35:48 AM ******/
DROP PROCEDURE [dbo].[proc_dropDownList]
GO
/****** Object:  StoredProcedure [dbo].[proc_dropDownList]    Script Date: 7/4/2019 11:35:48 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[proc_dropDownList]	@FLAG		VARCHAR(20),
	@USER		VARCHAR(50) = NULL,
	@typeId		INT			= NULL,
	@BRANCH_ID	INT			= NULL,
	@CTYPE		VARCHAR(30) = NULL,
	@SEARCHVALUE VARCHAR(30)= NULL,
	@SEARCHTYPE	VARCHAR(30) = NULL
	
AS
SET NOCOUNT ON;
IF @FLAG = 'staticDdl'
BEGIN
	SELECT ID,REF_CODE FROM FastMoneyPro_account.dbo.staticdatadetail WITH(NOLOCK) WHERE [TYPE_ID] = @typeId
	RETURN
END	
IF @FLAG = 'transferType'
BEGIN
	SELECT detailTitle,detailTitle FROM staticDataValue WITH(NOLOCK) where typeID=1400
	RETURN
END	
ELSE IF @FLAG = 'roleType'
BEGIN
	SELECT NULL 'value','ALL' 'text' UNION ALL
	SELECT 'H','HO/Admin' UNION ALL
	SELECT 'A','Agent'
	RETURN
END
ELSE IF @FLAG ='gender'
BEGIN
	SELECT id refid,ref_code FROM FastMoneyPro_account.dbo.StaticDataDetail WITH(NOLOCK) WHERE type_id = 3 ORDER BY ref_code
	RETURN
END
----## DRILLDOWN FOR GRID
ELSE IF @FLAG = 'haschange_Grid'  --## CHECK CUSTOMER HAS APPROVED FOR GRID
BEGIN
	SELECT NULL 'value','ALL' 'Text' UNION ALL
	SELECT 'Yes','Yes' UNION ALL
	SELECT 'No','No'
	RETURN
END

ELSE IF @FLAG ='gl_group'
BEGIN
	SELECT gl_code,gl_name FROM GL_Group WITH(NOLOCK)
	RETURN
END
ELSE IF @FLAG='ledgerMove'
BEGIN
	SELECT gl_code,gl_name = CONVERT(VARCHAR,gl_code)+'|'+CONVERT(VARCHAR,gl_name) FROM GL_GROUP with (nolock) order by gl_code
	RETURN 
END
ELSE IF @FLAG = 'isActive'
BEGIN
	SELECT NULL 'value','ALL' 'text' UNION ALL
	SELECT 'Y','Yes' UNION ALL
	SELECT 'N','No'
	RETURN
END
ELSE IF @FLAG='AdminMenu'
BEGIN
	SELECT functionId FROM applicationFunctions(NOLOCK) WHERE parentFunctionId = '20260000'
	RETURN 
END
ELSE IF @FLAG='AgentMenu'
BEGIN
	SELECT functionId,functionName FROM applicationFunctions (NOLOCK) WHERE parentFunctionId = '20261000'
	RETURN 
END
ELSE IF @FLAG='voucherDDL'
BEGIN
	SELECT 
		functionName 
		,value = CASE functionName 
					WHEN 'Journal Voucher' THEN 'J' 
					WHEN 'Contra Voucher' THEN 'C'
					WHEN 'Payment Voucher' THEN 'Y' 
					WHEN 'Receipt Voucher' THEN 'R' 
				END
	FROM applicationFunctions (NOLOCK) 
		WHERE parentFunctionId = '20102000'
	RETURN 
END
ELSE IF @FLAG='logType'
BEGIN

	SELECT NULL 'value','ALL' 'Text' UNION ALL
	SELECT DISTINCT LOGTYPE as value, LOGTYPE as [text]
	FROM LoginLogs WITH(NOLOCK) 
END	
ELSE IF @FLAG='payPartner'
BEGIN
	SELECT agentId,agentName 
	FROM agentMaster (NOLOCK)
	WHERE agentId  IN (1176)
END	
ELSE IF @FLAG='banklist'
BEGIN
	SELECT value=rowId, [text]=bankName+' - '+bankCode,bankCode FROM koreanBankList(nolock) order by bankName
END	
ELSE IF @FLAG ='currList'
BEGIN
	DECLARE @CurrencyName 	VARCHAR(30) ='KRW'
	SELECT  currencyCode+' ('+currencyName+')' currencyName,currencyCode 
		FROM currencyMaster WITH(NOLOCK) 
	WHERE currencyCode <> @CurrencyName  
	AND ISACTIVE='Y' 
	ORDER BY currencyCode
	RETURN
END

ELSE IF @FLAG ='branchList'
BEGIN
	IF( @BRANCH_ID  IS NULL OR @BRANCH_ID = '')
	BEGIN
		SELECT agentId,agentName
		FROM  FastMoneyPro_Remit.DBO.agentMaster (NOLOCK) WHERE parentid='1008'AND agentGrp = 11023
	END
     ELSE
	 BEGIN
		SELECT agentId,agentName
		FROM  FastMoneyPro_Remit.DBO.agentMaster (NOLOCK) WHERE parentid='1008'AND agentGrp=11023
		AND agentId <> @BRANCH_ID
	END
END

ELSE IF @FLAG ='Fx_Branch_List'
BEGIN
SELECT value =agentId,[text] =agentName
		FROM  agentMaster (NOLOCK) WHERE parentid='1008'
		AND agentId = ISNULL(@BRANCH_ID,agentId)
END
ELSE IF @FLAG = 'tranType'  ---->> TRANSACTION TYPE
BEGIN
	SELECT NULL 'value','Both' 'text' UNION ALL
	SELECT 'P','BUY' UNION ALL
	SELECT 'S','SELL'
END
ELSE IF @FLAG = 'searchType' -- SEARCH CUSTOMER FROM OPERATION PAGE
BEGIN
	SELECT 'cName' val, 'Customer Name' txt UNION ALL
	SELECT 'idNumber','ID Number' UNION ALL
	SELECT 'contact','Contact Number' 
END
ELSE IF @FLAG = 'aSearch' --CUSTOMER ADVANCE SEARCH 
BEGIN
	DECLARE @SQL VARCHAR(500) =''

	SET @SQL = 'SELECT C.cid,R.ref_desc, CTYPE,C.cName,C.cAddress,r.id IDTYPE,C.idNumber,C.contact 
				FROM EXCHANGE_CUSTOMERSETUP C WITH(NOLOCK)
				 LEFT JOIN FastMoneyPro_Account.dbo.StaticDataDetail R WITH(NOLOCK) ON c.idType = R.id
				--LEFT JOIN staticDataValue ct WITH(NOLOCK) ON C.cType = ct.typeID
				--LEFT JOIN staticdatatype id WITH(NOLOCK) ON C.idType = id.typeID
				WHERE 1=1 AND approvedDate IS NOT NULL'
	--AND C.branchId ='''+@BRANCH_ID+'''
	IF @SEARCHVALUE IS NOT NULL
		SET @SQL = @SQL + ' AND '+ @SEARCHTYPE + ' LIKE '''+@SEARCHVALUE +'%'''
	
	IF @CTYPE IS NOT NULL
		SET @SQL = @SQL +' AND C.cType = '''+CAST(@CTYPE AS VARCHAR)+''''
	
	PRINT @SQL	
	EXEC(@SQL)
	
END
ELSE IF @FLAG ='exCurrList' -- branch transfer
BEGIN
	SELECT  currencyCode+' ('+currencyName+')' currencyName,currencyCode 
	 FROM dbo.currencyMaster (NOLOCK) cm
	INNER JOIN dbo.EXCHANGE_COSTRATE_SETUP (NOLOCK) cr ON cr.baseCurrency=cm.currencyCode
	WHERE cr.agentId=ISNULL(@BRANCH_ID,'') AND isActive='Y' 
	ORDER BY currencyCode	
	RETURN
END
ELSE IF @FLAG = 'docDesc'
BEGIN
	SELECT valueId,detailTitle  FROM dbo.staticDataValue WITH(NOLOCK) WHERE typeID='1300' 
	RETURN 
END
ELSE IF @FLAG ='txnHistBycId' ---- TRANSACTION HISTORY BY CUSTOMER ID
BEGIN
	SELECT T.customer_name [Customer Name],R.type_id [ID],T.id_number [ID Number],T.Nationality
		,BillNo = '<a href="#" onClick="OpenReceipt('''+RTRIM(T.tran_type)+'='+CAST(T.tran_id AS VARCHAR)+''')"> '+ T.BillNo +'</a>'
		,T.entered_date [Txn. Date]
		,[Txn. Type] = CASE T.tran_type WHEN 'P' THEN 'BUY' WHEN 'S' THEN 'SELL' END 
		,CONVERT(VARCHAR,CAST(ISNULL(T.total_amt,0) AS MONEY),1) [Txn. Amount]
	FROM EXCHANGE_CUSTOMER C WITH(NOLOCK)
	INNER JOIN EXCHANGE_transaction_info T WITH(NOLOCK) ON C.tran_id = T.tran_id 
	INNER JOIN FastMoneyPro_Account.dbo.StaticDataDetail R WITH(NOLOCK) ON T.id_type = R.id
	 WHERE CID = @SEARCHVALUE
	 RETURN
END
ELSE IF @FLAG = 'custByCtype' -->> customer detail by customer id
BEGIN
	 SELECT a.acct_num,C.cType,C.cName,C.country,C.cAddress,C.contact,C.nativCountry
	 ,CONVERT(VARCHAR,CAST(C.dob AS DATE),101) DOB,C.idType,C.idNumber,C.postalCode,C.occupation ,businessType = C.businessType
	 FROM EXCHANGE_CUSTOMERSETUP C 
	 LEFT join FastMoneyPro_Account.DBO.ac_master a ON c.cid = a.acct_type_code AND a.acct_rpt_code ='C'
	 WHERE cid = @BRANCH_ID
END	

GO
