Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var steps = -1;
- var aIndiceList = [];
- var i = 0;
- var dataIndices = [];
- var timeout = null;
- $(document).ready(function () {
- var aCalc = ["0","x","1","2","3","4","5","6","7","8","9"];
- var indiceStart = [];
- var x = 0;
- $(".exportTheMagic2").attr("disabled", true);
- $(".runTheMagic2").click(function() {
- $(".runTheMagic2").attr("disabled", true);
- $(".exportTheMagic2").attr("disabled", true);
- indiceStart = $(".indiceList2").val().trim().replace(/\s/g,'');
- var limit = $(".limitList").val();
- limit = parseInt(limit);
- var newIndice = indiceStart;
- var formatedFirst = formatIndice(newIndice.split('.').join(""));
- if (limit > 0) {
- $(".results2").append("<tr><td>" + formatedFirst + ";</td></tr>");
- $(".indiceList1").val($(".indiceList1").val() + formatedFirst + ";");
- }
- else{
- $(".results2").append("<tr><td>" + formatedFirst + "</td></tr>");
- $(".indiceList1").val($(".indiceList1").val() + formatedFirst);
- }
- for (var i = 0; i < limit; i++) {
- var indiceTemp = newIndice;
- x = aCalc.indexOf(indiceTemp.substr(indiceTemp.length - 1).toLowerCase());
- var temp = indiceTemp.substr(indiceTemp.length-4);
- var index1 = temp.substr(0,3);
- var index2 = temp.substr(temp.length - 1);
- index1 = parseInt(index1) + 1;
- if (index1%100 == 0) {
- if (x == 2)
- x = 10;
- else if (x == 1)
- x = 9;
- else if (x == 0)
- x = 8;
- else
- x = x-3;
- index2 = aCalc[x];
- } else if (index1%10 == 0) {
- if (x == 7)
- x = 0;
- else if (x == 8)
- x = 1;
- else if (x == 9)
- x = 2;
- else if (x == 10)
- x = 3;
- else
- x = x+4;
- index2 = aCalc[x];
- } else {
- if (x == 1)
- x = 10;
- else if (x == 0)
- x = 9;
- else
- x = x-2;
- index2 = aCalc[x];
- }
- index1 = index1.toString();
- if (index1.length == 1)
- index1 = "00" + index1;
- else if (index1.length == 2)
- index1 = "0" + index1;
- newIndice = indiceTemp.substr(0,indiceTemp.length-4) + index1 + index2;
- var formated = formatIndice(newIndice.split('.').join(""));
- if (i == limit - 1) {
- $(".results2").append("<tr><td>" + formated + "</td></tr>");
- $(".indiceList1").val($(".indiceList1").val() + formated);
- }
- else {
- $(".results2").append("<tr><td>" + formated + ";</td></tr>");
- $(".indiceList1").val($(".indiceList1").val() + formated + ";");
- }
- }
- $(".runTheMagic2").attr("disabled", false);
- $(".exportTheMagic2").attr("disabled", false);
- });
- $(".exportTheMagic2").click(function() {
- $(".results2").table2excel({
- // exclude CSS class
- exclude: ".noExl",
- name: "Resultados Indices",
- filename: "ResultadosIndices" //do not include extension
- });
- });
- $(".gerarIndiceNumero").click(function() {
- gerarIndiceNumero($(".indiceBuscar").val().trim().replace(/\s/g,''));
- });
- $(".exportTheMagic1").attr("disabled", true);
- $(".stopTheMagic1").click(function() {
- steps = -1;
- });
- $(".runTheMagic1").click(function() {
- $(".runTheMagic").attr("disabled", true);
- $(".exportTheMagic").attr("disabled", true);
- i = 0;
- aIndiceList = [];
- dataIndices = [];
- aIndiceList = $(".indiceList1").val().split(';');
- if (aIndiceList.length > 0) {
- if (aIndiceList[i] != "") {
- loadData();
- }
- i++;
- }
- });
- $(".exportTheMagic1").click(function() {
- $(".results1").table2excel({
- // exclude CSS class
- exclude: ".noExl",
- name: "Resultados Script",
- filename: "ResultadosScript" //do not include extension
- });
- });
- });
- document.getElementById('iframeid').onload = function() {
- if (steps == -1) {
- steps = 0;
- console.log("Step Inicial");
- } else if (steps == 0) {
- steps = 1;
- console.log("Step Save");
- saveData();
- clearTimeout(timeout);
- timeout = setTimeout(function(){ reloadIframe(); }, 10000);
- } else if (steps == 1) {
- steps = 2;
- console.log("Step Wait");
- clearTimeout(timeout);
- timeout = setTimeout(function(){ reloadIframe(); }, 10000);
- } else if (steps == 2) {
- steps = 0;
- clearTimeout(timeout);
- timeout = setTimeout(function(){ reloadIframe(); }, 10000);
- console.log("Step Reload");
- if (i < aIndiceList.length) {
- if (aIndiceList[i] != "") {
- loadData(aIndiceList[i]);
- } else {
- alert("Erro ao finalizar, verificar console");
- console.log("Step Final - Último Índice verificado: " + aIndiceList[i-1]);
- $(".runTheMagic1").attr("disabled", false);
- $(".exportTheMagic1").attr("disabled", false);
- }
- i++;
- } else {
- alert("Finalizado");
- console.log("Step Final");
- $(".runTheMagic1").attr("disabled", false);
- $(".exportTheMagic1").attr("disabled", false);
- }
- } else {
- steps = 0;
- console.log("Step Error");
- $(".runTheMagic1").attr("disabled", false);
- $(".exportTheMagic1").attr("disabled", false);
- }
- };
- function reloadIframe() {
- var iframe = document.getElementById('iframeid');
- iframe.src = iframe.src;
- }
- function loadData() {
- console.log("Load: " + aIndiceList[i]);
- $('#iframeid').contents().find('#inputIndice').val(aIndiceList[i]);
- $('#iframeid')[0].contentWindow.mojarra.jsfcljs($('#iframeid').contents().find('#meuForm')[0],{'pesquisar':'pesquisar'},'');
- }
- function saveData() {
- console.log("Save: " + aIndiceList[i-1]);
- ".ui-messages-warn-detail"
- var cpfNome = $('#iframeid').contents().find('#mainContent')[0].childNodes[1].childNodes[7].innerText;
- if ($('#iframeid').contents().find('#j_idt43')[0] == undefined) {
- if (cpfNome == "")
- cpfNome = $('#iframeid').contents().find('#mainContent')[0].childNodes[1].childNodes[8].innerText;
- var data = {
- indice: aIndiceList[i-1].toString(),
- cpf: cpfNome.substring(5,19),
- nome: cpfNome.substring(22,cpfNome.length)
- }
- dataIndices.push(data);
- $(".results1").append("<tr><td>"+data.indice+"</td><td>"+data.nome+"</td><td>"+data.cpf+"</td></tr>");
- } else {
- $(".results1").append("<tr><td>"+aIndiceList[i-1].toString()+"</td><td>"+$('#iframeid').contents().find('#j_idt43')[0].childNodes[0].childNodes[1].innerText.trim()+"</td><td></td></tr>");
- }
- }
- function formatIndice(indice) {
- if (indice.length == 15) {
- return indice;
- } else if(indice.length == 13) {
- var result = indice.splice(6, 0, " ");
- result = result.splice(10, 0, " ");
- return result;
- } else {
- if (indice.length == 14) {
- var pos1 = indice.charAt(6);
- var pos2 = indice.charAt(9);
- if (isNaN(pos1)) {
- var result = indice.splice(10, 0, " ");
- return result;
- } else if (isNaN(pos2)) {
- var result = indice.splice(6, 0, " ");
- return result;
- }
- }
- }
- return 0;
- }
- function formatIndiceDiscover(indice) {
- if (indice.length == 14) {
- var result = indice.splice(6, 1, getNumberAlphabet(indice.charAt(6)));
- result = result.splice(10, 1, getNumberAlphabet(indice.charAt(10)));
- return result;
- } else if(indice.length == 12) {
- var result = indice.splice(6, 0, 0);
- result = result.splice(10, 0, 0);
- return result;
- } else {
- if (indice.length == 13) {
- var pos1 = indice.charAt(6);
- var pos2 = indice.charAt(9);
- if (isNaN(pos1)) {
- var result = indice.splice(6, 1, getNumberAlphabet(indice.charAt(6)));
- result = result.splice(10, 0, 0);
- return result;
- } else if (isNaN(pos2)) {
- var result = indice.splice(6, 0, 0);
- result = result.splice(10, 1, getNumberAlphabet(result.charAt(10)));
- return result;
- }
- }
- }
- return 0;
- }
- function getNumberAlphabet(letter) {
- var x = 0;
- switch(letter.toLowerCase()){
- case "a":
- x = 1;
- break;
- case "b":
- x = 2;
- break;
- case "c":
- x = 3;
- break;
- case "d":
- x = 4;
- break;
- case "e":
- x = 5;
- break;
- case "f":
- x = 6;
- break;
- case "g":
- x = 7;
- break;
- case "h":
- x = 8;
- break;
- case "i":
- x = 9;
- break;
- case "j":
- x = 10;
- break;
- case "k":
- x = 11;
- break;
- case "l":
- x = 12;
- break;
- case "m":
- x = 13;
- break;
- case "n":
- x = 14;
- break;
- case "o":
- x = 15;
- break;
- case "p":
- x = 16;
- break;
- case "q":
- x = 17;
- break;
- case "r":
- x = 18;
- break;
- case "s":
- x = 19;
- break;
- case "t":
- x = 20;
- break;
- case "u":
- x = 21;
- break;
- case "v":
- x = 22;
- break;
- case "w":
- x = 23;
- break;
- case "x":
- x = 24;
- break;
- case "y":
- x = 25;
- break;
- case "z":
- x = 26;
- break;
- default:
- x = 0;
- }
- return x;
- }
- String.prototype.splice = function(idx, rem, str) {
- return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem));
- };
- function gerarIndiceNumero(indice) {
- var formated = formatIndiceDiscover(indice.split('.').join(""));
- var indicePendente = formated.split('');
- var calcIndice = [3,2,7,6,5,4,3,2,7,6,5,4,3,2];
- var resultCalc = [];
- var total = 0;
- var prenum = 0;
- var lastNum = 0;
- resultCalc[0] = parseInt(indicePendente[0]) * calcIndice[0];
- resultCalc[1] = parseInt(indicePendente[1]) * calcIndice[1];
- resultCalc[2] = parseInt(indicePendente[2]) * calcIndice[2];
- resultCalc[3] = parseInt(indicePendente[3]) * calcIndice[3];
- resultCalc[4] = parseInt(indicePendente[4]) * calcIndice[4];
- resultCalc[5] = parseInt(indicePendente[5]) * calcIndice[5];
- resultCalc[6] = parseInt(indicePendente[6]) * calcIndice[6];
- resultCalc[7] = parseInt(indicePendente[7]) * calcIndice[7];
- resultCalc[8] = parseInt(indicePendente[8]) * calcIndice[8];
- resultCalc[9] = parseInt(indicePendente[9]) * calcIndice[9];
- resultCalc[10] = parseInt(indicePendente[10]) * calcIndice[10];
- resultCalc[11] = parseInt(indicePendente[11]) * calcIndice[11];
- resultCalc[12] = parseInt(indicePendente[12]) * calcIndice[12];
- resultCalc[13] = parseInt(indicePendente[13]) * calcIndice[13];
- for (var i = 0; i < resultCalc.length; i++) {
- total = total + resultCalc[i];
- }
- prenum = total - 11 * Math.floor(total / 11);
- if (prenum === 0)
- lastnum = 'X';
- else if(prenum === 1)
- lastnum = '0';
- else
- lastnum = 11-prenum;
- var formatIndiceFinal = indice.split('.').join("");
- formatIndiceFinal = formatIndiceFinal + lastnum;
- $(".indiceBuscar").val(formatIndiceFinal);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement