|
| 1 | +<!doctype html> |
| 2 | +<html lang="en"> |
| 3 | + <head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 6 | + |
| 7 | + <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> |
| 8 | + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/css/select2.min.css" /> |
| 9 | + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css" /> |
| 10 | + <title>Hello, world!</title> |
| 11 | + </head> |
| 12 | + <body> |
| 13 | + |
| 14 | + <div class="container"> |
| 15 | + |
| 16 | + <div class="row"> |
| 17 | + |
| 18 | + <div class="col-12 text-center"> |
| 19 | + <h1 class="mt-2 mb-4">Consulta CNPJ</h1> |
| 20 | + </div> |
| 21 | + |
| 22 | + <div class="col-7"> |
| 23 | + <label for="cnae">Buscar por CNAE</label> |
| 24 | + <select name="cnae" id="cnae" class="form-control" serachable="true"> |
| 25 | + <option> Selecione </option> |
| 26 | + </select> |
| 27 | + </div> |
| 28 | + |
| 29 | + <!-- by cep--> |
| 30 | + <div class="col-3"> |
| 31 | + <label for="cep">Buscar por CEP</label> |
| 32 | + <input type="text" name="cep" id="cep" class="form-control"> |
| 33 | + </div> |
| 34 | + |
| 35 | + <div class="col-2"> |
| 36 | + <label for="quantidade">Quantidade CNPJs</label> |
| 37 | + <input type="number" name="quantidade" id="quantidade" class="form-control" value="25"> |
| 38 | + </div> |
| 39 | + </div> |
| 40 | + |
| 41 | + <hr class="my-4"> |
| 42 | + |
| 43 | + <div class=""> |
| 44 | + |
| 45 | + <button onclick="exportTableToCSV('cnpjs.csv')" class="btn btn-primary mt-2 mb-2">Exportar CSV</button> |
| 46 | + |
| 47 | + <table class="table"> |
| 48 | + <thead> |
| 49 | + <tr> |
| 50 | + <th scope="col">CNPJ</th> |
| 51 | + <th scope="col">Capital Social</th> |
| 52 | + <th scope="col">Razao Social</th> |
| 53 | + <th scope="col">Bairro</th> |
| 54 | + <th scope="col">Cidade</th> |
| 55 | + <th scope="col">E-mail</th> |
| 56 | + <th scope="col">Telefone 1</th> |
| 57 | + <th scope="col">Telefone 2</th> |
| 58 | + </tr> |
| 59 | + </thead> |
| 60 | + </table> |
| 61 | + |
| 62 | + </div> |
| 63 | + |
| 64 | + </div> |
| 65 | +</div> |
| 66 | + |
| 67 | +<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> |
| 68 | +<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script> |
| 69 | +<script src="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/js/select2.full.min.js"></script> |
| 70 | + |
| 71 | +<script> |
| 72 | + |
| 73 | + let credenciais = { |
| 74 | + "Content-Type": "application/json", |
| 75 | + "DeviceToken": "SUAS_CREDENCIAIS_AQUI", |
| 76 | + "Authorization": "Bearer SUAS_CREDENCIAIS_AQUI" |
| 77 | + }; |
| 78 | + |
| 79 | + let settings = { |
| 80 | + "url": "https://cluster.apigratis.com/api/v2/dados/lista-cnaes", |
| 81 | + "method": "POST", |
| 82 | + "headers": credenciais, |
| 83 | + "data": JSON.stringify({ |
| 84 | + "quantidade": "1300" |
| 85 | + }), |
| 86 | + }; |
| 87 | + |
| 88 | + function exportTableToCSV(filename) { |
| 89 | + let csv = []; |
| 90 | + let rows = document.querySelectorAll("table tr"); |
| 91 | + |
| 92 | + for (var i = 0; i < rows.length; i++) { |
| 93 | + let row = [], cols = rows[i].querySelectorAll("td, th"); |
| 94 | + |
| 95 | + for (var j = 0; j < cols.length; j++){ |
| 96 | + row.push(cols[j].innerText); |
| 97 | + csv.push(row.join(",")); |
| 98 | + } |
| 99 | + } |
| 100 | + downloadCSV(csv.join("\n"), filename); |
| 101 | + } |
| 102 | + |
| 103 | + function downloadCSV(csv, filename) { |
| 104 | + let csvFile; |
| 105 | + let downloadLink; |
| 106 | + |
| 107 | + csvFile = new Blob([csv], {type: "text/csv"}); |
| 108 | + downloadLink = document.createElement("a"); |
| 109 | + downloadLink.download = filename; |
| 110 | + downloadLink.href = window.URL.createObjectURL(csvFile); |
| 111 | + downloadLink.style.display = "none"; |
| 112 | + document.body.appendChild(downloadLink); |
| 113 | + downloadLink.click(); |
| 114 | + } |
| 115 | + |
| 116 | + $(document).ready(function(){ |
| 117 | + |
| 118 | + $( '#cnae' ).select2( { |
| 119 | + theme: 'bootstrap-5' |
| 120 | + }); |
| 121 | + |
| 122 | + $.ajax(settings).done(function (response) { |
| 123 | + let cnaes = response?.response?.cnae || []; |
| 124 | + cnaes.forEach(cnae => { |
| 125 | + $('#cnae').append(`<option value="${cnae.codigo}">${cnae.codigo} - ${cnae.descricao}</option>`); |
| 126 | + }); |
| 127 | + }); |
| 128 | + |
| 129 | + $('#cnae').on('change', function(){ |
| 130 | + |
| 131 | + let cnae = $(this).val(); |
| 132 | + let quantidade = $('#quantidade').val(); |
| 133 | + |
| 134 | + settings.url = "https://cluster.apigratis.com/api/v2/dados/cnae"; |
| 135 | + |
| 136 | + settings.data = JSON.stringify({ |
| 137 | + "cnae": cnae, |
| 138 | + "quantidade": quantidade |
| 139 | + }); |
| 140 | + |
| 141 | + $.ajax(settings).done(function (response) { |
| 142 | + |
| 143 | + let cnae = response?.response?.cnae || []; |
| 144 | + |
| 145 | + if(cnae.length > 1){ |
| 146 | + $('table tbody').remove(); |
| 147 | + } |
| 148 | + |
| 149 | + cnae.forEach(cnae => { |
| 150 | + $('table').append(` |
| 151 | + <tbody> |
| 152 | + <tr> |
| 153 | + <td>${cnae?.cnpj ?? ''}</td> |
| 154 | + <td>${cnae?.capital_social ? parseInt(cnae.capital_social).toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }) : ''}</td> |
| 155 | + <td>${cnae?.razao_social ?? ''}</td> |
| 156 | + <td>${cnae?.bairro ?? ''}</td> |
| 157 | + <td>${cnae?.municipio_descricao ?? ''}</td> |
| 158 | + <td>${cnae?.correio_eletronico ?? ''}</td> |
| 159 | + <td><a href="https://wa.me/55${cnae?.ddd1}${cnae.telefone1}">${cnae?.ddd1}${cnae.telefone1}</a></td> |
| 160 | + <td><a href="https://wa.me/55${cnae?.ddd2}${cnae.telefone2}">${cnae?.ddd2}${cnae.telefone2}</a></td> |
| 161 | + </tr> |
| 162 | + </tbody> |
| 163 | + `); |
| 164 | + }); |
| 165 | + |
| 166 | + }); |
| 167 | + |
| 168 | + }); |
| 169 | + |
| 170 | + $('#cep').on('focusout', function(){ |
| 171 | + |
| 172 | + let cep = $(this).val(); |
| 173 | + let cnae = $('#cnae').val(); |
| 174 | + let quantidade = $('#quantidade').val(); |
| 175 | + |
| 176 | + settings.url = "https://cluster.apigratis.com/api/v2/dados/cep"; |
| 177 | + |
| 178 | + settings.data = JSON.stringify({ |
| 179 | + "cep": cep, |
| 180 | + "quantidade": quantidade, |
| 181 | + "cnae": cnae |
| 182 | + }); |
| 183 | + |
| 184 | + $.ajax(settings).done(function (response) { |
| 185 | + |
| 186 | + let cpnjs = response?.response?.cep || []; |
| 187 | + |
| 188 | + if(cpnjs.length > 1){ |
| 189 | + $('table tbody').remove(); |
| 190 | + } |
| 191 | + |
| 192 | + cpnjs.forEach(cnae => { |
| 193 | + $('table').append(` |
| 194 | + <tbody> |
| 195 | + <tr> |
| 196 | + <td>${cnae?.cnpj ?? ''}</td> |
| 197 | + <td>${cnae?.capital_social ? parseInt(cnae.capital_social).toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }) : ''}</td> |
| 198 | + <td>${cnae?.razao_social ?? ''}</td> |
| 199 | + <td>${cnae?.bairro ?? ''}</td> |
| 200 | + <td>${cnae?.municipio_descricao ?? ''}</td> |
| 201 | + <td>${cnae?.correio_eletronico ?? ''}</td> |
| 202 | + <td><a href="https://wa.me/55${cnae?.ddd1}${cnae.telefone1}">${cnae?.ddd1}${cnae.telefone1}</a></td> |
| 203 | + <td><a href="https://wa.me/55${cnae?.ddd2}${cnae.telefone2}">${cnae?.ddd2}${cnae.telefone2}</a></td> |
| 204 | + </tr> |
| 205 | + </tbody> |
| 206 | + `); |
| 207 | + }); |
| 208 | + |
| 209 | + }); |
| 210 | + }); |
| 211 | + |
| 212 | + }); |
| 213 | + |
| 214 | +</script> |
| 215 | +</body> |
| 216 | +</html> |
0 commit comments