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.

161 lines
6.5 KiB

  1. using System;
  2. using System.Data;
  3. using System.Text;
  4. using Swift.DAL.BL.Remit.Transaction;
  5. using Swift.web.Library;
  6. namespace Swift.web.Responsive.Reports.SOADomestic
  7. {
  8. public partial class soa : System.Web.UI.Page
  9. {
  10. private readonly TranReportDao rptDao = new TranReportDao();
  11. private readonly RemittanceLibrary rl = new RemittanceLibrary();
  12. protected void Page_Load(object sender, EventArgs e)
  13. {
  14. rl.CheckSession();
  15. string mode = GetStatic.ReadQueryString("mode", "").ToLower();
  16. if (mode == "download")
  17. {
  18. string format = "xls";
  19. string reportName = "soa";
  20. Response.Clear();
  21. Response.ClearContent();
  22. Response.ClearHeaders();
  23. Response.ContentType = "application/vnd.ms-excel";
  24. Response.AddHeader("Content-Disposition", "attachment; filename=" + reportName + "." + format);
  25. exportDiv.Visible = false;
  26. }
  27. ShowReport();
  28. }
  29. private void ShowReport()
  30. {
  31. var fromDate = GetStatic.ReadQueryString("fromDate", "");
  32. var toDate = GetStatic.ReadQueryString("toDate", "");
  33. var agent = GetStatic.ReadQueryString("agent", "");
  34. var reportFor = GetStatic.ReadQueryString("reportFor", "");
  35. var branchID = GetStatic.GetBranch();
  36. DataTable Dt = rptDao.AgentSoaReport(fromDate, toDate, agent, "pay", reportFor, branchID);
  37. LoadSoaHtml(Dt);
  38. lblAgentName.Text = GetStatic.GetAgentNameByMapCodeInt(agent);
  39. lblFrmDate.Text = fromDate;
  40. lbltoDate.Text = toDate;
  41. lblGeneratedDate.Text = DateTime.Now.ToString("MM/dd/yyyy");
  42. }
  43. private void LoadSoaHtml(DataTable dt)
  44. {
  45. int cols = dt.Columns.Count;
  46. var str = new StringBuilder("<table class='TBLReport table table-condensed table-bordered table-striped'>");
  47. str.Append("<tr>");
  48. str.Append("<th><div align=\"left\">Date</div></th>");
  49. str.Append("<th><div align=\"left\">Particulars</div></th>");
  50. str.Append("<th><div align=\"left\">DR</div></th>");
  51. str.Append("<th><div align=\"left\">CR</div></th>");
  52. str.Append("<th><div align=\"left\">Balance</div></th>");
  53. str.Append("<th><div align=\"left\">&nbsp;</div></th>");
  54. str.Append("</tr>");
  55. int cnt = 0;
  56. double DR = 0.00;
  57. double CR = 0.00;
  58. double BAL = 0.00;
  59. double OPBal = 0.00;
  60. double CrTotal = 0.00;
  61. double DrTotal = 0.00;
  62. double GTotal = -0.00;
  63. string DrCr = "";
  64. int rowsCount = dt.Rows.Count;
  65. if (rowsCount == 0)
  66. {
  67. str.Append("<tr><td colspan='4'><b>No Record Found</td></tr></table>");
  68. rptDiv.InnerHtml = str.ToString();
  69. return;
  70. }
  71. OPBal = double.Parse(dt.Rows[0]["DR"].ToString());
  72. DrCr = (OPBal < 0) ? "DR" : "CR";
  73. str.Append("<tr>");
  74. str.Append("<td><div align=\"left\"></div></td>");
  75. str.Append("<td><div align=\"left\">Opening Balance</div></td>");
  76. str.Append("<td><div align=\"left\"></div></td>");
  77. str.Append("<td><div align=\"left\"></div></td>");
  78. str.Append("<td><div align=\"right\"><b>" + GetStatic.ShowDecimal(Math.Abs(OPBal).ToString()) + "</b></div></td>");
  79. str.Append("<td>" + DrCr + "</td>");
  80. str.Append("</tr>");
  81. foreach (DataRow dr in dt.Rows)
  82. {
  83. cnt = cnt + 1;
  84. BAL = 0;
  85. if (dr["Particulars"].ToString() != "Opening Balance")
  86. {
  87. str.Append("<tr>");
  88. DR = DR + double.Parse(dr["DR"].ToString());
  89. CR = CR + double.Parse(dr["CR"].ToString());
  90. BAL = BAL + (OPBal - DR + CR);
  91. DrCr = (BAL < 0) ? "DR" : "CR";
  92. GTotal = GTotal + BAL;
  93. if (double.Parse(dr["DR"].ToString()) > 0)
  94. {
  95. DrTotal = DrTotal + 1;
  96. }
  97. else
  98. {
  99. CrTotal = CrTotal + 1;
  100. }
  101. for (int i = 0; i < cols; i++)
  102. {
  103. if (i > 1)
  104. {
  105. str.Append("<td><div align=\"right\">" + GetStatic.ShowDecimal(dr[i].ToString()) +
  106. "</div></td>");
  107. }
  108. else
  109. {
  110. str.Append("<td><div align=\"left\">" + dr[i].ToString() + "</div></td>");
  111. }
  112. }
  113. str.Append("<td><div align=\"right\"><b>" + GetStatic.ShowDecimal(Math.Abs(BAL).ToString()) + "</b></div></td>");
  114. str.Append("<td>" + DrCr + "</td>");
  115. str.Append("</tr>");
  116. }
  117. }
  118. str.Append("<tr>");
  119. str.Append("<td colspan='2'><div align=\"right\"><b>Total</b> </div></td>");
  120. str.Append("<td><div align=\"right\"><b>" + GetStatic.ShowDecimal(DR.ToString()) + "</b></div></td>");
  121. str.Append("<td><div align=\"right\"><b>" + GetStatic.ShowDecimal(CR.ToString()) + "</b></div></td>");
  122. str.Append("<td><div align=\"right\"></div></td>");
  123. str.Append("<td>" + DrCr + "</td>");
  124. str.Append("</tr>");
  125. str.Append("</table>");
  126. rptDiv.InnerHtml = str.ToString();
  127. lblOpSing.Text = (OPBal < 0) ? "DR" : "CR";
  128. lblOpAmt.Text = GetStatic.ShowDecimal(Math.Abs(OPBal).ToString());
  129. if (rowsCount == 1)
  130. {
  131. lblCloAmt.Text = GetStatic.ShowDecimal(Math.Abs(OPBal).ToString());
  132. lblCloSign.Text = (OPBal < 0) ? "DR" : "CR";
  133. }
  134. else
  135. {
  136. lblCloAmt.Text = GetStatic.ShowDecimal(Math.Abs(BAL).ToString());
  137. lblCloSign.Text = (BAL < 0) ? "DR" : "CR";
  138. }
  139. lblDrTotal.Text = GetStatic.ShowDecimal(Math.Abs(DR).ToString());
  140. lblCrTotal.Text = GetStatic.ShowDecimal(Math.Abs(CR).ToString());
  141. lblAmtMsg.Text = (BAL > 0) ? "<i>Payable to Agent</i>" : "<i>Receivable From Agent</i>";
  142. }
  143. }
  144. }