valsaned

uncompleted retire duplicates prior to importing

Nov 7th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. //STARTS HERE This is the array that I want to import. It has been transformed and parsed By your method.
  2. //Iwant to retire certain records that are duplicates
  3. <!DOCTYPE html>
  4. <html>
  5. <head>
  6. <title>Archivos itau</title>
  7.  
  8. <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
  9. <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
  10. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.js"></script>
  11. <script src="https://cdnjs.cloudflare.com/ajax/libs/accounting.js/0.4.1/accounting.min.js"></script>
  12. <script src="https://cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js"></script>
  13.  
  14.  
  15.  
  16.  
  17. <script>
  18. //File: myscript.js
  19. var radioValue;
  20. $(function(){
  21. var dbid = "bj.....";
  22. var dbidTable = "bj...";
  23. var apptoken = "b6.....";
  24. $.ajaxSetup({data: {apptoken: apptoken}});
  25.  
  26. $(document).ready(function(){
  27. $("input[type='button']").click(function(){
  28. radioValue = $("input[name='itau']:checked").val();
  29. alert(radioValue);
  30. });
  31. alert(radioValue);
  32. });
  33.  
  34. var parseFile = function(id) {
  35. return $.Deferred(function(dfd) {
  36. $("#" + id).on("change", function(){
  37. var reader = new FileReader();
  38. reader.onload = function () {
  39.  
  40. var dsv = d3.dsv(";", "text/plain");//creates a parser with ";""
  41. var header = "Data_Mov;Historico;Valor"//creates a header cause text has no header
  42. var data = dsv.parse(header + "\n" + reader.result);
  43. dfd.resolve(data);
  44. };
  45. reader.readAsText(this.files[0]);
  46. });
  47. }).promise();
  48. };
  49.  
  50. parseFile("myFile").then(function(data){
  51. var csv_array = [];
  52. console.log(JSON.stringify(data, null, " "));
  53. data.forEach(function(row) {
  54. var csv_line = [];
  55.  
  56. csv_line.push(radioValue);
  57. csv_line.push(row["Data_Mov"]);
  58. csv_line.push(row["Historico"]);
  59. csv_line.push(row["Valor"]);
  60. csv_line.push(row["Data_Mov"] + "-" + row["Historico"] + "-" + row["Valor"]);//creates a unique field
  61.  
  62.  
  63. csv_array.push('"' + csv_line.join('","') + '"');
  64. });
  65. console.log(csv_array.join("\n"));
  66. alert("CONSOLA MIRA QUE BONITO");
  67.  
  68. var csv_data = csv_array.join("\n");
  69.  
  70. //In this moment I think I have to variables csv_array that is json comparable, and csv_data that can be imported.
  71. //Ido a do query I only need 1 field to compare I include [Record ID]
  72.  
  73. var promise = $.get(dbidTable, {
  74. act: "API_DoQuery",
  75. clist: "3.57",
  76. options: "num-10"
  77. });
  78.  
  79. $.when(promise).then(function(xml) {
  80. alert("all done");
  81. console.dirxml(xml);
  82. console.log(promise);
  83. }).get();
  84.  
  85. //something like this is supposed to convert XML toJson Array??
  86.  
  87. $.get("promise",function(xml){
  88. var json_data = $.xml2json(promise);
  89. var jason_parse_data = JSON.parse(json_data)
  90. alert(json.message);
  91. //test if it is a Json Object o creepy thing
  92. console.log(json_parse_data);
  93. });
  94. //Have to compare csv_array with jason_data using unnderscore reject as suggested By Dan
  95. //Have to compare 5 column of csv_array with 2 column of json_data
  96.  
  97. // var new_csv_array = _.reject(jason_data, predicate, [context]);
  98.  
  99. // // Have no idea of predicate and Context, I am stuck or have been a long time ago
  100. // // ...result
  101.  
  102. // var new_csv_data = new_csv_array.join("\n");
  103. // var promise2 = $.post(dbidTable, {
  104. // act: "API_ImportFromCSV",
  105. // records_csv: new_csv_data,
  106. // clist: "117.27.9.59.57" //match Array order with fids of my table
  107.  
  108. // });
  109. });
  110. });
  111. </script>
  112. </head>
  113.  
  114. <body>
  115. <h4>Selecione a conta Itau.</h4>
  116. <p>
  117. <label><input type="radio" name="itau" value="2">Itau Impostos: 705-52464-3</label>
  118. <label><input type="radio" name="itau" value="1">Itau Normal: 705-45669-7</label>
  119. </p>
  120. <p><input type="button" value="ENVIAR"></p>
  121.  
  122. <input type="file" id="myFile" accept=".txt">
  123. </body>
  124. </html>
Advertisement
Add Comment
Please, Sign In to add comment