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.

1286 lines
85 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_modifyTranInt_122315] Script Date: 9/27/2019 1:30:14 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. CREATE proc [dbo].[proc_modifyTranInt_122315]
  9. @flag VARCHAR(50) = NULL
  10. ,@user VARCHAR(30) = NULL
  11. ,@tranId INT = NULL
  12. ,@rowId INT = NULL
  13. ,@fieldName VARCHAR(200) = NULL
  14. ,@oldValue VARCHAR(200) = NULL
  15. ,@newTxtValue VARCHAR(200) = NULL
  16. ,@newDdlValue VARCHAR(200) = NULL
  17. ,@firstName VARCHAR(200) = NULL
  18. ,@middleName VARCHAR(200) = NULL
  19. ,@lastName1 VARCHAR(200) = NULL
  20. ,@lastName2 VARCHAR(200) = NULL
  21. ,@contactNo VARCHAR(200) = NULL
  22. ,@bankNewName VARCHAR(100) = NULL
  23. ,@branchNewName VARCHAR(100) = NULL
  24. ,@isAPI CHAR(1) = NULL
  25. ,@fieldValue VARCHAR(200) = NULL
  26. ,@branchId VARCHAR(50) = NULL
  27. ,@emailId VARCHAR(200) = NULL
  28. ,@sendSmsEmail VARCHAR(20) = NULL
  29. AS
  30. /*
  31. EXEC [proc_modifyTXN] @flag = 'u', @user = 'admin', @tranId = '2',
  32. @fieldName = 'senderName', @oldValue = 'Shiva Khanal', @newTxtValue = null,
  33. @newDdlValue = null, @firstName = 'Bijay', @middleName = null, @lastName1 = 'Shahi', @lastName2 = null
  34. */
  35. SET NOCOUNT ON
  36. SET XACT_ABORT ON
  37. BEGIN TRY
  38. CREATE TABLE #msg(errorCode INT, msg VARCHAR(100), id INT)
  39. DECLARE @controlNo varchar(30), @message VARCHAR(100), @agentRefId VARCHAR(15), @controlNoEncrypted VARCHAR(30), @tranNo BIGINT
  40. DECLARE @xml XML
  41. DECLARE @pDistrict VARCHAR(100), @pDistrictId INT, @pState VARCHAR(100), @pStateId INT
  42. DECLARE
  43. @deliveryMethodId INT
  44. ,@deliveryMethod VARCHAR(50)
  45. ,@sBranch INT
  46. ,@pSuperAgent INT
  47. ,@sCountryId INT
  48. ,@sCountry VARCHAR(100)
  49. ,@pCountryId INT
  50. ,@pCountry VARCHAR(100)
  51. ,@pLocation INT
  52. ,@agentId INT
  53. ,@amount MONEY
  54. ,@oldSc MONEY
  55. ,@newSc MONEY
  56. ,@collCurr VARCHAR(3)
  57. ,@senderName VARCHAR(200)
  58. ,@receiverName VARCHAR(200)
  59. ,@senderOfacRes VARCHAR(MAX)
  60. ,@receiverOfacRes VARCHAR(MAX)
  61. ,@ofacRes VARCHAR(MAX)
  62. ,@ofacReason VARCHAR(200)
  63. DECLARE @parentId as int,
  64. @branchName as varchar(200),
  65. @agentName as varchar(200),
  66. @locationCode as int,
  67. @locationName as varchar(200),
  68. @oldLocation as varchar(200),
  69. @oldAgentId as int,
  70. @oldAgentName as varchar(200),
  71. @supAgentId as int,
  72. @supAgentName as varchar(200)
  73. DECLARE @MAXID INT,@MINID INT,@modifyId INT
  74. SET @agentRefId = '1' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '000000000', 8)
  75. SELECT @controlNo = dbo.FNADecryptString(controlNo)
  76. ,@pCountry = pCountry
  77. ,@controlNoEncrypted = controlNo
  78. FROM remitTran WITH(NOLOCK) WHERE id = @tranId
  79. -- >> direct modification from admin panel
  80. IF @flag='u'
  81. BEGIN
  82. -->> updated inficare as well
  83. IF @fieldName='senderName'
  84. BEGIN
  85. IF @firstName IS NULL
  86. BEGIN
  87. EXEC proc_errorHandler 1, 'Please enter valid first name!', @tranId
  88. RETURN
  89. END
  90. SELECT @firstName = UPPER(@firstName), @middleName = UPPER(@middleName), @lastName1 = UPPER(@lastName1), @lastName2 = UPPER(@lastName2)
  91. SET @senderName = ISNULL(@firstName, '') + ISNULL(' ' + @middleName, '') + ISNULL(' ' + @lastName1, '') + ISNULL(' ' +@lastName2, '')
  92. UPDATE tranSenders SET
  93. firstName = UPPER(@firstName)
  94. ,middleName = UPPER(@middleName)
  95. ,lastName1 = UPPER(@lastName1)
  96. ,lastName2 = UPPER(@lastName2)
  97. WHERE tranId = @tranId
  98. UPDATE remitTran SET
  99. senderName = upper(@senderName)
  100. WHERE id = @tranId
  101. SET @message = 'Sender Name:'+ ISNULL(@oldValue, '') + ' has been changed to ' + ISNULL(@firstName, '') + ISNULL(' ' + @middleName, '') + ISNULL(' ' + @lastName1, '') + ISNULL(' ' +@lastName2, '')
  102. INSERT INTO tranModifyLog (tranId,message,createdBy,createdDate,MsgType)
  103. SELECT @tranId, @message, @user,GETDATE(),'MODIFY'
  104. EXEC proc_ofacTracker @flag = 't', @name = @senderName, @Result = @senderOfacRes OUTPUT
  105. END
  106. -->> updated inficare as well
  107. ELSE IF @fieldName='receiverName'
  108. BEGIN
  109. if @firstName is null
  110. begin
  111. EXEC proc_errorHandler 1, 'Please enter valid first name!' , @tranId
  112. return
  113. end
  114. SELECT @firstName = UPPER(@firstName), @middleName = UPPER(@middleName), @lastName1 = UPPER(@lastName1), @lastName2 = UPPER(@lastName2)
  115. SET @receiverName = ISNULL(@firstName, '') + ISNULL(' ' + @middleName, '') + ISNULL(' ' + @lastName1, '') + ISNULL(' ' + @lastName2, '')
  116. update tranReceivers SET
  117. firstName = @firstName
  118. ,middleName = @middleName
  119. ,lastName1 = @lastName1
  120. ,lastName2 = @lastName2
  121. WHERE tranId = @tranId
  122. UPDATE remitTran SET
  123. receiverName = upper(@receiverName)
  124. WHERE id = @tranId
  125. SET @message = 'Receiver Name:' + ISNULL(@oldValue, '') + ' has been changed to ' + ISNULL(@firstName, '') + ISNULL(' ' + @middleName, '') + ISNULL(' ' + @lastName1, '') + ISNULL(' ' + @lastName2, '')
  126. insert into tranModifyLog (tranId,message,createdBy,createdDate,MsgType)
  127. select @tranId,@message,@user,GETDATE(),'MODIFY'
  128. EXEC proc_ofacTracker @flag = 't', @name = @receiverName, @Result = @receiverOfacRes OUTPUT
  129. end
  130. -->> updated inficare as well
  131. ELSE IF @fieldName='rAddress'
  132. BEGIN
  133. if @newTxtValue is null
  134. begin
  135. EXEC proc_errorHandler 1, 'Please enter valid address!', @tranId
  136. return
  137. end
  138. UPDATE tranReceivers SET
  139. address = @newTxtValue
  140. WHERE tranId = @tranId
  141. SET @message = 'Receiver Address:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@newTxtValue,'')
  142. INSERT INTO tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  143. SELECT @tranId, @message, @user, GETDATE(), 'MODIFY'
  144. END
  145. -->> updated inficare as well
  146. ELSE IF @fieldName='rIdType'
  147. BEGIN
  148. if @newDdlValue is null
  149. begin
  150. EXEC proc_errorHandler 1, 'Please enter valid id type!', @tranId
  151. return
  152. end
  153. update tranReceivers SET
  154. idType = @newDdlValue
  155. WHERE tranId = @tranId
  156. SET @message = 'Receiver Id Type:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@newDdlValue,'')
  157. insert into tranModifyLog (tranId,message,createdBy,createdDate,MsgType)
  158. select @tranId,@message,@user,GETDATE(),'MODIFY'
  159. END
  160. ELSE IF @fieldName='rTelNo'
  161. BEGIN
  162. if @contactNo is null
  163. begin
  164. EXEC proc_errorHandler 1, 'Please enter valid telephone number!', @tranId
  165. return
  166. end
  167. update tranSenders SET
  168. homephone = @contactNo
  169. WHERE tranId = @tranId
  170. SET @message = 'Sender telephone number:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@contactNo,'')
  171. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  172. select @tranId,@message,@user,GETDATE(),'MODIFY'
  173. END
  174. -->> updated inficare as well
  175. ELSE IF @fieldName='sIdType'
  176. BEGIN
  177. if @newDdlValue is null
  178. begin
  179. EXEC proc_errorHandler 1, 'Please enter valid id type!', @tranId
  180. return
  181. end
  182. update tranSenders SET
  183. idType = @newDdlValue
  184. WHERE tranId = @tranId
  185. SET @message = 'Sender Id Type:' + ISNULL(@oldValue, '') + ' has been changed to ' + ISNULL(@newDdlValue, '')
  186. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  187. select @tranId,@message,@user,GETDATE(),'MODIFY'
  188. end
  189. -->> updated inficare as well
  190. ELSE IF @fieldName='sAddress'
  191. BEGIN
  192. if @newTxtValue is null
  193. begin
  194. EXEC proc_errorHandler 1, 'Please enter valid address!', @tranId
  195. return
  196. end
  197. update tranSenders SET
  198. address = @newTxtValue
  199. WHERE tranId = @tranId
  200. SET @message = 'Sender Address:' + ISNULL(@oldValue,'') + ' has been changed to ' + ISNULL(@newTxtValue, '')
  201. INSERT INTO tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  202. select @tranId,@message,@user,GETDATE(),'MODIFY'
  203. END
  204. -->> updated inficare as well
  205. ELSE IF @fieldName='sContactNo'
  206. BEGIN
  207. IF @contactNo IS NULL
  208. BEGIN
  209. EXEC proc_errorHandler 1, 'Please enter valid contact number!', @tranId
  210. RETURN
  211. END
  212. UPDATE tranSenders SET
  213. mobile = @contactNo
  214. WHERE tranId = @tranId
  215. SET @message = 'Sender Contact No:'+ ISNULL(@oldValue,'')+' has been changed to '+ISNULL(@contactNo,'')
  216. INSERT INTO tranModifyLog(tranId,MESSAGE,createdBy,createdDate,MsgType)
  217. SELECT @tranId,@message,@user,GETDATE(),'MODIFY'
  218. END
  219. -->> updated inficare as well: mobile number
  220. ELSE IF @fieldName='rContactNo'
  221. BEGIN
  222. if @contactNo is null
  223. begin
  224. EXEC proc_errorHandler 1, 'Please enter valid contact number!', @tranId
  225. return
  226. end
  227. update tranReceivers SET
  228. mobile = @contactNo
  229. WHERE tranId = @tranId
  230. SET @message = 'Receiver Contact No:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@contactNo,'')
  231. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  232. select @tranId,@message,@user,GETDATE(),'MODIFY'
  233. END
  234. -->> updated inficare as well
  235. ELSE IF @fieldName='sIdNo'
  236. BEGIN
  237. if @newTxtValue is null
  238. begin
  239. EXEC proc_errorHandler 1, 'Please enter valid id number!', @tranId
  240. return
  241. end
  242. update tranSenders SET
  243. idNumber = @newTxtValue
  244. WHERE tranId = @tranId
  245. SET @message = 'Sender ID No:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@newTxtValue,'')
  246. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  247. select @tranId,@message,@user,GETDATE(),'MODIFY'
  248. end
  249. ELSE IF @fieldName='relationship'
  250. BEGIN
  251. IF @newDdlValue IS NULL
  252. BEGIN
  253. EXEC proc_errorHandler 1, 'Please enter valid Receiver relationship with sender!', @tranId
  254. RETURN
  255. END
  256. UPDATE remitTran SET
  257. relWithSender = @newDdlValue
  258. WHERE id = @tranId
  259. SET @message = 'Receiver relationship with sender :'+ ISNULL(@oldValue,'')+' has been changed to '+ISNULL(@newDdlValue,'')
  260. INSERT INTO tranModifyLog(tranId,MESSAGE,createdBy,createdDate,MsgType)
  261. SELECT @tranId,@message,@user,GETDATE(),'MODIFY'
  262. end
  263. -->> updated inficare as well
  264. ELSE IF @fieldName='rIdNo'
  265. BEGIN
  266. if @newTxtValue is null
  267. begin
  268. EXEC proc_errorHandler 1, 'Please enter valid id number!', @tranId
  269. return
  270. end
  271. update tranReceivers SET
  272. idNumber = @newTxtValue
  273. WHERE tranId = @tranId
  274. SET @message = 'Receiver ID No:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@newTxtValue,'')
  275. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  276. select @tranId,@message,@user,GETDATE(),'MODIFY'
  277. end
  278. ELSE IF @fieldName='txnTestQuestion'
  279. BEGIN
  280. if @newTxtValue is null
  281. begin
  282. EXEC proc_errorHandler 1, 'Please enter valid id number!', @tranId
  283. return
  284. end
  285. update tranSenders SET
  286. txnTestQuestion = @newTxtValue
  287. WHERE tranId = @tranId
  288. SET @message = 'Test Question:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@newTxtValue,'')
  289. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  290. select @tranId,@message,@user,GETDATE(),'MODIFY'
  291. end
  292. ELSE IF @fieldName='txnTestAnswer'
  293. BEGIN
  294. if @newTxtValue is null
  295. begin
  296. EXEC proc_errorHandler 1, 'Please enter valid id number!', @tranId
  297. return
  298. end
  299. update tranSenders SET
  300. txnTestAnswer = @newTxtValue
  301. WHERE tranId = @tranId
  302. SET @message = 'Test Answer:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@newTxtValue,'')
  303. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  304. select @tranId,@message,@user,GETDATE(),'MODIFY'
  305. end
  306. ELSE IF @fieldName='accountNo'
  307. BEGIN
  308. IF @newDdlValue IS NULL
  309. BEGIN
  310. EXEC proc_errorHandler 1, 'Please enter valid account number!', @tranId
  311. RETURN
  312. END
  313. UPDATE remitTran SET
  314. accountNo = @newDdlValue
  315. WHERE id = @tranId
  316. SET @message = 'Account Number:'+ ISNULL(@oldValue,'')+' has been changed to '+ISNULL(@newDdlValue,'')
  317. INSERT INTO tranModifyLog(tranId,MESSAGE,createdBy,createdDate,MsgType)
  318. SELECT @tranId,@message,@user,GETDATE(),'MODIFY'
  319. END
  320. ELSE IF @fieldName='BankName'
  321. BEGIN
  322. if @bankNewName is null
  323. begin
  324. EXEC proc_errorHandler 1, 'Please enter valid bank name!', @tranId
  325. return
  326. end
  327. if @branchNewName is null
  328. begin
  329. EXEC proc_errorHandler 1, 'Please enter valid bank name!', @tranId
  330. return
  331. end
  332. update remitTran SET
  333. pBank = @bankNewName,
  334. pBankName=dbo.GetAgentNameFromId(@bankNewName),
  335. pBankBranch = @branchNewName,
  336. pBankBranchName=dbo.GetAgentNameFromId(@branchNewName)
  337. WHERE id = @tranId
  338. SET @message = 'Bank Name:'+ isnull(@oldValue,'')+' has been changed to '+isnull(dbo.GetAgentNameFromId(@bankNewName),'')
  339. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  340. select @tranId,@message,@user,GETDATE(),'MODIFY'
  341. DECLARE @message2 VARCHAR(200) = NULL
  342. SET @message2 = 'Branch name has been changed to '+isnull(dbo.GetAgentNameFromId(@branchNewName),'')
  343. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  344. select @tranId,@message2,@user,GETDATE(),'MODIFY'
  345. END
  346. ELSE IF @fieldName='BranchName'
  347. BEGIN
  348. EXEC proc_errorHandler 1, 'Feature not available at the moment', @tranId
  349. RETURN
  350. if @newDdlValue is null
  351. begin
  352. EXEC proc_errorHandler 1, 'Please enter valid branch name!', @tranId
  353. return
  354. end
  355. update remitTran SET
  356. pBankBranch = @newDdlValue,
  357. pBankBranchName=dbo.GetAgentNameFromId(@newDdlValue)
  358. WHERE id = @tranId
  359. SET @message = 'Branch Name:'+ isnull(@oldValue,'')+' has been changed to '+isnull(dbo.GetAgentNameFromId(@newDdlValue),'')
  360. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  361. select @tranId,@message,@user,GETDATE(),'MODIFY'
  362. DECLARE @pBankType CHAR(1)
  363. SELECT @pBankType = pBankType FROM remitTran WITH(NOLOCK) WHERE id = @tranId
  364. END
  365. ELSE IF @fieldName='pBranchName'
  366. BEGIN
  367. if @newDdlValue is null
  368. begin
  369. EXEC proc_errorHandler 1, 'Please enter valid branch name!', @tranId
  370. return
  371. end
  372. select @locationCode=agentLocation from agentMaster where agentId=@newDdlValue
  373. select @locationName=districtName from api_districtList where districtCode=@locationCode
  374. select @oldAgentId= case when isnull(pAgent,0)=isnull(pBranch,0) then pSuperAgent else pAgent end
  375. from remitTran where id=@tranId
  376. select @oldAgentName=agentName from agentMaster where agentId=@oldAgentId
  377. if exists(select actAsBranch from agentMaster where agentId=@newDdlValue and actAsBranch='y')
  378. begin
  379. -- ## branch name
  380. select @branchName=agentName
  381. from agentMaster
  382. where agentId=@newDdlValue
  383. -- ## super agent
  384. select @supAgentId=parentId
  385. from agentMaster where agentId=@newDdlValue
  386. select @supAgentName=agentName
  387. from agentMaster where agentId=@supAgentId
  388. -- ## update if agent act as a branch
  389. update remitTran SET
  390. pAgent = @newDdlValue,
  391. pBranch=@newDdlValue,
  392. pAgentName=@branchName,
  393. pBranchName=@branchName,
  394. pSuperAgent=@supAgentId,
  395. pSuperAgentName=@supAgentName
  396. WHERE id = @tranId
  397. -- ## update transaction log
  398. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  399. select @tranId,'Branch Name:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@branchName,''),@user,GETDATE(),'MODIFY'
  400. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  401. select @tranId,'Agent Name:'+ isnull(@oldAgentName,'')+' has been changed to '+isnull(@supAgentName,''),@user,GETDATE(),'MODIFY'
  402. end
  403. else
  404. begin
  405. -- ## branch name & agent name
  406. select @parentId=parentId,@branchName=agentName
  407. from agentMaster
  408. where agentId=@newDdlValue
  409. select @agentName=agentName
  410. from agentMaster
  411. where agentId=@parentId
  412. -- ## super agent
  413. select @supAgentId=parentId
  414. from agentMaster where agentId=@parentId
  415. select @supAgentName=agentName
  416. from agentMaster where agentId=@supAgentId
  417. -- ## update remitTran
  418. update remitTran SET
  419. pAgent = @parentId,
  420. pBranch=@newDdlValue,
  421. pAgentName=@agentName,
  422. pBranchName=@branchName,
  423. pSuperAgent=@supAgentId,
  424. pSuperAgentName=@supAgentName
  425. WHERE id = @tranId
  426. -- ## update transaction log
  427. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  428. select @tranId,'Branch Name:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@branchName,''),@user,GETDATE(),'MODIFY'
  429. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  430. select @tranId,'Agent Name:'+ isnull(@oldAgentName,'')+' has been changed to '+isnull(@agentName,''),@user,GETDATE(),'MODIFY'
  431. end
  432. END
  433. ELSE IF @fieldName = 'rCity'
  434. BEGIN
  435. IF @newTxtValue IS NULL
  436. BEGIN
  437. EXEC proc_errorHandler 1, 'Please enter valid receiver city!', @tranId
  438. RETURN
  439. END
  440. UPDATE tranreceivers SET
  441. city = @newTxtValue
  442. WHERE tranId = @tranId
  443. SET @message = 'Receiver City :'+ ISNULL(@oldValue,'')+' has been changed to '+ISNULL(@newTxtValue,'')
  444. INSERT INTO tranModifyLog(tranId,MESSAGE,createdBy,createdDate,MsgType)
  445. SELECT @tranId,@message,@user,GETDATE(),'MODIFY'
  446. END
  447. ELSE IF @fieldName = 'sCity'
  448. BEGIN
  449. IF @newTxtValue IS NULL
  450. BEGIN
  451. EXEC proc_errorHandler 1, 'Please enter valid Sender City!', @tranId
  452. RETURN
  453. END
  454. UPDATE transenders SET
  455. city = @newTxtValue
  456. WHERE tranId = @tranId
  457. SET @message = 'Sender City :'+ ISNULL(@oldValue,'')+' has been changed to '+ISNULL(@newTxtValue,'')
  458. INSERT INTO tranModifyLog(tranId,MESSAGE,createdBy,createdDate,MsgType)
  459. SELECT @tranId,@message,@user,GETDATE(),'MODIFY'
  460. END
  461. EXEC proc_errorHandler 0, 'Record has been updated successfully.', @tranId
  462. IF (ISNULL(@isAPI, 'N') = 'Y')
  463. BEGIN
  464. IF(@fieldName = 'pAgentLocation')
  465. BEGIN
  466. EXEC proc_modifyTxnAPI @flag = 'mpl', @controlNo = @controlNo, @user = @user, @newPLocation = @newDdlValue, @agentRefId = NULL
  467. END
  468. ELSE
  469. BEGIN
  470. EXEC proc_addCommentAPI @flag = 'i', @controlNo = @controlNo, @user = @user, @message = @message, @agentRefId = NULL, @updateInSwift = 'N'
  471. END
  472. END
  473. END
  474. -->> transaction modification : hold only (from agent panel)
  475. IF @flag='uHoldtxn'
  476. BEGIN
  477. IF @fieldName='senderName'
  478. BEGIN
  479. IF @firstName IS NULL
  480. BEGIN
  481. EXEC proc_errorHandler 1, 'Please enter valid first name!', @tranId
  482. RETURN
  483. END
  484. SELECT @firstName = UPPER(@firstName), @middleName = UPPER(@middleName), @lastName1 = UPPER(@lastName1), @lastName2 = UPPER(@lastName2)
  485. SET @senderName = ISNULL(@firstName, '') + ISNULL(' ' + @middleName, '') + ISNULL(' ' + @lastName1, '') + ISNULL(' ' + @lastName2, '')
  486. UPDATE tranSendersTemp SET
  487. firstName = @firstName
  488. ,middleName = @middleName
  489. ,lastName1 = @lastName1
  490. ,lastName2 = @lastName2
  491. WHERE tranId = @tranId
  492. UPDATE remitTranTemp SET
  493. senderName = upper(@senderName)
  494. WHERE id = @tranId
  495. SET @message = 'Sender Name:'+ ISNULL(@oldValue, '') + ' has been changed to ' + ISNULL(@firstName, '') + ISNULL(' ' + @middleName, '') + ISNULL(' ' + @lastName1, '') + ISNULL(' ' +@lastName2, '')
  496. INSERT INTO tranModifyLog (tranId,message,createdBy,createdDate,MsgType)
  497. SELECT @tranId, @message, @user,GETDATE(),'MODIFY'
  498. END
  499. ELSE IF @fieldName='receiverName'
  500. BEGIN
  501. if @firstName is null
  502. begin
  503. EXEC proc_errorHandler 1, 'Please enter valid first name!' , @tranId
  504. return
  505. end
  506. SELECT @firstName = UPPER(@firstName), @middleName = UPPER(@middleName), @lastName1 = UPPER(@lastName1), @lastName2 = UPPER(@lastName2)
  507. SET @receiverName = ISNULL(@firstName, '') + ISNULL(' ' + @middleName, '') + ISNULL(' ' + @lastName1, '') + ISNULL(' ' + @lastName2, '')
  508. update tranReceiversTemp SET
  509. firstName = @firstName
  510. ,middleName = @middleName
  511. ,lastName1 = @lastName1
  512. ,lastName2 = @lastName2
  513. WHERE tranId = @tranId
  514. UPDATE remitTranTemp SET
  515. receiverName = upper(@receiverName)
  516. WHERE id = @tranId
  517. SET @message = 'Receiver Name:' + ISNULL(@oldValue, '') + ' has been changed to ' + ISNULL(@firstName, '') + ISNULL(' ' + @middleName, '') + ISNULL(' ' + @lastName1, '') + ISNULL(' ' + @lastName2, '')
  518. insert into tranModifyLog (tranId,message,createdBy,createdDate,MsgType)
  519. select @tranId,@message,@user,GETDATE(),'MODIFY'
  520. end
  521. ELSE IF @fieldName='sIdType'
  522. BEGIN
  523. if @newDdlValue is null
  524. begin
  525. EXEC proc_errorHandler 1, 'Please enter valid id type!', @tranId
  526. return
  527. end
  528. update tranSendersTemp SET
  529. idType = @newDdlValue
  530. WHERE tranId = @tranId
  531. SET @message = 'Sender Id Type:' + ISNULL(@oldValue, '') + ' has been changed to ' + ISNULL(@newDdlValue, '')
  532. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  533. select @tranId,@message,@user,GETDATE(),'MODIFY'
  534. end
  535. ELSE IF @fieldName='rIdType'
  536. BEGIN
  537. if @newDdlValue is null
  538. begin
  539. EXEC proc_errorHandler 1, 'Please enter valid id type!', @tranId
  540. return
  541. end
  542. update tranReceiversTemp SET
  543. idType = @newDdlValue
  544. WHERE tranId = @tranId
  545. SET @message = 'Receiver Id Type:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@newDdlValue,'')
  546. insert into tranModifyLog (tranId,message,createdBy,createdDate,MsgType)
  547. select @tranId,@message,@user,GETDATE(),'MODIFY'
  548. end
  549. ELSE IF @fieldName='relationship'
  550. BEGIN
  551. IF @newDdlValue IS NULL
  552. BEGIN
  553. EXEC proc_errorHandler 1, 'Please enter valid Receiver relationship with sender!', @tranId
  554. RETURN
  555. END
  556. UPDATE remitTranTemp SET
  557. relWithSender = @newDdlValue
  558. WHERE id = @tranId
  559. SET @message = 'Receiver relationship with sender :'+ ISNULL(@oldValue,'')+' has been changed to '+ISNULL(@newDdlValue,'')
  560. INSERT INTO tranModifyLog(tranId,MESSAGE,createdBy,createdDate,MsgType)
  561. SELECT @tranId,@message,@user,GETDATE(),'MODIFY'
  562. end
  563. ELSE IF @fieldName='rAddress'
  564. BEGIN
  565. if @newTxtValue is null
  566. begin
  567. EXEC proc_errorHandler 1, 'Please enter valid address!', @tranId
  568. return
  569. end
  570. update tranReceiversTemp SET
  571. address = @newTxtValue
  572. WHERE tranId = @tranId
  573. SET @message = 'Receiver Address:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@newTxtValue,'')
  574. INSERT INTO tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  575. SELECT @tranId, @message, @user, GETDATE(), 'MODIFY'
  576. END
  577. ELSE IF @fieldName='sAddress'
  578. BEGIN
  579. if @newTxtValue is null
  580. begin
  581. EXEC proc_errorHandler 1, 'Please enter valid address!', @tranId
  582. return
  583. end
  584. update tranSendersTemp SET
  585. address = @newTxtValue
  586. WHERE tranId = @tranId
  587. SET @message = 'Sender Address:' + ISNULL(@oldValue,'') + ' has been changed to ' + ISNULL(@newTxtValue, '')
  588. INSERT INTO tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  589. select @tranId,@message,@user,GETDATE(),'MODIFY'
  590. end
  591. ELSE IF @fieldName='sContactNo'
  592. BEGIN
  593. IF @contactNo IS NULL
  594. BEGIN
  595. EXEC proc_errorHandler 1, 'Please enter valid contact number!', @tranId
  596. RETURN
  597. END
  598. UPDATE tranSendersTemp SET
  599. mobile = @contactNo
  600. WHERE tranId = @tranId
  601. SET @message = 'Sender Contact No:'+ ISNULL(@oldValue,'')+' has been changed to '+ISNULL(@contactNo,'')
  602. INSERT INTO tranModifyLog(tranId,MESSAGE,createdBy,createdDate,MsgType)
  603. SELECT @tranId,@message,@user,GETDATE(),'MODIFY'
  604. END
  605. ELSE IF @fieldName='rTelNo'
  606. BEGIN
  607. if @contactNo is null
  608. begin
  609. EXEC proc_errorHandler 1, 'Please enter valid telephone number!', @tranId
  610. return
  611. end
  612. update tranReceiversTemp SET
  613. homephone = @contactNo
  614. WHERE tranId = @tranId
  615. SET @message = 'Receiver telephone number:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@contactNo,'')
  616. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  617. select @tranId,@message,@user,GETDATE(),'MODIFY'
  618. end
  619. ELSE IF @fieldName='sTelNo'
  620. BEGIN
  621. if @contactNo is null
  622. begin
  623. EXEC proc_errorHandler 1, 'Please enter valid telephone number!', @tranId
  624. return
  625. end
  626. update tranSendersTemp SET
  627. homephone = @contactNo
  628. WHERE tranId = @tranId
  629. SET @message = 'Sender telephone number:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@contactNo,'')
  630. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  631. select @tranId,@message,@user,GETDATE(),'MODIFY'
  632. end
  633. ELSE IF @fieldName='rContactNo'
  634. BEGIN
  635. if @contactNo is null
  636. begin
  637. EXEC proc_errorHandler 1, 'Please enter valid contact number!', @tranId
  638. return
  639. end
  640. update tranReceiversTemp SET
  641. mobile = @contactNo
  642. WHERE tranId = @tranId
  643. SET @message = 'Receiver Contact No:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@contactNo,'')
  644. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  645. select @tranId,@message,@user,GETDATE(),'MODIFY'
  646. end
  647. ELSE IF @fieldName='sIdNo'
  648. BEGIN
  649. if @newTxtValue is null
  650. begin
  651. EXEC proc_errorHandler 1, 'Please enter valid id number!', @tranId
  652. return
  653. end
  654. update tranSendersTemp SET
  655. idNumber = @newTxtValue
  656. WHERE tranId = @tranId
  657. SET @message = 'Sender ID No:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@newTxtValue,'')
  658. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  659. select @tranId,@message,@user,GETDATE(),'MODIFY'
  660. end
  661. ELSE IF @fieldName='rIdNo'
  662. BEGIN
  663. if @newTxtValue is null
  664. begin
  665. EXEC proc_errorHandler 1, 'Please enter valid id number!', @tranId
  666. return
  667. end
  668. update tranReceiversTemp SET
  669. idNumber = @newTxtValue
  670. WHERE tranId = @tranId
  671. SET @message = 'Receiver ID No:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@newTxtValue,'')
  672. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  673. select @tranId,@message,@user,GETDATE(),'MODIFY'
  674. end
  675. ELSE IF @fieldName='txnTestQuestion'
  676. BEGIN
  677. if @newTxtValue is null
  678. begin
  679. EXEC proc_errorHandler 1, 'Please enter valid id number!', @tranId
  680. return
  681. end
  682. update tranSendersTemp SET
  683. txnTestQuestion = @newTxtValue
  684. WHERE tranId = @tranId
  685. SET @message = 'Test Question:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@newTxtValue,'')
  686. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  687. select @tranId,@message,@user,GETDATE(),'MODIFY'
  688. end
  689. ELSE IF @fieldName='txnTestAnswer'
  690. BEGIN
  691. if @newTxtValue is null
  692. begin
  693. EXEC proc_errorHandler 1, 'Please enter valid id number!', @tranId
  694. return
  695. end
  696. update tranSendersTemp SET
  697. txnTestAnswer = @newTxtValue
  698. WHERE tranId = @tranId
  699. SET @message = 'Test Answer:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@newTxtValue,'')
  700. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  701. select @tranId,@message,@user,GETDATE(),'MODIFY'
  702. end
  703. ELSE IF @fieldName='accountNo'
  704. BEGIN
  705. IF @newTxtValue IS NULL
  706. BEGIN
  707. EXEC proc_errorHandler 1, 'Please enter valid account number!', @tranId
  708. RETURN
  709. END
  710. UPDATE remitTranTemp SET
  711. accountNo = @newTxtValue
  712. WHERE id = @tranId
  713. SET @message = 'Account Number:'+ ISNULL(@oldValue,'')+' has been changed to '+ISNULL(@newTxtValue,'')
  714. INSERT INTO tranModifyLog(tranId,MESSAGE,createdBy,createdDate,MsgType)
  715. SELECT @tranId,@message,@user,GETDATE(),'MODIFY'
  716. END
  717. ELSE IF @fieldName='BankName'
  718. BEGIN
  719. if @bankNewName is null
  720. begin
  721. EXEC proc_errorHandler 1, 'Please enter valid bank name!', @tranId
  722. return
  723. end
  724. if @branchNewName is null
  725. begin
  726. EXEC proc_errorHandler 1, 'Please enter valid bank name!', @tranId
  727. return
  728. end
  729. update remitTranTemp SET
  730. pBank = @bankNewName,
  731. pBankName=dbo.GetAgentNameFromId(@bankNewName),
  732. pBankBranch = @branchNewName,
  733. pBankBranchName=dbo.GetAgentNameFromId(@branchNewName)
  734. WHERE id = @tranId
  735. SET @message = 'Bank Name:'+ isnull(@oldValue,'')+' has been changed to '+isnull(dbo.GetAgentNameFromId(@bankNewName),'')
  736. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  737. select @tranId,@message,@user,GETDATE(),'MODIFY'
  738. ----DECLARE @message3 VARCHAR(200) = NULL
  739. SET @message = 'Branch name has been changed to '+isnull(dbo.GetAgentNameFromId(@branchNewName),'')
  740. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  741. select @tranId,@message,@user,GETDATE(),'MODIFY'
  742. END
  743. ELSE IF @fieldName='BranchName'
  744. BEGIN
  745. if @newDdlValue is null
  746. begin
  747. EXEC proc_errorHandler 1, 'Please enter valid branch name!', @tranId
  748. return
  749. end
  750. update remitTranTemp SET
  751. pBankBranch = @newDdlValue,
  752. pBankBranchName=dbo.GetAgentNameFromId(@newDdlValue)
  753. WHERE id = @tranId
  754. SET @message = 'Branch Name:'+ isnull(@oldValue,'')+' has been changed to '+isnull(dbo.GetAgentNameFromId(@newDdlValue),'')
  755. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  756. select @tranId,@message,@user,GETDATE(),'MODIFY'
  757. END
  758. ELSE IF @fieldName='pBranchName'
  759. BEGIN
  760. if @newDdlValue is null
  761. begin
  762. EXEC proc_errorHandler 1, 'Please enter valid branch name!', @tranId
  763. return
  764. end
  765. select @locationCode=agentLocation from agentMaster where agentId=@newDdlValue
  766. select @locationName=districtName from api_districtList where districtCode=@locationCode
  767. select @oldAgentId= case when isnull(pAgent,0)=isnull(pBranch,0) then pSuperAgent else pAgent end
  768. from remitTranTemp where id=@tranId
  769. select @oldAgentName=agentName from agentMaster where agentId=@oldAgentId
  770. if exists(select actAsBranch from agentMaster where agentId=@newDdlValue and actAsBranch='y')
  771. begin
  772. -- ## branch name
  773. select @branchName=agentName
  774. from agentMaster
  775. where agentId=@newDdlValue
  776. -- ## super agent
  777. select @supAgentId=parentId
  778. from agentMaster where agentId=@newDdlValue
  779. select @supAgentName=agentName
  780. from agentMaster where agentId=@supAgentId
  781. -- ## update if agent act as a branch
  782. update remitTranTemp SET
  783. pAgent = @newDdlValue,
  784. pBranch=@newDdlValue,
  785. pAgentName=@branchName,
  786. pBranchName=@branchName,
  787. pSuperAgent=@supAgentId,
  788. pSuperAgentName=@supAgentName
  789. WHERE id = @tranId
  790. -- ## update transaction log
  791. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  792. select @tranId,'Branch Name:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@branchName,''),@user,GETDATE(),'MODIFY'
  793. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  794. select @tranId,'Agent Name:'+ isnull(@oldAgentName,'')+' has been changed to '+isnull(@supAgentName,''),@user,GETDATE(),'MODIFY'
  795. end
  796. else
  797. begin
  798. -- ## branch name & agent name
  799. select @parentId=parentId,@branchName=agentName
  800. from agentMaster
  801. where agentId=@newDdlValue
  802. select @agentName=agentName
  803. from agentMaster
  804. where agentId=@parentId
  805. -- ## super agent
  806. select @supAgentId=parentId
  807. from agentMaster where agentId=@parentId
  808. select @supAgentName=agentName
  809. from agentMaster where agentId=@supAgentId
  810. -- ## update remitTran
  811. update remitTranTemp SET
  812. pAgent = @parentId,
  813. pBranch=@newDdlValue,
  814. pAgentName=@agentName,
  815. pBranchName=@branchName,
  816. pSuperAgent=@supAgentId,
  817. pSuperAgentName=@supAgentName
  818. WHERE id = @tranId
  819. -- ## update transaction log
  820. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  821. select @tranId,'Branch Name:'+ isnull(@oldValue,'')+' has been changed to '+isnull(@branchName,''),@user,GETDATE(),'MODIFY'
  822. insert into tranModifyLog(tranId,message,createdBy,createdDate,MsgType)
  823. select @tranId,'Agent Name:'+ isnull(@oldAgentName,'')+' has been changed to '+isnull(@agentName,''),@user,GETDATE(),'MODIFY'
  824. end
  825. END
  826. EXEC proc_errorHandler 0, 'Record has been updated successfully.', @tranId
  827. IF (ISNULL(@isAPI, 'N') = 'Y')
  828. BEGIN
  829. IF(@fieldName = 'pAgentLocation')
  830. BEGIN
  831. EXEC proc_modifyTxnAPI @flag = 'mpl', @controlNo = @controlNo, @user = @user, @newPLocation = @newDdlValue, @agentRefId = NULL
  832. END
  833. ELSE
  834. BEGIN
  835. EXEC proc_addCommentAPI @flag = 'i', @controlNo = @controlNo, @user = @user, @message = @message, @agentRefId = NULL
  836. END
  837. END
  838. END
  839. IF @flag='sa'
  840. BEGIN
  841. SELECT pBank FROM remitTran WHERE id=@tranId
  842. END
  843. -->> transaction modification approve requested by branches
  844. IF @flag = 'approveAll'
  845. BEGIN
  846. SELECT @controlNoEncrypted = controlNo, @pCountry = pCountry FROM remitTran WITH(NOLOCK) WHERE id = @tranId
  847. IF OBJECT_ID('tempdb..#TEMPTABLE') IS NOT NULL
  848. DROP TABLE #TEMPTABLE
  849. CREATE TABLE #TEMPTABLE
  850. (
  851. tranId INT NULL,
  852. modifyId INT NULL,
  853. fieldName VARCHAR(100) NULL,
  854. fieldValue VARCHAR(MAX) NULL,
  855. oldValue VARCHAR(500) NULL,
  856. MSG VARCHAR(MAX) NULL
  857. )
  858. INSERT INTO #TEMPTABLE(tranId,modifyId,fieldName,fieldValue,oldValue,MSG)
  859. SELECT @tranId,rowId,fieldName,fieldValue,oldValue,message
  860. FROM tranModifyLog WHERE tranId = @tranId AND STATUS = 'Request'
  861. ALTER TABLE #TEMPTABLE ADD rowId INT IDENTITY(1,1)
  862. SELECT @MAXID =MAX(rowId) FROM #TEMPTABLE
  863. SET @MINID = 1
  864. WHILE @MAXID >= @MINID
  865. BEGIN
  866. SELECT @modifyId = modifyId,
  867. @fieldName = fieldName,
  868. @fieldValue = fieldValue,
  869. @oldValue = oldValue
  870. FROM #TEMPTABLE WITH(NOLOCK)
  871. WHERE rowId = @MINID
  872. IF @fieldName='senderName'
  873. BEGIN
  874. SET @xml = @fieldValue
  875. SELECT
  876. @firstName = p.value('@firstName','VARCHAR(50)')
  877. ,@middleName = p.value('@middleName','VARCHAR(50)')
  878. ,@lastName1 = p.value('@firstLastName','VARCHAR(50)')
  879. ,@lastName2 = p.value('@secondLastName','VARCHAR(50)')
  880. FROM @xml.nodes('/root/row') AS tmp(p)
  881. SELECT @firstName = UPPER(@firstName), @middleName = UPPER(@middleName), @lastName1 = UPPER(@lastName1), @lastName2 = UPPER(@lastName2)
  882. SET @senderName = @firstName + ISNULL(' ' + @middleName, '') + ISNULL(' ' + @lastName1, '') + ISNULL(' ' + @lastName2, '')
  883. UPDATE tranSenders SET
  884. firstName = @firstName
  885. ,middleName = @middleName
  886. ,lastName1 = @lastName1
  887. ,lastName2 = @lastName2
  888. ,fullName = @senderName
  889. WHERE tranId = @tranId
  890. UPDATE remitTran SET
  891. senderName = @senderName
  892. WHERE id = @tranId
  893. SET @message = 'Sender Name [<b>'+@oldValue+'</b>] has been replaced to [<b>' + ISNULL(@firstName, '') + ISNULL(' ' + @middleName, '') + ISNULL(' ' + @lastName1, '') + ISNULL(' ' +@lastName2, '')+'</b>]'
  894. EXEC proc_ofacTracker @flag = 't', @name = @senderName, @Result = @senderOfacRes OUTPUT
  895. END
  896. ELSE IF @fieldName='receiverName'
  897. BEGIN
  898. SET @xml = @fieldValue
  899. SELECT
  900. @firstName = p.value('@firstName','VARCHAR(50)')
  901. ,@middleName = p.value('@middleName','VARCHAR(50)')
  902. ,@lastName1 = p.value('@firstLastName','VARCHAR(50)')
  903. ,@lastName2 = p.value ('@secondLastName','VARCHAR(50)')
  904. FROM @xml.nodes('/root/row') AS tmp(p)
  905. SELECT @firstName = UPPER(@firstName), @middleName = UPPER(@middleName), @lastName1 = UPPER(@lastName1), @lastName2 = UPPER(@lastName2)
  906. SET @receiverName = @firstName + ISNULL(' ' + @middleName, '') + ISNULL(' ' + @lastName1, '') + ISNULL(' ' + @lastName2, '')
  907. UPDATE tranReceivers SET
  908. firstName = @firstName
  909. ,middleName = @middleName
  910. ,lastName1 = @lastName1
  911. ,lastName2 = @lastName2
  912. ,fullName = @receiverName
  913. WHERE tranId = @tranId
  914. UPDATE remitTran SET
  915. receiverName = @receiverName
  916. WHERE id = @tranId
  917. SET @message = 'Receiver Name [<b>'+@oldValue+'</b>] has been replaced to [<b>' + ISNULL(@firstName, '') + ISNULL(' ' + @middleName, '') + ISNULL(' ' + @lastName1, '') + ISNULL(' ' + @lastName2, '')+'</b>]'
  918. EXEC proc_ofacTracker @flag = 't', @name = @receiverName, @Result = @receiverOfacRes OUTPUT
  919. END
  920. ELSE IF @fieldName='rIdType'
  921. BEGIN
  922. UPDATE tranReceivers SET idType = @fieldValue WHERE tranId = @tranId
  923. SET @message = 'Receiver Id Type [<b>'+ISNULL(@oldValue, '') +'</b>] has been replaced to [<b>'+isnull(@fieldValue,'')+'</b>]'
  924. END
  925. ELSE IF @fieldName='rAddress'
  926. BEGIN
  927. UPDATE tranReceivers SET address = @fieldValue WHERE tranId = @tranId
  928. SET @message = 'Receiver Address [<b>'+ISNULL(@oldValue, '')+'</b>] has been replaced to [<b>'+isnull(@fieldValue,'')+'</b>]'
  929. END
  930. ELSE IF @fieldName='rContactNo'
  931. BEGIN
  932. UPDATE tranReceivers SET mobile = @fieldValue WHERE tranId = @tranId
  933. SET @message = 'Receiver Contact No [<b>'+ISNULL(@oldValue, '')+'</b>] has been replaced to [<b>'+isnull(@fieldValue,'')+'</b>]'
  934. END
  935. ELSE IF @fieldName='rIdNo'
  936. BEGIN
  937. UPDATE tranReceivers SET idNumber = @fieldValue WHERE tranId = @tranId
  938. SET @message = 'Receiver ID No [<b>'+ISNULL(@oldValue, '')+'</b>] has been replaced to [<b>'+isnull(@fieldValue,'')+'</b>]'
  939. END
  940. ELSE IF @fieldName='accountNo'
  941. BEGIN
  942. UPDATE remitTran SET accountNo = @fieldValue WHERE id = @tranId
  943. SET @message = 'Receiver Bank Ac No [<b>'+ISNULL(@oldValue, '')+'</b>] has been replaced to [<b>'+isnull(@fieldValue,'')+'</b>]'
  944. END
  945. UPDATE tranModifyLog SET
  946. MESSAGE = @message
  947. ,MsgType = 'MODIFY'
  948. ,resolvedBy = @user
  949. ,resolvedDate = GETDATE()
  950. ,status = 'approved'
  951. WHERE rowId = @modifyId
  952. SET @MINID = @MINID + 1
  953. DECLARE @newId VARCHAR(50) = NEWID()
  954. END
  955. SELECT @branchId= sBranch,@user = createdBy FROM remitTran WITH(NOLOCK) WHERE id = @tranId
  956. SELECT @emailId= dbo.FNAGetBranchEmail(@branchId,@user)
  957. UPDATE remitTran SET tranStatus = 'Payment' WHERE id = @tranId
  958. IF ISNULL(@senderOfacRes, '') <> ''
  959. BEGIN
  960. SET @ofacReason = 'Matched by sender name during transaction ammendment'
  961. SET @ofacRes = @senderOfacRes
  962. END
  963. IF ISNULL(@receiverOfacRes, '') <> ''
  964. BEGIN
  965. SET @ofacReason = 'Matched by receiver name during transaction ammendment'
  966. SET @ofacRes = @receiverOfacRes
  967. END
  968. IF ISNULL(@senderOfacRes, '') <> '' AND ISNULL(@receiverOfacRes, '') <> ''
  969. BEGIN
  970. SET @ofacReason = 'Matched by both sender name and receiver name during transaction ammendment'
  971. SET @ofacRes = @senderOfacRes + ',' + @receiverOfacRes
  972. END
  973. IF ISNULL(@ofacRes, '') <> ''
  974. BEGIN
  975. INSERT INTO remitTranOfac(TranId, blackListId, reason)
  976. SELECT @tranId, @ofacRes, @ofacReason
  977. UPDATE remitTran SET
  978. tranStatus = 'OFAC'
  979. WHERE id = @tranId
  980. RETURN
  981. END
  982. ------TROUBLE TICKET
  983. DECLARE @msg VARCHAR(MAX)
  984. ,@mobileNo VARCHAR(100)
  985. ,@country VARCHAR(100)
  986. ,@email VARCHAR(100)
  987. ,@subject VARCHAR(100)
  988. ,@mm VARCHAR(MAX)
  989. ,@cn VARCHAR(MAX)
  990. SET @cn=dbo.fnaEncryptString(@controlNo)
  991. Set @mm=(SELECT top 1 message FROM tranModifyLog WHERE ISNULL(status,'1')='Request' AND controlNo=@cn)
  992. SET @msg= 'Dear Customer,ICN('+@controlNo+'):'+ isnull(@mm,'') +'Please confirm the detail and visit sending agent,if modification required.'
  993. SET @mobileNo =(SELECT mobile FROM tranSenders WHERE tranId = '500809502')
  994. SET @country =(SELECT country FROM tranSenders WHERE tranId = @tranId)
  995. SELECT
  996. @agentId=rt.sAgent
  997. ,@branchId=rt.sBranch from remitTran rt
  998. INNER JOIn tranSenders ts on ts.tranId=rt.id WHERE tranid=@tranId
  999. SET @email=
  1000. (
  1001. SELECT am.agentEmail1 FROM remitTran rt
  1002. INNER JOIN agentMaster am ON rt.sAgent=am.agentId
  1003. WHERE rt.id=@tranId)
  1004. IF @sendSmsEmail iS NOT NULL
  1005. BEGIN
  1006. IF @sendSmsEmail='sms'
  1007. BEGIN
  1008. EXEC sp_InsertIntoSMSQueue 'sms' ,@user ,@msg,@country,NULL,@agentId ,@branchId ,@mobileNo ,@controlNo,NULL,@tranId
  1009. EXEC proc_errorHandler 0,' ',@emailId
  1010. RETURn
  1011. END
  1012. ELSE IF @sendSmsEmail='email'
  1013. BEGIN
  1014. EXEC sp_InsertIntoSMSQueue 'email' ,@user ,@msg,@country,@email,@agentId ,@branchId ,NULL,@controlNo , @subject,@tranId
  1015. EXEC proc_errorHandler 0,' ',@emailId
  1016. RETURn
  1017. END
  1018. ELSE IF @sendSmsEmail='both'
  1019. BEGIN
  1020. EXEC sp_InsertIntoSMSQueue 'both' ,@user ,@msg,@country,@email,@agentId ,@branchId ,@mobileNo,@controlNo,@subject,@tranId
  1021. EXEC proc_errorHandler 0,' ',@emailId
  1022. RETURn
  1023. END
  1024. END
  1025. EXEC proc_errorHandler 0,'Modification Request Approved successfully',@emailId
  1026. END
  1027. -->> transaction modification reject requested by branches
  1028. if @flag = 'reject'
  1029. begin
  1030. SELECT @controlNoEncrypted = controlNo, @pCountry = pCountry FROM remitTran WITH(NOLOCK) WHERE id = @tranId
  1031. INSERT INTO tranModifyRejectLog(tranId, controlNo, message, createdBy, createdDate, rejectedBy, rejectedDate, fieldName, fieldValue)
  1032. SELECT tranId, controlNo, message, createdBy, createdDate, @user, GETDATE(), fieldName, fieldValue FROM tranModifyLog WHERE tranId = @tranId AND STATUS = 'Request'
  1033. DELETE
  1034. FROM tranModifyLog WHERE tranId = @tranId AND STATUS = 'Request'
  1035. UPDATE remitTran SET tranStatus = 'Payment' WHERE id = @tranId
  1036. EXEC proc_errorHandler 0,'Modification request rejected successfully',@controlNoEncrypted
  1037. end
  1038. if @flag ='branchByTranId'
  1039. BEGIN
  1040. DECLARE @pBank INT
  1041. SELECT @pBank = pBank, @pBankType = pBankType FROM vwRemitTran with(nolock) where id = @tranId
  1042. IF @pBankType = 'I'
  1043. BEGIN
  1044. SELECT
  1045. agentId
  1046. ,agentName
  1047. FROM agentMaster WITH(NOLOCK) WHERE parentId = @pBank order by agentName
  1048. END
  1049. ELSE IF @pBankType = 'E'
  1050. BEGIN
  1051. SELECT
  1052. agentId = extBankId
  1053. ,agentName = branchName
  1054. FROM externalBankBranch WITH(NOLOCK) WHERE extBankId = @pBank order by branchName
  1055. END
  1056. END
  1057. END TRY
  1058. BEGIN CATCH
  1059. IF @@TRANCOUNT > 0
  1060. ROLLBACK TRANSACTION
  1061. DECLARE @errorMessage VARCHAR(MAX)
  1062. SET @errorMessage = ERROR_MESSAGE()
  1063. EXEC proc_errorHandler 1, @errorMessage, @tranId
  1064. END CATCH
  1065. GO