Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.07 KB | None | 0 0
  1. var steps = -1;
  2. var aIndiceList = [];
  3. var i = 0;
  4. var dataIndices = [];
  5. var timeout = null;
  6.  
  7. $(document).ready(function () {
  8. var aCalc = ["0","x","1","2","3","4","5","6","7","8","9"];
  9. var indiceStart = [];
  10. var x = 0;
  11. $(".exportTheMagic2").attr("disabled", true);
  12. $(".runTheMagic2").click(function() {
  13. $(".runTheMagic2").attr("disabled", true);
  14. $(".exportTheMagic2").attr("disabled", true);
  15.  
  16. indiceStart = $(".indiceList2").val().trim().replace(/\s/g,'');
  17. var limit = $(".limitList").val();
  18. limit = parseInt(limit);
  19. var newIndice = indiceStart;
  20. var formatedFirst = formatIndice(newIndice.split('.').join(""));
  21. if (limit > 0) {
  22. $(".results2").append("<tr><td>" + formatedFirst + ";</td></tr>");
  23. $(".indiceList1").val($(".indiceList1").val() + formatedFirst + ";");
  24. }
  25. else{
  26. $(".results2").append("<tr><td>" + formatedFirst + "</td></tr>");
  27. $(".indiceList1").val($(".indiceList1").val() + formatedFirst);
  28. }
  29.  
  30. for (var i = 0; i < limit; i++) {
  31. var indiceTemp = newIndice;
  32. x = aCalc.indexOf(indiceTemp.substr(indiceTemp.length - 1).toLowerCase());
  33.  
  34. var temp = indiceTemp.substr(indiceTemp.length-4);
  35.  
  36. var index1 = temp.substr(0,3);
  37. var index2 = temp.substr(temp.length - 1);
  38.  
  39. index1 = parseInt(index1) + 1;
  40.  
  41. if (index1%100 == 0) {
  42. if (x == 2)
  43. x = 10;
  44. else if (x == 1)
  45. x = 9;
  46. else if (x == 0)
  47. x = 8;
  48. else
  49. x = x-3;
  50.  
  51. index2 = aCalc[x];
  52. } else if (index1%10 == 0) {
  53. if (x == 7)
  54. x = 0;
  55. else if (x == 8)
  56. x = 1;
  57. else if (x == 9)
  58. x = 2;
  59. else if (x == 10)
  60. x = 3;
  61. else
  62. x = x+4;
  63.  
  64. index2 = aCalc[x];
  65. } else {
  66. if (x == 1)
  67. x = 10;
  68. else if (x == 0)
  69. x = 9;
  70. else
  71. x = x-2;
  72.  
  73. index2 = aCalc[x];
  74. }
  75.  
  76. index1 = index1.toString();
  77. if (index1.length == 1)
  78. index1 = "00" + index1;
  79. else if (index1.length == 2)
  80. index1 = "0" + index1;
  81. newIndice = indiceTemp.substr(0,indiceTemp.length-4) + index1 + index2;
  82. var formated = formatIndice(newIndice.split('.').join(""));
  83. if (i == limit - 1) {
  84. $(".results2").append("<tr><td>" + formated + "</td></tr>");
  85. $(".indiceList1").val($(".indiceList1").val() + formated);
  86. }
  87. else {
  88. $(".results2").append("<tr><td>" + formated + ";</td></tr>");
  89. $(".indiceList1").val($(".indiceList1").val() + formated + ";");
  90. }
  91.  
  92. }
  93. $(".runTheMagic2").attr("disabled", false);
  94. $(".exportTheMagic2").attr("disabled", false);
  95.  
  96. });
  97.  
  98. $(".exportTheMagic2").click(function() {
  99. $(".results2").table2excel({
  100. // exclude CSS class
  101. exclude: ".noExl",
  102. name: "Resultados Indices",
  103. filename: "ResultadosIndices" //do not include extension
  104. });
  105. });
  106.  
  107. $(".gerarIndiceNumero").click(function() {
  108. gerarIndiceNumero($(".indiceBuscar").val().trim().replace(/\s/g,''));
  109. });
  110.  
  111. $(".exportTheMagic1").attr("disabled", true);
  112. $(".stopTheMagic1").click(function() {
  113. steps = -1;
  114. });
  115. $(".runTheMagic1").click(function() {
  116. $(".runTheMagic").attr("disabled", true);
  117. $(".exportTheMagic").attr("disabled", true);
  118. i = 0;
  119. aIndiceList = [];
  120. dataIndices = [];
  121. aIndiceList = $(".indiceList1").val().split(';');
  122. if (aIndiceList.length > 0) {
  123. if (aIndiceList[i] != "") {
  124. loadData();
  125. }
  126. i++;
  127. }
  128.  
  129. });
  130.  
  131. $(".exportTheMagic1").click(function() {
  132. $(".results1").table2excel({
  133. // exclude CSS class
  134. exclude: ".noExl",
  135. name: "Resultados Script",
  136. filename: "ResultadosScript" //do not include extension
  137. });
  138. });
  139. });
  140.  
  141. document.getElementById('iframeid').onload = function() {
  142. if (steps == -1) {
  143. steps = 0;
  144. console.log("Step Inicial");
  145. } else if (steps == 0) {
  146. steps = 1;
  147. console.log("Step Save");
  148. saveData();
  149. clearTimeout(timeout);
  150. timeout = setTimeout(function(){ reloadIframe(); }, 10000);
  151. } else if (steps == 1) {
  152. steps = 2;
  153. console.log("Step Wait");
  154. clearTimeout(timeout);
  155. timeout = setTimeout(function(){ reloadIframe(); }, 10000);
  156. } else if (steps == 2) {
  157. steps = 0;
  158. clearTimeout(timeout);
  159. timeout = setTimeout(function(){ reloadIframe(); }, 10000);
  160. console.log("Step Reload");
  161. if (i < aIndiceList.length) {
  162. if (aIndiceList[i] != "") {
  163. loadData(aIndiceList[i]);
  164. } else {
  165. alert("Erro ao finalizar, verificar console");
  166. console.log("Step Final - Último Índice verificado: " + aIndiceList[i-1]);
  167. $(".runTheMagic1").attr("disabled", false);
  168. $(".exportTheMagic1").attr("disabled", false);
  169. }
  170. i++;
  171. } else {
  172. alert("Finalizado");
  173. console.log("Step Final");
  174. $(".runTheMagic1").attr("disabled", false);
  175. $(".exportTheMagic1").attr("disabled", false);
  176. }
  177. } else {
  178. steps = 0;
  179. console.log("Step Error");
  180. $(".runTheMagic1").attr("disabled", false);
  181. $(".exportTheMagic1").attr("disabled", false);
  182. }
  183. };
  184.  
  185. function reloadIframe() {
  186. var iframe = document.getElementById('iframeid');
  187. iframe.src = iframe.src;
  188. }
  189.  
  190. function loadData() {
  191. console.log("Load: " + aIndiceList[i]);
  192. $('#iframeid').contents().find('#inputIndice').val(aIndiceList[i]);
  193. $('#iframeid')[0].contentWindow.mojarra.jsfcljs($('#iframeid').contents().find('#meuForm')[0],{'pesquisar':'pesquisar'},'');
  194. }
  195.  
  196. function saveData() {
  197. console.log("Save: " + aIndiceList[i-1]);
  198. ".ui-messages-warn-detail"
  199. var cpfNome = $('#iframeid').contents().find('#mainContent')[0].childNodes[1].childNodes[7].innerText;
  200. if ($('#iframeid').contents().find('#j_idt43')[0] == undefined) {
  201. if (cpfNome == "")
  202. cpfNome = $('#iframeid').contents().find('#mainContent')[0].childNodes[1].childNodes[8].innerText;
  203. var data = {
  204. indice: aIndiceList[i-1].toString(),
  205. cpf: cpfNome.substring(5,19),
  206. nome: cpfNome.substring(22,cpfNome.length)
  207. }
  208. dataIndices.push(data);
  209. $(".results1").append("<tr><td>"+data.indice+"</td><td>"+data.nome+"</td><td>"+data.cpf+"</td></tr>");
  210. } else {
  211. $(".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>");
  212. }
  213. }
  214.  
  215. function formatIndice(indice) {
  216. if (indice.length == 15) {
  217. return indice;
  218. } else if(indice.length == 13) {
  219. var result = indice.splice(6, 0, " ");
  220. result = result.splice(10, 0, " ");
  221. return result;
  222. } else {
  223. if (indice.length == 14) {
  224. var pos1 = indice.charAt(6);
  225. var pos2 = indice.charAt(9);
  226. if (isNaN(pos1)) {
  227. var result = indice.splice(10, 0, " ");
  228. return result;
  229. } else if (isNaN(pos2)) {
  230. var result = indice.splice(6, 0, " ");
  231. return result;
  232. }
  233. }
  234. }
  235. return 0;
  236. }
  237.  
  238. function formatIndiceDiscover(indice) {
  239. if (indice.length == 14) {
  240. var result = indice.splice(6, 1, getNumberAlphabet(indice.charAt(6)));
  241. result = result.splice(10, 1, getNumberAlphabet(indice.charAt(10)));
  242. return result;
  243. } else if(indice.length == 12) {
  244. var result = indice.splice(6, 0, 0);
  245. result = result.splice(10, 0, 0);
  246. return result;
  247. } else {
  248. if (indice.length == 13) {
  249. var pos1 = indice.charAt(6);
  250. var pos2 = indice.charAt(9);
  251. if (isNaN(pos1)) {
  252. var result = indice.splice(6, 1, getNumberAlphabet(indice.charAt(6)));
  253. result = result.splice(10, 0, 0);
  254. return result;
  255. } else if (isNaN(pos2)) {
  256. var result = indice.splice(6, 0, 0);
  257. result = result.splice(10, 1, getNumberAlphabet(result.charAt(10)));
  258. return result;
  259. }
  260. }
  261. }
  262. return 0;
  263. }
  264.  
  265. function getNumberAlphabet(letter) {
  266. var x = 0;
  267. switch(letter.toLowerCase()){
  268. case "a":
  269. x = 1;
  270. break;
  271. case "b":
  272. x = 2;
  273. break;
  274. case "c":
  275. x = 3;
  276. break;
  277. case "d":
  278. x = 4;
  279. break;
  280. case "e":
  281. x = 5;
  282. break;
  283. case "f":
  284. x = 6;
  285. break;
  286. case "g":
  287. x = 7;
  288. break;
  289. case "h":
  290. x = 8;
  291. break;
  292. case "i":
  293. x = 9;
  294. break;
  295. case "j":
  296. x = 10;
  297. break;
  298. case "k":
  299. x = 11;
  300. break;
  301. case "l":
  302. x = 12;
  303. break;
  304. case "m":
  305. x = 13;
  306. break;
  307. case "n":
  308. x = 14;
  309. break;
  310. case "o":
  311. x = 15;
  312. break;
  313. case "p":
  314. x = 16;
  315. break;
  316. case "q":
  317. x = 17;
  318. break;
  319. case "r":
  320. x = 18;
  321. break;
  322. case "s":
  323. x = 19;
  324. break;
  325. case "t":
  326. x = 20;
  327. break;
  328. case "u":
  329. x = 21;
  330. break;
  331. case "v":
  332. x = 22;
  333. break;
  334. case "w":
  335. x = 23;
  336. break;
  337. case "x":
  338. x = 24;
  339. break;
  340. case "y":
  341. x = 25;
  342. break;
  343. case "z":
  344. x = 26;
  345. break;
  346. default:
  347. x = 0;
  348. }
  349. return x;
  350. }
  351.  
  352. String.prototype.splice = function(idx, rem, str) {
  353. return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem));
  354. };
  355.  
  356. function gerarIndiceNumero(indice) {
  357. var formated = formatIndiceDiscover(indice.split('.').join(""));
  358. var indicePendente = formated.split('');
  359. var calcIndice = [3,2,7,6,5,4,3,2,7,6,5,4,3,2];
  360. var resultCalc = [];
  361. var total = 0;
  362. var prenum = 0;
  363. var lastNum = 0;
  364.  
  365. resultCalc[0] = parseInt(indicePendente[0]) * calcIndice[0];
  366. resultCalc[1] = parseInt(indicePendente[1]) * calcIndice[1];
  367. resultCalc[2] = parseInt(indicePendente[2]) * calcIndice[2];
  368. resultCalc[3] = parseInt(indicePendente[3]) * calcIndice[3];
  369. resultCalc[4] = parseInt(indicePendente[4]) * calcIndice[4];
  370. resultCalc[5] = parseInt(indicePendente[5]) * calcIndice[5];
  371. resultCalc[6] = parseInt(indicePendente[6]) * calcIndice[6];
  372. resultCalc[7] = parseInt(indicePendente[7]) * calcIndice[7];
  373. resultCalc[8] = parseInt(indicePendente[8]) * calcIndice[8];
  374. resultCalc[9] = parseInt(indicePendente[9]) * calcIndice[9];
  375. resultCalc[10] = parseInt(indicePendente[10]) * calcIndice[10];
  376. resultCalc[11] = parseInt(indicePendente[11]) * calcIndice[11];
  377. resultCalc[12] = parseInt(indicePendente[12]) * calcIndice[12];
  378. resultCalc[13] = parseInt(indicePendente[13]) * calcIndice[13];
  379.  
  380. for (var i = 0; i < resultCalc.length; i++) {
  381. total = total + resultCalc[i];
  382. }
  383. prenum = total - 11 * Math.floor(total / 11);
  384. if (prenum === 0)
  385. lastnum = 'X';
  386. else if(prenum === 1)
  387. lastnum = '0';
  388. else
  389. lastnum = 11-prenum;
  390. var formatIndiceFinal = indice.split('.').join("");
  391. formatIndiceFinal = formatIndiceFinal + lastnum;
  392. $(".indiceBuscar").val(formatIndiceFinal);
  393. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement