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.

1308 lines
43 KiB

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