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.

1049 lines
85 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[ws_int_proc_SendTransaction_JP_debug] 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_debug] (
  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')
  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. IF @CALC_BY NOT IN('S','P')
  316. BEGIN
  317. SELECT @errorCode = '1004', @errorMsg = 'Invalid Parameter CALC BY'
  318. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  319. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  320. RETURN
  321. END
  322. -->>Get Sending Agent Details
  323. SELECT @sCountryId = countryId, @sBranch = agentId FROM applicationUsers WITH (NOLOCK) WHERE userName = @USER_ID
  324. SELECT TOP 1 @collCurr = CM.currencyCode,@sCountry = C.countryName FROM countryCurrency CC WITH (NOLOCK)
  325. INNER JOIN countryMaster C WITH(NOLOCK ) ON C.countryId = CC.countryId
  326. INNER JOIN currencyMaster CM WITH(NOLOCK) ON CC.currencyId = CM.currencyId
  327. WHERE CC.countryId = @sCountryId AND ISNULL(Cc.isDeleted,'N') = 'N'
  328. -- DECLARE
  329. -- @pBank INT,@pBankBranch INT
  330. -- ,@pBankType CHAR(1)
  331. -- ,@pBankCountry VARCHAR(100) = 'Nepal'
  332. -- ,@EXTERNALCODE VARCHAR(50)
  333. --SELECT
  334. -- --@pAgent = 1251
  335. -- --,@pAgentName = 'International Money Express( IME) - HO'
  336. -- @pSuperAgent = 1002
  337. -- ,@pSuperAgentName = 'International Money Express (IME) Pvt. Ltd'
  338. -- ,@pCountryId = 151
  339. -- --,@pCurr = 'NPR'
  340. --IF @PAYMENTTYPE = 'B'
  341. --BEGIN
  342. -- SELECT TOP 1
  343. -- @pBank = extBankId, @pBankName = bankName, @EXTERNALCODE = externalCode
  344. -- FROM externalBank WITH(NOLOCK)
  345. -- WHERE routingCode = @BANKID AND ISNULL(isDeleted, 'N') = 'N'
  346. -- SELECT
  347. -- @pBankName = ISNULL(@pBankName, @BANK_NAME)
  348. -- ,@pBankBranchName = @BANK_BRANCH_NAME
  349. -- ,@pBankType = 'E'
  350. -- -->>Validate BANK_ID only for Bank Transfer and Account Deposit
  351. -- IF @pBank IS NULL
  352. -- BEGIN
  353. -- SELECT '102' CODE, 'Invalid BANK ID' MESSAGE, * FROM @errorTable
  354. -- RETURN
  355. -- END
  356. --END
  357. SELECT @sAgent = parentId,@sBranchName = agentName FROM agentMaster WITH (NOLOCK) WHERE agentId = @sBranch AND ISNULL(isActive,'N')='Y'
  358. SELECT @sSuperAgent = parentId,@sAgentName = agentName FROM agentMaster WITH (NOLOCK) WHERE agentId = @sAgent AND ISNULL(isActive,'N')='Y'
  359. SELECT @sSuperAgentName = agentName FROM agentMaster WITH (NOLOCK) WHERE agentId = @sSuperAgent AND ISNULL(isActive,'N') = 'Y'
  360. --<<End of Get Sending Agent Details
  361. -->>Get Payout Agent Details--
  362. DECLARE @pBank INT, @pBankType CHAR(1), @pBankCountry VARCHAR(100)
  363. -->>Validate LOCATION_ID. IF LOCATION_ID is bankId then find head office Id
  364. DECLARE @agentType INT, @locationCountry VARCHAR(100), @isHeadOffice CHAR(1)
  365. IF @PAYMENTMODE = 'B'
  366. BEGIN
  367. DECLARE @parentMapCode VARCHAR(10)
  368. SELECT TOP 1 @parentMapCode = pam.mapCodeInt, @pBankBranchName = am.agentName FROM agentMaster am WITH(NOLOCK)
  369. INNER JOIN agentMaster pam WITH(NOLOCK) ON am.parentId = pam.agentId
  370. WHERE am.mapCodeInt = @BANKID
  371. SELECT TOP 1
  372. @pBank = extBankId, @pBankName = bankName, @EXTERNALCODE = externalCode
  373. FROM externalBank WITH(NOLOCK)
  374. WHERE mapCodeInt = @parentMapCode AND ISNULL(isDeleted, 'N') = 'N'
  375. --SET @pBankBranchName = @BANK_BRANCH_NAME
  376. --SELECT @pAgent = 1004, @pAgentName = 'IME Nepal',
  377. SET @pBankType = 'E'
  378. IF @pBank IS NULL
  379. BEGIN
  380. SELECT @pBank = extBankId, @pBankBranch = extBranchId, @pBankBranchName = branchName FROM externalBankBranch WITH(NOLOCK) WHERE extBranchId = @BANKID
  381. SELECT @pBankName = bankName, @EXTERNALCODE = externalCode FROM externalBank WITH(NOLOCK) WHERE extBankId = @pBank
  382. END
  383. IF @pBank IS NULL
  384. BEGIN
  385. SELECT @errorCode = '1001', @errorMsg = 'Invalid BANK ID'
  386. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  387. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  388. RETURN
  389. END
  390. END
  391. SELECT @pBank, @pBankName, @pBankBranch, @pBankBranchName, @externalCode
  392. RETURN
  393. DECLARE @currDecimal INT
  394. SELECT @pCountryId = countryId FROM countryMaster WITH(NOLOCK) WHERE countryName = @RECEIVER_COUNTRY
  395. SELECT TOP 1 @pCurr = CM.currencyCode, @currDecimal = CM.countAfterDecimal FROM countryCurrency CC WITH(NOLOCK)
  396. INNER JOIN currencyMaster CM WITH(NOLOCK) ON CC.currencyId = CM.currencyId
  397. WHERE CC.countryId = @pCountryId AND ISNULL(cc.isDeleted, 'N') = 'N'
  398. IF @pCurr IS NULL
  399. BEGIN
  400. SELECT @errorCode = '3008', @errorMsg = 'You are not allowed to send to country ' + @RECEIVER_COUNTRY
  401. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  402. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  403. RETURN
  404. END
  405. --<<End of Get Payout Agent Details
  406. -------------------END ----------------------------------
  407. -->>Manage Payment Type
  408. SELECT
  409. @deliveryMethodId = serviceTypeId, @deliveryMethod = typeTitle
  410. FROM serviceTypeMaster WITH(NOLOCK)
  411. WHERE ISNULL(isDeleted,'N') = 'N'
  412. AND typeTitle = CASE WHEN @PAYMENTMODE = 'C' THEN 'CASH PAYMENT'
  413. WHEN @PAYMENTMODE = 'B' THEN 'BANK DEPOSIT'
  414. END
  415. -->>Start:Field Validation according to setup
  416. DECLARE @errTable TABLE(errorCode VARCHAR(10), msg VARCHAR(200), id VARCHAR(10))
  417. INSERT INTO @errTable(errorCode, msg, id)
  418. EXEC proc_sendValidation
  419. @agentId = @sAgent
  420. ,@senIdType = @SENDER_ID_TYPE
  421. ,@senIdNo = @SENDER_ID_NUMBER
  422. ,@senIdValidDate = @SENDER_ID_EXPIRE_DATE
  423. ,@senDob = @SENDER_DATE_OF_BIRTH
  424. ,@senAddress = @SENDER_ADDRESS
  425. ,@senCity = @SENDER_CITY
  426. ,@senContact = @SENDER_MOBILE
  427. ,@recAddress = @RECEIVER_ADDRESS
  428. ,@recCity = @RECEIVER_CITY
  429. ,@recContact = @RECEIVER_CONTACT_NUMBER
  430. ,@paymentMethod = @deliveryMethod
  431. ,@deliveryMethodId = @deliveryMethodId
  432. ,@pBank = @pBank
  433. ,@pBankBranchName = @pBankBranchName
  434. ,@accountNo = @BANK_ACCOUNT_NUMBER
  435. ,@pAgent = @pAgent
  436. ,@pBankType = @pBankType
  437. ,@pCountryId = @pCountryId
  438. ,@sCountryId = @sCountryId
  439. IF NOT EXISTS(SELECT 'X' FROM @errTable WHERE errorCode = '0')
  440. BEGIN
  441. DECLARE @msg VARCHAR(200)
  442. SELECT @msg = msg FROM @errTable
  443. SELECT @errorCode = '1001', @errorMsg = @msg
  444. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  445. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  446. RETURN
  447. END
  448. --<<End:Field Validation according to Setup
  449. DECLARE @collMode VARCHAR(20),@iCollDetailAmt MONEY
  450. SET @collMode = 'Cash'
  451. DECLARE @iServiceCharge MONEY,@tAmt MONEY,@pAmt MONEY,@cAmt MONEY
  452. DECLARE @rowId INT, @place INT
  453. -->>Find Decimal Mask for payout amount rounding
  454. SELECT @place = place, @currDecimal = currDecimal
  455. FROM currencyPayoutRound WHERE ISNULL(isDeleted, 'N') = 'N'
  456. AND currency = @pCurr AND tranType IS NULL
  457. -->>Start:Get Exchange Rate Details
  458. DECLARE @customerRate MONEY,@sCurrCostRate MONEY,@sCurrHoMargin MONEY,@sCurrAgentMargin MONEY,@pCurrCostRate MONEY,@pCurrHoMargin MONEY
  459. ,@pCurrAgentMargin MONEY,@agentCrossSettRate MONEY,@treasuryTolerance MONEY,@sharingValue MONEY,@sharingType CHAR(1),@customerPremium MONEY
  460. ,@sAgentComm MONEY,@sAgentCommCurrency VARCHAR(3)
  461. SELECT
  462. @customerRate = customerRate
  463. ,@sCurrCostRate = sCurrCostRate
  464. ,@sCurrHoMargin = sCurrHoMargin
  465. ,@sCurrAgentMargin = sCurrAgentMargin
  466. ,@pCurrCostRate = pCurrCostRate
  467. ,@pCurrHoMargin = pCurrHoMargin
  468. ,@pCurrAgentMargin = pCurrAgentMargin
  469. ,@agentCrossSettRate = agentCrossSettRate
  470. ,@treasuryTolerance = treasuryTolerance
  471. ,@customerPremium = customerPremium
  472. ,@sharingValue = sharingValue
  473. ,@sharingType = sharingType
  474. FROM dbo.FNAGetExRate(@sCountryId,@sAgent,@sBranch,@collCurr,@pCountryId,@pAgent,@pCurr,@deliveryMethodId)
  475. IF @customerRate IS NULL
  476. BEGIN
  477. SELECT @errorCode = '1001', @errorMsg = 'Transaction cannot be proceed. Exchange Rate not defined'
  478. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  479. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  480. RETURN
  481. END
  482. --<<End:Get Exchange Rate Details
  483. -->>Start:Get tAmt, cAmt, pAmt on the basis of CALCBY
  484. SELECT
  485. @cAmt = CASE WHEN @CALC_BY = 'S' THEN CAST(@TRANSFERAMOUNT AS MONEY) ELSE '0' END
  486. ,@pAmt = CASE WHEN @CALC_BY = 'P' THEN CAST(@TRANSFERAMOUNT AS MONEY) ELSE '0' END
  487. IF ISNULL(@cAmt, 0.00) <> 0.00 AND @CALC_BY = 'S'
  488. BEGIN
  489. SELECT @iServiceCharge = amount FROM [dbo].FNAGetServiceCharge(
  490. @sCountryId, @sSuperAgent, @sAgent, @sBranch
  491. ,@pCountryId, NULL, @pAgent, NULL
  492. ,@deliveryMethodId, @cAmt, @collCurr
  493. )
  494. IF @iServiceCharge IS NULL
  495. BEGIN
  496. SELECT @errorCode = '1001', @errorMsg = 'Service Charge Not Defined for Receiving Country'
  497. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  498. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  499. RETURN;
  500. END
  501. SET @tAmt = @cAmt - @iServiceCharge
  502. SET @pAmt = (@tAmt) * (@customerRate)
  503. SET @currDecimal = ISNULL(@currDecimal, 0)
  504. IF @currDecimal IS NOT NULL
  505. BEGIN
  506. SET @pAmt = ROUND(@pAmt, @currDecimal, 1)
  507. END
  508. ELSE IF @place IS NOT NULL
  509. BEGIN
  510. SET @pAmt = ROUND(@pAmt, -@place, 1)
  511. END
  512. END
  513. ELSE
  514. BEGIN
  515. SET @tAmt = @pAmt/(@customerRate)
  516. SELECT @iServiceCharge = amount FROM [dbo].FNAGetServiceCharge(
  517. @sCountryId, NULL, @sAgent, NULL
  518. ,@pCountryId, NULL, @pAgent, NULL
  519. ,@deliveryMethodId, @tAmt, @collCurr
  520. )
  521. IF @iServiceCharge IS NULL
  522. BEGIN
  523. SELECT @errorCode = '1001', @errorMsg = 'Service Charge Not Defined for Receiving Country'
  524. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  525. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  526. RETURN;
  527. END
  528. SET @cAmt = (@tAmt + @iServiceCharge)
  529. END
  530. IF @iServiceCharge > @cAmt
  531. BEGIN
  532. SELECT @errorCode = '3009', @errorMsg = 'Sent Amount must be more than Service Charge'
  533. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  534. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  535. RETURN;
  536. END
  537. --<<End:Get tAmt, cAmt, pAmt on the basis of CALCBY
  538. -->>Start:Commission Calculation
  539. DECLARE @sSettlementRate FLOAT, @pSettlementRate FLOAT,@tellerBalance MONEY
  540. SET @sSettlementRate = @sCurrCostRate + @sCurrHoMargin
  541. SET @pSettlementRate = @pCurrCostRate - @pCurrHoMargin
  542. SELECT @sAgentComm = amount, @sAgentCommCurrency = commissionCurrency FROM dbo.FNAGetSendComm(
  543. @sCountryId, @sSuperAgent, @sAgent, @sBranch,
  544. @pCountryId, @pSuperAgent, @pAgent, @pBranch,
  545. @collCurr, @deliveryMethodId, @cAmt, @pAmt, @iServiceCharge, NULL, NULL,
  546. @sSettlementRate, @pSettlementRate)
  547. --<<End:Commission Calculation
  548. -->>Start:Verify Agent Send Per Txn
  549. IF EXISTS(SELECT 'X' FROM sendTranLimit
  550. WHERE agentId = @sAgent
  551. AND ISNULL(receivingCountry, ISNULL(@pCountryId, 0)) = ISNULL(@pCountryId, 0)
  552. AND ISNULL(tranType, ISNULL(@deliveryMethodId, 0)) = ISNULL(@deliveryMethodId, 0)
  553. AND currency = @collCurr AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  554. )
  555. BEGIN
  556. IF EXISTS(SELECT 'X' FROM sendTranLimit WITH(NOLOCK) WHERE agentId = @sAgent AND receivingCountry = @pCountryId
  557. AND tranType = @deliveryMethodId AND currency = @collCurr
  558. AND @cAmt < minLimitAmt
  559. AND @cAmt > maxLimitAmt
  560. AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N')
  561. BEGIN
  562. SELECT @errorCode = '3012', @errorMsg = 'Partner Balance Exceed, Cannot Make a TXN'
  563. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  564. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  565. RETURN
  566. END
  567. IF EXISTS(SELECT 'X' FROM sendTranLimit WITH(NOLOCK) WHERE agentId = @sAgent AND receivingCountry = @pCountryId
  568. AND tranType IS NULL AND currency = @collCurr
  569. AND @cAmt < minLimitAmt
  570. AND @cAmt > maxLimitAmt
  571. AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N')
  572. BEGIN
  573. SELECT @errorCode = '3012', @errorMsg = 'Partner Balance Exceed, Cannot Make a TXN'
  574. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  575. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  576. RETURN
  577. END
  578. IF EXISTS(SELECT 'X' FROM sendTranLimit WITH(NOLOCK) WHERE agentId IS NULL AND receivingCountry = @pCountryId
  579. AND tranType = @deliveryMethodId AND currency = @collCurr
  580. AND @cAmt < minLimitAmt
  581. AND @cAmt > maxLimitAmt
  582. AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N')
  583. BEGIN
  584. SELECT @errorCode = '3012', @errorMsg = 'Partner Balance Exceed, Cannot Make a TXN'
  585. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  586. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  587. RETURN
  588. END
  589. IF EXISTS(SELECT 'X' FROM sendTranLimit WITH(NOLOCK) WHERE agentId = @sAgent AND receivingCountry = @pCountryId
  590. AND tranType IS NULL AND currency = @collCurr
  591. AND @cAmt < minLimitAmt
  592. AND @cAmt > maxLimitAmt
  593. AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N')
  594. BEGIN
  595. SELECT @errorCode = '3012', @errorMsg = 'Partner Balance Exceed, Cannot Make a TXN'
  596. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  597. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  598. RETURN
  599. END
  600. END
  601. --<<End:Verify Agent Send Per Txn
  602. -->>Start:Verify Payout Per Txn Limit
  603. IF EXISTS(SELECT 'X' FROM receiveTranLimit WITH(NOLOCK) WHERE ISNULL(sendingCountry, ISNULL(@sCountryId, 0)) = ISNULL(@sCountryId, 0)
  604. AND countryId = @pCountryId AND agentId = @pAgent AND currency = @pCurr
  605. AND ISNULL(tranType, ISNULL(@deliveryMethodId, 0)) = ISNULL(@deliveryMethodId, 0)
  606. AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  607. )
  608. BEGIN
  609. IF EXISTS(SELECT 'X' FROM receiveTranLimit WITH(NOLOCK)
  610. WHERE sendingCountry = @sCountryId AND countryId = @pCountryId AND agentId = @pAgent AND currency = @pCurr
  611. AND tranType = @deliveryMethodId AND @pAmt > maxLimitAmt AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  612. )
  613. BEGIN
  614. SELECT @errorCode = '3011', @errorMsg = 'Payout Amount Limit Exceed'
  615. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  616. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  617. RETURN
  618. END
  619. IF EXISTS(SELECT 'X' FROM receiveTranLimit WITH(NOLOCK)
  620. WHERE sendingCountry = @sCountryId AND countryId = @pCountryId AND agentId = @pAgent AND currency = @pCurr
  621. AND tranType IS NULL AND @pAmt > maxLimitAmt AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  622. )
  623. BEGIN
  624. SELECT @errorCode = '3011', @errorMsg = 'Payout Amount Limit Exceed'
  625. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  626. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  627. RETURN
  628. END
  629. IF EXISTS(SELECT 'X' FROM receiveTranLimit WITH(NOLOCK)
  630. WHERE sendingCountry IS NULL AND countryId = @pCountryId AND agentId = @pAgent AND currency = @pCurr
  631. AND tranType = @deliveryMethodId AND @pAmt > maxLimitAmt AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  632. )
  633. BEGIN
  634. SELECT @errorCode = '3011', @errorMsg = 'Payout Amount Limit Exceed'
  635. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  636. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  637. RETURN
  638. END
  639. IF EXISTS(SELECT 'X' FROM receiveTranLimit WITH(NOLOCK)
  640. WHERE sendingCountry IS NULL AND countryId = @pCountryId AND agentId = @pAgent AND currency = @pCurr
  641. AND tranType IS NULL AND @pAmt > maxLimitAmt AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  642. )
  643. BEGIN
  644. SELECT @errorCode = '3011', @errorMsg = 'Payout Amount Limit Exceed'
  645. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  646. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  647. RETURN
  648. END
  649. END
  650. IF NOT EXISTS(SELECT 'X' FROM receiveTranLimit WITH(NOLOCK)
  651. WHERE ISNULL(sendingCountry, ISNULL(@sCountryId, 0)) = ISNULL(@sCountryId, 0)
  652. AND agentId IS NULL AND countryId = @pCountryId AND currency = @pCurr
  653. AND ISNULL(tranType, ISNULL(@deliveryMethodId, 0)) = ISNULL(@deliveryMethodId, 0)
  654. AND maxLimitAmt >= @pAmt AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  655. )
  656. BEGIN
  657. SELECT @errorCode = '3011', @errorMsg = 'Payout Amount Limit Exceed'
  658. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  659. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  660. RETURN
  661. END
  662. -->>End:Verify Payout Per Txn Limit
  663. IF EXISTS(SELECT TOP 1 'X' FROM thirdPartyAgentTxnId WITH(NOLOCK) WHERE agentTxnId = @AGENT_SESSION_ID)
  664. BEGIN
  665. SELECT TOP 1 @controlNo = controlNo FROM remitTran WHERE controlNo2 = @AGENT_SESSION_ID AND createdBy = 'kodhead123'
  666. SELECT @errorCode = '1001', @errorMsg = 'Duplicate Ref ID : ' + @AGENT_SESSION_ID + '; ICN : ' + dbo.FNADecryptString(@controlNo)
  667. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  668. SELECT TOP 1 @errorCode CODE
  669. ,MESSAGE = @errorMsg
  670. ,AGENT_REFID = @AGENT_SESSION_ID
  671. ,REFID = dbo.FNADecryptString(@controlNo)
  672. ,AGENT_TXNID = 1
  673. ,COLLECT_AMT = cAmt
  674. ,COLLECT_CURRENCY = collCurr
  675. ,EXRATE = customerRate
  676. ,SERVICE_CHARGE = serviceCharge
  677. ,PAYOUTAMT = pAmt
  678. ,PAYOUTCURRENCY = payoutCurr
  679. ,TXN_DATE = createdDate
  680. FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNo
  681. RETURN
  682. END
  683. -->>Start:Get Data Compliance for Compliance Checking and suspicious duplicate txn
  684. DECLARE @today VARCHAR(10) = CONVERT(VARCHAR, dbo.FNADateFormatTZ(GETDATE(), @USER_ID), 101)
  685. DECLARE @remitTranTemp TABLE(tranId BIGINT, controlNo VARCHAR(20), controlNo2 VARCHAR(50), cAmt MONEY, receiverName VARCHAR(200), receiverIdType VARCHAR(100), receiverIdNumber VARCHAR(50), dot DATETIME)
  686. INSERT INTO @remitTranTemp(tranId, controlNo, controlNo2, cAmt, receiverName, receiverIdType, receiverIdNumber, dot)
  687. SELECT rt.id, rt.controlNo, rt.controlNo2, rt.cAmt, rt.receiverName, rec.idType, rec.idNumber, rt.createdDate
  688. FROM vwRemitTran rt WITH(NOLOCK)
  689. INNER JOIN vwTranSenders sen WITH(NOLOCK) ON rt.id = sen.tranId
  690. INNER JOIN vwTranReceivers rec WITH(NOLOCK) ON rt.id = rec.tranId
  691. WHERE sen.idNumber = @SENDER_ID_NUMBER
  692. AND tranStatus <> 'CancelRequest' AND tranStatus <> 'Cancel'
  693. AND (rt.approvedDate BETWEEN @today AND @today + ' 23:59:59'
  694. OR (approvedBy IS NULL AND cancelApprovedBy IS NULL))
  695. IF EXISTS(SELECT 'X' FROM @remitTranTemp WHERE cAmt = @cAmt
  696. AND (receiverName = @RECEIVER_NAME)
  697. AND DATEDIFF(MI, dot, dbo.FNADateFormatTZ(GETDATE(), @USER_ID)) <= 2
  698. )
  699. BEGIN
  700. SELECT @errorCode = '1001', @errorMsg = 'Similar transaction found'
  701. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  702. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  703. RETURN
  704. END
  705. --<<End:Get Data Compliance for Compliance Checking and suspicious duplicate txn
  706. DECLARE @agentFxGain FLOAT
  707. SET @agentFxGain = (@tAmt * (@agentCrossSettRate - @customerRate))/@agentCrossSettRate
  708. -->>Start:OFAC/Compliance Checking
  709. DECLARE @receiverOfacRes VARCHAR(MAX),@ofacRes VARCHAR(MAX),@ofacReason VARCHAR(MAX)
  710. EXEC proc_ofacTracker @flag = 't', @name = @SENDER_NAME, @Result = @ofacRes OUTPUT
  711. EXEC proc_ofacTracker @flag = 't', @name = @RECEIVER_NAME, @Result = @receiverOfacRes OUTPUT
  712. DECLARE @result VARCHAR(MAX)
  713. DECLARE @csMasterId INT, @complianceRes VARCHAR(20), @totalRows INT, @count INT, @compFinalRes VARCHAR(20)
  714. DECLARE @csMasterRec TABLE (rowId INT IDENTITY(1,1), masterId INT)
  715. IF ISNULL(@ofacRes, '') <> ''
  716. BEGIN
  717. SET @ofacReason = 'Matched by sender name'
  718. END
  719. IF ISNULL(@receiverOfacRes, '') <> ''
  720. BEGIN
  721. SET @ofacRes = ISNULL(@ofacRes + ',' + @receiverOfacRes, '' + @receiverOfacRes)
  722. SET @ofacReason = 'Matched by receiver name'
  723. END
  724. IF ISNULL(@ofacRes, '') <> '' AND ISNULL(@receiverOfacRes, '') <> ''
  725. BEGIN
  726. SET @ofacReason = 'Matched by both sender name and receiver name'
  727. END
  728. --INSERT @csMasterRec(masterId)
  729. --SELECT masterId FROM dbo.FNAGetComplianceRuleMaster(@sBranch, @pCountryId, NULL, @pBranch, NULL, NULL, NULL)
  730. --SELECT @totalRows = COUNT(*) FROM @csMasterRec
  731. --IF EXISTS(SELECT 'X' FROM @csMasterRec)
  732. --BEGIN
  733. -- SET @count = 1
  734. -- WHILE(@count <= @totalRows)
  735. -- BEGIN
  736. -- SELECT @csMasterId = masterId FROM @csMasterRec WHERE rowId = @count
  737. -- EXEC proc_complianceRuleDetail
  738. -- @user = @USER_ID
  739. -- ,@tranId = @tranId
  740. -- ,@tAmt = @tAmt
  741. -- ,@senId = NULL
  742. -- ,@benId = NULL
  743. -- ,@beneficiaryName = @RECEIVER_NAME
  744. -- ,@beneficiaryMobile = @RECEIVER_CONTACT_NUMBER
  745. -- ,@benAccountNo = @BANK_ACCOUNT_NUMBER
  746. -- ,@masterId = @csMasterId
  747. -- ,@paymentMethod = @deliveryMethodId
  748. -- ,@checkingFor = 'v'
  749. -- ,@agentRefId = @AGENT_TXNID
  750. -- ,@result = @complianceRes OUTPUT
  751. -- ,@senderId = @SENDER_ID_NUMBER
  752. -- ,@senderName = @SENDER_NAME
  753. -- ,@senderMobile = @SENDER_MOBILE
  754. -- SET @compFinalRes = ISNULL(@compFinalRes, '') + ISNULL(@complianceRes, '')
  755. -- SET @count = @count + 1
  756. -- END
  757. --END
  758. -->>Start:Control Number Generation
  759. SET @controlNo = '9080' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 7)
  760. IF EXISTS(SELECT 'X' FROM controlNoList WITH(NOLOCK) WHERE controlNo = @controlNo)
  761. BEGIN
  762. SET @controlNo = '9080' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 7)
  763. IF EXISTS(SELECT 'X' FROM controlNoList WITH(NOLOCK) WHERE controlNo = @controlNo)
  764. BEGIN
  765. SELECT @errorCode = '9001', @errorMsg = 'Technical error occurred. Please try again'
  766. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  767. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  768. RETURN
  769. END
  770. END
  771. SET @pAmt = ROUND(@pAmt, 0, 1)
  772. DECLARE @controlNoEncrypted VARCHAR(50)
  773. SET @controlNoEncrypted = dbo.FNAEncryptString(@controlNo)
  774. --<<End:Control Number Generation
  775. IF @PAYMENTMODE = 'B'
  776. BEGIN
  777. SELECT TOP 1 @pAgent = internalCode, @pAgentName = bankName FROM externalBank WITH(NOLOCK) WHERE extBankId = @pBank
  778. --SELECT TOP 1 @pAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pAgent
  779. SELECT @pBranchName = ISNULL(@pBankBranchName, @BANK_BRANCH_NAME)
  780. END
  781. SELECT 'I am here'
  782. RETURN
  783. BEGIN
  784. BEGIN TRANSACTION
  785. -->>Start:Data Insert into remitTran, tranSenders, tranReceivers
  786. INSERT INTO remitTran
  787. (
  788. controlNo
  789. ,sCurrCostRate,sCurrHoMargin,sCurrAgentMargin,sAgentSettRate
  790. ,pCurrCostRate,pCurrHoMargin,pCurrAgentMargin
  791. ,agentCrossSettRate,customerRate,treasuryTolerance,customerPremium
  792. ,sharingValue,serviceCharge, agentFxGain
  793. ,sAgentComm,sAgentCommCurrency,sSuperAgentComm,sSuperAgentCommCurrency
  794. ,sCountry,sSuperAgent,sSuperAgentName,sAgent,sAgentName,sBranch,sBranchName
  795. ,pCountry,pSuperAgent,pSuperAgentName,pAgent,pAgentName,pBranch,pBranchName
  796. ,paymentMethod
  797. ,pBank,pBankName,pBankBranch,pBankBranchName,pBankType
  798. ,accountNo,externalBankCode
  799. ,collMode,collCurr,tAmt,cAmt,pAmt,payoutCurr
  800. ,tranStatus,payStatus
  801. ,createdDate,createdDateLocal,createdBy
  802. ,approvedDate,approvedDateLocal,approvedBy
  803. ,tranType
  804. ,senderName,receiverName,controlNo2
  805. )
  806. SELECT
  807. @controlNoEncrypted
  808. ,@sCurrCostRate,@sCurrHoMargin,@sCurrAgentMargin,@sSettlementRate
  809. ,@pCurrCostRate,@pCurrHoMargin,@pCurrAgentMargin
  810. ,@agentCrossSettRate,@customerRate,@treasuryTolerance,@customerPremium
  811. ,@sharingValue,@iServiceCharge,@agentFxGain
  812. ,@sAgentComm,@sAgentCommCurrency,0,@sAgentCommCurrency
  813. ,@sCountry,@sSuperAgent,@sSuperAgentName,@sAgent,@sAgentName,@sBranch,@sBranchName
  814. ,@RECEIVER_COUNTRY,@pSuperAgent,@pSuperAgentName,@pAgent,@pAgentName,@pBranch,@pBranchName
  815. ,@deliveryMethod
  816. ,@pBank,@pBankName,@pBankBranch,ISNULL(@pBankBranchName, @BANK_BRANCH_NAME),@pBankType
  817. ,@BANK_ACCOUNT_NUMBER,@EXTERNALCODE
  818. ,@collMode,@collCurr,@tAmt,@cAmt,@pAmt,@pCurr
  819. ,'Payment', 'Unpaid'
  820. ,dbo.FNADateFormatTZ(GETDATE(),@USER_ID),GETDATE(),@USER_ID
  821. ,dbo.FNADateFormatTZ(GETDATE(),@USER_ID),GETDATE(),@USER_ID
  822. ,'I'
  823. ,@SENDER_NAME,@RECEIVER_NAME,@AGENT_SESSION_ID
  824. SET @tranId = @@IDENTITY
  825. DECLARE @sFirstName VARCHAR(100),@sMiddleName VARCHAR(100),@sLastName VARCHAR(100),@sLastName2 VARCHAR(100)
  826. DECLARE @rFirstName VARCHAR(100),@rMiddleName VARCHAR(100),@rLastName VARCHAR(100),@rLastName2 VARCHAR(100)
  827. SELECT @sFirstName = firstName, @sMiddleName = middleName, @sLastName = lastName1, @sLastName2 = lastName2 FROM dbo.FNASplitName(@SENDER_NAME)
  828. SELECT @rFirstName = firstName, @rMiddleName = middleName, @rLastName = lastName1, @rLastName2 = lastName2 FROM dbo.FNASplitName(@RECEIVER_NAME)
  829. DECLARE @memberCode VARCHAR(50),@senderId INT,@sIdTypeId INT
  830. SELECT @senderId = C.customerId FROM customers C WITH (NOLOCK) INNER JOIN customerIdentity CI WITH (NOLOCK) ON C.customerId = CI.customerId
  831. INNER JOIN staticDataValue SV WITH (NOLOCK) ON CI.idType = SV.valueId WHERE SV.detailTitle = @SENDER_ID_TYPE AND CI.idNumber = @SENDER_ID_NUMBER
  832. INSERT INTO tranSenders
  833. (
  834. customerId
  835. ,gender
  836. ,tranId
  837. ,firstName,middleName,lastName1,lastName2,fullName
  838. ,country,city,address,homePhone,mobile
  839. ,idType,idNumber
  840. ,issuedDate,validDate,dob
  841. )
  842. SELECT
  843. @senderId
  844. ,@SENDER_GENDER
  845. ,@tranId
  846. ,@sFirstName,@sMiddleName,@sLastName,@sLastName2,@SENDER_NAME
  847. ,@sCountry,@SENDER_CITY,@SENDER_ADDRESS,@SENDER_MOBILE,@SENDER_MOBILE
  848. ,@SENDER_ID_TYPE,@SENDER_ID_NUMBER
  849. ,@SENDER_ID_ISSUE_DATE,@SENDER_ID_EXPIRE_DATE,@SENDER_DATE_OF_BIRTH
  850. INSERT INTO tranReceivers
  851. (
  852. tranId
  853. ,firstName,middleName,lastName1,lastName2,fullName
  854. ,city,address,homePhone,workPhone,country
  855. )
  856. SELECT
  857. @tranId
  858. ,@rFirstName,@rMiddleName,@rLastName,@rLastName2,@RECEIVER_NAME
  859. ,@RECEIVER_CITY,@RECEIVER_ADDRESS,@RECEIVER_CONTACT_NUMBER,@RECEIVER_CONTACT_NUMBER,@RECEIVER_COUNTRY
  860. -->>End:Data Insert into remitTran, tranSenders, tranReceivers
  861. INSERT INTO controlNoList(controlNo)
  862. SELECT @controlNo
  863. INSERT INTO thirdPartyAgentTxnId(agentTxnId)
  864. SELECT @AGENT_SESSION_ID
  865. -->>Start:Verify Compliance
  866. IF EXISTS(SELECT 'X' FROM remitTranComplianceTemp WITH(NOLOCK) WHERE agentRefId = @AGENT_TXNID)
  867. BEGIN
  868. INSERT INTO remitTranCompliance(TranId, csDetailTranId, matchTranId)
  869. SELECT @tranId, csDetailTranId, matchTranId FROM remitTranComplianceTemp WITH(NOLOCK) WHERE agentRefId = @AGENT_TXNID
  870. SET @compFinalRes = 'C'
  871. END
  872. 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))
  873. BEGIN
  874. INSERT INTO remitTranCompliance(TranId, csDetailTranId, matchTranId, reason)
  875. SELECT @tranId, 0, tranid, 'Suspected duplicate transaction' FROM @remitTranTemp WHERE cAmt = @cAmt AND (receiverName = @RECEIVER_NAME)
  876. SET @compFinalRes = 'C'
  877. END
  878. IF(ISNULL(@compFinalRes, '') <> '' OR ISNULL(@ofacRes, '') <> '')
  879. BEGIN
  880. IF(@ofacRes <> '' AND ISNULL(@compFinalRes, '') = '')
  881. BEGIN
  882. INSERT remitTranOfac(TranId, blackListId, reason, flag)
  883. SELECT @tranId, @ofacRes, @ofacReason, dbo.FNAGetOFAC_Flag(@ofacRes)
  884. UPDATE remitTran SET
  885. tranStatus = 'OFAC'
  886. WHERE controlNo = @controlNoEncrypted
  887. END
  888. ELSE IF(@compFinalRes <> '' AND ISNULL(@ofacRes, '') = '')
  889. BEGIN
  890. UPDATE remitTran SET
  891. tranStatus = 'Compliance'
  892. WHERE controlNo = @controlNoEncrypted
  893. END
  894. ELSE IF(ISNULL(@compFinalRes, '') <> '' AND ISNULL(@ofacRes, '') <> '')
  895. BEGIN
  896. INSERT remitTranOfac(TranId, blackListId, reason, flag)
  897. SELECT @tranId, @ofacRes, @ofacReason, dbo.FNAGetOFAC_Flag(@ofacRes)
  898. UPDATE remitTran SET
  899. tranStatus = 'OFAC/Compliance'
  900. WHERE controlNo = @controlNoEncrypted
  901. END
  902. END
  903. UPDATE apiRequestLog SET
  904. errorCode = '0'
  905. ,errorMsg = 'Transaction saved successfully'
  906. ,controlNo = @controlNoEncrypted
  907. WHERE rowId = @apiRequestId
  908. IF @@TRANCOUNT > 0
  909. COMMIT TRANSACTION
  910. SELECT
  911. CODE = '0'
  912. ,AGENT_REFID = @AGENT_SESSION_ID
  913. ,MESSAGE = 'Transaction saved successfully'
  914. ,REFID = @controlNo
  915. ,AGENT_TXNID = '1'
  916. ,COLLECT_AMT = cAmt
  917. ,COLLECT_CURRENCY = collCurr
  918. ,EXRATE = customerRate
  919. ,SERVICE_CHARGE = serviceCharge
  920. ,PAYOUTAMT = pAmt
  921. ,PAYOUTCURRENCY = payoutCurr
  922. ,TXN_DATE = createdDate
  923. FROM remitTran WITH(NOLOCK)
  924. WHERE id = @tranId
  925. INSERT INTO PinQueueList(ICN)
  926. SELECT @controlNoEncrypted
  927. --IF @PAYMENTMODE = 'D'
  928. --BEGIN
  929. -- EXEC proc_transactionRouting @flag = 'update', @user = @USER_ID, @tranIds = @tranId, @pAgent = @pAgent
  930. --END
  931. END
  932. END TRY
  933. BEGIN CATCH
  934. IF @@TRANCOUNT > 0
  935. ROLLBACK TRAN
  936. SELECT @errorCode = '9001', @errorMsg = 'Technical Error : ' + ERROR_MESSAGE()
  937. EXEC ws_int_proc_responseLog @flag = 's', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg
  938. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  939. INSERT INTO Logs (errorPage, errorMsg, errorDetails, createdBy, createdDate)
  940. SELECT 'API SP Error',@errorMsg MESSAGE,'ws_int_proc_SendTransaction_JP','admin', GETDATE()
  941. END CATCH
  942. GO