PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/BaliEnterpriseSystems/BaliEnterpriseSystems/PaymentReports.aspx.cs

https://github.com/sirivedula/BEST
C# | 179 lines | 167 code | 12 blank | 0 comment | 22 complexity | 9953dbb5f61b899bcc54e77064842719 MD5 | raw file
  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using System.Web.UI.HtmlControls;
  12. using System.Xml.Linq;
  13. using System.Text;
  14. using BaliEnterpriseSystems.BestObjects;
  15. using System.Collections.Generic;
  16. using System.Data.OleDb;
  17. namespace BaliEnterpriseSystems
  18. {
  19. public partial class PaymentReports : System.Web.UI.Page
  20. {
  21. protected void Page_LoadComplete(object sender, EventArgs e)
  22. {
  23. if (HttpContext.Current.Session["CurrentUser"] == null)
  24. {
  25. Response.Redirect("Logout.aspx");
  26. }
  27. ltrSubMenu.Text = UtilMenu.PaymentMenu("paymentreports");
  28. if (!Utils.User.UserRoleByName("Payment - Reports").allowView)
  29. {
  30. ltrGrid.Text = "You do not have rights to view.";
  31. return;
  32. }
  33. string ms = Request.QueryString["ms"];
  34. ltrMScript.Text = Utils.MenuSelectScript(ms);
  35. StringBuilder rowshtml = new StringBuilder();
  36. string fromdate = Request.Form["fromdate"];
  37. if (string.IsNullOrEmpty(fromdate)) fromdate = DateTime.Today.ToString("MM/dd/yyyy");
  38. string todate = Request.Form["todate"];
  39. if (string.IsNullOrEmpty(todate)) todate = DateTime.Today.AddMonths(1).AddDays(-1).ToString("MM/dd/yyyy");
  40. string summaryby = Request.Form["summaryby"];
  41. string incstd = Request.Form["incstudent"];
  42. if (string.IsNullOrEmpty(summaryby)) summaryby = "";
  43. if (string.IsNullOrEmpty(incstd)) incstd = "";
  44. if (IsPostBack)
  45. {
  46. bool canReport = true;
  47. if (!string.IsNullOrEmpty(fromdate))
  48. {
  49. try
  50. {
  51. DateTime fromdt = Convert.ToDateTime(fromdate);
  52. }
  53. catch (Exception ex)
  54. {
  55. ltrValidateMsg.Text = Utils.WarningMessage(ex.Message);
  56. canReport = false;
  57. }
  58. }
  59. else
  60. {
  61. ltrValidateMsg.Text = Utils.WarningMessage("From Date is Required.");
  62. canReport = false;
  63. }
  64. if (!string.IsNullOrEmpty(todate))
  65. {
  66. try
  67. {
  68. DateTime todt = Convert.ToDateTime(todate);
  69. }
  70. catch (Exception ex)
  71. {
  72. ltrValidateMsg.Text = Utils.WarningMessage(ex.Message);
  73. canReport = false;
  74. }
  75. }
  76. else
  77. {
  78. ltrValidateMsg.Text = Utils.WarningMessage("To Date is Required.");
  79. canReport = false;
  80. }
  81. if (canReport)
  82. {
  83. BestField bffromdate = new BestField() { fieldName = "fromdate", fieldSize = 40, fieldType = "System.DateTime", paramOledbType = System.Data.OleDb.OleDbType.DBTimeStamp, displayField = false };
  84. bffromdate.fieldValue = fromdate;
  85. BestField bftodate = new BestField() { fieldName = "todate", fieldSize = 40, fieldType = "System.DateTime", paramOledbType = System.Data.OleDb.OleDbType.DBTimeStamp, displayField = false };
  86. bftodate.fieldValue = todate;
  87. string tsql = "select paymentDate, bpd.amount, (firstname + ' ' + lastname) from BestPaymentDetails bpd inner join BestStudents bstd on bstd.guidfield = bpd.studentGuid where paymentdate >= ? and paymentdate <= ? AND BSTD.CENTERID=?";
  88. if (!string.IsNullOrEmpty(summaryby))
  89. {
  90. tsql = "select [paramGroupBy], sum(bpd.amount) as payAmount [paramStudents] from BestPaymentDetails bpd inner join BestStudents bstd on bstd.guidfield = bpd.studentGuid where paymentdate >= ? and paymentdate <= ? AND BSTD.CENTERID=? group by [paramGroupBy] [paramStudents]";
  91. if (summaryby.Equals("paymonth"))
  92. {
  93. tsql = tsql.Replace("[paramGroupBy]", "datename(MONTH, paymentDate)");
  94. }
  95. else if (summaryby.Equals("payweek"))
  96. {
  97. }
  98. else if (summaryby.Equals("payyear"))
  99. {
  100. tsql = tsql.Replace("[paramGroupBy]", "year(paymentdate)");
  101. }
  102. else
  103. {
  104. tsql = tsql.Replace("[paramGroupBy]", "paymentdate");
  105. }
  106. if (incstd.Equals("on"))
  107. {
  108. tsql = tsql.Replace("[paramStudents]", ",(firstname + ' ' + lastname)");
  109. }
  110. else
  111. {
  112. tsql = tsql.Replace("[paramStudents]", "");
  113. }
  114. }
  115. BestDatabase db = new BestDatabase();
  116. OleDbCommand myCmd = db.dbCmd;
  117. myCmd.CommandText = tsql;
  118. myCmd.Parameters.Add(bffromdate.Param);
  119. myCmd.Parameters.Add(bftodate.Param);
  120. myCmd.Parameters.Add(Utils.User.CenterIdField.Param);
  121. OleDbDataReader tblReader = myCmd.ExecuteReader();
  122. double total = 0;
  123. rowshtml.Append("<br /><div id=\"paymentReport\"><table class=\"tblreports\" cellspacing=\"0\" cellpadding=\"0\">");
  124. rowshtml.Append("<thead><tr><td colspan=\"9\" style=\"font-weight:bold;font-size:12px;\">" + Utils.User.CenterId + " Payments Report</td></thead>");
  125. rowshtml.Append("<tr><th style=\"text-align:center;\">Payment By</th>");
  126. if (incstd.Equals("on"))
  127. {
  128. rowshtml.Append("<th style=\"text-align:center;\">Student Name</th>");
  129. }
  130. rowshtml.Append("<th style=\"text-align:center;\">Amount</th></tr>");
  131. while (tblReader.Read())
  132. {
  133. string paydate = tblReader[0].ToString();
  134. double payAmt = Convert.ToDouble(tblReader[1].ToString());
  135. total += payAmt;
  136. rowshtml.Append("<tr><td>" + paydate.Replace("12:00:00 AM","") + "</td>");
  137. if (incstd.Equals("on"))
  138. {
  139. rowshtml.Append("<td>" + HttpUtility.HtmlEncode(tblReader[2].ToString()) + "</td>");
  140. }
  141. rowshtml.Append("<td class=\"ra\" style=\"padding-right:3px;\">" + payAmt.ToString("0.00") + "</td></tr>");
  142. }
  143. rowshtml.Append("<tr><th>Total</th>");
  144. if (incstd.Equals("on")) rowshtml.Append("<th>&nbsp;</th>");
  145. rowshtml.Append("<th class=\"ra\" style=\"padding-right:3px;\">" + total.ToString("0.00") + "</th></tr>");
  146. rowshtml.Append("</table></div><br />");
  147. rowshtml.Append("<div><input type=\"button\" value=\"Print\" onclick=\"PrintTable('paymentReport');\" /></div>");
  148. }
  149. }
  150. StringBuilder sb = new StringBuilder();
  151. sb.Append("<div class=\"centered\">");
  152. sb.Append("<table class=\"bestgrid\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">");
  153. sb.Append("<tr><td style=\"text-align:center;\" colspan=\"4\">Payment Reports</td></tr>");
  154. sb.Append("<tr><td>From Date <input type=\"text\" id=\"fromdate\" name=\"fromdate\" size=\"9\" maxlength=\"10\" value=\"" + fromdate + "\" /></td><td>To Date <input type=\"text\" id=\"todate\" name=\"todate\" size=\"9\" maxlength=\"10\" value=\"" + todate + "\" /></td></tr>");
  155. sb.Append("<tr><td>Summary By <select id=\"summaryby\" name=\"summaryby\"><option value=\"\"></option>");
  156. sb.Append("<option value=\"paydate\" " + (summaryby.Equals("paydate") ? " selected " : "") + ">Payment Date</option>");
  157. sb.Append("<option value=\"payweek\" " + (summaryby.Equals("payweek") ? " selected " : "") + ">Week</option>");
  158. sb.Append("<option value=\"paymonth\" " + (summaryby.Equals("paymonth") ? " selected " : "") + ">Month</option>");
  159. sb.Append("<option value=\"payyear\" " + (summaryby.Equals("payyear") ? " selected " : "") + ">Year</option>");
  160. sb.Append("</select></td>");
  161. sb.Append("<td><input type=\"checkbox\" id=\"incstudent\" name=\"incstudent\" " + (incstd.Equals("on") ? " checked " : "") + " /><label for=\"incstudent\">Include Student</label></td></tr>");
  162. sb.Append("<tr><td colspan=\"2\"><input type=\"button\" value=\"Report\" onclick=\"submit();\" /></td></tr>");
  163. sb.Append("</table>");
  164. ltrGrid.Text = sb.ToString() + rowshtml.ToString() + "</div>";
  165. }
  166. }
  167. }