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.

576 lines
38 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_txnDocumentsForAgent] 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_txnDocumentsForAgent]
  9. @flag VARCHAR(50)
  10. ,@user VARCHAR(50) = NULL
  11. ,@rowId BIGINT = NULL
  12. ,@tranId VARCHAR(50) = NULL
  13. ,@agentId VARCHAR(50) = NULL
  14. ,@fromDate VARCHAR(50) = NULL
  15. ,@toDate VARCHAR(30) = NULL
  16. ,@agent VARCHAR(200) = NULL
  17. ,@status VARCHAR(50) = NULL
  18. ,@receivedId VARCHAR(50) = NULL
  19. ,@controlNo VARCHAR(20) = NULL
  20. ,@tranAmt VARCHAR(50) = Null
  21. ,@senderName VARCHAR(50) = NULL
  22. ,@receiverName VARCHAR(50) = NULL
  23. ,@createdBy VARCHAR(50) = NULL
  24. ,@createdDate DATE = NULL
  25. ,@fileDescription VARCHAR(100) = NULL
  26. ,@fileType VARCHAR(100) = NULL
  27. ,@txnYear VARCHAR(100) = NULL
  28. ,@fileName VARCHAR(100) = NULL
  29. ,@sortBy VARCHAR(50) = NULL
  30. ,@sortOrder VARCHAR(50) = NULL
  31. ,@pageSize VARCHAR(50) = NULL
  32. ,@pageNumber VARCHAR(50) = NULL
  33. ,@txnType VARCHAR(50) = NULL
  34. ,@userName VARCHAR(100) = NULl
  35. ,@isDocUpload VARCHAR(100) = NULL
  36. ,@vouType VARCHAR(20) = NULL
  37. ,@remarks VARCHAR(Max) = NULL
  38. ,@agentName VARCHAR(200) = NULL
  39. ,@pAmt VARCHAR(100) = NULL
  40. ,@sendCardNo VARCHAR(50) = NULL
  41. ,@recCardNo VARCHAR(50) = NULL
  42. AS
  43. /*
  44. EXEC proc_txnDocuments @flag='deleteDoc',@user='admin',@rowId='28'
  45. */
  46. SET NOCOUNT ON;
  47. CREATE TABLE #msg(errorCode INT, msg VARCHAR(100), id INT)
  48. DECLARE @table VARCHAR(MAX)
  49. ,@selectFieldList VARCHAR(MAX)
  50. ,@extraFieldList VARCHAR(MAX)
  51. ,@sqlFilter VARCHAR(MAX)
  52. ,@sql VARCHAR(MAX)
  53. IF @flag = 's'
  54. BEGIN
  55. IF @sortBy IS NULL
  56. SET @sortBy = 'id'
  57. IF @sortOrder IS NULL
  58. SET @sortOrder = 'DESC'
  59. SET @table = '( SELECT DISTINCT
  60. rt.id,controlNo = dbo.FNADecryptString(rt.controlNo)
  61. ,tranAmt = rt.pAmt
  62. ,senderName = rt.senderName
  63. ,receiverName = rt.receiverName
  64. ,txnType1 = CASE WHEN rT.sAgent = '''+@agent+''' AND tranType = ''D'' THEN ''sd''
  65. WHEN pAgent = '''+@agent+''' AND tranType = ''D'' THEN ''pd''
  66. WHEN pAgent = '''+@agent+''' AND tranType = ''I'' THEN ''pi'' END
  67. ,txnType = CASE WHEN rT.sAgent = '''+@agent+''' AND tranType = ''D'' THEN ''Send Domestic''
  68. WHEN pAgent = '''+@agent+''' AND tranType = ''D'' THEN ''Paid Domestic''
  69. WHEN pAgent = '''+@agent+''' AND tranType = ''I'' THEN ''Paid Intl'' END
  70. ,createdDate =rt.createdDate
  71. ,[status] = CASE WHEN v.tranId IS NULL THEN ''Not-Reconciled'' ELSE v.status END
  72. ,isDocUpload = CASE WHEN d.tdId IS NOT NULL THEN ''Y'' ELSE ''N'' END
  73. FROM remitTran rt(NOLOCK)
  74. LEFT JOIN txnDocuments D(NOLOCK) ON RT.id = D.tdId AND D.AGENTID = '''+@agent+''' --AND D.txnType<>D.txnType
  75. LEFT JOIN voucherReconcilation V (NOLOCK) on d.tdId = v.tranId and d.txnType = v.voucherType
  76. WHERE rT.tranType IS NOT NULL and (rT.sagent = '''+@agent+''' or rT.pagent = '''+@agent+''') '
  77. SET @sqlFilter = ''
  78. print @table
  79. IF @controlNo IS NOT NULL
  80. SET @sqlFilter=@sqlFilter + ' AND controlNo LIKE ''' +@controlNo+''''
  81. IF @txnType IS NOT NULL
  82. SET @sqlFilter=@sqlFilter + ' AND txnType1 = ''' +@txnType+''''
  83. IF @status IS NOT NULL
  84. SET @sqlFilter=@sqlFilter + ' AND status = ''' +@status+''''
  85. IF @isDocUpload IS NOT NULL
  86. SET @sqlFilter=@sqlFilter + ' AND isDocUpload = ''' +@isDocUpload+''''
  87. IF @fromDate IS NOT NULL AND @toDate IS NOT NULL
  88. BEGIN
  89. IF ISNULL(@txnType,'') = 'sd'
  90. BEGIN
  91. SET @table = @table + ' AND rt.createdDate BETWEEN ''' + CONVERT(VARCHAR,@fromDate,101) + ''' AND ''' + CONVERT(VARCHAR,@toDate,101) + ' 23:59:59'''
  92. END
  93. ELSE IF ISNULL(@txnType,'') IN('pd','pi')
  94. BEGIN
  95. SET @table = @table + ' AND rt.PaidDate BETWEEN ''' + CONVERT(VARCHAR,@fromDate,101) + ''' AND ''' + CONVERT(VARCHAR,@toDate,101) + ' 23:59:59'''
  96. END
  97. ELSE
  98. BEGIN
  99. SET @table = @table + ' AND (rt.createdDate BETWEEN ''' + CONVERT(VARCHAR,@fromDate,101) + ''' AND ''' + CONVERT(VARCHAR,@toDate,101) + ' 23:59:59'''
  100. SET @table = @table + ' OR rt.PaidDate BETWEEN ''' + CONVERT(VARCHAR,@fromDate,101) + ''' AND ''' + CONVERT(VARCHAR,@toDate,101) + ' 23:59:59'')'
  101. END
  102. END
  103. SET @table = @table + ')x'
  104. SET @table='(SELECT
  105. x.id
  106. , x.controlNo
  107. , x.tranAmt
  108. , x.senderName
  109. , x.receiverName
  110. ,x.txnType
  111. ,convert(varchar,x.createdDate,101) as createdDate
  112. ,x.txnType1
  113. ,x.status
  114. -- ,link1=CASE WHEN x.status=''Reconciled'' THEN ''<a class="button" style="text-decoration:none;color:white; !important" href="BrowseDoc.aspx?status=''+x.status+''&txnType=''+x.txnType1+''&id=''+cast(x.id as varchar)+''">Browse Doc</a>'' ELSE ''<a c
  115. lass="button" style="text-decoration:none;color:white; !important" href="BrowseDoc.aspx?txnType=''+x.txnType1+''&id=''+cast(x.id as varchar)+''">Browse Doc</a><input type="button" value="Scan" onclick=''''ScanDocument("''+cast(id as varchar)+''", "''+cont
  116. rolNo+''","''+txnType1+''");''''/>'' END
  117. ,link=CASE WHEN x.status=''Reconciled'' THEN ''<input type="button" value="Browse Doc" onClick=OpenInNewWindow("BrowseDoc.aspx?status=''+x.status+''&txnType=''+x.txnType1+''&id=''+cast(x.id as varchar)+''")></a>'' ELSE ''<input type="button" value="
  118. Browse Doc" onClick=OpenInNewWindow("BrowseDoc.aspx?txnType=''+x.txnType1+''&id=''+cast(x.id as varchar)+''")></a><input type="button" value="Scan" onclick=''''ScanDocument("''+cast(id as varchar)+''", "''+controlNo+''","''+txnType1+''");''''/>'' END
  119. ,x.isDocUpload
  120. FROM '+@table+ ')a';
  121. SET @selectFieldList = '
  122. id
  123. , controlNo
  124. , tranAmt
  125. , senderName
  126. , receiverName
  127. ,txnType
  128. ,createdDate
  129. ,txnType1
  130. ,status
  131. ,link
  132. ,isDocUpload
  133. '
  134. print @table
  135. EXEC dbo.proc_paging
  136. @table
  137. ,@sqlFilter
  138. ,@selectFieldList
  139. ,@extraFieldList
  140. ,@sortBy
  141. ,@sortOrder
  142. ,@pageSize
  143. ,@pageNumber
  144. END
  145. IF @flag = 'i'
  146. BEGIN
  147. SELECT
  148. @controlNo=dbo.FNADecryptString(controlNo)
  149. FROM remittran WITH(NOLOCK)
  150. WHERE id=@rowId
  151. DECLARE @sn INT
  152. SELECT
  153. @sn = COUNT(*)
  154. FROM txnDocuments (NOLOCK) WHERE controlNo = @controlNo
  155. SELECT @sn = ISNULL(@sn, 0) + 1
  156. SET @fileName = @ControlNo + +'_'+ CAST(@sn AS VARCHAR) + '.' + @fileType
  157. INSERT INTO txnDocuments (tdId, controlNo, [fileName], fileDescription, fileType, [year], agentId, createdBy, createdDate,txnType)
  158. SELECT @rowId, @controlNo, @fileName, @fileDescription, @fileType, @txnYear, @agentId, @user, GETDATE(),@txnType
  159. SET @rowId = SCOPE_IDENTITY()
  160. EXEC proc_errorHandler 0, 'File Uploaded Successfully', @fileName
  161. RETURN
  162. END
  163. ELSE IF @flag='displayDoc'
  164. BEGIN
  165. SELECT
  166. rowId
  167. ,tdId
  168. ,fileName
  169. ,fileDescription
  170. ,createdBy
  171. ,createdDate
  172. ,[year]
  173. ,agentId
  174. ,txnType
  175. FROM txnDocuments WITH(NOLOCK)
  176. WHERE tdId=@rowId
  177. AND (isDeleted = 'N' OR isDeleted IS NULL)
  178. AND txnType=@txnType
  179. RETURN
  180. END
  181. ELSE IF @flag = 'a'
  182. BEGIN
  183. SELECT * FROM txnDocuments WITH(NOLOCK) WHERE rowId = @rowId
  184. RETURN
  185. END
  186. ELSE IF @flag='image-display'
  187. BEGIN
  188. SELECT
  189. [fileName] = fileName
  190. ,fileDescription
  191. ,agentId
  192. FROM txnDocuments a WITH(NOLOCK)
  193. WHERE tdid=@rowId AND isDeleted IS NULL
  194. RETURN
  195. END
  196. ELSE IF @flag='deleteDoc'
  197. BEGIN
  198. SELECT @tranId=tdid from txnDocuments WHERE rowId = @rowId
  199. IF EXISTS(SELECT 'x' FROM voucherReconcilation WITH(NOLOCK) WHERE tranId = @tranId and status='Reconciled' AND voucherType=@txnType)
  200. BEGIN
  201. EXEC proc_errorHandler 1, 'Document Already Reconciled!! You Cannot Delete this document', NULL
  202. RETURN
  203. END
  204. DECLARE @path VARCHAR(255)
  205. SELECT
  206. @path = CAST([Year] AS VARCHAR(20)) + '\' + CAST(agentId AS VARCHAR(20)) + '\' + [fileName]
  207. FROM txnDocuments (NOLOCK) WHERE rowId = @rowId
  208. DELETE txnDocuments WHERE rowId = @rowId
  209. EXEC proc_errorHandler 0, 'File Deleted Successfully', @path
  210. RETURN
  211. END
  212. ELSE IF @flag='at'
  213. BEGIN
  214. SELECT NULL [value], 'Select' [text] UNION ALL
  215. SELECT 'sd','Send Domestic' UNION ALL
  216. SELECT 'pd','Paid Domestic' UNION ALL
  217. SELECT 'pi','Paid International'
  218. RETURN
  219. END
  220. ELSE IF @flag='isDoc'
  221. BEGIN
  222. SELECT NULL [value], 'Select' [text] UNION ALL
  223. SELECT 'y','Yes' UNION ALL
  224. SELECT 'n','No'
  225. RETURN
  226. END
  227. ELSE IF @flag='status'
  228. BEGIN
  229. SELECT NULL as value, 'Select' [text] UNION ALL
  230. SELECT 'Reconciled','Reconciled' UNION ALL
  231. SELECT 'Complain','Complain' UNION ALL
  232. SELECT 'Not-Reconciled','Not-Reconciled'
  233. RETURN
  234. END
  235. IF @flag = 'agent-wise'
  236. BEGIN
  237. SET @sql = 'SELECT
  238. x.[date] As Date
  239. ,count([Transaction]) AS [Transaction]
  240. ,count([Upload Transaction]) AS [Upload Transaction]
  241. ,count([Transaction])-count([Upload Transaction]) AS [Remaining Transaction]
  242. FROM
  243. (
  244. SELECT
  245. [date]=CONVERT(VARCHAR,rt.createdDate,101)
  246. ,rt.id AS [Transaction]
  247. ,td.tdId AS [Upload Transaction]
  248. FROM remitTran rt LEFT JOIN txnDocuments td ON rt.id=td.tdId
  249. WHERE (rt.sAgent='''+@agentId+''' or rt.pAgent='''+@agentId+''')
  250. AND rt.createdDate BETWEEN '''+@fromDate+''' and '''+@toDate+' 23:59:59'' '
  251. IF @controlNo is not null
  252. SET @sql = @sql +' AND dbo.FNADecryptString(rt.controlNo)='''+ @controlNo +''''
  253. IF @isDocUpload IS NOT NULL
  254. BEGIN
  255. SET @sql = @sql + CASE @isDocUpload WHEN 'Y' THEN ' AND td.tdId IS NOT NULL ' ELSE ' AND td.tdId IS NULL ' END
  256. END
  257. SET @sql= @sql + ')x WHERE 1=1 '
  258. SET @sql=@sql+' GROUP by x.[date]'
  259. PRINT @sql
  260. EXEC(@sql)
  261. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  262. SELECT 'Date Range From ' head, @fromDate +' - '+ @toDate value ,NULl
  263. UNION ALL
  264. SELECT 'ICN' head, @controlNo value ,NULL
  265. UNION ALL
  266. SELECT 'Is Doc-Uploaded' head, @isDocUpload value ,NULL
  267. SELECT 'Agent Send/Paid - Reconciliation Report ' title
  268. RETURN;
  269. END
  270. IF @flag = 'list'
  271. BEGIN
  272. IF @sortBy IS NULL
  273. SET @sortBy = 'id'
  274. IF @sortOrder IS NULL
  275. SET @sortOrder = 'DESC'
  276. SET @table = '(
  277. SELECT
  278. controlNo
  279. ,agentName
  280. ,id
  281. ,DATE
  282. ,txnType
  283. ,txnType1
  284. ,agent
  285. ,status
  286. ,senderName
  287. ,receiverName
  288. ,pAmt
  289. ,sendCardNo
  290. ,recCardNo
  291. FROM
  292. (
  293. SELECT DISTINCT
  294. controlNo
  295. ,agentName
  296. ,id
  297. ,MAX(date) As DATE
  298. ,txnType
  299. ,txnType1
  300. ,agent
  301. ,status
  302. ,senderName
  303. ,receiverName
  304. ,pAmt
  305. ,sendCardNo
  306. ,recCardNo
  307. FROM
  308. (
  309. SELECT
  310. controlNo=dbo.fnaDecryptString(rt.controlNo)
  311. ,agentName=am.agentName
  312. ,id=rt.id
  313. ,td.date
  314. ,txnType= CASE
  315. WHEN td.txnTYpe=''sd'' THEN ''Send Domestic''
  316. WHEN td.txnTYpe=''pd'' THEN ''Paid Domestic''
  317. WHEN td.txnTYpe=''pi'' THEN ''Paid Intl''
  318. END
  319. ,txnType1 = td.txnType
  320. ,agent=td.agentId
  321. ,status=CASE WHEN vr.tranId IS NULL THEN ''Not-Reconciled'' ELSE vr.status END
  322. ,rt.senderName
  323. ,rt.receiverName
  324. ,rt.pAmt
  325. ,sendCardNo=sen.membershipId
  326. ,recCardNo=rec.membershipId
  327. FROM
  328. (
  329. SELECT Distinct
  330. agentId
  331. ,tdid
  332. ,txnType
  333. ,date = max(createdDate)
  334. FROM txnDocuments (NOLOCK) WHERE 1 = 1
  335. ' +
  336. CASE WHEN @txnType IS NOT NULL THEN 'AND txnType = ''' +@txnType+'''' ELSE '' END
  337. +
  338. '
  339. GROUP BY agentId, tdid, txnType
  340. ) td
  341. INNER JOIN dbo.remitTran rt ON td.tdId=rt.id
  342. INNER JOIN agentMaster am (NOLOCK) ON am.agentId=td.agentId
  343. LEFT JOIN dbo.voucherReconcilation vr ON vr.tranId = rt.id and vr.vouchertype = td.txnType
  344. INNER JOIN tranSenders sen with(nolock) on rt.id=sen.tranId
  345. INNER JOIN tranReceivers rec with(nolock) on rt.id=rec.tranId
  346. )xx GROUP BY controlNo,agentName,id,txnType,txnType1,agent,status,senderName ,receiverName,pAmt,sendCardNo,recCardNo
  347. )yy WHERE 1=1
  348. ) pp'
  349. SET @sqlFilter = ''
  350. IF @controlNo IS NOT NULL
  351. SET @sqlFilter=@sqlFilter + ' AND controlNo = ''' +@controlNo+''''
  352. IF @agentName IS NOT NULL
  353. SET @sqlFilter=@sqlFilter + ' AND agentName LIKE ''' +@agentName+'%'''
  354. IF @senderName IS NOT NULL
  355. SET @sqlFilter=@sqlFilter + ' AND senderName LIKE ''' +@senderName+'%'''
  356. IF @receiverName IS NOT NULL
  357. SET @sqlFilter=@sqlFilter + ' AND receiverName LIKE ''' +@receiverName+'%'''
  358. IF @pAmt IS NOT NULL
  359. SET @sqlFilter=@sqlFilter + ' AND pAmt = ''' +@pAmt+''''
  360. IF @txnType IS NOT NULL
  361. SET @sqlFilter=@sqlFilter + ' AND txnType1 = ''' +@txnType+''''
  362. IF @status IS NOT NULL
  363. SET @sqlFilter=@sqlFilter + ' AND status = ''' +@status+''''
  364. IF @sendCardNo IS NOT NULL
  365. SET @sqlFilter=@sqlFilter +' and sendCardNo ='''+@sendCardNo+''''
  366. IF @recCardNo IS NOT NULL
  367. SET @sqlFilter=@sqlFilter +' and recCardNo ='''+@recCardNo+''''
  368. IF @fromDate IS NOT NULL AND @toDate IS NOT NULL
  369. SET @sqlFilter = @sqlFilter + ' AND date BETWEEN ''' + CONVERT(VARCHAR,@fromDate,101) + ''' AND ''' + CONVERT(VARCHAR,@toDate,101) + ' 23:59:59'''
  370. SET @selectFieldList = '
  371. id
  372. , controlNo
  373. , agent
  374. , date
  375. , status
  376. , txnType
  377. ,txnType1
  378. ,agentName
  379. ,senderName
  380. ,receiverName
  381. ,pAmt
  382. ,sendCardNo
  383. ,recCardNo
  384. '
  385. EXEC dbo.proc_paging
  386. @table
  387. ,@sqlFilter
  388. ,@selectFieldList
  389. ,@extraFieldList
  390. ,@sortBy
  391. ,@sortOrder
  392. ,@pageSize
  393. ,@pageNumber
  394. END
  395. ELSE IF @flag='approve'
  396. BEGIN
  397. IF NOT EXISTS(SELECT 'x' FROM txnDocuments WITH(NOLOCK) WHERE tdid = @tranId )
  398. BEGIN
  399. EXEC proc_errorHandler 1, 'Document Has been Deleted!!', NULL
  400. RETURN
  401. END
  402. IF @user IS NULL
  403. BEGIN
  404. EXEC proc_errorHandler 1, 'Your session has expired. Please relogin to the system.' , NULL
  405. RETURN
  406. END
  407. IF EXISTS(SELECT 'x' FROM voucherReconcilation WITH(NOLOCK) WHERE tranId = @tranId AND voucherType = @vouType AND agentId=@agentId)
  408. BEGIN
  409. UPDATE voucherReconcilation SET status='Reconciled' ,remarks=@remarks WHERE tranId = @tranId AND voucherType = @vouType AND agentId=@agentId
  410. EXEC proc_errorHandler 0, 'Document Reconciled Successfully', NULL
  411. END
  412. IF @vouType='sd'
  413. BEGIN
  414. INSERT INTO voucherReconcilation(receivedId,boxNo,fileNo,tranId,remarks,status,voucherType,voucherDate,createdBy,createdDate,agentId)
  415. SELECT '','','',@tranId,@remarks,'Reconciled',@vouType,approvedDate,@user,GETDATE(),@agentId
  416. FROM remittran WITH(NOLOCK) WHERE id=@tranId
  417. END
  418. IF @vouType='pd'
  419. BEGIN
  420. INSERT INTO voucherReconcilation(receivedId,boxNo,fileNo,tranId,remarks,status,voucherType,voucherDate,createdBy,createdDate,agentId)
  421. SELECT '','','',@tranId,@remarks,'Reconciled',@vouType,approvedDate,@user,GETDATE(),@agentId
  422. FROM remittran WITH(NOLOCK) WHERE id=@tranId
  423. END
  424. IF @vouType='pi'
  425. BEGIN
  426. INSERT INTO voucherReconcilation(receivedId,boxNo,fileNo,tranId,remarks,status,voucherType,voucherDate,createdBy,createdDate,agentId)
  427. SELECT '','','',@tranId,@remarks,'Reconciled',@vouType,paidDate,@user,GETDATE(),@agentId
  428. FROM remittran WITH(NOLOCK) WHERE id=@tranId
  429. END
  430. EXEC proc_errorHandler 0, 'Document Reconciled Successfully', NULL
  431. UPDATE txnDocuments SET
  432. --approvedBy = @user
  433. --,approvedDate = GetDate()
  434. status = 'Approved'
  435. WHERE tdid = @tranId and txnType = @vouType AND agentId=@agentId
  436. EXEC proc_errorHandler 0, 'Document Uploaded Successfully', NULL
  437. END
  438. ELSE IF @flag='reject'
  439. BEGIN
  440. IF NOT EXISTS(SELECT 'x' FROM txnDocuments WITH(NOLOCK) WHERE tdid = @tranId )
  441. BEGIN
  442. EXEC proc_errorHandler 1, 'Document has been Deleted!!', NULL
  443. RETURN
  444. END
  445. IF @user IS NULL
  446. BEGIN
  447. EXEC proc_errorHandler 1, 'Your session has expired. Please relogin to the system.' , NULL
  448. RETURN
  449. END
  450. IF EXISTS(SELECT 'x' FROM voucherReconcilation WITH(NOLOCK) WHERE tranId = @tranId and voucherType = @vouType AND agentId=@agentId)
  451. BEGIN
  452. UPDATE voucherReconcilation SET status='Complain' ,remarks=@remarks WHERE tranId=@tranId AND voucherType = @vouType AND agentId=@agentId
  453. EXEC proc_errorHandler 0, 'Document Rejected Successfully' , NULL
  454. END
  455. IF @vouType='sd'
  456. BEGIN
  457. INSERT INTO voucherReconcilation(receivedId,boxNo,fileNo,tranId,remarks,status,voucherType,voucherDate,createdBy,createdDate,agentId)
  458. SELECT '','','',@tranId,@remarks,'Complain',@vouType,approvedDate,@user,GETDATE(),@agentId
  459. FROM remittran WITH(NOLOCK) WHERE id=@tranId
  460. END
  461. IF @vouType='pd'
  462. BEGIN
  463. INSERT INTO voucherReconcilation(receivedId,boxNo,fileNo,tranId,remarks,status,voucherType,voucherDate,createdBy,createdDate,agentId)
  464. SELECT '','','',@tranId,@remarks,'Complain',@vouType,approvedDate,@user,GETDATE(),@agentId
  465. FROM remittran WITH(NOLOCK) WHERE id=@tranId
  466. END
  467. IF @vouType='pi'
  468. BEGIN
  469. INSERT INTO voucherReconcilation(receivedId,boxNo,fileNo,tranId,remarks,status,voucherType,voucherDate,createdBy,createdDate,agentId)
  470. SELECT '','','',@tranId,@remarks,'Complain',@vouType,paidDate,@user,GETDATE(),@agentId
  471. FROM remittran WITH(NOLOCK) WHERE id=@tranId
  472. END
  473. EXEC proc_errorHandler 0, 'Document Rejected Successfully' , NULL
  474. Update txnDocuments Set
  475. --approvedBy=@user
  476. --,approvedDate=GetDate()
  477. status='Rejected'
  478. WHERE tdid = @tranId and txnType = @vouType AND agentId=@agentId
  479. EXEC proc_errorHandler 0, 'Document Rejected Successfully', NULL
  480. RETURN
  481. END
  482. ELSE IF @flag = 'details'
  483. BEGIN
  484. SELECT DISTINCT
  485. agentName=am.agentName
  486. ,txnType = CASE WHEN td.txnTYpe='sd' THEN 'Send Domestic'
  487. WHEN td.txnTYpe='pd' THEN 'Paid Domestic'
  488. WHEN td.txnTYpe='pi' THEN 'Paid Intl'
  489. END
  490. ,rt.senderName
  491. ,rt.receiverName
  492. ,rt.pAmt
  493. ,status=CASE WHEN vr.tranId IS NULL THEN 'Not-Reconciled' ELSE vr.status END
  494. ,controlNo=dbo.FNADecryptString(rt.controlNo)
  495. ,remarks=vr.remarks
  496. FROM remittran rt
  497. INNER JOIN txnDocuments td (NOLOCK) ON td.tdId=rt.id
  498. INNER JOIN agentMaster am (NOLOCK) ON am.agentId=td.agentId
  499. LEFT JOIN dbo.voucherReconcilation vr ON vr.tranId=rt.id and vr.voucherType = td.txnType
  500. WHERE rt.id = @rowId AND td.txnType=@txnType
  501. RETURN
  502. END
  503. GO