Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //STARTS HERE This is the array that I want to import. It has been transformed and parsed By your method.
- //Iwant to retire certain records that are duplicates
- <!DOCTYPE html>
- <html>
- <head>
- <title>Archivos itau</title>
- <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/accounting.js/0.4.1/accounting.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js"></script>
- <script>
- //File: myscript.js
- var radioValue;
- $(function(){
- var dbid = "bj.....";
- var dbidTable = "bj...";
- var apptoken = "b6.....";
- $.ajaxSetup({data: {apptoken: apptoken}});
- $(document).ready(function(){
- $("input[type='button']").click(function(){
- radioValue = $("input[name='itau']:checked").val();
- alert(radioValue);
- });
- alert(radioValue);
- });
- var parseFile = function(id) {
- return $.Deferred(function(dfd) {
- $("#" + id).on("change", function(){
- var reader = new FileReader();
- reader.onload = function () {
- var dsv = d3.dsv(";", "text/plain");//creates a parser with ";""
- var header = "Data_Mov;Historico;Valor"//creates a header cause text has no header
- var data = dsv.parse(header + "\n" + reader.result);
- dfd.resolve(data);
- };
- reader.readAsText(this.files[0]);
- });
- }).promise();
- };
- parseFile("myFile").then(function(data){
- var csv_array = [];
- console.log(JSON.stringify(data, null, " "));
- data.forEach(function(row) {
- var csv_line = [];
- csv_line.push(radioValue);
- csv_line.push(row["Data_Mov"]);
- csv_line.push(row["Historico"]);
- csv_line.push(row["Valor"]);
- csv_line.push(row["Data_Mov"] + "-" + row["Historico"] + "-" + row["Valor"]);//creates a unique field
- csv_array.push('"' + csv_line.join('","') + '"');
- });
- console.log(csv_array.join("\n"));
- alert("CONSOLA MIRA QUE BONITO");
- var csv_data = csv_array.join("\n");
- //In this moment I think I have to variables csv_array that is json comparable, and csv_data that can be imported.
- //Ido a do query I only need 1 field to compare I include [Record ID]
- var promise = $.get(dbidTable, {
- act: "API_DoQuery",
- clist: "3.57",
- options: "num-10"
- });
- $.when(promise).then(function(xml) {
- alert("all done");
- console.dirxml(xml);
- console.log(promise);
- }).get();
- //something like this is supposed to convert XML toJson Array??
- $.get("promise",function(xml){
- var json_data = $.xml2json(promise);
- var jason_parse_data = JSON.parse(json_data)
- alert(json.message);
- //test if it is a Json Object o creepy thing
- console.log(json_parse_data);
- });
- //Have to compare csv_array with jason_data using unnderscore reject as suggested By Dan
- //Have to compare 5 column of csv_array with 2 column of json_data
- // var new_csv_array = _.reject(jason_data, predicate, [context]);
- // // Have no idea of predicate and Context, I am stuck or have been a long time ago
- // // ...result
- // var new_csv_data = new_csv_array.join("\n");
- // var promise2 = $.post(dbidTable, {
- // act: "API_ImportFromCSV",
- // records_csv: new_csv_data,
- // clist: "117.27.9.59.57" //match Array order with fids of my table
- // });
- });
- });
- </script>
- </head>
- <body>
- <h4>Selecione a conta Itau.</h4>
- <p>
- <label><input type="radio" name="itau" value="2">Itau Impostos: 705-52464-3</label>
- <label><input type="radio" name="itau" value="1">Itau Normal: 705-45669-7</label>
- </p>
- <p><input type="button" value="ENVIAR"></p>
- <input type="file" id="myFile" accept=".txt">
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment