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.

1214 lines
48 KiB

  1. using Swift.DAL.AccountReport;
  2. using Swift.DAL.SwiftDAL;
  3. using Swift.web.Library;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Globalization;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Web.UI;
  12. namespace Swift.web.AccountReport
  13. {
  14. public partial class Reports : Page
  15. {
  16. private Boolean AllowDrillDown;
  17. private string cssClass = "TBLReport table table-bordered table-condensed table-striped";
  18. private string fieldAlignment = "";
  19. private string fieldFormat = "";
  20. private string fieldWrap = "";
  21. private string tblCaption = "";
  22. private Boolean mergeColumnHead;
  23. private ReportResult reportResult = new ReportResult();
  24. private string excludeColumns = "";
  25. private bool includeSerialNo = false;
  26. private bool useDBRowColorCode = false;
  27. private int subTotalBy = -1;
  28. private int totalTextCol = -1;
  29. private int subTotalTextCol = -1;
  30. private string subTotalFields = "";
  31. private string subTotalText = "";
  32. private string totalFields = "";
  33. private string totalText = "";
  34. private int totalPage = 0;
  35. private int pageNo = 0;
  36. private double grandTotal = 0.00;
  37. private double grandTotalUsd = 0.00;
  38. private double grandTotal_1 = 0.00;
  39. private string reportName = "";
  40. private int extraCol = 0;
  41. private string flag = "";
  42. protected string Url = GetStatic.GetUrlRoot();
  43. private string isExportFull = "";
  44. protected void Page_Load(object sender, EventArgs e)
  45. {
  46. if (!IsPostBack)
  47. {
  48. if (GetStatic.GetUser() == "")
  49. Response.Redirect(GetStatic.GetDefaultPage());
  50. }
  51. PrintReport();
  52. }
  53. private void PrintHead()
  54. {
  55. Page.Title = reportResult.ReportHead;
  56. head.InnerHtml = reportResult.ReportHead;
  57. }
  58. private void PrintFilters()
  59. {
  60. var user = GetStatic.GetUser();
  61. var now = GetStatic.GetUserDateTime();
  62. filters.InnerHtml = "Filters Applied : <br />" + reportResult.Filters +
  63. "<br /><br />Generated On=" + now +
  64. " || Generated By=" + user;
  65. }
  66. private void PrintError()
  67. {
  68. rptDiv.InnerHtml = "<div class = \"reportError\">" + reportResult.Msg + "</div>";
  69. }
  70. protected string GetURL()
  71. {
  72. return Request.Url.AbsoluteUri.Replace("&pageNumber=" + GetPageNumber(), "");
  73. }
  74. private void PrintReport()
  75. {
  76. string reportName = GetStatic.ReadQueryString("reportName", "").ToLower();
  77. string mode = GetStatic.ReadQueryString("mode", "").ToLower();
  78. isExportFull = mode.ToLower() == "download" ? "Y" : "N";
  79. reportResult = PrepareReport(reportName);
  80. if (mode == "download")
  81. {
  82. string format = GetStatic.ReadQueryString("format", "xls");
  83. Response.Clear();
  84. Response.ClearContent();
  85. Response.ClearHeaders();
  86. Response.ContentType = "application/vnd.ms-excel";
  87. Response.AddHeader("Content-Disposition", "attachment; filename=" + reportName + "." + format);
  88. exportDiv.Visible = false;
  89. }
  90. PrintHead();
  91. PrintFilters();
  92. if (reportResult.ErrorCode != "0")
  93. {
  94. PrintError();
  95. return;
  96. }
  97. if (reportName == "usermatrix")
  98. {
  99. PrintUserMatrixReport();
  100. return;
  101. }
  102. DataTable dt;
  103. int tableCount = reportResult.Result.Tables.Count;
  104. if (tableCount > 4)
  105. {
  106. if (mode != "download")
  107. ShowPaging(reportResult.Result.Tables[0]);
  108. dt = reportResult.Result.Tables[1];
  109. }
  110. else
  111. {
  112. dt = reportResult.ResultSet;
  113. }
  114. string reportText = GenerateReport(ref dt);
  115. rptDiv.InnerHtml = reportText;
  116. }
  117. private void ShowPaging(DataTable dt)
  118. {
  119. DataTable dtPaging = dt;
  120. int totalRecords = Convert.ToInt32(dtPaging.Rows[0]["TXNCOUNT"].ToString());
  121. int PageSizes = Convert.ToInt32(dtPaging.Rows[0]["PAGESIZE"].ToString());
  122. int PageNumber = Convert.ToInt32(dtPaging.Rows[0]["PAGENUMBER"].ToString());
  123. if (dtPaging.Columns.Count > 3)
  124. grandTotal = Convert.ToDouble(dtPaging.Rows[0]["GRANDTOTAL"].ToString());
  125. if (dtPaging.Columns.Count > 4)
  126. grandTotalUsd = Convert.ToDouble(dtPaging.Rows[0]["GRANDTOTAL_USD"].ToString());
  127. string cssLink = "pagingLink";
  128. totalPage = totalRecords / PageSizes;
  129. if ((totalPage * PageSizes) < totalRecords)
  130. totalPage++;
  131. var sbPaging = new StringBuilder("<table width='100%' class='table table-bordered table-condensed table-striped'><tr><td nowrap='nowrap'>");
  132. sbPaging.AppendLine("<div class='reportFilters' width='100%'>");
  133. sbPaging.AppendLine("<span style='float:left; width:auto; margin-top:5px;'>Results:&nbsp; " + totalRecords + " records &nbsp; </span>");
  134. paging.Visible = true;
  135. int currPage = GetPageNumber();
  136. int startPage = (currPage - 5 <= 0 ? 1 : currPage - 5);
  137. int offSet = (startPage == 1 ? ((currPage - 5) * -1 + 1) : 0);
  138. int endPage = currPage + 4 + offSet;
  139. endPage = currPage == 0 ? 10 : endPage;
  140. endPage = (endPage > totalPage ? totalPage : endPage);
  141. if (currPage > 10 && (endPage - startPage) + 1 != 10)
  142. {
  143. startPage = startPage - (10 - (endPage - startPage + 1));
  144. }
  145. if (totalRecords > PageSizes)// Convert.ToInt32(GetStatic.GetReportPagesize()))
  146. {
  147. string url = GetURL();
  148. sbPaging.AppendLine("<img onclick='GotoPage(1);' src='../../Images/paging_Icons/first_page.png' alt='First Page' style='margin-top:5px;float:left;border:none;cursor:pointer' />");
  149. sbPaging.AppendLine("<img " + (GetPageNumber() != 1 ? " onclick='GotoPage(" + (GetPageNumber() - 1) + ");'" : "") + " src='../../Images/paging_Icons/" + (GetPageNumber() == 1 ? "previous_page_dis" : "previous_page") + ".png' style='margin-top:5px;float:left;border:none;cursor:pointer' alt='Previous Page' /></a>");
  150. for (int i = startPage; i < endPage + 1; i++)
  151. {
  152. cssLink = PageNumber == i ? "pagingLinkSelected" : "pagingLink";
  153. sbPaging.AppendLine("<span onclick ='GotoPage(" + i + ");' class='" + cssLink + "'>" + i + "</span>");
  154. }
  155. sbPaging.AppendLine("<img " + (GetPageNumber() != totalPage ? "onclick=GotoPage(" + (GetPageNumber() + 1) + ");" : "") + " src='../../Images/paging_Icons/" + (GetPageNumber() == totalPage ? "next_page_dis" : "next_page") + ".png' style='margin-top:5px;border:none;cursor:pointer' alt='Next Page' /></a>");
  156. sbPaging.AppendLine("<img onclick=GotoPage(" + totalPage + "); src='../../Images/paging_Icons/last_page.png' style='margin-top:5px;border:none;cursor:pointer' />");
  157. }
  158. sbPaging.AppendLine("</div></td><td nowrap='nowrap' width='135' align=\"right\">");
  159. if (totalRecords > PageSizes) //Convert.ToInt32(GetStatic.GetReportPagesize()))
  160. sbPaging.AppendLine("Goto Page: " + GotoList(totalPage));
  161. sbPaging.AppendLine("</td></tr></table>");
  162. paging.InnerHtml = sbPaging.ToString();
  163. }
  164. private string GotoList(int totalPage)
  165. {
  166. StringBuilder sb = new StringBuilder("");
  167. sb.AppendLine("<select id='gotoLabel' onchange=GotoPage(this.value); style='min-width:50px'>");
  168. for (int i = 0; i < totalPage; i++)
  169. {
  170. sb.AppendLine("<option value='" + (i + 1) + "' " + (GetPageNumber() == (i + 1) ? "Selected=Selected" : "") + " >" + (i + 1) + "</option>");
  171. }
  172. sb.AppendLine("</select>");
  173. return sb.ToString();
  174. }
  175. private ReportResult PrepareReport(string reportName)
  176. {
  177. if (reportName == "intoldreport")
  178. {
  179. reportResult = PrepareReport_IntOldReport();
  180. }
  181. else if (reportName == "intmonthlyreport")
  182. {
  183. reportResult = PrepareReport_IntMonthlyReport();
  184. }
  185. else if (reportName == "intshowcentralizereport")
  186. {
  187. reportResult = PrepareReport_IntShowCentralizeReport();
  188. }
  189. else if (reportName == "intnewreport")
  190. {
  191. reportResult = PrepareReport_IntNewReport();
  192. }
  193. else if (reportName == "intshowreport")
  194. {
  195. reportResult = PrepareReport_IntShowReport();
  196. }
  197. else if (reportName == "intlreconcilerpt")
  198. {
  199. reportResult = PrepareReport_IntlReconcileRpt();
  200. }
  201. else if (reportName == "domestictxn")
  202. {
  203. reportResult = PrepareReport_domestictxn();
  204. }
  205. else if (reportName == "domestictxnreceiving")
  206. {
  207. reportResult = PrepareReport_domestictxnreceiving();
  208. }
  209. else if (reportName == "agentsummaryrpt")
  210. {
  211. reportResult = PrepareAgentSummaryRpt();
  212. }
  213. else if (reportName == "nrbreport")
  214. {
  215. reportResult = PrepareNRBRpt();
  216. }
  217. else if (reportName == "paidtxnrpt")
  218. {
  219. reportResult = PreparePaidTxnRpt();
  220. }
  221. else if (reportName == "dsettlementreport")
  222. {
  223. reportResult = PreparedSettlementRpt();
  224. }
  225. else if (reportName == "settlementdetailrpt")
  226. {
  227. reportResult = PrepareTxnDetailRpt();
  228. }
  229. else if (reportName == "settlementhoreport")
  230. {
  231. reportResult = PrepareSettlementHoRpt();
  232. }
  233. else if (reportName == "settlementhoreportdrilldown")
  234. {
  235. reportResult = PrepareSettlementHoRptDrillDown();
  236. }
  237. else if (reportName == "nrbprocessrpt")
  238. {
  239. reportResult = PrepareNrbProcessRpt();
  240. }
  241. else if (reportName == "dailysettlementrpt")
  242. {
  243. reportResult = DailySettlemetReport();
  244. }
  245. else if (reportName == "individualtxnrpt")
  246. {
  247. reportResult = IndividualTxnRpt();
  248. }
  249. else if (reportName == "tdsrpt")
  250. {
  251. reportResult = PrepareTdsRpt();
  252. }
  253. else if (reportName == "compiletoweb")
  254. {
  255. reportResult = PrepareCompileToWebRpt();
  256. }
  257. else if (reportName == "currpositionreport")
  258. {
  259. reportResult = PrepareReport_currpositionReport();
  260. }
  261. else if (reportName == "multicurrencyclosingreport")
  262. {
  263. reportResult = PrepareReport_multicurrencyclosingReport();
  264. }
  265. return reportResult;
  266. }
  267. private ReportResult PrepareReport_multicurrencyclosingReport()
  268. {
  269. string asOnDate = GetStatic.ReadQueryString("asOnDate", "");
  270. string partner = GetStatic.ReadQueryString("partner", "");
  271. string user = GetStatic.GetUser();
  272. includeSerialNo = true;
  273. totalFields = "1||3|4|5|6|7|8";
  274. fieldFormat = "|N|N|N|N|N|N|N|N|";
  275. fieldAlignment = "|R|R|R|R|R|R|R|";
  276. totalText = "Total";
  277. return (new AccountReportDao().MultiCurrencyClosingRpt(user, asOnDate, partner));
  278. }
  279. #region Report part
  280. private ReportResult DailySettlemetReport()
  281. {
  282. string fromDate = GetStatic.ReadQueryString("fromDate", "");
  283. string toDate = GetStatic.ReadQueryString("toDate", "");
  284. fieldAlignment = "|||R|R|R|R|R|R|R|R";
  285. totalFields = "3|4|5|6|7|8|9|10|11";
  286. totalText = "Net Settlement";
  287. fieldFormat = "||||N|N";
  288. return (new AccountReportDao().GetDailySettlemetReport(fromDate, toDate));
  289. }
  290. private ReportResult IndividualTxnRpt()
  291. {
  292. string icn = GetStatic.ReadQueryString("icn", "");
  293. string toDate = GetStatic.ReadQueryString("toDate", "");
  294. fieldAlignment = "|||R|R|R|R|R|R|R|R";
  295. totalFields = "3|4|5|6|7|8|9|10|11";
  296. totalText = "Net Settlement";
  297. fieldFormat = "||||N|N";
  298. return (new AccountReportDao().GetIndividualTxnRpt(icn));
  299. }
  300. private ReportResult PrepareSettlementHoRpt()
  301. {
  302. string branch = GetStatic.ReadQueryString("branch", "");
  303. string agentId = GetStatic.ReadQueryString("agentId", "");
  304. string fromDate = GetStatic.ReadQueryString("fromDate", "");
  305. string toDate = GetStatic.ReadQueryString("toDate", "");
  306. string user = GetStatic.GetUser();
  307. includeSerialNo = true;
  308. fieldAlignment = "|||R|R|R|R|R|R|R|R";
  309. totalFields = "3|4|5|6|7|8|9|10|11";
  310. totalText = "Net Settlement";
  311. fieldFormat = "||||N|N";
  312. return (new AccountReportDao().GetSettlementHoRpt(fromDate, toDate, agentId, branch, user));
  313. }
  314. private ReportResult PrepareSettlementHoRptDrillDown()
  315. {
  316. string flag = GetStatic.ReadQueryString("FLAG", "");
  317. string branch = GetStatic.ReadQueryString("BRANCH", "");
  318. string agentId = GetStatic.ReadQueryString("AGENT", "");
  319. string fromDate = GetStatic.ReadQueryString("DATE1", "");
  320. string toDate = GetStatic.ReadQueryString("DATE2", "");
  321. string country = GetStatic.ReadQueryString("COUNTRY", "");
  322. string user = GetStatic.GetUser();
  323. includeSerialNo = true;
  324. fieldAlignment = "|||R|R|R|R|R|R|R|R";
  325. totalFields = "4|5";
  326. totalText = "Total";
  327. fieldFormat = "||||N|N||";
  328. return (new AccountReportDao().GetSettlementHoRptDrillDown(fromDate, toDate, agentId, branch, user, country, flag));
  329. }
  330. private ReportResult PrepareTxnDetailRpt()
  331. {
  332. string agentId = GetStatic.ReadQueryString("agentId", "");
  333. string fromDate = GetStatic.ReadQueryString("fromDate", "");
  334. string toDate = GetStatic.ReadQueryString("toDate", "");
  335. fieldAlignment = "||||R|R|R|R|R|R|R|R";
  336. totalFields = "4|5|6|7|8|9|10|11";
  337. totalText = "Grand Total";
  338. mergeColumnHead = true;
  339. fieldFormat = "||||N||N||N||N|N";
  340. return (new AccountReportDao().GetTxnDetailRpt(fromDate, toDate, agentId));
  341. }
  342. private ReportResult PreparedSettlementRpt()
  343. {
  344. string fromDate = GetStatic.ReadQueryString("fromDate", "");
  345. fieldFormat = "|||N";
  346. fieldAlignment = "|||R";
  347. return (new AccountReportDao().GetDomesticSettlementReport(fromDate));
  348. }
  349. private ReportResult PrepareAgentSummaryRpt()
  350. {
  351. string agentGrp = GetStatic.ReadQueryString("agentGrp", "");
  352. string agentId = GetStatic.ReadQueryString("agentId", "");
  353. string date = GetStatic.ReadQueryString("date", "");
  354. string tranType = GetStatic.ReadQueryString("tranType", "");
  355. includeSerialNo = true;
  356. fieldAlignment = "|||R|R|R|R|R|R|R|R";
  357. fieldFormat = "|||N|N|N|N|N|N|N|N";
  358. totalFields = "3|4|5|6|7|8|9|10|11";
  359. totalText = "Total";
  360. return (new AccountReportDao().GetAgentSummaryRpt(agentGrp, date, tranType, agentId));
  361. }
  362. // Intl Rpt start ...
  363. private ReportResult PrepareReport_IntMonthlyReport()
  364. {
  365. var sagentId = GetStatic.ReadQueryString("ragentId", "");
  366. var ragentId = GetStatic.ReadQueryString("sagentId", "");
  367. var fromDate = GetStatic.ReadQueryString("fromDate", "");
  368. var toDate = GetStatic.ReadQueryString("toDate", "");
  369. var dateType = GetStatic.ReadQueryString("dateType", "");
  370. var paymentStatus = GetStatic.ReadQueryString("paymentStatus", "");
  371. var reportType = GetStatic.ReadQueryString("reportType", "");
  372. includeSerialNo = true;
  373. mergeColumnHead = true;
  374. return (new AccountReportDao().GetIntMonthlyReport(sagentId, ragentId, fromDate, toDate, dateType, paymentStatus, reportType));
  375. }
  376. private ReportResult PrepareReport_IntShowReport()
  377. {
  378. var agentId = GetStatic.ReadQueryString("agentId", "");
  379. var fromDate = GetStatic.ReadQueryString("fromDate", "");
  380. var toDate = GetStatic.ReadQueryString("toDate", "");
  381. var dateType = GetStatic.ReadQueryString("dateType", "");
  382. var paymentStatus = GetStatic.ReadQueryString("paymentStatus", "");
  383. includeSerialNo = true;
  384. subTotalBy = 1;
  385. subTotalFields = "2|3|4";
  386. subTotalText = "<B>Total</B>";
  387. fieldFormat = "|N|N|N";
  388. fieldAlignment = "|R|R|R|R";
  389. return (new AccountReportDao().GetIntShowReport(agentId, fromDate, toDate, dateType, paymentStatus));
  390. }
  391. private ReportResult PrepareReport_IntShowCentralizeReport()
  392. {
  393. var agentId = GetStatic.ReadQueryString("agentId", "");
  394. var fromDate = GetStatic.ReadQueryString("fromDate", "");
  395. var toDate = GetStatic.ReadQueryString("toDate", "");
  396. var dateType = GetStatic.ReadQueryString("dateType", "");
  397. var paymentStatus = GetStatic.ReadQueryString("paymentStatus", "");
  398. includeSerialNo = true;
  399. subTotalBy = 1;
  400. subTotalFields = "2|3|4";
  401. subTotalText = "<B>Total</B>";
  402. fieldFormat = "|N|N|N";
  403. fieldAlignment = "|R|R|R|R";
  404. return (new AccountReportDao().GetIntShowCentralizeReport(agentId, fromDate, toDate, dateType, paymentStatus));
  405. }
  406. private ReportResult PrepareReport_IntNewReport()
  407. {
  408. var agentId = GetStatic.ReadQueryString("agentId", "");
  409. var fromDate = GetStatic.ReadQueryString("fromDate", "");
  410. var toDate = GetStatic.ReadQueryString("toDate", "");
  411. var dateType = GetStatic.ReadQueryString("dateType", "");
  412. var paymentStatus = GetStatic.ReadQueryString("paymentStatus", "");
  413. includeSerialNo = true;
  414. subTotalBy = 1;
  415. subTotalFields = "2|3|4";
  416. subTotalText = "<B>Total</B>";
  417. fieldFormat = "|N|N|N";
  418. fieldAlignment = "|R|R|R|R";
  419. return (new AccountReportDao().GetIntNewReport(agentId, fromDate, toDate, dateType, paymentStatus));
  420. }
  421. private ReportResult PrepareReport_IntOldReport()
  422. {
  423. var agentId = GetStatic.ReadQueryString("agentId", "");
  424. var fromDate = GetStatic.ReadQueryString("fromDate", "");
  425. var toDate = GetStatic.ReadQueryString("toDate", "");
  426. var dateType = GetStatic.ReadQueryString("dateType", "");
  427. var paymentStatus = GetStatic.ReadQueryString("paymentStatus", "");
  428. includeSerialNo = true;
  429. subTotalBy = 1;
  430. subTotalFields = "2|3|4";
  431. subTotalText = "<B>Total</B>";
  432. fieldFormat = "|N|N|N";
  433. fieldAlignment = "|R|R|R|R";
  434. return (new AccountReportDao().GetIntOldReport(agentId, fromDate, toDate, dateType, paymentStatus));
  435. }
  436. // Intl Rpt end ...
  437. private ReportResult PrepareReport_IntlReconcileRpt()
  438. {
  439. var sDate = GetStatic.ReadQueryString("fromDate", "");
  440. var eDate = GetStatic.ReadQueryString("toDate", "");
  441. includeSerialNo = true;
  442. subTotalBy = 1;
  443. mergeColumnHead = true;
  444. subTotalFields = "3|5|7|9|11";
  445. subTotalText = "<B>Sub Total</B>";
  446. subTotalTextCol = 1;
  447. totalFields = "3|5|7|9|11";
  448. fieldFormat = "|||N||N||N||N||N";
  449. totalText = "<B>Grand Total</B>";
  450. return (new AccountReportDao().GetIntlReconcileRpt(sDate, eDate));
  451. }
  452. private ReportResult PrepareReport_domestictxn()
  453. {
  454. string fromDate = GetStatic.ReadQueryString("fromDate", "");
  455. string todate = GetStatic.ReadQueryString("todate", "");
  456. string agentId = GetStatic.ReadQueryString("agentId", "");
  457. string DateType = GetStatic.ReadQueryString("DateType", "");
  458. string payment_status = GetStatic.ReadQueryString("payment_status", "");
  459. string type = GetStatic.ReadQueryString("type", "");
  460. string user = GetStatic.GetUser();
  461. includeSerialNo = true;
  462. fieldFormat = "||||N|N||||";
  463. fieldAlignment = "||||R|R||||";
  464. return (new AccountReportDao().GetDomesticTxnReport(user, agentId, fromDate, todate, DateType, payment_status, type));
  465. }
  466. private ReportResult PrepareReport_domestictxnreceiving()
  467. {
  468. string fromDate = GetStatic.ReadQueryString("fromDate", "");
  469. string todate = GetStatic.ReadQueryString("todate", "");
  470. string agentId = GetStatic.ReadQueryString("agentId", "");
  471. string DateType = GetStatic.ReadQueryString("DateType", "");
  472. string payment_status = GetStatic.ReadQueryString("payment_status", "");
  473. string type = GetStatic.ReadQueryString("type", "");
  474. string user = GetStatic.GetUser();
  475. includeSerialNo = true;
  476. fieldFormat = "||||N|N|";
  477. fieldAlignment = "||||R||";
  478. return (new AccountReportDao().GetDomesticReceivingTxnReport(user, agentId, fromDate, todate, DateType, payment_status, type));
  479. }
  480. private ReportResult PrepareNRBRpt()
  481. {
  482. mergeColumnHead = true;
  483. string fromDate = GetStatic.ReadQueryString("fromDate", "");
  484. string todate = GetStatic.ReadQueryString("todate", "");
  485. string agentId = GetStatic.ReadQueryString("agentId", "");
  486. string flag = GetStatic.ReadQueryString("flag", "");
  487. includeSerialNo = true;
  488. return (new AccountReportDao().GetNrbDetailReport(flag, fromDate, todate, agentId));
  489. }
  490. private ReportResult PrepareNrbProcessRpt()
  491. {
  492. mergeColumnHead = true;
  493. string fromDate = GetStatic.ReadQueryString("fromDate", "");
  494. string todate = GetStatic.ReadQueryString("todate", "");
  495. string agentId = GetStatic.ReadQueryString("agentId", "");
  496. totalFields = "3|4|6";
  497. fieldFormat = "|||||N||N|";
  498. fieldAlignment = "|||||R||R|";
  499. totalText = "Total";
  500. includeSerialNo = true;
  501. return (new AccountReportDao().GetNrbProcessReport(fromDate, todate, agentId));
  502. }
  503. private ReportResult PreparePaidTxnRpt()
  504. {
  505. mergeColumnHead = true;
  506. includeSerialNo = true;
  507. totalFields = "1|2|3|4|5|6";
  508. fieldFormat = "|N|N|N|N|N|N|";
  509. fieldAlignment = "|R|R|R|R|R|R|";
  510. totalText = "Total";
  511. string fromDate = GetStatic.ReadQueryString("fromDate", "");
  512. string todate = GetStatic.ReadQueryString("todate", "");
  513. string dateType = GetStatic.ReadQueryString("dateType", "");
  514. string reportType = GetStatic.ReadQueryString("reportType", "");
  515. return (new AccountReportDao().GetPaidTxnReport(fromDate, todate, dateType, reportType));
  516. }
  517. private ReportResult PrepareTdsRpt()
  518. {
  519. mergeColumnHead = true;
  520. includeSerialNo = true;
  521. string fromDate = GetStatic.ReadQueryString("fromDate", "");
  522. string party = GetStatic.ReadQueryString("party", "");
  523. return (new AccountReportDao().GetTdsReport(fromDate, party));
  524. }
  525. private ReportResult PrepareCompileToWebRpt()
  526. {
  527. mergeColumnHead = true;
  528. includeSerialNo = true;
  529. string agentCode = GetStatic.ReadQueryString("agentcode", "");
  530. string asOnDate = GetStatic.ReadQueryString("asOnDate", "");
  531. string includeZeroValue = GetStatic.ReadQueryString("includeZeroValue", "");
  532. string fromDrAmt = GetStatic.ReadQueryString("fromDrAmt", "");
  533. string toDrAmt = GetStatic.ReadQueryString("toDrAmt", "");
  534. string fromCrAmt = GetStatic.ReadQueryString("fromCrAmt", "");
  535. string toCrAmt = GetStatic.ReadQueryString("toCrAmt", "");
  536. string bankCode = GetStatic.ReadQueryString("bankCode", "");
  537. totalFields = "4|5";
  538. totalText = "Total";
  539. fieldFormat = "||||N|N|";
  540. fieldAlignment = "||||R|R|";
  541. return (new AccountReportDao().GetCompileReport(asOnDate, agentCode, includeZeroValue, bankCode, fromDrAmt, toDrAmt, fromCrAmt, toCrAmt));
  542. }
  543. private ReportResult PrepareReport_currpositionReport()
  544. {
  545. string startDate = GetStatic.ReadQueryString("startDate", "");
  546. string endDate = GetStatic.ReadQueryString("endDate", "");
  547. string flag = GetStatic.ReadQueryString("flag", "");
  548. string user = GetStatic.GetUser();
  549. includeSerialNo = true;
  550. if (flag == "p")
  551. {
  552. totalFields = "1|2|3";
  553. fieldFormat = "|||||N||N|";
  554. fieldAlignment = "R|R|R|";
  555. totalText = "Total";
  556. }
  557. return (new AccountReportDao().CurrencyPositionRpt(user, startDate, endDate, flag));
  558. }
  559. private int GetPageNumber()
  560. {
  561. return
  562. Convert.ToInt32(GetStatic.ReadNumericDataFromQueryString("pageNumber") == 0
  563. ? 1
  564. : GetStatic.ReadNumericDataFromQueryString("pageNumber"));
  565. }
  566. #endregion Report part
  567. #region Generate Report
  568. public String GenerateReport(ref DataTable dt)
  569. {
  570. Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us");
  571. var ExcludeFieldList = new ArrayList();
  572. foreach (var col in excludeColumns.Split('|'))
  573. {
  574. ExcludeFieldList.Add(col.ToLower());
  575. }
  576. ExcludeFieldList.Add("rowcolor");
  577. var html = new StringBuilder("");
  578. html.AppendLine("<div style = \"float:left;clear:both\">");
  579. html.AppendLine("<table border=\"0\" class=\"table table-condensed table-bordered table-striped\" cellpadding=\"0\" cellspacing=\"0\" align=\"left\">");
  580. if (tblCaption != "")
  581. html.AppendLine("<tr><td style='td' colspan=\"" + (dt.Columns.Count + extraCol).ToString() +
  582. "\">" + tblCaption + "</td></tr>");
  583. html.AppendLine(CreateReportHead(ref dt, mergeColumnHead, ref ExcludeFieldList));
  584. html.AppendLine(CreateReportBody(ref dt, subTotalFields, totalFields, ref ExcludeFieldList, totalTextCol,
  585. subTotalTextCol));
  586. html.AppendLine("<tr><td style='td' colspan=\"" + (dt.Columns.Count + extraCol) + "\" align=\"center\">");
  587. if (totalPage == 0)
  588. totalPage = 1;
  589. html.AppendLine("Page " + (GetPageNumber() == 0 ? 1 : GetPageNumber()) + " of " + totalPage +
  590. "");
  591. html.AppendLine("</td></tr>");
  592. html.AppendLine("</table>");
  593. html.AppendLine("</div>");
  594. return html.ToString();
  595. }
  596. private int SerialNo = 0;
  597. private String CreateReportBody(ref DataTable dt, string subTotalFieldList, string totalFieldList,
  598. ref ArrayList ExcludeFieldList, int totalTextCol, int subTotalTextCol)
  599. {
  600. int cnt = 0;
  601. var body = new StringBuilder("");
  602. var SerialNoColumnValue = "";
  603. bool doSubTotal = subTotalBy > -1 ? true : false;
  604. bool doTotal = totalFieldList != "" ? true : false;
  605. string[] totalFieldsArray = totalFieldList.Replace(" ", "").Split('|');
  606. var totalValues = new double[totalFieldsArray.Length];
  607. string[] subTotalFieldsArray = subTotalFieldList.Replace(" ", "").Split('|');
  608. var subTotalValues = new double[subTotalFieldsArray.Length];
  609. string[] fieldFormatList = fieldFormat.Replace(" ", "").Split('|');
  610. string tmpSubTotalText = "||";
  611. var hasRowColorCol = dt.Columns.Contains("rowColor");
  612. foreach (DataRow row in dt.Rows)
  613. {
  614. if (includeSerialNo)
  615. {
  616. SerialNo++;
  617. SerialNoColumnValue = "<td style='td' align=\"right\">" + SerialNo.ToString() + "</td>";
  618. }
  619. else
  620. {
  621. SerialNoColumnValue = "";
  622. }
  623. if (doSubTotal)
  624. {
  625. if (tmpSubTotalText == "||")
  626. tmpSubTotalText = row[subTotalBy].ToString();
  627. if (tmpSubTotalText != row[subTotalBy].ToString())
  628. {
  629. body.AppendLine(CreateTotalRow(ref dt, subTotalText, subTotalBy, subTotalFieldsArray,
  630. subTotalValues, fieldFormatList, fieldAlignment, fieldWrap,
  631. ref ExcludeFieldList, subTotalTextCol, includeSerialNo));
  632. tmpSubTotalText = row[subTotalBy].ToString();
  633. for (int i = 0; i < subTotalValues.Length; i++)
  634. {
  635. subTotalValues[i] = 0;
  636. }
  637. }
  638. }
  639. if (useDBRowColorCode && hasRowColorCol)
  640. {
  641. body.AppendLine("<tr style=\"background:" + row["rowColor"].ToString() + ";\">");
  642. }
  643. else
  644. {
  645. body.AppendLine(++cnt % 2 == 1 ? "<tr>" : "<tr style=\"background: #F0F0F0;\">");
  646. }
  647. body.AppendLine(SerialNoColumnValue);
  648. for (int i = 0; i < dt.Columns.Count; i++)
  649. {
  650. if (ExcludeFieldList.IndexOf(dt.Columns[i].ColumnName.ToLower()) > -1)
  651. {
  652. continue;
  653. }
  654. string format = GetFormat(fieldFormatList, i);
  655. string data = row[i].ToString();
  656. if (format != "")
  657. {
  658. double dataParse;
  659. double.TryParse(row[i].ToString(), out dataParse);
  660. data = dataParse < 0 ? GetStatic.ParseMinusValue(dataParse) : dataParse.ToString(format);
  661. //Parse Minus Value
  662. }
  663. if (AllowDrillDown)
  664. {
  665. data = CreateLink(data);
  666. }
  667. string alignment = GetAlignment(fieldAlignment, i);
  668. string noWrapProperty = GetNoWrapping(fieldWrap, i);
  669. body.AppendLine("<td style='td' " + alignment + noWrapProperty + ">" + data + "</td>");
  670. var data2 = row[i].ToString();
  671. if (doTotal)
  672. {
  673. int pos = Array.IndexOf(totalFieldsArray, i.ToString());
  674. if (pos >= 0)
  675. {
  676. if (data2.IndexOf('<') > -1)
  677. {
  678. data2 = GetStatic.RemoveAllTags(data2);
  679. }
  680. double value;
  681. double.TryParse(data2, out value);
  682. totalValues[pos] = totalValues[pos] + value;
  683. }
  684. }
  685. if (doSubTotal)
  686. {
  687. int pos = Array.IndexOf(subTotalFieldsArray, i.ToString());
  688. if (pos >= 0)
  689. {
  690. if (data2.IndexOf('<') > -1)
  691. {
  692. data2 = GetStatic.RemoveAllTags(data2);
  693. }
  694. double value;
  695. double.TryParse(data2, out value);
  696. subTotalValues[pos] = subTotalValues[pos] + value;
  697. }
  698. }
  699. }
  700. body.AppendLine("</tr>");
  701. }
  702. if (doSubTotal)
  703. {
  704. body.AppendLine(CreateTotalRow(ref dt, subTotalText, subTotalBy, subTotalFieldsArray, subTotalValues,
  705. fieldFormatList, fieldAlignment, fieldWrap, ref ExcludeFieldList,
  706. totalTextCol, includeSerialNo));
  707. }
  708. if (doTotal)
  709. {
  710. if (grandTotal != 0.00)
  711. {
  712. if (totalPage == GetPageNumber())
  713. body.AppendLine(CreatGrandTotalRow(ref dt, totalText, 0, totalFieldsArray, grandTotal,
  714. fieldFormatList,
  715. fieldAlignment, fieldWrap, grandTotal, grandTotalUsd,
  716. grandTotal_1, ref ExcludeFieldList, includeSerialNo));
  717. }
  718. else
  719. {
  720. body.AppendLine(CreateTotalRow(ref dt, totalText, 0, totalFieldsArray, totalValues, fieldFormatList,
  721. fieldAlignment, fieldWrap, ref ExcludeFieldList, totalTextCol, includeSerialNo));
  722. }
  723. }
  724. return body.ToString();
  725. }
  726. private static String CreateTotalRow(ref DataTable dt, string totalText, int totalFieldIndex,
  727. string[] totalFields, Double[] totalValues, string[] fieldFormatList,
  728. string fieldAlignmentList, string fieldWrapList,
  729. ref ArrayList ExcludeFieldList, int totalTextCol, bool includeSerialNo)
  730. {
  731. var rowText = new StringBuilder("");
  732. rowText.AppendLine("<tr>");
  733. if (includeSerialNo)
  734. {
  735. if (totalText.IndexOf("<td>") == -1)
  736. rowText.AppendLine("<td></td>");
  737. }
  738. for (int i = 0; i < dt.Columns.Count; i++)
  739. {
  740. if (ExcludeFieldList.IndexOf(dt.Columns[i].ColumnName.ToLower()) > -1)
  741. {
  742. continue;
  743. }
  744. int pos = Array.IndexOf(totalFields, i.ToString());
  745. string data = "";
  746. string alignment = "";
  747. string nowrapProperty = "";
  748. if (pos >= 0)
  749. {
  750. string format = GetFormat(fieldFormatList, i);
  751. data = totalValues[pos] < 0
  752. ? GetStatic.ParseMinusValue(totalValues[pos])
  753. : totalValues[pos].ToString(format.ToUpper());
  754. alignment = GetAlignment(fieldAlignmentList, i);
  755. nowrapProperty = GetNoWrapping(fieldWrapList, i);
  756. }
  757. if (totalTextCol > -1)
  758. {
  759. totalFieldIndex = totalTextCol;
  760. }
  761. if (i == totalFieldIndex) data = totalText;
  762. rowText.AppendLine("<td style='td' " + alignment + nowrapProperty + ">" + data + "</td>");
  763. }
  764. rowText.AppendLine("</tr>");
  765. return rowText.ToString();
  766. }
  767. private static String CreatGrandTotalRow(ref DataTable dt, string totalText, int totalFieldIndex,
  768. string[] totalFields, Double totalValues, string[] fieldFormatList,
  769. string fieldAlignmentList, string fieldWrapList, Double grandTotal,
  770. Double grandTotalUsd, Double grandTotal_1,
  771. ref ArrayList ExcludeFieldList, bool includeSerialNo)
  772. {
  773. var rowText = new StringBuilder("");
  774. rowText.AppendLine("<tr>");
  775. if (includeSerialNo)
  776. {
  777. if (totalText.IndexOf("<td>") == -1)
  778. rowText.AppendLine("<td></td>");
  779. }
  780. for (int i = 0; i < dt.Columns.Count; i++)
  781. {
  782. if (ExcludeFieldList.IndexOf(dt.Columns[i].ColumnName.ToLower()) > -1)
  783. {
  784. continue;
  785. }
  786. int pos = Array.IndexOf(totalFields, i.ToString());
  787. string data = "";
  788. string alignment = "";
  789. string nowrapProperty = "";
  790. if (pos >= 0)
  791. {
  792. data = GetStatic.ParseMinusValue(grandTotal.ToString());
  793. alignment = GetAlignment(fieldAlignmentList, i);
  794. nowrapProperty = GetNoWrapping(fieldWrapList, i);
  795. }
  796. if (i == totalFieldIndex)
  797. data = totalText;
  798. if (i == 9 && grandTotal != 0.00)
  799. {
  800. rowText.AppendLine("<td style='td' align=\"right\">" + GetStatic.ParseMinusValue(grandTotal) +
  801. "</td>");
  802. }
  803. else if (i == 11 && grandTotalUsd != 0.00)
  804. {
  805. rowText.AppendLine("<td style='td' align=\"right\">" + GetStatic.ParseMinusValue(grandTotalUsd) +
  806. "</td>");
  807. }
  808. else if (i == 13 && grandTotal_1 != 0.00)
  809. {
  810. rowText.AppendLine("<td style='td' align=\"right\">" + GetStatic.ParseMinusValue(grandTotal_1) +
  811. "</td>");
  812. }
  813. else
  814. {
  815. rowText.AppendLine("<td style='td' " + alignment + nowrapProperty + ">" + data + "</td>");
  816. }
  817. }
  818. rowText.AppendLine("</tr>");
  819. return rowText.ToString();
  820. }
  821. private static string GetFormat(string[] fieldFormatList, int currFieldIndex)
  822. {
  823. return fieldFormatList.Length > currFieldIndex ? fieldFormatList[currFieldIndex] : "";
  824. //return ( pos == -1 ? "": fieldFormatList[pos]);
  825. }
  826. private static string GetNoWrapping(string fieldWrapList, int currFieldIndex)
  827. {
  828. if (fieldWrapList == "")
  829. return "";
  830. string[] wrapListArray = fieldWrapList.Split('|');
  831. string isWrap = wrapListArray.Length > currFieldIndex ? wrapListArray[currFieldIndex] : "";
  832. string noWrapValue = "";
  833. if (isWrap == "Y")
  834. noWrapValue = " nowrap = \"nowrap\"";
  835. return noWrapValue;
  836. }
  837. private static string GetAlignment(string fieldAlignmentList, int currFieldIndex)
  838. {
  839. if (fieldAlignmentList == "")
  840. return "";
  841. string[] alignListArray = fieldAlignmentList.Split('|');
  842. string alignName = alignListArray.Length > currFieldIndex ? alignListArray[currFieldIndex] : "";
  843. string align = "";
  844. switch (alignName.ToUpper())
  845. {
  846. case "R":
  847. align = " align=\"right\"";
  848. break;
  849. case "L":
  850. align = " align=\"left\"";
  851. break;
  852. case "C":
  853. align = " align=\"center\"";
  854. break;
  855. default:
  856. break;
  857. }
  858. return align;
  859. }
  860. private static string CreateLink(string data)
  861. {
  862. return "";
  863. }
  864. private String CreateReportHead(ref DataTable dt, Boolean merge, ref ArrayList ExcludeFieldList)
  865. {
  866. var head = new StringBuilder("");
  867. var SerialNoColumnHead = "";
  868. if (includeSerialNo)
  869. {
  870. SerialNoColumnHead = "<th style='th'>SN.</th>";
  871. extraCol = 1;
  872. }
  873. if (!merge)
  874. {
  875. head.AppendLine("<tr>");
  876. head.AppendLine(SerialNoColumnHead);
  877. foreach (DataColumn col in dt.Columns)
  878. {
  879. if (ExcludeFieldList.IndexOf(col.ColumnName.ToLower()) > -1)
  880. {
  881. extraCol--;
  882. continue;
  883. }
  884. head.AppendLine("<th style='th'>" + col.ColumnName + "</th>");
  885. }
  886. head.AppendLine("</tr>");
  887. }
  888. else
  889. {
  890. var columns = new Dictionary<string, string>();
  891. foreach (DataColumn col in dt.Columns)
  892. {
  893. if (ExcludeFieldList.IndexOf(col.ColumnName.ToLower()) > -1)
  894. {
  895. extraCol--;
  896. continue;
  897. }
  898. var splitPos = col.ColumnName.IndexOf('_');
  899. if (splitPos == -1)
  900. {
  901. columns.Add(col.ColumnName, col.ColumnName);
  902. }
  903. else
  904. {
  905. var key = col.ColumnName.Substring(0, splitPos);
  906. var value = col.ColumnName.Substring(splitPos + 1, col.ColumnName.Length - splitPos - 1);
  907. if (!columns.ContainsKey(key))
  908. {
  909. columns.Add(key, value);
  910. }
  911. else
  912. {
  913. columns[key] = columns[key] + "|" + value;
  914. }
  915. }
  916. }
  917. var row1 = "";
  918. var row2 = "";
  919. foreach (var kvp in columns)
  920. {
  921. string[] values = kvp.Value.Split('|');
  922. if (values.Length == 1)
  923. {
  924. row1 = row1 + "<th style='th' rowspan=\"2\">" + kvp.Key + "</th>";
  925. }
  926. else
  927. {
  928. row1 = row1 + "<th style='th' align=\"center\" colspan=\"" + values.Length + "\">" + kvp.Key +
  929. "</th>";
  930. foreach (string value in values)
  931. {
  932. row2 = row2 + "<th style='th'>" + value + "</th>";
  933. }
  934. }
  935. }
  936. if (includeSerialNo)
  937. {
  938. SerialNoColumnHead = "<th style='th' rowspan=\"2\">SN.</th>";
  939. }
  940. head.AppendLine("<tr>" + SerialNoColumnHead + row1 + "</tr>");
  941. head.AppendLine("<tr>" + row2 + "</tr>");
  942. }
  943. return head.ToString();
  944. }
  945. #endregion Generate Report
  946. private void PrintUserMatrixReport()
  947. {
  948. const string pStart = "<p style=\"page-break-after: always\">";
  949. const string pEnd = "</p>";
  950. var html = new StringBuilder();
  951. cssClass = "TBLReportMatrix table table-bordered table-condensed table-striped";
  952. int employeeTable = 0;
  953. foreach (DataRow dr in reportResult.Result.Tables[0].Rows)
  954. {
  955. string name = dr["Name"].ToString();
  956. string department = dr["department"].ToString();
  957. string branch = dr["branch"].ToString();
  958. string supervisor = dr["supervisor"].ToString();
  959. DataTable rptDt = reportResult.Result.Tables[++employeeTable];
  960. string reportText = GenerateReport(ref rptDt).Replace("<td", "<td nowrap = \"nowrap\"");
  961. html.AppendLine(pStart);
  962. html.AppendLine("<div class = \"welcome-div\">");
  963. html.AppendLine("User Name: " + name + "");
  964. html.AppendLine("<br />");
  965. //html.AppendLine("Department: " + department + "");
  966. //html.AppendLine("<br />");
  967. html.AppendLine("Agent/Branch Name: " + branch + "");
  968. //html.AppendLine("<br />");
  969. //html.AppendLine("Supervisor: " + supervisor + "");
  970. html.AppendLine("</div>");
  971. html.AppendLine(reportText);
  972. html.AppendLine(pEnd);
  973. }
  974. rptDiv.InnerHtml = html.ToString();
  975. head.Visible = false;
  976. filters.Visible = false;
  977. hr1.Visible = false;
  978. hr2.Visible = false;
  979. export.Visible = false;
  980. }
  981. private ColDefinatoin GetColumnNameToIndex(DataTable dt, string totalFieldNameList, string subTotalFieldNameList)
  982. {
  983. var r = new ColDefinatoin();
  984. var fList = new ArrayList();
  985. r.Alignment = "";
  986. r.Format = " ";
  987. r.SubTotalFields = " ";
  988. r.TotalFields = " ";
  989. for (var i = 0; i < dt.Columns.Count; i++)
  990. {
  991. var cp = new ColProperties(i);
  992. fList.Add(cp);
  993. }
  994. var cList = totalFieldNameList.Split('|');
  995. foreach (var colName in cList)
  996. {
  997. var pos = dt.Columns.IndexOf(colName);
  998. if (pos >= 0)
  999. {
  1000. var cp = (ColProperties)fList[pos];
  1001. cp.IsTotal = true;
  1002. fList[pos] = cp;
  1003. }
  1004. }
  1005. foreach (var colName in cList)
  1006. {
  1007. var pos = dt.Columns.IndexOf(colName);
  1008. pos = pos - 1;
  1009. if (pos >= 0)
  1010. {
  1011. var cp = (ColProperties)fList[pos];
  1012. cp.IsNumeric = true;
  1013. fList[pos] = cp;
  1014. }
  1015. }
  1016. cList = subTotalFieldNameList.Split('|');
  1017. foreach (var colName in cList)
  1018. {
  1019. var pos = dt.Columns.IndexOf(colName);
  1020. if (pos >= 0)
  1021. {
  1022. var cp = (ColProperties)fList[pos];
  1023. cp.IsSubTotal = true;
  1024. fList[pos] = cp;
  1025. }
  1026. }
  1027. foreach (ColProperties itm in fList)
  1028. {
  1029. r.Alignment = r.Alignment + (r.Alignment.Length > 0 ? "|" : "") +
  1030. ((itm.IsSubTotal || itm.IsTotal) ? "R" : "L");
  1031. r.Format = r.Format + (r.Format.Length > 0 ? "|" : "") + ((itm.IsNumeric) ? "N" : "");
  1032. r.SubTotalFields = r.SubTotalFields + (r.SubTotalFields.Length > 0 ? "|" : "") +
  1033. (itm.IsSubTotal ? itm.Index.ToString() : "");
  1034. r.TotalFields = r.TotalFields + (r.TotalFields.Length > 0 ? "|" : "") +
  1035. (itm.IsTotal ? itm.Index.ToString() : "");
  1036. }
  1037. return r;
  1038. }
  1039. public class ColDefinatoin
  1040. {
  1041. public string TotalFields { get; set; }
  1042. public string SubTotalFields { get; set; }
  1043. public string Alignment { get; set; }
  1044. public string Format { get; set; }
  1045. }
  1046. public class ColProperties
  1047. {
  1048. public int Index { get; set; }
  1049. public bool IsTotal { get; set; }
  1050. public bool IsNumeric { get; set; }
  1051. public bool IsSubTotal { get; set; }
  1052. public ColProperties()
  1053. {
  1054. }
  1055. public ColProperties(int index)
  1056. {
  1057. Index = index;
  1058. IsTotal = false;
  1059. IsSubTotal = false;
  1060. IsNumeric = false;
  1061. }
  1062. }
  1063. }
  1064. }