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.

129 lines
8.3 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_sambaBatchManager] 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_sambaBatchManager]
  9. (
  10. @user VARCHAR(50)
  11. )
  12. AS
  13. SET NOCOUNT ON;
  14. SET XACT_ABORT ON;
  15. BEGIN TRY
  16. IF NOT EXISTS(SELECT 'X' FROM RemittanceLogData.dbo.[temp_money] WITH(NOLOCK) WHERE FLAG IS NULL)
  17. BEGIN
  18. EXEC proc_errorHandler 1, 'Transaction Not Found.', @user
  19. RETURN;
  20. END
  21. INSERT INTO remitTranTemp
  22. (
  23. [controlNo]
  24. ,[senderName]
  25. ,[receiverName]
  26. ,[sCountry]
  27. ,[sSuperAgent]
  28. ,[sSuperAgentName]
  29. ,[sAgent]
  30. ,[sAgentName]
  31. ,[sBranch]
  32. ,[sBranchName]
  33. ,[paymentMethod]
  34. ,[cAmt]
  35. ,[tAmt]
  36. ,[pAmt]
  37. ,[customerRate]
  38. ,[payoutCurr]
  39. ,[pCountry]
  40. ,[pBank]
  41. ,[pbankName]
  42. ,[pBankBranch]
  43. ,[pBankBranchName]
  44. ,pBankType
  45. ,[accountNo]
  46. ,[tranStatus]
  47. ,[payStatus]
  48. ,[collCurr]
  49. ,[tranType]
  50. ,[serviceCharge]
  51. ,[sAgentComm]
  52. ,[sCurrCostRate]
  53. ,[pMessage]
  54. ,[createdBy]
  55. ,[createdDate]
  56. ,[createdDateLocal]
  57. )
  58. SELECT controlNo = refno ,
  59. senderName = SenderName ,
  60. ReceiverName receiverName,
  61. sCountry = SenderCountry ,
  62. sSuperAgent = '4641',
  63. sSuperAgentName = 'INTERNATIONAL AGENTS',
  64. sAgent = '4873',
  65. sAgentName = 'SAMBA FINANCIAL GROUP',
  66. sBranch = '4874',
  67. sBranchName = 'SAMBA FINANCIAL GROUP - RIYADH',
  68. paymentMethod = CASE WHEN tm.paymentType = 'Cash Pay' THEN 'Cash Payment' WHEN tm.paymentType = 'Bank Transfer' THEN 'Bank Deposit' ELSE tm.paymentType END,
  69. cAmt = paidAmt-1.87,
  70. tAmt = paidAmt-1.87,
  71. pAmt = TotalRoundAmt,
  72. customerRate = Today_Dollar_rate,
  73. payoutCurr = receiveCType,
  74. pCountry = 'Nepal',
  75. pBank = CASE WHEN tm.paymentType = 'Bank Transfer' THEN eb.extBankId ELSE NULL END,
  76. pBankName = CASE WHEN tm.paymentType = 'Bank Transfer' THEN eb.bankName ELSE NULL END,
  77. pBankBranch = NULL,
  78. pBankBranchName = CASE WHEN tm.paymentType = 'Bank Transfer' THEN rBankBranch ELSE NULL END,
  79. pBankType = CASE WHEN tm.paymentType = 'Bank Transfer' THEN 'E' ELSE NULL END,
  80. accountNo = tm.rBankACNo,
  81. tranStatus = 'Hold',
  82. payStatus = 'Unpaid',
  83. collCurr = paidCType,
  84. tranType = 'I',
  85. serviceCharge = 0,
  86. sAgentComm=0,
  87. sCurrCostRate = '1',
  88. pMessage = ReciverMessage,
  89. createdBy =SEmpID,
  90. createdDate = local_DOT,
  91. createdDateLocal = local_DOT
  92. FROM RemittanceLogData.dbo.[temp_money] tm WITH(NOLOCK)
  93. LEFT JOIN agentMaster pb WITH(NOLOCK) ON pb.mapCodeInt = tm.rBankID AND (pb.agentType IN (2904, 2906) OR (pb.agentType = 2903 AND pb.actAsBranch = 'Y'))
  94. LEFT JOIN agentMaster pa WITH(NOLOCK) ON pb.parentId = pa.agentId AND pa.agentType IN (2903, 2905)
  95. LEFT JOIN externalBank eb WITH(NOLOCK) ON eb.mapCodeInt = pa.mapCodeInt
  96. WHERE tm.FLAG is null
  97. INSERT INTO tranSendersTemp(tranId,firstName,address,city,country,nativeCountry,email,companyName,idType,idNumber)
  98. SELECT rt.id, tm.SenderName, tm.SenderAddress, tm.SenderCity, tm.SenderCountry, tm.SenderNativeCountry,tm.SenderEmail,SenderCompany,'Passport',senderPassport
  99. FROM RemittanceLogData.dbo.[temp_money] tm WITH(NOLOCK) INNER JOIN remitTranTemp rt ON tm.refno = rt.controlNo
  100. WHERE tm.FLAG is null
  101. INSERT INTO tranReceiversTemp(tranId,firstName,address,homePhone,workPhone,city,country,idType,idNumber)
  102. SELECT rt.id,tm.ReceiverName,ReceiverAddress+'(AC:'+tm.rBankACNo+')', ReceiverPhone,receiver_mobile, ReceiverCity,ReceiverCountry,
  103. ReceiverIDDescription ,ReceiverID
  104. FROM RemittanceLogData.dbo.[temp_money] tm WITH(NOLOCK) INNER JOIN remitTranTemp rt ON tm.refno = rt.controlNo
  105. WHERE tm.FLAG is null
  106. UPDATE RemittanceLogData.dbo.[temp_money] SET FLAG = 'Y' WHERE FLAG IS NULL
  107. EXEC proc_errorHandler 0, 'Data submitted successfully', @user
  108. END TRY
  109. BEGIN CATCH
  110. IF @@TRANCOUNT<>0
  111. ROLLBACK TRANSACTION
  112. DECLARE @errorMessage VARCHAR(MAX)
  113. SET @errorMessage = ERROR_MESSAGE()
  114. EXEC proc_errorHandler 1, @errorMessage, @user
  115. END CATCH
  116. --alter table temp_money add flag char(1)
  117. GO