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.

348 lines
13 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_categoryContact] 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_categoryContact]
  9. @flag VARCHAR(50) = NULL
  10. ,@user VARCHAR(30) = NULL
  11. ,@id INT = NULL
  12. ,@catId INT = NULL
  13. ,@categoryName VARCHAR(200) = NULL
  14. ,@categoryDesc VARCHAR(max) = NULL
  15. ,@customerName VARCHAR(200) = NULL
  16. ,@customerAddress VARCHAR(max) = NULL
  17. ,@mobile VARCHAR(100) = NULL
  18. ,@email VARCHAR(100) = NULL
  19. ,@sortBy VARCHAR(50) = NULL
  20. ,@sortOrder VARCHAR(5) = NULL
  21. ,@pageSize INT = NULL
  22. ,@pageNumber INT = NULL
  23. AS
  24. SET NOCOUNT ON;
  25. SET XACT_ABORT ON;
  26. BEGIN TRY
  27. CREATE TABLE #msg(errorCode INT, msg VARCHAR(100), id INT)
  28. DECLARE
  29. @sql VARCHAR(MAX)
  30. ,@oldValue VARCHAR(MAX)
  31. ,@newValue VARCHAR(MAX)
  32. ,@module VARCHAR(10)
  33. ,@tableAlias VARCHAR(100)
  34. ,@logIdentifier VARCHAR(50)
  35. ,@logParamMod VARCHAR(100)
  36. ,@logParamMain VARCHAR(100)
  37. ,@table VARCHAR(MAX)
  38. ,@select_field_list VARCHAR(MAX)
  39. ,@extra_field_list VARCHAR(MAX)
  40. ,@sql_filter VARCHAR(MAX)
  41. ,@modType VARCHAR(6)
  42. ,@ApprovedFunctionId INT
  43. SELECT
  44. @logIdentifier = 'id'
  45. ,@logParamMain = 'categoryContact'
  46. ,@module = '20'
  47. ,@tableAlias = 'Customer Category Contact Details'
  48. --select * from categoryContact
  49. IF @flag IN ('s')
  50. BEGIN
  51. SET @table = '(
  52. SELECT
  53. id
  54. ,categoryName
  55. ,categoryDesc
  56. ,createdBy
  57. ,createdDate
  58. ,modifiedDate
  59. ,modifiedBy
  60. ,hasChanged = ''Y''
  61. FROM categoryContact main where isnull(isDeleted,''N'')<>''Y''
  62. )a '
  63. --select (@table)
  64. --return;
  65. END
  66. IF @flag = 'i'
  67. BEGIN
  68. INSERT INTO categoryContact (
  69. categoryName
  70. ,categoryDesc
  71. ,createdBy
  72. ,createdDate
  73. )
  74. SELECT
  75. @categoryName
  76. ,@categoryDesc
  77. ,@user
  78. ,GETDATE()
  79. SET @id = SCOPE_IDENTITY()
  80. IF @@TRANCOUNT > 0
  81. COMMIT TRANSACTION
  82. EXEC proc_errorHandler 0, 'Record has been added successfully.', @id
  83. END
  84. ELSE IF @flag = 'a'
  85. BEGIN
  86. SELECT
  87. id
  88. ,categoryName
  89. ,categoryDesc
  90. ,createdBy
  91. ,createdDate
  92. ,modifiedBy
  93. ,modifiedDate
  94. FROM categoryContact where id=@id
  95. END
  96. ELSE IF @flag = 'u'
  97. BEGIN
  98. UPDATE categoryContact SET
  99. categoryName = @categoryName
  100. ,categoryDesc = @categoryDesc
  101. ,modifiedBy = @user
  102. ,modifiedDate = GETDATE()
  103. WHERE id = @id
  104. IF @@TRANCOUNT > 0
  105. COMMIT TRANSACTION
  106. EXEC proc_errorHandler 0, 'Record updated successfully.', @id
  107. END
  108. ELSE IF @flag = 'd'
  109. BEGIN
  110. update categoryContact set isDeleted='Y' WHERE ID=@id
  111. EXEC proc_errorHandler 0, 'Record deleted successfully.', @id
  112. END
  113. ELSE IF @flag = 's'
  114. BEGIN
  115. IF @sortBy IS NULL
  116. SET @sortBy = 'id'
  117. IF @sortOrder IS NULL
  118. SET @sortOrder = 'ASC'
  119. SET @table = '(
  120. SELECT
  121. id
  122. ,categoryName
  123. ,categoryDesc
  124. ,createdBy
  125. ,createdDate
  126. ,modifiedDate
  127. ,modifiedBy
  128. ,hasChanged
  129. FROM ' + @table + '
  130. ) x
  131. '
  132. --select @table
  133. --return;
  134. SET @sql_filter = ''
  135. SET @select_field_list ='
  136. id
  137. ,categoryName
  138. ,categoryDesc
  139. ,createdBy
  140. ,createdDate
  141. ,modifiedDate
  142. ,modifiedBy
  143. ,hasChanged
  144. '
  145. EXEC dbo.proc_paging
  146. @table
  147. ,@sql_filter
  148. ,@select_field_list
  149. ,@extra_field_list
  150. ,@sortBy
  151. ,@sortOrder
  152. ,@pageSize
  153. ,@pageNumber
  154. END
  155. --- ## Customer Contact List ## ---
  156. IF @flag IN ('sc')
  157. BEGIN
  158. SET @table = '(
  159. SELECT
  160. id
  161. ,catId
  162. ,customerName
  163. ,customerAddress
  164. ,email
  165. ,mobile
  166. ,createdBy
  167. ,createdDate
  168. ,modifiedDate
  169. ,modifiedBy
  170. ,hasChanged = ''Y''
  171. FROM customerContactList main where isnull(isDeleted,''N'')<>''Y''
  172. AND catId=''' + cast(@catId as varchar)+ '''
  173. )a '
  174. END
  175. IF @flag = 'ic'
  176. BEGIN
  177. INSERT INTO customerContactList
  178. (
  179. catId
  180. ,customerName
  181. ,customerAddress
  182. ,mobile
  183. ,email
  184. ,createdBy
  185. ,createdDate
  186. )
  187. SELECT
  188. @catId
  189. ,@customerName
  190. ,@customerAddress
  191. ,@mobile
  192. ,@email
  193. ,@user
  194. ,GETDATE()
  195. SET @id = SCOPE_IDENTITY()
  196. IF @@TRANCOUNT > 0
  197. COMMIT TRANSACTION
  198. EXEC proc_errorHandler 0, 'Record has been added successfully.', @id
  199. END
  200. ELSE IF @flag = 'ac'
  201. BEGIN
  202. SELECT
  203. id
  204. ,catId
  205. ,customerName
  206. ,CustomerAddress
  207. ,mobile
  208. ,email
  209. ,createdBy
  210. ,createdDate
  211. ,modifiedBy
  212. ,modifiedDate
  213. FROM customerContactList where id=@id
  214. END
  215. ELSE IF @flag = 'uc'
  216. BEGIN
  217. UPDATE customerContactList SET
  218. catId=@catId
  219. ,customerName = @customerName
  220. ,CustomerAddress = @customerAddress
  221. ,mobile=@mobile
  222. ,email=@email
  223. ,modifiedBy = @user
  224. ,modifiedDate = GETDATE()
  225. WHERE id = @id
  226. IF @@TRANCOUNT > 0
  227. COMMIT TRANSACTION
  228. EXEC proc_errorHandler 0, 'Record updated successfully.', @id
  229. END
  230. ELSE IF @flag = 'dc'
  231. BEGIN
  232. update customerContactList set isDeleted='Y' WHERE ID=@id
  233. EXEC proc_errorHandler 0, 'Record deleted successfully.', @id
  234. END
  235. ELSE IF @flag = 'sc'
  236. BEGIN
  237. IF @sortBy IS NULL
  238. SET @sortBy = 'id'
  239. IF @sortOrder IS NULL
  240. SET @sortOrder = 'ASC'
  241. SET @table = '(
  242. SELECT
  243. id
  244. ,catId
  245. ,customerName
  246. ,customerAddress
  247. ,email
  248. ,mobile
  249. ,createdBy
  250. ,createdDate
  251. ,modifiedDate
  252. ,modifiedBy
  253. ,hasChanged
  254. FROM ' + @table + '
  255. ) x
  256. '
  257. --select @table
  258. --return;
  259. SET @sql_filter = ''
  260. SET @select_field_list ='
  261. id
  262. ,catId
  263. ,customerName
  264. ,customerAddress
  265. ,email
  266. ,mobile
  267. ,createdBy
  268. ,createdDate
  269. ,modifiedDate
  270. ,modifiedBy
  271. ,hasChanged
  272. '
  273. EXEC dbo.proc_paging
  274. @table
  275. ,@sql_filter
  276. ,@select_field_list
  277. ,@extra_field_list
  278. ,@sortBy
  279. ,@sortOrder
  280. ,@pageSize
  281. ,@pageNumber
  282. END
  283. END TRY
  284. BEGIN CATCH
  285. IF @@TRANCOUNT > 0
  286. ROLLBACK TRANSACTION
  287. DECLARE @errorMessage VARCHAR(MAX)
  288. SET @errorMessage = ERROR_MESSAGE()
  289. EXEC proc_errorHandler 1, @errorMessage, @id
  290. END CATCH
  291. GO