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.

356 lines
15 KiB

  1. using Swift.DAL.VoucherReport;
  2. using Swift.web.Library;
  3. using System;
  4. using System.Data;
  5. using System.IO;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using System.Web.UI.WebControls;
  9. namespace Swift.web.BillVoucher.DollarVoucherEntry
  10. {
  11. public partial class VoucherEntry : System.Web.UI.Page
  12. {
  13. private const string ViewFunctionId = "20150080";
  14. private const string DateFunctionId = "20150040";
  15. private readonly RemittanceLibrary _sdd = new RemittanceLibrary();
  16. private readonly VoucherReportDAO _vrd = new VoucherReportDAO();
  17. protected void Page_Load(object sender, EventArgs e)
  18. {
  19. Authenticate();
  20. if (!IsPostBack)
  21. {
  22. AllowChangeDate();
  23. Misc.MakeAmountTextBox(ref amt);
  24. transactionDate.Text = DateTime.Today.ToString("yyyy-MM-dd");
  25. //transactionDate.ReadOnly = true;
  26. PopulateDDL();
  27. }
  28. divuploadMsg.Visible = false;
  29. }
  30. private void PopulateDDL()
  31. {
  32. _sdd.SetDDL(ref voucherType, "EXEC Proc_dropdown_remit @FLAG='voucherDDL'", "value", "functionName", "", "");
  33. _sdd.SetDDL(ref FCY, "EXEC Proc_dropdown_remit @FLAG='Currency'", "val", "Name", "", "FCY");
  34. _sdd.SetDDL(ref Department, "EXEC Proc_dropdown_remit @FLAG='Department'", "RowId", "DepartmentName", "", "Select Department");
  35. _sdd.SetDDL(ref Branch, "EXEC Proc_dropdown_remit @FLAG='Branch'", "agentId", "agentName", "", "Select Branch");
  36. }
  37. private void Authenticate()
  38. {
  39. _sdd.CheckAuthentication(ViewFunctionId);
  40. }
  41. protected bool AllowChangeDate()
  42. {
  43. return _sdd.HasRight(DateFunctionId);
  44. }
  45. protected void addBtn_Click(object sender, EventArgs e)
  46. {
  47. if (GetStatic.ParseDouble(amt.Text) <= 0)
  48. {
  49. GetStatic.AlertMessage(this, "Please enter valid Amount! ");
  50. amt.Text = " ";
  51. amt.Focus();
  52. return;
  53. }
  54. var result = _vrd.InsertTempVoucherEntry(GetStatic.GetSessionId(), GetStatic.GetUser(), acInfo.Value, dropDownDrCr.Text, amt.Text, Department.Text, Branch.Text
  55. , EmpName.Text, Field1.Text, "", FCY.Text, FCYAmt.Text, Rate.Text, "", "");
  56. if (result.ErrorCode == "1")
  57. {
  58. GetStatic.AlertMessage(this, result.Msg);
  59. }
  60. else
  61. {
  62. ShowTempVoucher();
  63. }
  64. }
  65. private void ShowTempVoucher()
  66. {
  67. //show data on div
  68. int sno = 0, drCount = 0, crCount = 0;
  69. double drTotal = 0, crTotal = 0;
  70. var dt = _vrd.GetTempVoucherEntryData(GetStatic.GetSessionId());
  71. var sb = new StringBuilder("");
  72. sb.AppendLine("<div class=\"table-responsive\">");
  73. sb.AppendLine("<table class=\"table table-bordered\">");
  74. sb.AppendLine("<tr>");
  75. sb.AppendLine("<th>S. No</th>");
  76. sb.AppendLine("<th>AC information</th>");
  77. sb.AppendLine("<th>Voucher Date</th>");
  78. sb.AppendLine("<th>FCY</th>");
  79. sb.AppendLine("<th>FCY Amount</th>");
  80. sb.AppendLine("<th>Rate</th>");
  81. sb.AppendLine("<th>JPY Amount</th>");
  82. sb.AppendLine("<th>Department</th>");
  83. sb.AppendLine("<th>Branch</th>");
  84. sb.AppendLine("<th>EmployeeName</th>");
  85. sb.AppendLine("<th>Type</th>");
  86. sb.AppendLine("<th>Select</th>");
  87. sb.AppendLine("</tr>");
  88. if (dt == null || dt.Rows.Count == 0)
  89. {
  90. sb.AppendLine("<tr><td colspan='11' align='center'>No transaction found!</td></tr></table></div>");
  91. rpt_tempVoucherTrans.InnerHtml = sb.ToString();
  92. return;
  93. }
  94. foreach (DataRow item in dt.Rows)
  95. {
  96. sno++;
  97. if (item["part_tran_type"].ToString().ToLower() == "dr")
  98. {
  99. drCount++;
  100. drTotal = drTotal + Convert.ToDouble(item["tran_amt"]);
  101. }
  102. else if (item["part_tran_type"].ToString().ToLower() == "cr")
  103. {
  104. crCount++;
  105. crTotal = crTotal + Convert.ToDouble(item["tran_amt"]);
  106. }
  107. sb.AppendLine("<tr>");
  108. sb.AppendLine("<td nowrap='nowrap' width='5%'>" + sno.ToString() + " </td>");
  109. sb.AppendLine("<td nowrap='nowrap' width='40%'> " + item["acct_num"].ToString() + "</td>");
  110. sb.AppendLine("<td nowrap='nowrap' width='40%'> " + item["tran_date"].ToString() + "</td>");
  111. sb.AppendLine("<td nowrap='nowrap' width='5%'> " + item["trn_currency"].ToString() + "</td>");
  112. sb.AppendLine("<td nowrap='nowrap' width='10%'> " + item["usd_amt"].ToString() + "</td>");
  113. sb.AppendLine("<td nowrap='nowrap' width='10%'> " + item["ex_rate"].ToString() + "</td>");
  114. sb.AppendLine("<td nowrap='nowrap' align='right' width='15%'> <div align='right' style='font-size:12px !important'> " + GetStatic.ShowDecimal(item["tran_amt"].ToString()) + "</div> </td>");
  115. sb.AppendLine("<td nowrap='nowrap' width='20%'> " + item["DepartmentName"].ToString() + "</td>");
  116. sb.AppendLine("<td nowrap='nowrap' width='20%'> " + item["agentName"].ToString() + "</td>");
  117. sb.AppendLine("<td nowrap='nowrap' width='20%'> " + item["emp_name"].ToString() + "</td>");
  118. sb.AppendLine("<td nowrap='nowrap' width='5%'>" + item["part_tran_type"].ToString() + " </td>");
  119. sb.AppendLine("<td nowrap='nowrap' width='5%'><div align='center'><span class=\"action-icon\"><a class=\"btn btn-xs btn-primary\" title=\"Delete\" data-placement=\"top\" data-toggle=\"tooltip\" href=\"#\" data-original-title=\"Delete\" style='text-decoration:none;' onclick='deleteRecord(" + item["tran_id"].ToString() + ")'><i class=\"fa fa-trash-o\"></i></a></span></div></td>");
  120. sb.AppendLine("</tr>");
  121. }
  122. sb.AppendLine("<tr>");
  123. sb.AppendLine("<td nowrap='nowrap' align='right' colspan='10' > <div align='right' style='font-size:12px !important'><strong>Total Dr</strong><span style=' text-align:right; font-weight: bold;' > (" + drCount.ToString() + "): &nbsp; &nbsp;" + GetStatic.ShowDecimal(drTotal.ToString()) + "</span></div> </td>");
  124. sb.AppendLine("</tr>");
  125. sb.AppendLine("<tr>");
  126. sb.AppendLine("<td nowrap='nowrap' align='right' colspan='10' > <div align='right' style='font-size:12px !important'><strong>Total Cr</strong><span style=' text-align:right; font-weight: bold;' > (" + crCount.ToString() + "): &nbsp; &nbsp;" + GetStatic.ShowDecimal(crTotal.ToString()) + "</span></div> </td>");
  127. sb.AppendLine("</tr>");
  128. sb.AppendLine("</table>");
  129. sb.AppendLine("</div>");
  130. rpt_tempVoucherTrans.InnerHtml = sb.ToString();
  131. }
  132. protected void btnDelete_Click(object sender, EventArgs e)
  133. {
  134. var res = _vrd.DeleteRecordVoucherEntry(hdnRowId.Value);
  135. if (res.ErrorCode == "0")
  136. {
  137. GetStatic.AlertMessage(this, res.Msg);
  138. }
  139. ShowTempVoucher();
  140. }
  141. protected void btnUnSave_Click(object sender, EventArgs e)
  142. {
  143. ShowTempVoucher();
  144. }
  145. protected void btnSave_Click(object sender, EventArgs e)
  146. {
  147. string voucherPath = "";
  148. if (VImage.HasFile)
  149. {
  150. // Get the file extension
  151. string fileExtension = System.IO.Path.GetExtension(VImage.FileName);
  152. if (!IsImage(VImage))
  153. {
  154. msg.Visible = true;
  155. mes.InnerHtml = "File types other than image are not acceptable.";
  156. return;
  157. }
  158. else
  159. {
  160. // Get the file size
  161. int fileSize = VImage.PostedFile.ContentLength;
  162. // If file size is greater than 2 MB
  163. if (fileSize > Convert.ToInt32(GetStatic.GetUploadFileSize()))
  164. {
  165. msg.Visible = true;
  166. mes.InnerHtml = "File size cannot be greater than 2 MB";
  167. return;
  168. }
  169. else
  170. {
  171. // Upload the file
  172. voucherPath = "UploadedVoucher-" + GetTimestamp(DateTime.Now) + fileExtension;
  173. string path = GetStatic.ReadWebConfig("filePath") + "VoucherDoc\\";
  174. if (!Directory.Exists(path))
  175. Directory.CreateDirectory(path);
  176. var filePath = path + voucherPath;
  177. VImage.SaveAs(filePath);
  178. }
  179. }
  180. }
  181. string date = transactionDate.Text;
  182. var res = _vrd.SaveTempTransactionUSD(GetStatic.GetSessionId(), date, narrationField.Text, chequeNo.Text, "J", GetStatic.GetUser(), voucherPath);
  183. if (res.ErrorCode == "0")
  184. {
  185. chequeNo.Text = "";
  186. narrationField.Text = "";
  187. rpt_tempVoucherTrans.InnerHtml = res.Msg;
  188. }
  189. else
  190. {
  191. GetStatic.AlertMessage(this, res.Msg);
  192. }
  193. }
  194. public static bool IsImage(FileUpload fileUpload)
  195. {
  196. if (Path.GetExtension(fileUpload.PostedFile.FileName).ToLower() != ".jpg"
  197. && Path.GetExtension(fileUpload.PostedFile.FileName).ToLower() != ".png"
  198. && Path.GetExtension(fileUpload.PostedFile.FileName).ToLower() != ".gif"
  199. && Path.GetExtension(fileUpload.PostedFile.FileName).ToLower() != ".jpeg")
  200. {
  201. return false;
  202. }
  203. if (fileUpload.PostedFile.ContentType.ToLower() != "image/jpg" &&
  204. fileUpload.PostedFile.ContentType.ToLower() != "image/jpeg" &&
  205. fileUpload.PostedFile.ContentType.ToLower() != "image/pjpeg" &&
  206. fileUpload.PostedFile.ContentType.ToLower() != "image/gif" &&
  207. fileUpload.PostedFile.ContentType.ToLower() != "image/x-png" &&
  208. fileUpload.PostedFile.ContentType.ToLower() != "image/png")
  209. {
  210. return false;
  211. }
  212. try
  213. {
  214. byte[] buffer = new byte[512];
  215. fileUpload.PostedFile.InputStream.Read(buffer, 0, 512);
  216. string content = Encoding.UTF8.GetString(buffer);
  217. if (Regex.IsMatch(content, @"<script|<html|<head|<title|<body|<pre|<table|<a\s+href|<img|<plaintext|<cross\-domain\-policy|<?php",
  218. RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Multiline))
  219. {
  220. return false;
  221. }
  222. }
  223. catch (Exception)
  224. {
  225. return false;
  226. }
  227. try
  228. {
  229. using (var bitmap = new System.Drawing.Bitmap(fileUpload.PostedFile.InputStream))
  230. {
  231. }
  232. }
  233. catch (Exception)
  234. {
  235. return false;
  236. }
  237. return true;
  238. }
  239. public static string GetTimestamp(DateTime value)
  240. {
  241. return value.ToString("yyyyMMddHHmmssffff");
  242. }
  243. protected void btnUpload_Click(object sender, EventArgs e)
  244. {
  245. if (fileUpload.FileContent.Length > 0)
  246. {
  247. if (fileUpload.FileName.ToLower().Contains(".csv"))
  248. {
  249. string path = Server.MapPath("..\\..\\") + "\\doc\\tmp\\" + fileUpload.FileName;
  250. string Remitpath = Server.MapPath("..\\..\\") + "\\SampleFile\\FCYVoucherEntry\\" + fileUpload.FileName;
  251. fileUpload.SaveAs(path);
  252. var xml = GetStatic.GetCSVFileInTable(path, true);
  253. //File.Move(path, Remitpath);
  254. File.Delete(path);
  255. var rs = _vrd.InsertTempVoucherEntryFCYFromFile(GetStatic.GetSessionId(), GetStatic.GetUser(), xml);
  256. if (rs.ErrorCode == "1")
  257. {
  258. GetStatic.AlertMessage(this, rs.Msg);
  259. }
  260. else
  261. {
  262. ShowTempVoucher();
  263. }
  264. }
  265. else
  266. {
  267. divuploadMsg.Visible = true;
  268. divuploadMsg.InnerHtml = "Invalid file format uploaded";
  269. }
  270. }
  271. }
  272. protected void btnUploadMultiple_Click(object sender, EventArgs e)
  273. {
  274. string voucherPath = "";
  275. if (VImage.HasFile)
  276. {
  277. // Get the file extension
  278. string fileExtension = System.IO.Path.GetExtension(VImage.FileName);
  279. if (!IsImage(VImage))
  280. {
  281. msg.Visible = true;
  282. mes.InnerHtml = "File types other than image are not acceptable.";
  283. return;
  284. }
  285. else
  286. {
  287. // Get the file size
  288. int fileSize = VImage.PostedFile.ContentLength;
  289. // If file size is greater than 2 MB
  290. if (fileSize > Convert.ToInt32(GetStatic.GetUploadFileSize()))
  291. {
  292. msg.Visible = true;
  293. mes.InnerHtml = "File size cannot be greater than 2 MB";
  294. return;
  295. }
  296. else
  297. {
  298. // Upload the file
  299. voucherPath = "UploadedVoucher-" + GetTimestamp(DateTime.Now) + fileExtension;
  300. string path = GetStatic.ReadWebConfig("filePath") + "VoucherDoc\\";
  301. if (!Directory.Exists(path))
  302. Directory.CreateDirectory(path);
  303. var filePath = path + voucherPath;
  304. VImage.SaveAs(filePath);
  305. }
  306. }
  307. }
  308. string date = transactionDate.Text;
  309. var res = _vrd.SaveTempTransactionUSDMultiple(GetStatic.GetSessionId(), date, narrationField.Text, chequeNo.Text, "J", GetStatic.GetUser(), voucherPath);
  310. StringBuilder sb = new StringBuilder("<table class='table table-responsive table-bordered'>");
  311. sb.AppendLine("<tr>");
  312. sb.AppendLine("<td>Narration</td>");
  313. sb.AppendLine("<td>Voucher No</td>");
  314. sb.AppendLine("<td>Msg</td>");
  315. sb.AppendLine("</tr>");
  316. foreach (DataRow item in res.Rows)
  317. {
  318. sb.AppendLine("<tr>");
  319. sb.AppendLine("<td>" + item["tran_particular"] + "</td>");
  320. sb.AppendLine("<td>" + item["ERROR_CODE"] + "</td>");
  321. sb.AppendLine("<td>" + item["MSG"] + "</td>");
  322. sb.AppendLine("</tr>");
  323. }
  324. rpt_tempVoucherTrans.InnerHtml = sb.ToString();
  325. }
  326. }
  327. }