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.

308 lines
15 KiB

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Upload.aspx.cs" Inherits="Swift.web.BillVoucher.CustomerDeposit.Upload" %>
  2. <!DOCTYPE html>
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title></title>
  6. <link href="/ui/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
  7. <link href="/js/jQuery/jquery-ui.css" rel="stylesheet" type="text/css" />
  8. <link href="/ui/css/menu.css" type="text/css" rel="stylesheet" />
  9. <link href="/ui/css/style.css" type="text/css" rel="stylesheet" />
  10. <link href="/ui/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
  11. <script type="text/javascript" src="/ui/js/jquery.min.js"></script>
  12. <script type="text/javascript" src="/ui/bootstrap/js/bootstrap.min.js"></script>
  13. <script src="/ui/js/jquery-ui.min.js"></script>
  14. <script src="/js/functions.js"></script>
  15. <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.7.7/xlsx.core.min.js"></script>
  16. <script src="https://cdnjs.cloudflare.com/ajax/libs/xls/0.7.4-a/xls.core.min.js"></script>
  17. </head>
  18. <body>
  19. <form id="form1" runat="server">
  20. <div class="page-wrapper">
  21. <div class="row">
  22. <div class="col-sm-12">
  23. <div class="page-title">
  24. <h1></h1>
  25. <ol class="breadcrumb">
  26. <li><a href="../../Front.aspx" target="mainFrame"><i class="fa fa-home"></i></a></li>
  27. <li><a href="#" onclick="return LoadModule('account')">Account</a></li>
  28. <li class="active"><a href="#">Bill & Voucher</a></li>
  29. <li class="active"><a href="Upload.aspx">Customer Deposit Voucher Upload</a></li>
  30. </ol>
  31. </div>
  32. </div>
  33. </div>
  34. <div class="row">
  35. <div class="col-md-12">
  36. <div class="panel panel-default recent-activites">
  37. <div class="panel-heading">
  38. <h4 class="panel-title">Customer Deposit Voucher Upload
  39. </h4>
  40. <div class="panel-actions">
  41. <a href="#" class="panel-action panel-action-toggle" data-panel-toggle></a><a href="#"
  42. class="panel-action panel-action-dismiss" data-panel-dismiss></a>
  43. </div>
  44. </div>
  45. <div class="panel-body">
  46. <div class="row" id="divUpload" runat="server">
  47. <div class="col-md-12 form-group">
  48. <label class="control-label" for="">
  49. Choose File:
  50. </label>
  51. <input type="file" id="excelfile" /><a href="/SampleFile/TwoEntryBatchUpload.csv">Sample File</a>
  52. <label style="color:red;">Note: Please Check File before upload(<i>by clicking on Check File</i>), to verify if the data is already uploaded or not!</label>
  53. </div>
  54. <div class="col-md-12 form-group">
  55. <input type="button" id="viewfile" value="Export To Table" class="btn btn-success" />
  56. <input type="button" id="checkData" value="Check File" class="btn btn-primary" />
  57. <input type="button" id="uploadFile" value="Upload File" class="btn btn-primary" />
  58. </div>
  59. </div>
  60. <div class="row" id="fileUploadDiv">
  61. <div class="col-md-12 form-group">
  62. <table class="table table-responsive table-bordered" id="exceltable">
  63. </table>
  64. </div>
  65. </div>
  66. <div class="row" id="finalResultDiv" style="display: none;">
  67. <div class="col-md-12 form-group">
  68. <table class="table table-responsive table-bordered" id="tblResponseSave">
  69. <thead>
  70. <tr>
  71. <th>S. No.</th>
  72. <th>Error Code</th>
  73. <th>Narration</th>
  74. <th>Voucher Number</th>
  75. </tr>
  76. </thead>
  77. <tbody id="tblResult" runat="server">
  78. <tr>
  79. <td colspan="3">No data to view</td>
  80. </tr>
  81. </tbody>
  82. </table>
  83. </div>
  84. </div>
  85. <div class="row" id="divReUpload" runat="server" visible="false">
  86. <div class="col-md-12 form-group">
  87. <asp:Button ID="btnReUpload" runat="server" CssClass="btn btn-primary" Text="Re Upload" />
  88. </div>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. </div>
  94. </div>
  95. <input type="hidden" id="hddCheck" value="N" />
  96. </form>
  97. <script type="text/javascript">
  98. $(document).ready(function () {
  99. $("body").on("click", "#viewfile", function () {
  100. $('#fileUploadDiv').show();
  101. $('#finalResultDiv').hide();
  102. ExportToTable();
  103. $('#excelfile').val('');
  104. });
  105. $("body").on("click", "#checkData", function () {
  106. $("#uploadFile").attr("disabled", true);
  107. $("#viewfile").attr("disabled", true);
  108. $("#checkData").attr("disabled", true);
  109. var xmlData = GetXMLData();
  110. if (xmlData == '') {
  111. $("#uploadFile").attr("disabled", false);
  112. $("#viewfile").attr("disabled", false);
  113. $("#checkData").attr("disabled", false);
  114. return alert('No data for checking!');
  115. }
  116. xmlData = xmlData.replace(/</g, '&lt;');
  117. xmlData = xmlData.replace(/>/g, '&gt;');
  118. var dataToSend = {
  119. MethodName: 'CheckData',
  120. XmlData: xmlData
  121. };
  122. $.post('/BillVoucher/CustomerDeposit/Upload.aspx', dataToSend, function (response) {
  123. $("#uploadFile").attr("disabled", false);
  124. $("#viewfile").attr("disabled", false);
  125. $("#checkData").attr("disabled", false);
  126. if (response.ErrorCode == '0') {
  127. $('#hddCheck').val('Y');
  128. }
  129. alert(response.Msg);
  130. });
  131. });
  132. $("body").on("click", "#uploadFile", function () {
  133. $("#uploadFile").attr("disabled", true);
  134. $("#viewfile").attr("disabled", true);
  135. $("#checkData").attr("disabled", true);
  136. if ($('#hddCheck').val() == 'N') {
  137. $("#uploadFile").attr("disabled", false);
  138. $("#viewfile").attr("disabled", false);
  139. $("#checkData").attr("disabled", false);
  140. return alert('You can not upload the file, either the file is not checked or file is aleardy uploaded with same data(Invalid)!');
  141. }
  142. var xmlData = GetXMLData();
  143. if (xmlData == '') {
  144. $("#uploadFile").attr("disabled", false);
  145. $("#viewfile").attr("disabled", false);
  146. $("#checkData").attr("disabled", false);
  147. return alert('No data to upload!');
  148. }
  149. xmlData = xmlData.replace(/</g, '&lt;');
  150. xmlData = xmlData.replace(/>/g, '&gt;');
  151. var dataToSend = {
  152. MethodName: 'UploadVoucher',
  153. XmlData: xmlData
  154. };
  155. $.post('/BillVoucher/CustomerDeposit/Upload.aspx', dataToSend, function (response) {
  156. $("#uploadFile").attr("disabled", false);
  157. $("#viewfile").attr("disabled", false);
  158. $("#checkData").attr("disabled", false);
  159. $('#fileUploadDiv').hide();
  160. $('#excelfile').val('');
  161. $('#finalResultDiv').show();
  162. $('#exceltable').empty();
  163. $('#hddCheck').val('N');
  164. var table = $('#tblResponseSave');
  165. table.find("tbody tr").remove();
  166. var result = jQuery.parseJSON(response); //response;
  167. var count = 1;
  168. $.each(result, function (i, d) {
  169. var row = '<tr>';
  170. row += '<td>' + count + '</td>';
  171. row += '<td>' + d['ERROR_CODE'] + '</td>';
  172. row += '<td>' + d['MSG'] + '</td>';
  173. row += '<td>' + d['ID'] + '</td>';
  174. row += '</tr>';
  175. table.append(row);
  176. count++;
  177. });
  178. });
  179. });
  180. });
  181. function ExportToTable() {
  182. var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.xlsx|.xls)$/;
  183. /*Checks whether the file is a valid excel file*/
  184. if (regex.test($("#excelfile").val().toLowerCase())) {
  185. var xlsxflag = false; /*Flag for checking whether excel is .xls format or .xlsx format*/
  186. if ($("#excelfile").val().toLowerCase().indexOf(".xlsx") > 0) {
  187. xlsxflag = true;
  188. }
  189. /*Checks whether the browser supports HTML5*/
  190. if (typeof (FileReader) != "undefined") {
  191. var reader = new FileReader();
  192. reader.onload = function (e) {
  193. var data = e.target.result;
  194. /*Converts the excel data in to object*/
  195. if (xlsxflag) {
  196. var workbook = XLSX.read(data, { type: 'binary' });
  197. }
  198. else {
  199. var workbook = XLS.read(data, { type: 'binary' });
  200. }
  201. /*Gets all the sheetnames of excel in to a variable*/
  202. var sheet_name_list = workbook.SheetNames;
  203. var cnt = 0; /*This is used for restricting the script to consider only first sheet of excel*/
  204. sheet_name_list.forEach(function (y) { /*Iterate through all sheets*/
  205. /*Convert the cell value to Json*/
  206. if (xlsxflag) {
  207. var exceljson = XLSX.utils.sheet_to_json(workbook.Sheets[y]);
  208. }
  209. else {
  210. var exceljson = XLS.utils.sheet_to_row_object_array(workbook.Sheets[y]);
  211. }
  212. if (exceljson.length > 0 && cnt == 0) {
  213. BindTable(exceljson, '#exceltable');
  214. cnt++;
  215. }
  216. });
  217. $('#exceltable').show();
  218. }
  219. if (xlsxflag) {/*If excel file is .xlsx extension than creates a Array Buffer from excel*/
  220. reader.readAsArrayBuffer($("#excelfile")[0].files[0]);
  221. }
  222. else {
  223. reader.readAsBinaryString($("#excelfile")[0].files[0]);
  224. }
  225. }
  226. else {
  227. alert("Sorry! Your browser does not support HTML5!");
  228. }
  229. }
  230. else {
  231. alert("Please upload a valid Excel file!");
  232. }
  233. }
  234. function BindTable(jsondata, tableid) {/*Function used to convert the JSON array to Html Table*/
  235. $(tableid).empty();
  236. var columns = BindTableHeader(jsondata, tableid); /*Gets all the column headings of Excel*/
  237. for (var i = 0; i < jsondata.length; i++) {
  238. var row$ = $('<tr/>');
  239. for (var colIndex = 0; colIndex < columns.length; colIndex++) {
  240. var cellValue = jsondata[i][columns[colIndex]];
  241. if (cellValue == null)
  242. cellValue = "";
  243. row$.append($('<td/>').html(cellValue));
  244. }
  245. $(tableid).append(row$);
  246. }
  247. }
  248. function BindTableHeader(jsondata, tableid) {/*Function used to get all column names from JSON and bind the html table header*/
  249. var columnSet = [];
  250. var headerTr$ = $('<tr/>');
  251. for (var i = 0; i < jsondata.length; i++) {
  252. var rowHash = jsondata[i];
  253. for (var key in rowHash) {
  254. if (rowHash.hasOwnProperty(key)) {
  255. if ($.inArray(key, columnSet) == -1) {/*Adding each unique column names to a variable array*/
  256. columnSet.push(key);
  257. headerTr$.append($('<th/>').html(key));
  258. }
  259. }
  260. }
  261. }
  262. $(tableid).append(headerTr$);
  263. return columnSet;
  264. }
  265. function GetXMLData() {
  266. var xml = '<root>';
  267. var table = $('#exceltable > tbody > tr');
  268. if (table.length == 0) {
  269. return '';
  270. }
  271. $(table).each(function (index, tr) {
  272. xml += '<row DT="' + ConvertDate(tr.cells[0].innerText, '-') + '" AMT="' + tr.cells[1].innerText + '" NARRATION="' + tr.cells[2].innerText + '" />';
  273. });
  274. //xml += '<row id=\"'++'\"';
  275. xml += '</root>';
  276. return xml;
  277. }
  278. function ConvertDate(dt, seprator) {
  279. var d = new Date(dt),
  280. month = '' + (d.getMonth() + 1),
  281. day = '' + d.getDate(),
  282. year = d.getFullYear();
  283. return [year, month, day].join(seprator);
  284. }
  285. </script>
  286. </body>
  287. </html>