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.

403 lines
23 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_agentMasterMigration] 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_agentMasterMigration]
  9. @flag VARCHAR(50) = NULL
  10. ,@user VARCHAR(30) = NULL
  11. ,@agentId VARCHAR(30) = NULL
  12. ,@parentId VARCHAR(30) = NULL
  13. ,@agentName VARCHAR(100) = NULL
  14. ,@agentCode VARCHAR(50) = NULL
  15. ,@agentAddress VARCHAR(200) = NULL
  16. ,@agentCity VARCHAR(100) = NULL
  17. ,@agentCountryId INT = NULL
  18. ,@agentCountry VARCHAR(100) = NULL
  19. ,@agentState VARCHAR(100) = NULL
  20. ,@agentDistrict VARCHAR(100) = NULL
  21. ,@agentZip VARCHAR(20) = NULL
  22. ,@agentLocation INT = NULL
  23. ,@agentPhone1 VARCHAR(50) = NULL
  24. ,@agentPhone2 VARCHAR(50) = NULL
  25. ,@agentFax1 VARCHAR(50) = NULL
  26. ,@agentFax2 VARCHAR(50) = NULL
  27. ,@agentMobile1 VARCHAR(50) = NULL
  28. ,@agentMobile2 VARCHAR(50) = NULL
  29. ,@agentEmail1 VARCHAR(100) = NULL
  30. ,@agentEmail2 VARCHAR(100) = NULL
  31. ,@businessOrgType INT = NULL
  32. ,@businessType INT = NULL
  33. ,@agentRole CHAR(1) = NULL
  34. ,@agentType INT = NULL
  35. ,@allowAccountDeposit CHAR(1) = NULL
  36. ,@actAsBranch CHAR(1) = NULL
  37. ,@contractExpiryDate DATETIME = NULL
  38. ,@renewalFollowupDate DATETIME = NULL
  39. ,@isSettlingAgent CHAR(1) = NULL
  40. ,@isHeadOffice CHAR(1) = NULL
  41. ,@agentGroup INT = NULL
  42. ,@businessLicense VARCHAR(100) = NULL
  43. ,@agentBlock CHAR(1) = NULL
  44. ,@agentcompanyName VARCHAR(200) = NULL
  45. ,@companyAddress VARCHAR(200) = NULL
  46. ,@companyCity VARCHAR(100) = NULL
  47. ,@companyCountry VARCHAR(100) = NULL
  48. ,@companyState VARCHAR(100) = NULL
  49. ,@companyDistrict VARCHAR(100) = NULL
  50. ,@companyZip VARCHAR(50) = NULL
  51. ,@companyPhone1 VARCHAR(50) = NULL
  52. ,@companyPhone2 VARCHAR(50) = NULL
  53. ,@companyFax1 VARCHAR(50) = NULL
  54. ,@companyFax2 VARCHAR(50) = NULL
  55. ,@companyEmail1 VARCHAR(100) = NULL
  56. ,@companyEmail2 VARCHAR(100) = NULL
  57. ,@localTime INT = NULL
  58. ,@localCurrency INT = NULL
  59. ,@agentDetails VARCHAR(MAX) = NULL
  60. ,@contactPerson VARCHAR(200) = NULL
  61. ,@cpPost VARCHAR(50) = NULL
  62. ,@cpEmail VARCHAR(100) = NULL
  63. ,@parentName VARCHAR(100) = NULL
  64. ,@haschanged CHAR(1) = NULL
  65. ,@isActive CHAR(1) = NULL
  66. ,@isDeleted CHAR(1) = NULL
  67. ,@sortBy VARCHAR(50) = NULL
  68. ,@sortOrder VARCHAR(5) = NULL
  69. ,@pageSize INT = NULL
  70. ,@pageNumber INT = NULL
  71. ,@populateBranch CHAR(1) = NULL
  72. ,@headMessage VARCHAR(MAX) = NULL
  73. ,@mapCodeInt VARCHAR(20) = NULL
  74. ,@mapCodeDom VARCHAR(20) = NULL
  75. ,@commCodeInt VARCHAR(20) = NULL
  76. ,@commCodeDom VARCHAR(20) = NULL
  77. ,@urlRoot VARCHAR(200) = NULL
  78. ,@joinedDate DATETIME = NULL
  79. ,@createdBy VARCHAR(50) = NULL
  80. ,@createdDate DATETIME = NULL
  81. ,@approvedBy VARCHAR(50) = NULL
  82. ,@approvedDate DATETIME = NULL
  83. AS
  84. SET NOCOUNT ON
  85. CREATE TABLE #tempACnum (acct_num VARCHAR(20));
  86. SET XACT_ABORT ON
  87. BEGIN TRY
  88. CREATE TABLE #msg(errorCode INT, msg VARCHAR(100), id INT)
  89. DECLARE
  90. @sql VARCHAR(MAX)
  91. ,@oldValue VARCHAR(MAX)
  92. ,@newValue VARCHAR(MAX)
  93. ,@tableName VARCHAR(50)
  94. ,@logIdentifier VARCHAR(100)
  95. ,@logParamMain VARCHAR(100)
  96. ,@tableAlias VARCHAR(100)
  97. ,@modType VARCHAR(6)
  98. ,@module INT
  99. ,@select_field_list VARCHAR(MAX)
  100. ,@extra_field_list VARCHAR(MAX)
  101. ,@table VARCHAR(MAX)
  102. ,@sql_filter VARCHAR(MAX)
  103. ,@ApprovedFunctionId INT
  104. ,@msg VARCHAR(MAX)
  105. SELECT
  106. @logIdentifier = 'agentId'
  107. ,@logParamMain = 'agentMaster'
  108. ,@tableAlias = 'Agent Setup'
  109. ,@module = 20
  110. ,@ApprovedFunctionId = 20101030
  111. IF @flag = 'i'
  112. BEGIN
  113. IF @agentName IS NULL
  114. BEGIN
  115. EXEC proc_errorHandler 1, 'Agent Name cannot be empty', NULL
  116. RETURN
  117. END
  118. /*
  119. IF EXISTS(SELECT 'X' FROM agentMaster WHERE agentName = @agentName AND agentType = @agentType AND ISNULL(isDeleted, 'N') <> 'Y' AND ISNULL(isActive, 'N') = 'Y')
  120. BEGIN
  121. SET @msg = 'Agent with name ' + @agentName + ' already exists'
  122. EXEC proc_errorHandler 1, @msg, NULL
  123. RETURN
  124. END
  125. */
  126. IF EXISTS(SELECT 'X' FROM agentMaster WITH(NOLOCK) WHERE mapCodeInt = @mapCodeInt)
  127. BEGIN
  128. SET @msg = 'Map Code ' + @mapCodeInt + ' already exists'
  129. EXEC proc_errorHandler 1, @msg, NULL
  130. RETURN
  131. END
  132. BEGIN TRANSACTION
  133. INSERT INTO agentMaster (
  134. parentId
  135. ,agentName
  136. ,agentCode
  137. ,agentAddress
  138. ,agentCity
  139. ,agentCountryId
  140. ,agentCountry
  141. ,agentState
  142. ,agentDistrict
  143. ,agentZip
  144. ,agentLocation
  145. ,agentPhone1
  146. ,agentPhone2
  147. ,agentFax1
  148. ,agentFax2
  149. ,agentMobile1
  150. ,agentMobile2
  151. ,agentEmail1
  152. ,agentEmail2
  153. ,businessOrgType
  154. ,businessType
  155. ,agentRole
  156. ,agentType
  157. ,allowAccountDeposit
  158. ,actAsBranch
  159. ,contractExpiryDate
  160. ,renewalFollowupDate
  161. ,isSettlingAgent
  162. ,isHeadOffice
  163. ,agentGrp
  164. ,businessLicense
  165. ,agentBlock
  166. ,agentcompanyName
  167. ,companyAddress
  168. ,companyCity
  169. ,companyCountry
  170. ,companyState
  171. ,companyDistrict
  172. ,companyZip
  173. ,companyPhone1
  174. ,companyPhone2
  175. ,companyFax1
  176. ,companyFax2
  177. ,companyEmail1
  178. ,companyEmail2
  179. ,localTime
  180. ,localCurrency
  181. ,agentDetails
  182. --,contactPerson
  183. --,cpPost
  184. ,cpEmail
  185. ,createdDate
  186. ,createdBy
  187. ,headMessage
  188. ,mapCodeInt
  189. ,mapCodeDom
  190. ,commCodeInt
  191. ,commCodeDom
  192. ,joinedDate
  193. ,approvedBy
  194. ,approvedDate
  195. ,isActive
  196. )
  197. SELECT
  198. @parentId
  199. ,@agentName
  200. ,@agentCode
  201. ,@agentAddress
  202. ,@agentCity
  203. ,@agentCountryId
  204. ,@agentCountry
  205. ,@agentState
  206. ,@agentDistrict
  207. ,@agentZip
  208. ,@agentLocation
  209. ,@agentPhone1
  210. ,@agentPhone2
  211. ,@agentFax1
  212. ,@agentFax2
  213. ,@agentMobile1
  214. ,@agentMobile2
  215. ,@agentEmail1
  216. ,@agentEmail2
  217. ,@businessOrgType
  218. ,@businessType
  219. ,@agentRole
  220. ,@agentType
  221. ,@allowAccountDeposit
  222. ,@actAsBranch
  223. ,@contractExpiryDate
  224. ,@renewalFollowupDate
  225. ,@isSettlingAgent
  226. ,@isHeadOffice
  227. ,@agentGroup
  228. ,@businessLicense
  229. ,@agentBlock
  230. ,@agentcompanyName
  231. ,@companyAddress
  232. ,@companyCity
  233. ,@companyCountry
  234. ,@companyState
  235. ,@companyDistrict
  236. ,@companyZip
  237. ,@companyPhone1
  238. ,@companyPhone2
  239. ,@companyFax1
  240. ,@companyFax2
  241. ,@companyEmail1
  242. ,@companyEmail2
  243. ,@localTime
  244. ,@localCurrency
  245. ,@agentDetails
  246. --,@contactPerson
  247. --,@cpPost
  248. ,@cpEmail
  249. ,ISNULL(@createdDate,GETDATE())
  250. ,ISNULL(@createdBy,@user)
  251. ,@headMessage
  252. ,@mapCodeInt
  253. ,@mapCodeDom
  254. ,@commCodeInt
  255. ,@commCodeDom
  256. ,@joinedDate
  257. ,ISNULL(@approvedBy, @user)
  258. ,ISNULL(@approvedDate, GETDATE())
  259. ,@isActive
  260. SET @agentId = SCOPE_IDENTITY()
  261. IF @agentCode IS NULL
  262. UPDATE agentMaster set agentCode = dbo.FNAGetAgentCode(@agentId) where agentId=@agentId
  263. COMMIT TRANSACTION
  264. EXEC proc_errorHandler 0, 'Record has been added successfully.', @agentId
  265. END
  266. ELSE IF @flag = 'approve'
  267. BEGIN
  268. SELECT @agentCountry = agentCountry, @contractExpiryDate = contractExpiryDate, @approvedBy = approvedBy, @approvedDate = approvedDate FROM agentMaster WITH(NOLOCK) WHERE agentId = @agentId
  269. UPDATE agentMaster SET
  270. isActive = 'Y'
  271. ,approvedBy = ISNULL(@approvedBy, @user)
  272. ,approvedDate = ISNULL(@approvedDate, GETDATE())
  273. WHERE agentId = @agentId
  274. /*
  275. INSERT INTO creditLimit(
  276. agentId,currency
  277. ,limitAmt,perTopUpAmt,maxLimitAmt
  278. ,expiryDate,isActive
  279. ,createdBy,createdDate,approvedBy,approvedDate
  280. ,topUpTillYesterday,topUpToday,todaysSent,todaysPaid,todaysCancelled,lienAmt
  281. )
  282. SELECT
  283. @agentId,2
  284. ,0,0,0
  285. ,@contractExpiryDate,'Y'
  286. ,@user,GETDATE(),@user,GETDATE()
  287. ,0,0,0,0,0,0
  288. */
  289. /*
  290. --Account Creation
  291. IF EXISTS(SELECT 'X' FROM agentMaster WHERE agentId = @agentId AND ISNULL(isSettlingAgent, 'N') = 'Y')
  292. BEGIN
  293. DECLARE @currency INT
  294. SELECT @agentCountry = agentCountry, @contractExpiryDate = contractExpiryDate FROM agentMaster WITH(NOLOCK) WHERE agentId = @agentId
  295. SELECT @currency = CASE WHEN @agentCountry = 'Nepal' THEN 1 ELSE 2 END
  296. INSERT INTO creditLimit(
  297. agentId,currency
  298. ,limitAmt,perTopUpAmt,maxLimitAmt
  299. ,expiryDate,isActive
  300. ,createdBy,createdDate,approvedBy,approvedDate
  301. ,topUpTillYesterday,topUpToday,todaysSent,todaysPaid,todaysCancelled,lienAmt
  302. )
  303. SELECT
  304. @agentId,@currency
  305. ,0,0,0
  306. ,@contractExpiryDate,'Y'
  307. ,@user,GETDATE(),@user,GETDATE()
  308. ,0,0,0,0,0,0
  309. END
  310. ---------------INSERTING AGENT ON IME SYSTEM--------------------
  311. ---------------INSERTING AGENT ON IME SYSTEM--------------------
  312. DECLARE @ismainAgent1 CHAR(1),@CENTRAL_SETT_CODE1 VARCHAR(30)
  313. DECLARE @agentRole1 VARCHAR(20)
  314. SELECT
  315. @isSettlingAgent= isSettlingAgent
  316. ,@agentName = agentName
  317. ,@agentAddress = agentAddress
  318. ,@agentCity = agentCity
  319. ,@agentPhone1 = agentPhone1
  320. ,@agentFax1 = agentFax1
  321. ,@agentEmail1 = agentEmail1
  322. ,@isActive = isActive
  323. ,@agentState = agentState
  324. ,@agentDistrict = agentDistrict
  325. ,@agentRole1 = CASE WHEN agentRole ='S' THEN 'Sending' ELSE 'Receiving' END
  326. ,@mapCodeInt = mapCodeInt
  327. ,@mapCodeDom = mapCodeDom
  328. ,@commCodeInt = commCodeInt
  329. ,@commCodeDom = commCodeDom
  330. FROM agentMaster WHERE agentId = @agentId
  331. IF @isSettlingAgent ='Y'
  332. BEGIN
  333. SET @ismainAgent1 = 'y'
  334. SET @CENTRAL_SETT_CODE1 = @mapCodeInt
  335. END
  336. IF ISNULL(@isSettlingAgent,'N') = 'N'
  337. BEGIN
  338. SET @ismainAgent1 = 'n'
  339. SET @CENTRAL_SETT_CODE1 = (SELECT mapCodeInt FROM agentMaster WHERE AGENTID = (SELECT parentId FROM agentMaster WHERE agentId = @agentId))
  340. END
  341. EXEC [192.168.1.234].IME_TEST.[dbo].[spa_agentdetail]
  342. @flag='i',
  343. @agent_id =@agentId,
  344. @agent_name =@agentName,
  345. @agent_short_name = NULL,
  346. @agent_address =@agentAddress,
  347. @agent_city = @agentCity,
  348. @agent_address2 = NULL,
  349. @agent_phone = @agentPhone1,
  350. @agent_fax = @agentFax1,
  351. @agent_email = @agentEmail1,
  352. @agent_contact_person =null,
  353. @agent_contact_person_mobile = null,
  354. @agent_status = @isActive,
  355. @MAP_code = @mapCodeInt,
  356. @MAP_code2 =@commCodeInt,
  357. @agenttype = @agentRole1 ,
  358. @agent_imecode = @mapCodeDom,
  359. @TDS_PCNT = null,
  360. @tid = @commCodeDom,
  361. @agentzone = @agentState,
  362. @agentdistrict = @agentDistrict,
  363. @agent_panno = null,
  364. @central_sett = 'y',
  365. @ismainAgent = @ismainAgent1,
  366. @CENTRAL_SETT_CODE = @CENTRAL_SETT_CODE1,
  367. @username = @user,
  368. @company_id ='1'
  369. ---------------ending AGENT ON IME SYSTEM--------------------
  370. */
  371. END
  372. END TRY
  373. BEGIN CATCH
  374. IF @@TRANCOUNT > 0
  375. ROLLBACK TRANSACTION
  376. SELECT 1 error_code, ERROR_MESSAGE() mes, null id
  377. END CATCH
  378. GO