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.

1072 lines
86 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[ws_int_proc_SendTransaction_JP] 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].[ws_int_proc_SendTransaction_JP] (
  9. @AGENT_CODE VARCHAR(50),
  10. @USER_ID VARCHAR(50),
  11. @PASSWORD VARCHAR(50),
  12. @AGENT_SESSION_ID VARCHAR(50),
  13. @AGENT_TXNID VARCHAR(50) = NULL,
  14. @LOCATION_ID VARCHAR(50),
  15. @SENDER_NAME VARCHAR(50),
  16. @SENDER_GENDER VARCHAR(50) = NULL,
  17. @SENDER_ADDRESS VARCHAR(50),
  18. @SENDER_MOBILE VARCHAR(50),
  19. @SENDER_CITY VARCHAR(100),
  20. @SENDER_COUNTRY VARCHAR(50),
  21. @SENDER_ID_TYPE VARCHAR(50),
  22. @SENDER_ID_NUMBER VARCHAR(50),
  23. @SENDER_ID_ISSUE_DATE VARCHAR(50) = NULL,
  24. @SENDER_ID_EXPIRE_DATE VARCHAR(50) = NULL,
  25. @SENDER_DATE_OF_BIRTH VARCHAR(50) = NULL,
  26. @RECEIVER_NAME VARCHAR(50),
  27. @RECEIVER_ADDRESS VARCHAR(50),
  28. @RECEIVER_CONTACT_NUMBER VARCHAR(50) = NULL,
  29. @RECEIVER_CITY VARCHAR(50) = NULL,
  30. @RECEIVER_COUNTRY VARCHAR(50),
  31. @TRANSFERAMOUNT MONEY,
  32. @PAYMENTMODE VARCHAR(50) ,
  33. @BANKID VARCHAR(50) = NULL,
  34. @BANK_ACCOUNT_NUMBER VARCHAR(50) = NULL,
  35. @CALC_BY VARCHAR(50) ,
  36. @OUR_SERVICE_CHARGE MONEY = NULL,
  37. @EXT_BANK_BRANCH_ID VARCHAR(50) = NULL,
  38. @RECEIVER_IDENTITY_TYPE VARCHAR(50) = NULL,
  39. @RECEIVER_IDENTITY_NUMBER VARCHAR(50) = NULL,
  40. @BANK_NAME VARCHAR(150) = NULL,
  41. @BANK_BRANCH_NAME VARCHAR(150) = NULL,
  42. @PAYOUT_AGENT_ID VARCHAR(50) = NULL
  43. )
  44. AS
  45. /*
  46. IF EXISTS (SELECT 'x' FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ws_proc_SendTransaction]') AND TYPE IN (N'P', N'PC'))
  47. DROP PROCEDURE [dbo].ws_proc_SendTransaction
  48. GO
  49. EXEC ws_proc_SendTransaction @AGENT_CODE='IMEADE01',@USER_ID='apioo1',@PASSWORD='pralhad123',@AGENT_SESSION_ID='1231',@AGENT_TXNID='12',@LOCATION_ID=10200700
  50. ,@SENDER_NAME='Pralhad Sedhai',@SENDER_ADDRESS='Menara jaya,KL',@SENDER_MOBILE='060123345671',@SENDER_CITY='kuala lampur',@SENDER_COUNTRY='Malaysia'
  51. ,@SENDER_ID_TYPE='Passport',@SENDER_ID_NUMBER='05708477',@SENDER_ID_ISSUE_DATE='2012-12-12',@SENDER_ID_EXPIRE_DATE='2014-12-11',@SENDER_DATE_OF_BIRTH='1989-05-03'
  52. ,@RECEIVER_NAME='Riwaj Rimal',@RECEIVER_ADDRESS='Kathmandu',@RECEIVER_CONTACT_NUMBER='9841234567',@RECEIVER_CITY='kathmandu',@RECEIVER_COUNTRY='Philipines'
  53. ,@TRANSFERAMOUNT='12000',@PAYMENTMODE='C',@CALC_BY='P'
  54. */
  55. SET NOCOUNT ON;
  56. SET XACT_ABORT ON;
  57. --select top 10 * from apiRequestLog
  58. BEGIN TRY
  59. DECLARE @apiRequestId INT
  60. INSERT INTO apiRequestLog(
  61. USER_ID,
  62. PASSWORD,
  63. AGENT_SESSION_ID,
  64. AGENT_CODE,
  65. LOCATION_ID,
  66. SENDER_NAME,
  67. --SENDER_GENDER,
  68. SENDER_ADDRESS,
  69. SENDER_MOBILE,
  70. SENDER_CITY,
  71. SENDER_COUNTRY,
  72. SENDER_ID_TYPE,
  73. SENDER_ID_NUMBER,
  74. SENDER_ID_ISSUE_DATE,
  75. SENDER_ID_EXPIRE_DATE,
  76. SENDER_DATE_OF_BIRTH,
  77. RECEIVER_NAME,
  78. RECEIVER_ADDRESS,
  79. RECEIVER_CONTACT_NUMBER,
  80. RECEIVER_CITY,
  81. RECEIVER_COUNTRY,
  82. TRANSFER_AMOUNT,
  83. PAYMENT_MODE,
  84. BANK_ID,
  85. BANK_ACCOUNT_NUMBER,
  86. CALC_BY,
  87. AUTHORIZED_REQUIRED,
  88. OUR_SERVICE_CHARGE,
  89. EXT_BANK_BRANCH_ID,
  90. RECEIVER_IDENTITY_TYPE,
  91. RECEIVER_IDENTITY_NUMBER,
  92. BANK_NAME,
  93. BANK_BRANCH_NAME,
  94. PAYOUT_AGENT_ID,
  95. REQUESTED_DATE
  96. )
  97. SELECT
  98. @USER_ID,
  99. @PASSWORD,
  100. @AGENT_SESSION_ID,
  101. @AGENT_TXNID,
  102. @LOCATION_ID,
  103. @SENDER_NAME,
  104. ----@SENDER_GENDER,
  105. @SENDER_ADDRESS,
  106. @SENDER_MOBILE,
  107. @SENDER_CITY,
  108. @SENDER_COUNTRY,
  109. @SENDER_ID_TYPE,
  110. @SENDER_ID_NUMBER,
  111. @SENDER_ID_ISSUE_DATE,
  112. @SENDER_ID_EXPIRE_DATE,
  113. @SENDER_DATE_OF_BIRTH,
  114. @RECEIVER_NAME,
  115. @RECEIVER_ADDRESS,
  116. @RECEIVER_CONTACT_NUMBER,
  117. @RECEIVER_CITY,
  118. @RECEIVER_COUNTRY,
  119. @TRANSFERAMOUNT,
  120. @PAYMENTMODE,
  121. @BANKID,
  122. @BANK_ACCOUNT_NUMBER,
  123. @CALC_BY,
  124. NULL,--@AUTHORIZED_REQUIRED,
  125. @OUR_SERVICE_CHARGE,
  126. @EXT_BANK_BRANCH_ID,
  127. @RECEIVER_IDENTITY_TYPE,
  128. @RECEIVER_IDENTITY_NUMBER,
  129. @BANK_NAME,
  130. @BANK_BRANCH_NAME,
  131. @PAYOUT_AGENT_ID,
  132. GETDATE()
  133. SET @apiRequestId = SCOPE_IDENTITY()
  134. IF @CALC_BY = 'C' SET @CALC_BY = 'S'
  135. SET @SENDER_NAME = UPPER(@SENDER_NAME)
  136. SET @RECEIVER_NAME = UPPER(@RECEIVER_NAME)
  137. DECLARE @controlNo VARCHAR(50),@tranId INT
  138. DECLARE
  139. @sCountryId INT,@sCountry VARCHAR(50),@collCurr VARCHAR(3), @sSuperAgent INT,@sSuperAgentName VARCHAR(200),@pBankName VARCHAR(200)
  140. ,@sAgent INT ,@sAgentName VARCHAR(200), @sBranch INT,@sBranchName VARCHAR(200),@deliveryMethod VARCHAR(100), @deliveryMethodId INT
  141. ,@pCountryId INT,@pCurr VARCHAR(3)
  142. ,@pSuperAgent INT,@pSuperAgentName VARCHAR(200), @pAgent INT,@pAgentName VARCHAR(200), @pBranch INT,@pBranchName VARCHAR(200)
  143. ,@pBankBranchName VARCHAR(200)
  144. ,@EXTERNALCODE VARCHAR(200)
  145. ,@agentApiType INT, @isItalianAgent BIT = 0, @isUAEAgent BIT = 0
  146. DECLARE @errorTable TABLE(
  147. AGENT_REFID VARCHAR(150), REFID VARCHAR(50), AGENT_TXNID INT, COLLECT_AMT MONEY, COLLECT_CURRENCY VARCHAR(3), EXRATE MONEY
  148. ,SERVICE_CHARGE MONEY, PAYOUTAMT MONEY, PAYOUTCURRENCY VARCHAR(3), TXN_DATE VARCHAR(10)
  149. )
  150. --SELECT @agentApiType = agentApiType FROM agentMaster WITH(NOLOCK) WHERE agentCode = @AGENT_CODE
  151. INSERT INTO @errorTable(AGENT_REFID)
  152. SELECT @AGENT_SESSION_ID
  153. DECLARE @errCode INT, @pBankBranch INT, @autMsg VARCHAR(500), @errorCode VARCHAR(10), @errorMsg VARCHAR(MAX)
  154. EXEC ws_int_proc_checkAuthntication @USER_ID,@PASSWORD,@AGENT_CODE,@errCode OUT, @autMsg OUT
  155. IF (@errCode = 1 )
  156. BEGIN
  157. SELECT @errorCode = '1002', @errorMsg = ISNULL(@autMsg, 'Authentication Fail')
  158. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  159. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  160. RETURN
  161. END
  162. IF EXISTS(SELECT 'X' FROM applicationUsers WITH(NOLOCK) WHERE userName = @USER_ID AND forceChangePwd = 'Y')
  163. BEGIN
  164. SELECT @errorCode = '1002', @errorMsg = 'You logged on first time,must first change your password and try again!'
  165. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  166. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  167. RETURN
  168. END
  169. -->>------------------VALIDATION-------------------------------
  170. IF @AGENT_SESSION_ID IS NULL
  171. BEGIN
  172. SELECT @errorCode = '1001', @errorMsg = 'AGENT SESSION ID Field is Empty'
  173. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  174. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  175. RETURN
  176. END
  177. IF @SENDER_NAME IS NULL
  178. BEGIN
  179. SELECT @errorCode = '1001', @errorMsg = 'SENDER NAME Field is Empty'
  180. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  181. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  182. RETURN
  183. END
  184. IF @SENDER_ADDRESS IS NULL
  185. BEGIN
  186. SELECT @errorCode = '1001', @errorMsg = 'SENDER ADDRESS Field is Empty'
  187. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  188. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  189. RETURN
  190. END
  191. IF @SENDER_CITY IS NULL
  192. BEGIN
  193. SELECT @errorCode = '1001', @errorMsg = 'SENDER CITY Field is Empty'
  194. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  195. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  196. RETURN
  197. END
  198. IF @SENDER_COUNTRY IS NULL
  199. BEGIN
  200. SELECT @errorCode = '1001', @errorMsg = 'SENDER COUNTRY Field is Empty'
  201. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  202. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  203. RETURN
  204. END
  205. IF @SENDER_ID_TYPE IS NULL
  206. BEGIN
  207. SELECT @errorCode = '1001', @errorMsg = 'SENDER ID TYPE Field is Empty'
  208. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  209. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  210. RETURN
  211. END
  212. IF @SENDER_ID_NUMBER IS NULL
  213. BEGIN
  214. SELECT @errorCode = '1001', @errorMsg = 'SENDER ID NUMBER Field is Empty'
  215. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  216. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  217. RETURN
  218. END
  219. IF @RECEIVER_NAME IS NULL
  220. BEGIN
  221. SELECT @errorCode = '1001', @errorMsg = 'RECEIVER NAME Field is Empty'
  222. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  223. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  224. RETURN
  225. END
  226. IF @RECEIVER_ADDRESS IS NULL
  227. BEGIN
  228. SELECT @errorCode = '1001', @errorMsg = 'RECEIVER ADDRESS Field is Empty'
  229. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  230. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  231. RETURN
  232. END
  233. IF @RECEIVER_COUNTRY IS NULL
  234. BEGIN
  235. SELECT @errorCode = '1001', @errorMsg = 'RECEIVER COUNTRY Field is Empty'
  236. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  237. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  238. RETURN
  239. END
  240. IF @TRANSFERAMOUNT IS NULL
  241. BEGIN
  242. SELECT @errorCode = '1001', @errorMsg = 'TRANSFER AMOUNT Field is Empty'
  243. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  244. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  245. RETURN
  246. END
  247. IF ISNUMERIC(@TRANSFERAMOUNT) = 0 AND @TRANSFERAMOUNT IS NOT NULL
  248. BEGIN
  249. SELECT @errorCode = '9001', @errorMsg = 'Technical Error: TRANSFER AMOUNT must be numeric'
  250. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  251. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  252. RETURN
  253. END
  254. IF ISNUMERIC(@LOCATION_ID) = 0 AND @LOCATION_ID IS NOT NULL
  255. BEGIN
  256. SELECT @errorCode = '9001', @errorMsg = 'Technical Error: LOCATION ID must be numeric'
  257. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  258. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  259. RETURN
  260. END
  261. --IF ISNUMERIC(@BANKID) = 0 AND @BANKID IS NOT NULL
  262. --BEGIN
  263. -- SELECT 9001 CODE, 'Technical Error: BANK ID must be numeric' MESSAGE, * FROM @errorTable
  264. -- RETURN
  265. --END
  266. IF ISDATE(@SENDER_DATE_OF_BIRTH) = 0 AND @SENDER_DATE_OF_BIRTH IS NOT NULL
  267. BEGIN
  268. SELECT @errorCode = '9001', @errorMsg = 'Technical Error: DOB must be date'
  269. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  270. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  271. RETURN
  272. END
  273. IF ISDATE(@SENDER_ID_EXPIRE_DATE) = 0 AND @SENDER_ID_EXPIRE_DATE IS NOT NULL
  274. BEGIN
  275. SELECT @errorCode = '9001', @errorMsg = 'Technical Error: ID expiry date must be date'
  276. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  277. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  278. RETURN
  279. END
  280. IF ISDATE(@SENDER_ID_ISSUE_DATE) = 0 AND @SENDER_ID_ISSUE_DATE IS NOT NULL
  281. BEGIN
  282. SELECT @errorCode = '9001', @errorMsg = 'Technical Error: ID issue date must be date'
  283. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  284. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  285. RETURN
  286. END
  287. IF DATEDIFF(D,@SENDER_ID_ISSUE_DATE,@SENDER_ID_EXPIRE_DATE)<0
  288. BEGIN
  289. SELECT @errorCode = '9001', @errorMsg = 'Technical Error: ID expiry date must be more than issue date'
  290. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  291. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  292. RETURN
  293. END
  294. IF @PAYMENTMODE IS NULL
  295. BEGIN
  296. SELECT @errorCode = '1001', @errorMsg = 'PAYMETHOD Field is Empty'
  297. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  298. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  299. RETURN
  300. END
  301. IF @CALC_BY IS NULL
  302. BEGIN
  303. SELECT @errorCode = '1001', @errorMsg = 'CALC BY Field is Empty'
  304. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  305. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  306. RETURN
  307. END
  308. IF @PAYMENTMODE NOT IN('C','B','CP', 'BP')
  309. BEGIN
  310. SELECT @errorCode = '3001', @errorMsg = 'Invalid Payment Type, Must be C - Cash Pickup B - Bank Deposit.'
  311. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  312. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  313. RETURN
  314. END
  315. DECLARE @promotionFlag CHAR(1)
  316. SET @promotionFlag = RIGHT(@PAYMENTMODE, 1)
  317. IF LEN(@PAYMENTMODE) > 1
  318. SET @PAYMENTMODE = LEFT(@PAYMENTMODE, LEN(@PAYMENTMODE) - 1)
  319. IF @CALC_BY NOT IN('S','P')
  320. BEGIN
  321. SELECT @errorCode = '1004', @errorMsg = 'Invalid Parameter CALC BY'
  322. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  323. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  324. RETURN
  325. END
  326. -->>Get Sending Agent Details
  327. SELECT @sCountryId = countryId, @sBranch = agentId FROM applicationUsers WITH (NOLOCK) WHERE userName = @USER_ID
  328. SELECT TOP 1 @collCurr = CM.currencyCode,@sCountry = C.countryName FROM countryCurrency CC WITH (NOLOCK)
  329. INNER JOIN countryMaster C WITH(NOLOCK ) ON C.countryId = CC.countryId
  330. INNER JOIN currencyMaster CM WITH(NOLOCK) ON CC.currencyId = CM.currencyId
  331. WHERE CC.countryId = @sCountryId AND ISNULL(Cc.isDeleted,'N') = 'N'
  332. -- DECLARE
  333. -- @pBank INT,@pBankBranch INT
  334. -- ,@pBankType CHAR(1)
  335. -- ,@pBankCountry VARCHAR(100) = 'Nepal'
  336. -- ,@EXTERNALCODE VARCHAR(50)
  337. --SELECT
  338. -- --@pAgent = 1251
  339. -- --,@pAgentName = 'International Money Express( IME) - HO'
  340. -- @pSuperAgent = 1002
  341. -- ,@pSuperAgentName = 'International Money Express (IME) Pvt. Ltd'
  342. -- ,@pCountryId = 151
  343. -- --,@pCurr = 'NPR'
  344. --IF @PAYMENTTYPE = 'B'
  345. --BEGIN
  346. -- SELECT TOP 1
  347. -- @pBank = extBankId, @pBankName = bankName, @EXTERNALCODE = externalCode
  348. -- FROM externalBank WITH(NOLOCK)
  349. -- WHERE routingCode = @BANKID AND ISNULL(isDeleted, 'N') = 'N'
  350. -- SELECT
  351. -- @pBankName = ISNULL(@pBankName, @BANK_NAME)
  352. -- ,@pBankBranchName = @BANK_BRANCH_NAME
  353. -- ,@pBankType = 'E'
  354. -- -->>Validate BANK_ID only for Bank Transfer and Account Deposit
  355. -- IF @pBank IS NULL
  356. -- BEGIN
  357. -- SELECT '102' CODE, 'Invalid BANK ID' MESSAGE, * FROM @errorTable
  358. -- RETURN
  359. -- END
  360. --END
  361. SELECT @sAgent = parentId,@sBranchName = agentName FROM agentMaster WITH (NOLOCK) WHERE agentId = @sBranch AND ISNULL(isActive,'N')='Y'
  362. SELECT @sSuperAgent = parentId,@sAgentName = agentName FROM agentMaster WITH (NOLOCK) WHERE agentId = @sAgent AND ISNULL(isActive,'N')='Y'
  363. SELECT @sSuperAgentName = agentName FROM agentMaster WITH (NOLOCK) WHERE agentId = @sSuperAgent AND ISNULL(isActive,'N') = 'Y'
  364. --<<End of Get Sending Agent Details
  365. -->>Get Payout Agent Details--
  366. DECLARE @pBank INT, @pBankType CHAR(1), @pBankCountry VARCHAR(100)
  367. -->>Validate LOCATION_ID. IF LOCATION_ID is bankId then find head office Id
  368. DECLARE @agentType INT, @locationCountry VARCHAR(100), @isHeadOffice CHAR(1)
  369. IF @PAYMENTMODE = 'B'
  370. BEGIN
  371. DECLARE @parentMapCode VARCHAR(10)
  372. SELECT TOP 1 @parentMapCode = pam.mapCodeInt, @pBankBranchName = am.agentName FROM agentMaster am WITH(NOLOCK)
  373. INNER JOIN agentMaster pam WITH(NOLOCK) ON am.parentId = pam.agentId
  374. WHERE am.mapCodeInt = @BANKID
  375. SELECT TOP 1
  376. @pBank = extBankId, @pBankName = bankName, @EXTERNALCODE = externalCode
  377. FROM externalBank WITH(NOLOCK)
  378. WHERE mapCodeInt = @parentMapCode AND ISNULL(isDeleted, 'N') = 'N'
  379. --SET @pBankBranchName = @BANK_BRANCH_NAME
  380. --SELECT @pAgent = 1004, @pAgentName = 'IME Nepal',
  381. SET @pBankType = 'E'
  382. IF @pBank IS NULL
  383. BEGIN
  384. SELECT @pBank = extBankId, @pBankBranch = extBranchId, @pBankBranchName = branchName FROM externalBankBranch WITH(NOLOCK) WHERE extBranchId = @BANKID
  385. SELECT @pBankName = bankName, @EXTERNALCODE = externalCode FROM externalBank WITH(NOLOCK) WHERE extBankId = @pBank
  386. END
  387. IF @pBank IS NULL
  388. BEGIN
  389. SELECT @errorCode = '1001', @errorMsg = 'Invalid BANK ID'
  390. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  391. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  392. RETURN
  393. END
  394. END
  395. DECLARE @currDecimal INT
  396. SELECT @pCountryId = countryId FROM countryMaster WITH(NOLOCK) WHERE countryName = @RECEIVER_COUNTRY
  397. SELECT TOP 1 @pCurr = CM.currencyCode, @currDecimal = CM.countAfterDecimal FROM countryCurrency CC WITH(NOLOCK)
  398. INNER JOIN currencyMaster CM WITH(NOLOCK) ON CC.currencyId = CM.currencyId
  399. WHERE CC.countryId = @pCountryId AND ISNULL(cc.isDeleted, 'N') = 'N'
  400. IF @pCurr IS NULL
  401. BEGIN
  402. SELECT @errorCode = '3008', @errorMsg = 'You are not allowed to send to country ' + @RECEIVER_COUNTRY
  403. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  404. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  405. RETURN
  406. END
  407. --<<End of Get Payout Agent Details
  408. -------------------END ----------------------------------
  409. -->>Manage Payment Type
  410. SELECT
  411. @deliveryMethodId = serviceTypeId, @deliveryMethod = typeTitle
  412. FROM serviceTypeMaster WITH(NOLOCK)
  413. WHERE ISNULL(isDeleted,'N') = 'N'
  414. AND typeTitle = CASE WHEN @PAYMENTMODE = 'C' THEN 'CASH PAYMENT'
  415. WHEN @PAYMENTMODE = 'B' THEN 'BANK DEPOSIT'
  416. END
  417. -->>Start:Field Validation according to setup
  418. DECLARE @errTable TABLE(errorCode VARCHAR(10), msg VARCHAR(200), id VARCHAR(10))
  419. INSERT INTO @errTable(errorCode, msg, id)
  420. EXEC proc_sendValidation
  421. @agentId = @sAgent
  422. ,@senIdType = @SENDER_ID_TYPE
  423. ,@senIdNo = @SENDER_ID_NUMBER
  424. ,@senIdValidDate = @SENDER_ID_EXPIRE_DATE
  425. ,@senDob = @SENDER_DATE_OF_BIRTH
  426. ,@senAddress = @SENDER_ADDRESS
  427. ,@senCity = @SENDER_CITY
  428. ,@senContact = @SENDER_MOBILE
  429. ,@recAddress = @RECEIVER_ADDRESS
  430. ,@recCity = @RECEIVER_CITY
  431. ,@recContact = @RECEIVER_CONTACT_NUMBER
  432. ,@paymentMethod = @deliveryMethod
  433. ,@deliveryMethodId = @deliveryMethodId
  434. ,@pBank = @pBank
  435. ,@pBankBranchName = @pBankBranchName
  436. ,@accountNo = @BANK_ACCOUNT_NUMBER
  437. ,@pAgent = @pAgent
  438. ,@pBankType = @pBankType
  439. ,@pCountryId = @pCountryId
  440. ,@sCountryId = @sCountryId
  441. IF NOT EXISTS(SELECT 'X' FROM @errTable WHERE errorCode = '0')
  442. BEGIN
  443. DECLARE @msg VARCHAR(200)
  444. SELECT @msg = msg FROM @errTable
  445. SELECT @errorCode = '1001', @errorMsg = @msg
  446. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  447. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  448. RETURN
  449. END
  450. --<<End:Field Validation according to Setup
  451. DECLARE @collMode VARCHAR(20),@iCollDetailAmt MONEY
  452. SET @collMode = 'Cash'
  453. DECLARE @iServiceCharge MONEY,@tAmt MONEY,@pAmt MONEY,@cAmt MONEY
  454. DECLARE @rowId INT, @place INT
  455. -->>Find Decimal Mask for payout amount rounding
  456. SELECT @place = place, @currDecimal = currDecimal
  457. FROM currencyPayoutRound WHERE ISNULL(isDeleted, 'N') = 'N'
  458. AND currency = @pCurr AND tranType IS NULL
  459. -->>Start:Get Exchange Rate Details
  460. DECLARE @customerRate MONEY,@sCurrCostRate MONEY,@sCurrHoMargin MONEY,@sCurrAgentMargin MONEY,@pCurrCostRate MONEY,@pCurrHoMargin MONEY
  461. ,@pCurrAgentMargin MONEY,@agentCrossSettRate MONEY,@treasuryTolerance MONEY,@sharingValue MONEY,@sharingType CHAR(1),@customerPremium MONEY
  462. ,@sAgentComm MONEY,@sAgentCommCurrency VARCHAR(3)
  463. SELECT
  464. @customerRate = customerRate
  465. ,@sCurrCostRate = sCurrCostRate
  466. ,@sCurrHoMargin = sCurrHoMargin
  467. ,@sCurrAgentMargin = sCurrAgentMargin
  468. ,@pCurrCostRate = pCurrCostRate
  469. ,@pCurrHoMargin = pCurrHoMargin
  470. ,@pCurrAgentMargin = pCurrAgentMargin
  471. ,@agentCrossSettRate = agentCrossSettRate
  472. ,@treasuryTolerance = treasuryTolerance
  473. ,@customerPremium = customerPremium
  474. ,@sharingValue = sharingValue
  475. ,@sharingType = sharingType
  476. FROM dbo.FNAGetExRate(@sCountryId,@sAgent,@sBranch,@collCurr,@pCountryId,@pAgent,@pCurr,@deliveryMethodId)
  477. IF @customerRate IS NULL
  478. BEGIN
  479. SELECT @errorCode = '1001', @errorMsg = 'Transaction cannot be proceed. Exchange Rate not defined'
  480. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  481. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  482. RETURN
  483. END
  484. --<<End:Get Exchange Rate Details
  485. -->>Start:Get tAmt, cAmt, pAmt on the basis of CALCBY
  486. SELECT
  487. @cAmt = CASE WHEN @CALC_BY = 'S' THEN CAST(@TRANSFERAMOUNT AS MONEY) ELSE '0' END
  488. ,@pAmt = CASE WHEN @CALC_BY = 'P' THEN CAST(@TRANSFERAMOUNT AS MONEY) ELSE '0' END
  489. DECLARE @scDiscount MONEY
  490. IF ISNULL(@cAmt, 0.00) <> 0.00 AND @CALC_BY = 'S'
  491. BEGIN
  492. SELECT @iServiceCharge = amount FROM [dbo].FNAGetServiceCharge(
  493. @sCountryId, @sSuperAgent, @sAgent, @sBranch
  494. ,@pCountryId, NULL, @pAgent, NULL
  495. ,@deliveryMethodId, @cAmt, @collCurr
  496. )
  497. IF @iServiceCharge IS NULL
  498. BEGIN
  499. SELECT @errorCode = '1001', @errorMsg = 'Service Charge Not Defined for Receiving Country'
  500. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  501. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  502. RETURN;
  503. END
  504. IF @promotionFlag = 'P'
  505. SET @iServiceCharge = 0
  506. --IF @pCountryId = 151
  507. --BEGIN
  508. -- SET @scDiscount = @iServiceCharge
  509. -- SET @iServiceCharge = 0
  510. --END
  511. SET @tAmt = @cAmt - @iServiceCharge
  512. SET @pAmt = (@tAmt) * (@customerRate)
  513. SET @currDecimal = ISNULL(@currDecimal, 0)
  514. IF @currDecimal IS NOT NULL
  515. BEGIN
  516. SET @pAmt = ROUND(@pAmt, @currDecimal, 1)
  517. END
  518. ELSE IF @place IS NOT NULL
  519. BEGIN
  520. SET @pAmt = ROUND(@pAmt, -@place, 1)
  521. END
  522. END
  523. ELSE
  524. BEGIN
  525. SET @tAmt = @pAmt/(@customerRate)
  526. SELECT @iServiceCharge = amount FROM [dbo].FNAGetServiceCharge(
  527. @sCountryId, NULL, @sAgent, NULL
  528. ,@pCountryId, NULL, @pAgent, NULL
  529. ,@deliveryMethodId, @tAmt, @collCurr
  530. )
  531. IF @iServiceCharge IS NULL
  532. BEGIN
  533. SELECT @errorCode = '1001', @errorMsg = 'Service Charge Not Defined for Receiving Country'
  534. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  535. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  536. RETURN;
  537. END
  538. IF @promotionFlag = 'P'
  539. SET @iServiceCharge = 0
  540. --IF @pCountryId = 151
  541. --BEGIN
  542. -- SET @scDiscount = @iServiceCharge
  543. -- SET @iServiceCharge = 0
  544. --END
  545. SET @cAmt = (@tAmt + @iServiceCharge)
  546. END
  547. IF @iServiceCharge > @cAmt
  548. BEGIN
  549. SELECT @errorCode = '3009', @errorMsg = 'Sent Amount must be more than Service Charge'
  550. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  551. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  552. RETURN;
  553. END
  554. --<<End:Get tAmt, cAmt, pAmt on the basis of CALCBY
  555. -->>Start:Commission Calculation
  556. DECLARE @sSettlementRate FLOAT, @pSettlementRate FLOAT,@tellerBalance MONEY
  557. SET @sSettlementRate = @sCurrCostRate + @sCurrHoMargin
  558. SET @pSettlementRate = @pCurrCostRate - @pCurrHoMargin
  559. SELECT @sAgentComm = amount, @sAgentCommCurrency = commissionCurrency FROM dbo.FNAGetSendComm(
  560. @sCountryId, @sSuperAgent, @sAgent, @sBranch,
  561. @pCountryId, @pSuperAgent, @pAgent, @pBranch,
  562. @collCurr, @deliveryMethodId, @cAmt, @pAmt, @iServiceCharge, NULL, NULL,
  563. @sSettlementRate, @pSettlementRate)
  564. --<<End:Commission Calculation
  565. -->>Start:Verify Agent Send Per Txn
  566. IF EXISTS(SELECT 'X' FROM sendTranLimit
  567. WHERE agentId = @sAgent
  568. AND ISNULL(receivingCountry, ISNULL(@pCountryId, 0)) = ISNULL(@pCountryId, 0)
  569. AND ISNULL(tranType, ISNULL(@deliveryMethodId, 0)) = ISNULL(@deliveryMethodId, 0)
  570. AND currency = @collCurr AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  571. )
  572. BEGIN
  573. IF EXISTS(SELECT 'X' FROM sendTranLimit WITH(NOLOCK) WHERE agentId = @sAgent AND receivingCountry = @pCountryId
  574. AND tranType = @deliveryMethodId AND currency = @collCurr
  575. AND @cAmt < minLimitAmt
  576. AND @cAmt > maxLimitAmt
  577. AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N')
  578. BEGIN
  579. SELECT @errorCode = '3012', @errorMsg = 'Partner Balance Exceed, Cannot Make a TXN'
  580. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  581. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  582. RETURN
  583. END
  584. IF EXISTS(SELECT 'X' FROM sendTranLimit WITH(NOLOCK) WHERE agentId = @sAgent AND receivingCountry = @pCountryId
  585. AND tranType IS NULL AND currency = @collCurr
  586. AND @cAmt < minLimitAmt
  587. AND @cAmt > maxLimitAmt
  588. AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N')
  589. BEGIN
  590. SELECT @errorCode = '3012', @errorMsg = 'Partner Balance Exceed, Cannot Make a TXN'
  591. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  592. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  593. RETURN
  594. END
  595. IF EXISTS(SELECT 'X' FROM sendTranLimit WITH(NOLOCK) WHERE agentId IS NULL AND receivingCountry = @pCountryId
  596. AND tranType = @deliveryMethodId AND currency = @collCurr
  597. AND @cAmt < minLimitAmt
  598. AND @cAmt > maxLimitAmt
  599. AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N')
  600. BEGIN
  601. SELECT @errorCode = '3012', @errorMsg = 'Partner Balance Exceed, Cannot Make a TXN'
  602. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  603. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  604. RETURN
  605. END
  606. IF EXISTS(SELECT 'X' FROM sendTranLimit WITH(NOLOCK) WHERE agentId = @sAgent AND receivingCountry = @pCountryId
  607. AND tranType IS NULL AND currency = @collCurr
  608. AND @cAmt < minLimitAmt
  609. AND @cAmt > maxLimitAmt
  610. AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N')
  611. BEGIN
  612. SELECT @errorCode = '3012', @errorMsg = 'Partner Balance Exceed, Cannot Make a TXN'
  613. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  614. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  615. RETURN
  616. END
  617. END
  618. --<<End:Verify Agent Send Per Txn
  619. -->>Start:Verify Payout Per Txn Limit
  620. IF EXISTS(SELECT 'X' FROM receiveTranLimit WITH(NOLOCK) WHERE ISNULL(sendingCountry, ISNULL(@sCountryId, 0)) = ISNULL(@sCountryId, 0)
  621. AND countryId = @pCountryId AND agentId = @pAgent AND currency = @pCurr
  622. AND ISNULL(tranType, ISNULL(@deliveryMethodId, 0)) = ISNULL(@deliveryMethodId, 0)
  623. AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  624. )
  625. BEGIN
  626. IF EXISTS(SELECT 'X' FROM receiveTranLimit WITH(NOLOCK)
  627. WHERE sendingCountry = @sCountryId AND countryId = @pCountryId AND agentId = @pAgent AND currency = @pCurr
  628. AND tranType = @deliveryMethodId AND @pAmt > maxLimitAmt AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  629. )
  630. BEGIN
  631. SELECT @errorCode = '3011', @errorMsg = 'Payout Amount Limit Exceed'
  632. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  633. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  634. RETURN
  635. END
  636. IF EXISTS(SELECT 'X' FROM receiveTranLimit WITH(NOLOCK)
  637. WHERE sendingCountry = @sCountryId AND countryId = @pCountryId AND agentId = @pAgent AND currency = @pCurr
  638. AND tranType IS NULL AND @pAmt > maxLimitAmt AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  639. )
  640. BEGIN
  641. SELECT @errorCode = '3011', @errorMsg = 'Payout Amount Limit Exceed'
  642. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  643. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  644. RETURN
  645. END
  646. IF EXISTS(SELECT 'X' FROM receiveTranLimit WITH(NOLOCK)
  647. WHERE sendingCountry IS NULL AND countryId = @pCountryId AND agentId = @pAgent AND currency = @pCurr
  648. AND tranType = @deliveryMethodId AND @pAmt > maxLimitAmt AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  649. )
  650. BEGIN
  651. SELECT @errorCode = '3011', @errorMsg = 'Payout Amount Limit Exceed'
  652. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  653. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  654. RETURN
  655. END
  656. IF EXISTS(SELECT 'X' FROM receiveTranLimit WITH(NOLOCK)
  657. WHERE sendingCountry IS NULL AND countryId = @pCountryId AND agentId = @pAgent AND currency = @pCurr
  658. AND tranType IS NULL AND @pAmt > maxLimitAmt AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  659. )
  660. BEGIN
  661. SELECT @errorCode = '3011', @errorMsg = 'Payout Amount Limit Exceed'
  662. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  663. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  664. RETURN
  665. END
  666. END
  667. IF NOT EXISTS(SELECT 'X' FROM receiveTranLimit WITH(NOLOCK)
  668. WHERE ISNULL(sendingCountry, ISNULL(@sCountryId, 0)) = ISNULL(@sCountryId, 0)
  669. AND agentId IS NULL AND countryId = @pCountryId AND currency = @pCurr
  670. AND ISNULL(tranType, ISNULL(@deliveryMethodId, 0)) = ISNULL(@deliveryMethodId, 0)
  671. AND maxLimitAmt >= @pAmt AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  672. )
  673. BEGIN
  674. SELECT @errorCode = '3011', @errorMsg = 'Payout Amount Limit Exceed'
  675. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  676. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  677. RETURN
  678. END
  679. -->>End:Verify Payout Per Txn Limit
  680. IF EXISTS(SELECT TOP 1 'X' FROM thirdPartyAgentTxnIdV2 WITH(NOLOCK) WHERE agentTxnId = @AGENT_SESSION_ID AND agentId = @sAgent)
  681. BEGIN
  682. SELECT TOP 1 @controlNo = controlNo FROM remitTran (NOLOCK) WHERE controlNo2 = @AGENT_SESSION_ID AND createdBy = 'kodhead123'
  683. SELECT @errorCode = '1001', @errorMsg = 'Duplicate Ref ID : ' + @AGENT_SESSION_ID + '; ICN : ' + dbo.FNADecryptString(@controlNo)
  684. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  685. SELECT TOP 1 @errorCode CODE
  686. ,MESSAGE = @errorMsg
  687. ,AGENT_REFID = @AGENT_SESSION_ID
  688. ,REFID = dbo.FNADecryptString(@controlNo)
  689. ,AGENT_TXNID = 1
  690. ,COLLECT_AMT = cAmt
  691. ,COLLECT_CURRENCY = collCurr
  692. ,EXRATE = customerRate
  693. ,SERVICE_CHARGE = serviceCharge
  694. ,PAYOUTAMT = pAmt
  695. ,PAYOUTCURRENCY = payoutCurr
  696. ,TXN_DATE = createdDate
  697. FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNo
  698. RETURN
  699. END
  700. -->>Start:Get Data Compliance for Compliance Checking and suspicious duplicate txn
  701. DECLARE @today VARCHAR(10) = CONVERT(VARCHAR, dbo.FNADateFormatTZ(GETDATE(), @USER_ID), 101)
  702. DECLARE @remitTranTemp TABLE(tranId BIGINT, controlNo VARCHAR(20), controlNo2 VARCHAR(50), cAmt MONEY, receiverName VARCHAR(200), receiverIdType VARCHAR(100), receiverIdNumber VARCHAR(50), dot DATETIME)
  703. INSERT INTO @remitTranTemp(tranId, controlNo, controlNo2, cAmt, receiverName, receiverIdType, receiverIdNumber, dot)
  704. SELECT rt.id, rt.controlNo, rt.controlNo2, rt.cAmt, rt.receiverName, rec.idType, rec.idNumber, rt.createdDate
  705. FROM vwRemitTran rt WITH(NOLOCK)
  706. INNER JOIN vwTranSenders sen WITH(NOLOCK) ON rt.id = sen.tranId
  707. INNER JOIN vwTranReceivers rec WITH(NOLOCK) ON rt.id = rec.tranId
  708. WHERE sen.idNumber = @SENDER_ID_NUMBER
  709. AND tranStatus <> 'CancelRequest' AND tranStatus <> 'Cancel'
  710. AND (rt.approvedDate BETWEEN @today AND @today + ' 23:59:59'
  711. OR (approvedBy IS NULL AND cancelApprovedBy IS NULL))
  712. IF EXISTS(SELECT 'X' FROM @remitTranTemp WHERE cAmt = @cAmt
  713. AND (receiverName = @RECEIVER_NAME)
  714. AND DATEDIFF(MI, dot, dbo.FNADateFormatTZ(GETDATE(), @USER_ID)) <= 2
  715. )
  716. BEGIN
  717. SELECT @errorCode = '1001', @errorMsg = 'Similar transaction found'
  718. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  719. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  720. RETURN
  721. END
  722. --<<End:Get Data Compliance for Compliance Checking and suspicious duplicate txn
  723. DECLARE @agentFxGain FLOAT
  724. SET @agentFxGain = (@tAmt * (@agentCrossSettRate - @customerRate))/@agentCrossSettRate
  725. -->>Start:OFAC/Compliance Checking
  726. DECLARE @receiverOfacRes VARCHAR(MAX),@ofacRes VARCHAR(MAX),@ofacReason VARCHAR(MAX)
  727. EXEC proc_ofacTracker @flag = 't', @name = @SENDER_NAME, @Result = @ofacRes OUTPUT
  728. EXEC proc_ofacTracker @flag = 't', @name = @RECEIVER_NAME, @Result = @receiverOfacRes OUTPUT
  729. DECLARE @result VARCHAR(MAX)
  730. DECLARE @csMasterId INT, @complianceRes VARCHAR(20), @totalRows INT, @count INT, @compFinalRes VARCHAR(20)
  731. DECLARE @csMasterRec TABLE (rowId INT IDENTITY(1,1), masterId INT)
  732. IF ISNULL(@ofacRes, '') <> ''
  733. BEGIN
  734. SET @ofacReason = 'Matched by sender name'
  735. END
  736. IF ISNULL(@receiverOfacRes, '') <> ''
  737. BEGIN
  738. SET @ofacRes = ISNULL(@ofacRes + ',' + @receiverOfacRes, '' + @receiverOfacRes)
  739. SET @ofacReason = 'Matched by receiver name'
  740. END
  741. IF ISNULL(@ofacRes, '') <> '' AND ISNULL(@receiverOfacRes, '') <> ''
  742. BEGIN
  743. SET @ofacReason = 'Matched by both sender name and receiver name'
  744. END
  745. --INSERT @csMasterRec(masterId)
  746. --SELECT masterId FROM dbo.FNAGetComplianceRuleMaster(@sBranch, @pCountryId, NULL, @pBranch, NULL, NULL, NULL)
  747. --SELECT @totalRows = COUNT(*) FROM @csMasterRec
  748. --IF EXISTS(SELECT 'X' FROM @csMasterRec)
  749. --BEGIN
  750. -- SET @count = 1
  751. -- WHILE(@count <= @totalRows)
  752. -- BEGIN
  753. -- SELECT @csMasterId = masterId FROM @csMasterRec WHERE rowId = @count
  754. -- EXEC proc_complianceRuleDetail
  755. -- @user = @USER_ID
  756. -- ,@tranId = @tranId
  757. -- ,@tAmt = @tAmt
  758. -- ,@senId = NULL
  759. -- ,@benId = NULL
  760. -- ,@beneficiaryName = @RECEIVER_NAME
  761. -- ,@beneficiaryMobile = @RECEIVER_CONTACT_NUMBER
  762. -- ,@benAccountNo = @BANK_ACCOUNT_NUMBER
  763. -- ,@masterId = @csMasterId
  764. -- ,@paymentMethod = @deliveryMethodId
  765. -- ,@checkingFor = 'v'
  766. -- ,@agentRefId = @AGENT_TXNID
  767. -- ,@result = @complianceRes OUTPUT
  768. -- ,@senderId = @SENDER_ID_NUMBER
  769. -- ,@senderName = @SENDER_NAME
  770. -- ,@senderMobile = @SENDER_MOBILE
  771. -- SET @compFinalRes = ISNULL(@compFinalRes, '') + ISNULL(@complianceRes, '')
  772. -- SET @count = @count + 1
  773. -- END
  774. --END
  775. -->>Start:Control Number Generation
  776. SET @controlNo = '9080' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 7)
  777. IF EXISTS(SELECT 'X' FROM controlNoList WITH(NOLOCK) WHERE controlNo = @controlNo)
  778. BEGIN
  779. SET @controlNo = '9496' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 7)
  780. IF EXISTS(SELECT 'X' FROM controlNoList WITH(NOLOCK) WHERE controlNo = @controlNo)
  781. BEGIN
  782. SELECT @errorCode = '9001', @errorMsg = 'Technical error occurred. Please try again'
  783. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  784. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  785. RETURN
  786. END
  787. END
  788. SET @pAmt = ROUND(@pAmt, 0, 1)
  789. DECLARE @controlNoEncrypted VARCHAR(50)
  790. SET @controlNoEncrypted = dbo.FNAEncryptString(@controlNo)
  791. --<<End:Control Number Generation
  792. IF @PAYMENTMODE = 'B'
  793. BEGIN
  794. SELECT TOP 1 @pAgent = internalCode, @pAgentName = bankName FROM externalBank WITH(NOLOCK) WHERE extBankId = @pBank
  795. --SELECT TOP 1 @pAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pAgent
  796. SELECT @pBranchName = ISNULL(@pBankBranchName, @BANK_BRANCH_NAME)
  797. END
  798. BEGIN
  799. BEGIN TRANSACTION
  800. -->>Start:Data Insert into remitTran, tranSenders, tranReceivers
  801. INSERT INTO remitTran
  802. (
  803. controlNo
  804. ,sCurrCostRate,sCurrHoMargin,sCurrAgentMargin,sAgentSettRate
  805. ,pCurrCostRate,pCurrHoMargin,pCurrAgentMargin
  806. ,agentCrossSettRate,customerRate,treasuryTolerance,customerPremium
  807. ,sharingValue,serviceCharge, agentFxGain, handlingFee
  808. ,sAgentComm,sAgentCommCurrency,sSuperAgentComm,sSuperAgentCommCurrency
  809. ,sCountry,sSuperAgent,sSuperAgentName,sAgent,sAgentName,sBranch,sBranchName
  810. ,pCountry,pSuperAgent,pSuperAgentName,pAgent,pAgentName,pBranch,pBranchName
  811. ,paymentMethod
  812. ,pBank,pBankName,pBankBranch,pBankBranchName,pBankType
  813. ,accountNo,externalBankCode
  814. ,collMode,collCurr,tAmt,cAmt,pAmt,payoutCurr
  815. ,tranStatus,payStatus
  816. ,createdDate,createdDateLocal,createdBy
  817. ,approvedDate,approvedDateLocal,approvedBy
  818. ,tranType
  819. ,senderName,receiverName,controlNo2
  820. )
  821. SELECT
  822. @controlNoEncrypted
  823. ,@sCurrCostRate,@sCurrHoMargin,@sCurrAgentMargin,@sSettlementRate
  824. ,@pCurrCostRate,@pCurrHoMargin,@pCurrAgentMargin
  825. ,@agentCrossSettRate,@customerRate,@treasuryTolerance,@customerPremium
  826. ,@sharingValue,@iServiceCharge,@agentFxGain, ISNULL(@scDiscount, 0)
  827. ,@sAgentComm,@sAgentCommCurrency,0,@sAgentCommCurrency
  828. ,@sCountry,@sSuperAgent,@sSuperAgentName,@sAgent,@sAgentName,@sBranch,@sBranchName
  829. ,@RECEIVER_COUNTRY,@pSuperAgent,@pSuperAgentName,@pAgent,@pAgentName,@pBranch,@pBranchName
  830. ,@deliveryMethod
  831. ,@pBank,@pBankName,@pBankBranch,ISNULL(@pBankBranchName, @BANK_BRANCH_NAME),@pBankType
  832. ,@BANK_ACCOUNT_NUMBER,@EXTERNALCODE
  833. ,@collMode,@collCurr,@tAmt,@cAmt,@pAmt,@pCurr
  834. ,'Payment', 'Unpaid'
  835. ,dbo.FNADateFormatTZ(GETDATE(),@USER_ID),GETDATE(),@USER_ID
  836. ,dbo.FNADateFormatTZ(GETDATE(),@USER_ID),GETDATE(),@USER_ID
  837. ,'I'
  838. ,@SENDER_NAME,@RECEIVER_NAME,@AGENT_SESSION_ID
  839. SET @tranId = @@IDENTITY
  840. DECLARE @sFirstName VARCHAR(100),@sMiddleName VARCHAR(100),@sLastName VARCHAR(100),@sLastName2 VARCHAR(100)
  841. DECLARE @rFirstName VARCHAR(100),@rMiddleName VARCHAR(100),@rLastName VARCHAR(100),@rLastName2 VARCHAR(100)
  842. SELECT @sFirstName = firstName, @sMiddleName = middleName, @sLastName = lastName1, @sLastName2 = lastName2 FROM dbo.FNASplitName(@SENDER_NAME)
  843. SELECT @rFirstName = firstName, @rMiddleName = middleName, @rLastName = lastName1, @rLastName2 = lastName2 FROM dbo.FNASplitName(@RECEIVER_NAME)
  844. DECLARE @memberCode VARCHAR(50),@senderId INT,@sIdTypeId INT
  845. SELECT @senderId = C.customerId FROM customers C WITH (NOLOCK) INNER JOIN customerIdentity CI WITH (NOLOCK) ON C.customerId = CI.customerId
  846. INNER JOIN staticDataValue SV WITH (NOLOCK) ON CI.idType = SV.valueId WHERE SV.detailTitle = @SENDER_ID_TYPE AND CI.idNumber = @SENDER_ID_NUMBER
  847. INSERT INTO tranSenders
  848. (
  849. customerId
  850. ,gender
  851. ,tranId
  852. ,firstName,middleName,lastName1,lastName2,fullName
  853. ,country,city,address,homePhone,mobile
  854. ,idType,idNumber
  855. ,issuedDate,validDate,dob
  856. )
  857. SELECT
  858. @senderId
  859. ,@SENDER_GENDER
  860. ,@tranId
  861. ,@sFirstName,@sMiddleName,@sLastName,@sLastName2,@SENDER_NAME
  862. ,@sCountry,@SENDER_CITY,@SENDER_ADDRESS,@SENDER_MOBILE,@SENDER_MOBILE
  863. ,@SENDER_ID_TYPE,@SENDER_ID_NUMBER
  864. ,@SENDER_ID_ISSUE_DATE,@SENDER_ID_EXPIRE_DATE,@SENDER_DATE_OF_BIRTH
  865. INSERT INTO tranReceivers
  866. (
  867. tranId
  868. ,firstName,middleName,lastName1,lastName2,fullName
  869. ,city,address,homePhone,workPhone,country
  870. )
  871. SELECT
  872. @tranId
  873. ,@rFirstName,@rMiddleName,@rLastName,@rLastName2,@RECEIVER_NAME
  874. ,@RECEIVER_CITY,@RECEIVER_ADDRESS,@RECEIVER_CONTACT_NUMBER,@RECEIVER_CONTACT_NUMBER,@RECEIVER_COUNTRY
  875. -->>End:Data Insert into remitTran, tranSenders, tranReceivers
  876. INSERT INTO controlNoList(controlNo)
  877. SELECT @controlNo
  878. INSERT INTO thirdPartyAgentTxnIdV2(agentTxnId, agentId)
  879. SELECT @AGENT_SESSION_ID, @sAgent
  880. -->>Start:Verify Compliance
  881. IF EXISTS(SELECT 'X' FROM remitTranComplianceTemp WITH(NOLOCK) WHERE agentRefId = @AGENT_TXNID)
  882. BEGIN
  883. INSERT INTO remitTranCompliance(TranId, csDetailTranId, matchTranId)
  884. SELECT @tranId, csDetailTranId, matchTranId FROM remitTranComplianceTemp WITH(NOLOCK) WHERE agentRefId = @AGENT_TXNID
  885. SET @compFinalRes = 'C'
  886. END
  887. IF EXISTS(SELECT 'X' FROM @remitTranTemp WHERE dot BETWEEN CONVERT(VARCHAR, dbo.FNADateFormatTZ(GETDATE(), @USER_ID), 101) AND CONVERT(VARCHAR, dbo.FNADateFormatTZ(GETDATE(), @USER_ID), 101) + ' 23:59:59' AND cAmt = @cAmt AND (receiverName = @RECEIVER_NAME))
  888. BEGIN
  889. INSERT INTO remitTranCompliance(TranId, csDetailTranId, matchTranId, reason)
  890. SELECT @tranId, 0, tranid, 'Suspected duplicate transaction' FROM @remitTranTemp WHERE cAmt = @cAmt AND (receiverName = @RECEIVER_NAME)
  891. SET @compFinalRes = 'C'
  892. END
  893. IF(ISNULL(@compFinalRes, '') <> '' OR ISNULL(@ofacRes, '') <> '')
  894. BEGIN
  895. IF(@ofacRes <> '' AND ISNULL(@compFinalRes, '') = '')
  896. BEGIN
  897. INSERT remitTranOfac(TranId, blackListId, reason, flag)
  898. SELECT @tranId, @ofacRes, @ofacReason, dbo.FNAGetOFAC_Flag(@ofacRes)
  899. UPDATE remitTran SET
  900. tranStatus = 'OFAC'
  901. WHERE controlNo = @controlNoEncrypted
  902. END
  903. ELSE IF(@compFinalRes <> '' AND ISNULL(@ofacRes, '') = '')
  904. BEGIN
  905. UPDATE remitTran SET
  906. tranStatus = 'Compliance'
  907. WHERE controlNo = @controlNoEncrypted
  908. END
  909. ELSE IF(ISNULL(@compFinalRes, '') <> '' AND ISNULL(@ofacRes, '') <> '')
  910. BEGIN
  911. INSERT remitTranOfac(TranId, blackListId, reason, flag)
  912. SELECT @tranId, @ofacRes, @ofacReason, dbo.FNAGetOFAC_Flag(@ofacRes)
  913. UPDATE remitTran SET
  914. tranStatus = 'OFAC/Compliance'
  915. WHERE controlNo = @controlNoEncrypted
  916. END
  917. END
  918. UPDATE apiRequestLog SET
  919. errorCode = '0'
  920. ,errorMsg = 'Transaction saved successfully'
  921. ,controlNo = @controlNoEncrypted
  922. WHERE rowId = @apiRequestId
  923. IF @@TRANCOUNT > 0
  924. COMMIT TRANSACTION
  925. SELECT
  926. CODE = '0'
  927. ,AGENT_REFID = @AGENT_SESSION_ID
  928. ,MESSAGE = 'Transaction saved successfully'
  929. ,REFID = @controlNo
  930. ,AGENT_TXNID = '1'
  931. ,COLLECT_AMT = cAmt
  932. ,COLLECT_CURRENCY = collCurr
  933. ,EXRATE = customerRate
  934. ,SERVICE_CHARGE = serviceCharge
  935. ,PAYOUTAMT = pAmt
  936. ,PAYOUTCURRENCY = payoutCurr
  937. ,TXN_DATE = createdDate
  938. FROM remitTran WITH(NOLOCK)
  939. WHERE id = @tranId
  940. INSERT INTO PinQueueList(ICN)
  941. SELECT @controlNoEncrypted
  942. --IF @PAYMENTMODE = 'D'
  943. --BEGIN
  944. -- EXEC proc_transactionRouting @flag = 'update', @user = @USER_ID, @tranIds = @tranId, @pAgent = @pAgent
  945. --END
  946. END
  947. END TRY
  948. BEGIN CATCH
  949. IF @@TRANCOUNT > 0
  950. ROLLBACK TRAN
  951. SELECT @errorCode = '9001', @errorMsg = 'Technical Error : ' + ERROR_MESSAGE()
  952. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  953. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  954. INSERT INTO Logs (errorPage, errorMsg, errorDetails, createdBy, createdDate)
  955. SELECT 'API SP Error',@errorMsg MESSAGE,'ws_int_proc_SendTransaction_JP','admin', GETDATE()
  956. END CATCH
  957. GO