You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

294 lines
22 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_ExchangeDropdown] Script Date: 9/27/2019 1:30:14 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. CREATE PROC [dbo].[proc_ExchangeDropdown]
  9. @FLAG VARCHAR(20),
  10. @BRANCH_ID VARCHAR(30) = NULL,
  11. @USER VARCHAR(50) = NULL,
  12. @CTYPE INT = NULL,
  13. @SEARCHTYPE VARCHAR(50) = NULL,
  14. @SEARCHVALUE VARCHAR(50) = NULL
  15. AS
  16. SET NOCOUNT ON;
  17. IF @BRANCH_ID IS NOT NULL
  18. SELECT @BRANCH_ID = BRANCH_ID from Branches WITH(NOLOCK) WHERE COMPANY_ID = @BRANCH_ID
  19. IF @FLAG ='operationDDL' -->> ONLY FOR BUY,SELL,CROSS OPERATION DO NOT CHANGE THE QUERY
  20. BEGIN
  21. --CURRENCY DDL
  22. IF @BRANCH_ID IS NOT NULL
  23. BEGIN
  24. select c.curr_code+'('+c.curr_name+')' [curr_name],c.curr_code
  25. from Branch_Currency b WITH(NOLOCK)
  26. INNER JOIN currency_setup c WITH(NOLOCK) on b.curr_code=c.rowid
  27. INNER JOIN Branches BS WITH(NOLOCK) ON b.branch_id = BS.BRANCH_ID
  28. where BS.BRANCH_ID = @BRANCH_ID AND C.curr_code <> 'MYR'
  29. ORDER BY ISNULL(CAST(b.displayOrder AS VARCHAR),C.curr_code)
  30. END
  31. ELSE
  32. BEGIN
  33. select curr_code+'('+curr_name+')' [curr_name],curr_code from currency_setup WHERE 1=2
  34. END
  35. --COUNTRY DDL
  36. SELECT refid,ref_code FROM ref_master WITH(NOLOCK) WHERE ref_rec_type=1 ORDER BY ref_code
  37. -->> Customer Type
  38. SELECT refid,ref_code FROM ref_master WITH(NOLOCK) WHERE ref_rec_type='106' order by ref_code
  39. -->> Purpose of Txn
  40. SELECT refid,ref_code FROM ref_master WITH(NOLOCK) WHERE ref_rec_type=104 order by ref_code
  41. -->> ID Type
  42. SELECT refid,ref_code FROM ref_master WITH(NOLOCK) WHERE ref_rec_type=101 order by ref_code
  43. -->> Occupation
  44. select refid,ref_code from ref_master WITH(NOLOCK) where ref_rec_type=102 order by ref_code
  45. -->> Source of Money
  46. select refid,ref_code from ref_master WITH(NOLOCK) where ref_rec_type=103 order by ref_code
  47. --BUSINESS TYPE
  48. select refid,ref_code from ref_master WITH(NOLOCK) where ref_rec_type=107 order by ref_code
  49. -- STR REASON
  50. select refid,ref_code from ref_master WITH(NOLOCK) where ref_rec_type=109 order by ref_code
  51. END
  52. IF @FLAG = 'BEXC' -->> BRANCHWISE CURRENCY LOAD FOR EXCHANGE
  53. BEGIN
  54. IF @BRANCH_ID IS NOT NULL
  55. BEGIN
  56. select c.curr_code+'('+c.curr_name+')' [curr_name],c.curr_code
  57. from Branch_Currency b WITH(NOLOCK)
  58. INNER JOIN currency_setup c WITH(NOLOCK) on b.curr_code=c.rowid
  59. INNER JOIN Branches BS WITH(NOLOCK) ON b.branch_id = BS.BRANCH_ID
  60. where BS.BRANCH_ID = @BRANCH_ID AND C.curr_code <> 'MYR'
  61. ORDER BY C.curr_code
  62. END
  63. ELSE
  64. BEGIN
  65. select curr_code+'('+curr_name+')' [curr_name],curr_code from currency_setup WHERE 1=2
  66. END
  67. END
  68. ELSE IF @FLAG='ct'-->> Customer Type
  69. BEGIN
  70. SELECT refid,ref_code FROM ref_master WITH(NOLOCK) WHERE ref_rec_type='106' order by ref_code
  71. End
  72. ELSE IF @FLAG='fc' -->> Filter Customer
  73. BEGIN
  74. select cid,cName from customerSetup WITH(NOLOCK) WHERE CTYPE ='726' AND branchId = @BRANCH_ID order by cName
  75. END
  76. ELSE IF @FLAG='c' -->> Country
  77. BEGIN
  78. select refid,ref_code from ref_master WITH(NOLOCK) where ref_rec_type=1 order by ref_code
  79. END
  80. ELSE IF @FLAG='pot' -->> Purpose of Txn
  81. BEGIN
  82. select refid,ref_code from ref_master WITH(NOLOCK) where ref_rec_type=104 order by ref_code
  83. END
  84. ELSE IF @FLAG='idt' -->> ID Type
  85. BEGIN
  86. select refid,ref_code from ref_master WITH(NOLOCK) where ref_rec_type=101 order by ref_code
  87. END
  88. ELSE IF @FLAG='occ' -->> Occupation
  89. BEGIN
  90. select refid,ref_code from ref_master WITH(NOLOCK) where ref_rec_type=102 order by ref_code
  91. END
  92. ELSE IF @FLAG='som' -->> Source of Money
  93. BEGIN
  94. select refid,ref_code from ref_master WITH(NOLOCK) where ref_rec_type=103 order by ref_code
  95. END
  96. ELSE IF @FLAG='pocm' -->> Purpose of Changing Money
  97. BEGIN
  98. select refid,ref_code from ref_master WITH(NOLOCK) where ref_rec_type=104 order by ref_code
  99. END
  100. ELSE IF @FLAG='bidt' -- Beneficiary ID Type
  101. BEGIN
  102. select refid,ref_code from ref_master WITH(NOLOCK) where ref_rec_type=101 order by ref_code
  103. END
  104. ELSE IF @FLAG = 'custByCtype' -->> customer detail by customer id
  105. BEGIN
  106. --select @SEARCHVALUE = fileName from customerdocument where fileDescription = 'Customer Id photo' and cid = @BRANCH_ID
  107. SELECT @SEARCHVALUE = FILENAME FROM CUSTOMERDOCUMENT WHERE FILEDESCRIPTION = 'CUSTOMER ID PHOTO' AND CUSTOMERID = @BRANCH_ID
  108. SELECT cid,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 = bt.refid,btypetxt = c.businessType ,s.*,@SEARCHVALUE 'custImage'FROM customerSetup C
  109. CROSS apply dbo.FNASplitName(C.CNAME) S
  110. LEFT join ac_master a ON c.cid = a.acct_type_code AND a.acct_rpt_code ='C'
  111. LEFT JOIN ref_master bt WITH(NOLOCK) ON c.businessType = bt.ref_code AND ref_rec_type = 107
  112. WHERE cid = @BRANCH_ID
  113. END
  114. ELSE IF @FLAG = 'cByCtype' -->> customer detail by customer type
  115. BEGIN
  116. SELECT cid,cName
  117. FROM customerSetup WITH(NOLOCK)
  118. WHERE CTYPE = @BRANCH_ID AND cType = @CTYPE ORDER BY cName
  119. END
  120. ELSE IF @FLAG='businessType' -- Beneficiary ID Type
  121. BEGIN
  122. select refid,ref_code from ref_master WITH(NOLOCK) where ref_rec_type=107 order by ref_code
  123. END
  124. ELSE IF @FLAG = 'searchType' -- SEARCH CUSTOMER FROM OPERATION PAGE
  125. BEGIN
  126. SELECT 'cName' val, 'Customer Name' txt UNION ALL
  127. SELECT 'CHKID','ID Number' UNION ALL
  128. SELECT 'contact','Contact Number'
  129. END
  130. ELSE IF @FLAG = 'aSearch' --CUSTOMER ADVANCE SEARCH
  131. BEGIN
  132. DECLARE @SQL VARCHAR(500) =''
  133. SET @SQL = 'SELECT C.cid,ct.ref_code CTYPE,C.cName,C.cAddress,id.ref_code IDTYPE,C.idNumber,C.contact
  134. FROM CUSTOMERSETUP C WITH(NOLOCK)
  135. INNER JOIN ref_master ct WITH(NOLOCK) ON C.cType = ct.refid
  136. LEFT JOIN ref_master id WITH(NOLOCK) ON C.idType = id.refid
  137. WHERE 1=1 AND approvedDate IS NOT NULL AND ISNULL(C.isActive,''Y'')=''Y'''
  138. --AND C.branchId ='''+@BRANCH_ID+'''
  139. IF @SEARCHTYPE ='CHKID'
  140. BEGIN
  141. UPDATE customersetup SET chkid=REPLACE(REPLACE(REPLACE(idnumber,' ',''),'-',''),'/','') WHERE chkid IS NULL AND idnumber IS NOT NULL
  142. SET @SEARCHVALUE = REPLACE(REPLACE(REPLACE(@SEARCHVALUE,' ',''),'-',''),'/','')
  143. END
  144. IF @SEARCHVALUE IS NOT NULL
  145. SET @SQL = @SQL + ' AND '+ @SEARCHTYPE + ' LIKE '''+@SEARCHVALUE +'%'''
  146. --IF @CTYPE IS NOT NULL
  147. -- SET @SQL = @SQL +' AND C.cType = '''+CAST(@CTYPE AS VARCHAR)+''''
  148. PRINT @SQL
  149. EXEC(@SQL)
  150. END
  151. ELSE IF @FLAG = 'docDesc'
  152. BEGIN
  153. SELECT refid ,ref_code FROM ref_master WITH(NOLOCK) WHERE ref_rec_type='108'
  154. END
  155. ELSE IF @FLAG = 'branchType'
  156. BEGIN
  157. SELECT DISTINCT CASE BRANCH_TYPE WHEN 'A' THEN 'Agent'
  158. WHEN 'AP' THEN 'Agent Partner'
  159. WHEN 'B' THEN 'Branch'
  160. WHEN 'H' THEN 'Hotel'
  161. END typeDesc
  162. ,RTRIM(BRANCH_TYPE) BRANCH_TYPE
  163. FROM Branches WITH(NOLOCK) WHERE BRANCH_TYPE IS NOT NULL
  164. END
  165. ELSE IF @FLAG = 'BranchByType' --## GET BRANCH LIST BY BRANCH TYPE
  166. BEGIN
  167. SELECT COMPANY_ID,BRANCH_NAME FROM Branches WITH(NOLOCK) WHERE RTRIM(BRANCH_TYPE) = @SEARCHVALUE AND COMPANY_ID IS NOT NULL ORDER BY BRANCH_NAME
  168. END
  169. ELSE IF @FLAG = 'branchList'
  170. BEGIN
  171. SELECT COMPANY_ID , BRANCH_NAME FROM Branches WITH(NOLOCK) where COMPANY_ID is not null order by BRANCH_NAME
  172. END
  173. ELSE IF @FLAG = 'branchList1'
  174. BEGIN
  175. SELECT null COMPANY_ID,'All' BRANCH_NAME union all
  176. SELECT COMPANY_ID , BRANCH_NAME FROM Branches WITH(NOLOCK) where COMPANY_ID is not null order by BRANCH_NAME
  177. END
  178. ELSE IF @FLAG ='currList'
  179. BEGIN
  180. select curr_code+'('+curr_name+')' [curr_name],curr_code
  181. from currency_setup WITH(NOLOCK) where curr_code <> 'MYR' ORDER BY curr_code
  182. END
  183. ELSE IF @FLAG ='RateCode'
  184. BEGIN
  185. SELECT ratecodeId,rate_code+'-'+rate_description RateCode
  186. FROM RateCodeTable WITH(NOLOCK) WHERE ISNULL(active,'N')='Y'
  187. END
  188. ELSE IF @FLAG ='BlankRateCode'
  189. BEGIN
  190. SELECT ratecodeId,rate_code+'-'+rate_description RateCode
  191. FROM RateCodeTable WITH(NOLOCK) WHERE ISNULL(active,'N')='Y'
  192. AND ratecodeId NOT IN(
  193. SELECT DISTINCT ratecode FROM ExchangeRateTable WHERE ISNULL(active,'N')='Y' )
  194. END
  195. ELSE IF @FLAG ='IndIdtype' ---->> ONLY FOR INDIVIDUAL CUSTOMER ID TYPE
  196. BEGIN
  197. SELECT * FROM ref_master WHERE refid <> 728 AND ref_rec_type=101
  198. END
  199. ELSE IF @FLAG ='NonIndIdtype' ---->> ONLY FOR OTHER THAN INDIVIDUAL CUSTOMER ID TYPE
  200. BEGIN
  201. SELECT * FROM ref_master WHERE refid=728 AND ref_rec_type=101
  202. END
  203. ELSE IF @FLAG='strReason' -->> str reason
  204. BEGIN
  205. select refid,ref_code from ref_master WITH(NOLOCK) where ref_rec_type=109 order by ref_code
  206. END
  207. ELSE IF @FLAG ='txnHistBycId' ---- TRANSACTION HISTORY BY CUSTOMER ID
  208. BEGIN
  209. SELECT T.customer_name [Customer Name],R.ref_code [ID],T.id_number [ID Number],T.Nationality
  210. ,BillNo = '<a href="#" onClick="OpenReceipt('''+RTRIM(T.tran_type)+'='+CAST(T.tran_id AS VARCHAR)+''')"> '+ T.BillNo +'</a>'
  211. ,T.entered_date [Txn. Date]
  212. ,[Txn. Type] = CASE T.tran_type WHEN 'P' THEN 'BUY' WHEN 'S' THEN 'SELL' END
  213. ,CONVERT(VARCHAR,CAST(ISNULL(T.total_amt,0) AS MONEY),1) [Txn. Amount]
  214. FROM CUSTOMER C WITH(NOLOCK)
  215. INNER JOIN transaction_info T WITH(NOLOCK) ON C.tran_id = T.tran_id
  216. INNER JOIN ref_master R WITH(NOLOCK) ON T.id_type = R.refid
  217. WHERE CID = @SEARCHVALUE
  218. END
  219. -->>## GRID DROP DOWN
  220. ELSE IF @FLAG = 'tranType' ---->> TRANSACTION TYPE
  221. BEGIN
  222. SELECT NULL '0','Both' '1' UNION ALL
  223. SELECT 'P','BUY' UNION ALL
  224. SELECT 'S','SELL'
  225. END
  226. ---->>>> USE ONLY IN GRID FILTER
  227. ELSE IF @FLAG = 'GetBranchList'
  228. BEGIN
  229. SELECT X.[0],X.[1] FROM (
  230. SELECT NULL AS [0], 'ALL' [1],1 VAL UNION ALL
  231. SELECT BRANCH_ID AS '0', BRANCH_NAME '1', 2 VAL FROM Branches WITH(NOLOCK)
  232. )X ORDER BY X.VAL,X.[1]
  233. END
  234. ELSE IF @FLAG='ct1'-->> Customer Type
  235. BEGIN
  236. SELECT X.[0],X.[1] FROM (
  237. SELECT NULL AS [0], 'ALL' [1],1 VAL UNION ALL
  238. SELECT refid,ref_code,2 VAL FROM ref_master WITH(NOLOCK) WHERE ref_rec_type='106'
  239. )X ORDER BY X.VAL,X.[1]
  240. End
  241. ELSE IF @FLAG = 'ctype_Grid' --## CUSTOMER TYPE FOR GRID
  242. BEGIN
  243. SELECT NULL '0','ALL' '1' UNION ALL
  244. SELECT refid '0',ref_code '1' FROM ref_master WITH(NOLOCK) WHERE ref_rec_type='106'
  245. RETURN
  246. END
  247. ELSE IF @FLAG = 'haschange_Grid' --## CHECK CUSTOMER HAS APPROVED FOR GRID
  248. BEGIN
  249. SELECT NULL '0','ALL' '1' UNION ALL
  250. SELECT 'Yes','Yes' UNION ALL
  251. SELECT 'No','No'
  252. RETURN
  253. END
  254. ELSE IF @FLAG ='RateCodeList'
  255. BEGIN
  256. SELECT NULL '0','ALL' '1' UNION ALL
  257. SELECT ratecodeId,rate_code+'-'+rate_description RateCode
  258. FROM RateCodeTable WITH(NOLOCK) WHERE ISNULL(active,'N')='Y'
  259. END
  260. ELSE IF @FLAG ='statusList'
  261. BEGIN
  262. SELECT NULL '0','ALL' '1' UNION ALL
  263. SELECT 'Approved','Approved' UNION ALL
  264. SELECT 'Rejected','Rejected'
  265. END
  266. ELSE IF @FLAG = 'hotelCust' ----## HOTEL ASSIGNED CUSTOMER
  267. BEGIN
  268. select TOP 12 c.cid,c.cName from customersetup C WITH(NOLOCK)
  269. INNER JOIN hotelCustomers H ON C.cid = h.cid
  270. RETURN
  271. END
  272. ELSE IF @FLAG = 'NonRetailctype' ----## NON RETAIL CUSTOMER TYPE LIST
  273. BEGIN
  274. SELECT NULL '0','ALL' '1' UNION ALL
  275. SELECT refid '0',ref_code '1' FROM ref_master WITH(NOLOCK) WHERE REFID <> 726 AND ref_rec_type='106'
  276. END
  277. GO