Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.60 KB | None | 0 0
  1. <?php
  2. //se nao existir volta para a pagina do form de login
  3. if(!isset($_SESSION['login_session']) and
  4. !isset($_SESSION['senha_session'])){
  5. header("Location:../index.php");
  6. exit;
  7. }
  8. ?>
  9.  
  10. <script src="js/jquery.min.js" type="text/javascript"></script>
  11. <script type="text/javascript">
  12.  
  13. function marcardesmarcar(){
  14. if ($("#todos").attr("checked")){
  15. $('.marcar').each(
  16. function(){
  17. $(this).attr("checked", true);
  18. }
  19. );
  20. }else{a
  21. $('.marcar').each(
  22. function(){
  23. $(this).attr("checked", false);
  24. }
  25. );
  26. }
  27. }
  28.  
  29. function validaCheckbox(v){
  30. todos = document.getElementsByTagName('input');
  31. for(x = 0; x < todos.length; x++) {
  32. if (todos[x].checked){
  33. return true;
  34. }
  35. }
  36. alert("Selecione pelo menos uma fatura!");
  37. return false;
  38. }
  39.  
  40. </script>
  41. <link href="css/jquery-ui-1.10.4.custom.css" rel="stylesheet" type="text/css">
  42. <script src="js/jquery-ui-1.10.4.custom.js"></script>
  43.  
  44. <div id="entrada">
  45. <div id="cabecalho"><h2><i class="icon-external-link-sign iconmd"></i>
  46. Gerar arquivo de Remessa</h2> <small>* Mostrando somente boletos já impressos e com remessa não gerada.</small></div>
  47. <div id="forms">
  48. <?php
  49. $res = mysqli_query($conexao,"SELECT * FROM bancos WHERE situacao='1'");
  50. $list = mysqli_fetch_array($res);
  51.  
  52. ?>
  53. <form name="form" action="remessa/gerar_remessa.php" method="post"
  54. enctype="multipart/form-data" onSubmit="return validaCheckbox(this);">
  55. <input name="pg" type="hidden" value="<?php echo $_GET['pg'] ?>">
  56. <?php
  57. if(isset($_POST['pesquizar']) && $_POST['pesquizar'] != ""){
  58. $pesquisar = $_POST['pesquizar'];
  59. $sql_1 = "SELECT * ,date_format(data_venci, '%d/%m/%Y') AS data FROM
  60. faturas WHERE situacao ='P' AND (nome LIKE '%$pesquisar%' OR num_doc LIKE '%$pesquisar%' OR nosso_numero LIKE '%$pesquisar%')";
  61. }
  62. elseif(isset($_POST['datai']) && $_POST['datai'] and $_POST['dataf'] != ""){
  63. $datai = implode("-",array_reverse(explode("/",$_POST['datai'])));
  64. $dataf = implode("-",array_reverse(explode("/",$_POST['dataf'])));
  65. $sql_1 = "SELECT * ,date_format(data_venci, '%d/%m/%Y') AS data FROM faturas WHERE situacao ='P' AND data_venci BETWEEN ('$datai') AND ('$dataf')";
  66.  
  67. }else{
  68. $sql_1 = "SELECT * FROM tblinvoices INNER JOIN tblclients ON tblinvoices.clientid = tblclients.userid WHERE tblinvoices.remessa = '0' ORDER BY tblinvoices.id DESC";
  69. }
  70.  
  71. @$p = $_GET["p"];
  72.  
  73. if(isset($p)) {
  74. $p = $p;
  75. } else {
  76. $p = 1;
  77. }
  78.  
  79. $qnt = 400;
  80.  
  81. $inicio = ($p*$qnt) - $qnt;
  82. ?>
  83. <div id="fundo-tabela">
  84.  
  85. <table width="100%" border="0" cellspacing="1" cellpadding="5" data rowindex="1" data-rowtype="1">
  86. <tbody>
  87. <tr>
  88. <td width="42" bgcolor="#0490fc"><input type="checkbox" name="todos" id="todos" value="todos" onclick="marcardesmarcar();" /></td>
  89. <td width="260" bgcolor="#0490fc"><span class="fontebranca">Nome</span>
  90. </td>
  91. <td width="309" bgcolor="#0490fc"><span
  92. class="fontebranca">Descrição</span></td>
  93. <td width="275" bgcolor="#0490fc"><span class="fontebranca">Nº Doc</span></td>
  94. <td width="275" bgcolor="#0490fc"><span class="fontebranca">Impresso</span></td>
  95. <td width="275" align="center" bgcolor="#0490fc"><span class="fontebranca">Data</span></td>
  96. <td width="108" align="center" bgcolor="#0490fc"><span class="fontebranca">Vencimento</span></td>
  97. <td width="83" align="center" bgcolor="#0490fc"><span class="fontebranca">Valor</span></td>
  98. <td width="145" align="center" bgcolor="#0490fc"><span class="fontebranca">Status</span></td>
  99. </tr>
  100. </tbody>
  101. <?php
  102.  
  103. $sql_select = $sql_1." LIMIT $inicio, $qnt";
  104.  
  105. $sql_query = mysqli_query($conexao,$sql_select);
  106.  
  107. while($array = mysqli_fetch_array($sql_query)) {
  108.  
  109. $nome = $array["company"];
  110. $nm = $array['nosso_numero'];
  111.  
  112. ?>
  113. <tr>
  114. <td><input type="checkbox" name="id_venda[]" class="marcar" value="<?php echo $array['id'] ?>" id="marcar"></td>
  115. <td align="left"><?php echo $array['company']; ?></td>
  116. <td align="left"><?php echo $array['clientnote']; ?></td>
  117. <td align="left"><?php echo $array['id']; ?></td>
  118. <td align="left"><?php
  119. if($array['nosso_numero'] != 0){
  120. echo 'SIM';
  121. }else{
  122. echo 'NÃO';
  123. }
  124. ?></td>
  125. <td align="center"><?php echo date('d/m/Y', strtotime($array['date'])); >
  126. </td>
  127. <td align="center"><?php echo date('d/m/Y',
  128. strtotime($array['duedate'])); ?></td>
  129. <td align="right"><?php echo number_format($array['total'], 2, ',', '.'); ?></td>
  130. <td align="center">
  131. <?php
  132. if($array['remessa'] == '0'){
  133. echo "Não gerado";
  134. }else{
  135. echo "Gerado";
  136. }
  137. ?>
  138.  
  139. </td>
  140. </tr>
  141. <?php } ?>
  142. <tr>
  143. <td colspan="7" bgcolor="#0490fc">
  144. <button type="submit" class="btn deleteboton ewButton" id="btnsubmit" onclick="return confirm('Gerar remessa para todos selecionados?')" style="width:200px;"/ >
  145. <i class="icon-text icon-white"></i> Gerar remessa dos Selecionados</button>
  146.  
  147. <?php
  148. $sqlsoma = mysqli_query($conexao,"SELECT sum(total) AS val FROM tblinvoices WHERE remessa='0' AND nosso_numero != 0");
  149. $c = mysqli_fetch_array($sqlsoma);
  150. $total = $c['val'];
  151.  
  152. ?>
  153. <div id="total-faturas"><strong>Valor total: <?php echo number_format($total, 2, ',', '.') ?></strong> </div>
  154.  
  155. </table>
  156. </form>
  157. </div>
  158.  
  159. <?php
  160. echo "<br />";
  161.  
  162. $sql_select_all = "SELECT * FROM tblinvoices WHERE remessa='0'";
  163. // Executa o query da seleção acimas
  164. $sql_query_all = mysqli_query($conexao,$sql_select_all);
  165. // Gera uma variável com o número total de registros no banco de dados
  166. $total_registros = mysqli_num_rows($sql_query_all);
  167.  
  168. $pags = ceil($total_registros/$qnt);
  169. $max_links = 3;
  170. echo "<a class="pag" href="inicio.php?pg=remessa&p=1" target="_self">&laquo;&laquo; Primeira</a> ";
  171.  
  172. for($i = $p-$max_links; $i <= $p-1; $i++) {
  173.  
  174. if($i <=0) {
  175. } else {
  176. echo "<a class="pag" href="inicio.php?pg=remessa&p=".$i."" target="_self">".$i."</a> ";
  177. }
  178. }
  179.  
  180. echo "<span class="pags">".$p."&nbsp;</span> ";
  181. // Cria outro for(), desta vez para exibir 3 links após a página atual
  182. for($i = $p+1; $i <= $p+$max_links; $i++) {
  183.  
  184. if($i > $pags)
  185. {
  186. //faz nada
  187. }
  188. // Se tiver tudo Ok gera os links.
  189. else
  190. {
  191. echo "<a class="pag" href="inicio.php?pg=remessa&p=".$i."" target="_self">".$i."</a> ";
  192. }
  193. }
  194.  
  195. echo "<a class="pag" href="inicio.php?pg=remessa&p=".$pags."" target="_self">Ultima &raquo;&raquo;</a> ";
  196. ?>
  197. </div>
  198.  
  199. <?php
  200. include '../classes/conexao.php';
  201.  
  202. error_reporting(0); // sem msg de erro
  203. error_reporting(E_ALL); // todas
  204. function gerarNome($total_caracteres){
  205.  
  206. $caracteres = 'ABCDEFGHIJKLMNOPQRSTUWXYZ';
  207. $caracteres .= 'abcdefghijklmnopqrstuwxyz';
  208. $caracteres .= '0123456789';
  209. $max = strlen($caracteres)-1;
  210. $senha = null;
  211. for($i=0; $i < $total_caracteres; $i++){
  212. $senha .= $caracteres{mt_rand(0, $max)};
  213. }
  214. return $senha;
  215. }
  216. $total_caracteres = 8;
  217. $nomeArquivo = gerarNome($total_caracteres);
  218.  
  219. function tiraPontos($valor) {
  220. $pontos = '.';
  221. $virgula = '-';
  222. $barra = '/';
  223. $result = str_replace($pontos, "", $valor);
  224. $result2 = str_replace($virgula, "", $result);
  225. $result3 = str_replace($barra, "", $result2);
  226. return $result3;
  227. }
  228.  
  229. $sql = mysqli_query($conexao,"SELECT * FROM config")or
  230. die(mysqli_error($conexao));
  231. $ver = mysqli_fetch_array($sql);
  232.  
  233. $sql2 = mysqli_query($conexao,"SELECT * FROM bancos WHERE situacao='1'")or die(mysqli_error($conexao));
  234. $banco = mysqli_fetch_array($sql2);
  235.  
  236. include 'vendor/autoload.php';
  237.  
  238. $codigo_banco = CnabBanco::ITAU;
  239. $arquivo = new CnabRemessaCnab400Arquivo($codigo_banco);
  240.  
  241. $arquivo->configure(array(
  242. 'data_geracao' => new DateTime(),
  243. 'data_gravacao' => new DateTime(),
  244. 'nome_fantasia' => $ver['nome'],
  245. 'razao_social' => $ver['nome'],
  246. 'cnpj' => preg_replace( '#[^0-9]#', '', $ver['cpf'] ),
  247. 'banco' => $codigo_banco,
  248. 'logradouro' => $ver['endereco'],
  249. 'numero' => $ver['numero'],
  250. 'bairro' => $ver['bairro'],
  251. 'cidade' => $ver['cidade'],
  252. 'uf' => $ver['uf'],
  253. 'cep' => preg_replace( '#[^0-9]#', '', $ver['cep'] ),
  254. 'agencia' => $banco['agencia'],
  255. 'conta' => $banco['conta'],
  256. 'conta_dac' => $banco['digito_co']
  257.  
  258. ));
  259.  
  260. foreach($_POST['id_venda'] as $key => $id_cliente){ $id_venda = isset($_POST['id_venda'][$key])? $_POST['id_venda'][$key] :null;
  261.  
  262. $seleciona = mysqli_query($conexao,"SELECT * FROM tblinvoices WHERE id = '$id_venda'") or die(mysqli_error($conexao));
  263. $fatura = mysqli_fetch_array($seleciona);
  264.  
  265. $IdCliente = $fatura['clientid'];
  266. $sq = mysqli_query($conexao,"SELECT * FROM tblclients WHERE userid='$IdCliente'") or die(mysqli_error($conexao));
  267. $cliente = mysqli_fetch_array($sq);
  268. $cpf = tiraPontos($cliente['vat']);
  269.  
  270. if(strlen($cpf) > 11){
  271. $documento = 'cnpj';
  272. }else{
  273. $documento = 'cpf';
  274. }
  275. $arquivo->insertDetalhe(array(
  276. 'codigo_ocorrencia' => 01,
  277. 'nosso_numero' => $fatura['id'],
  278. 'numero_documento' => $fatura['id'],
  279. 'carteira' => $banco['carteira'],
  280. 'especie' => $banco['especie'],
  281. 'valor' => $fatura['total'], // Valor do boleto
  282. 'instrucao1' => '05',
  283. 'instrucao2' => '10', // 10 nao protestar, 09 protestar
  284. 'sacado_nome' => $cliente['company'],
  285. 'sacado_razao_social' => $cliente['company'],
  286. 'sacado_tipo' => $documento,
  287. 'sacado_cpf' => $cpf,
  288. 'sacado_cnpj' => $cpf,
  289. 'sacado_logradouro' => $cliente['address'],
  290. 'sacado_bairro' => $cliente['bairro'],
  291. 'sacado_cep' => preg_replace( '#[^0-9]#', '', $cliente['zip'] ),
  292. 'sacado_cidade' => $cliente['city'],
  293. 'sacado_uf' => $cliente['state'],
  294. 'data_vencimento' => new DateTime($fatura['duedate']),
  295. 'data_cadastro' => new DateTime($fatura['date']),
  296. 'juros_de_um_dia' => 0.10, // Valor do juros de 1 dia'
  297. 'data_desconto' => new DateTime($fatura['duedate']),
  298. 'valor_desconto' => 0.0, // Valor do desconto
  299. 'prazo' => 30, // prazo de dias para o cliente pagar após o vencimento
  300. 'taxa_de_permanencia' => '00', //00 = Acata Comissão por Dia (recomendável), 51 Acata Condições de Cadastramento na CAIXA
  301. 'mensagem' => '',
  302. 'data_multa' => new DateTime($fatura['duedate']), // data da multa
  303. 'valor_multa' => 0.0, // valor da multa
  304. 'aceite' => 'N'
  305. ));
  306. }
  307. $arrnome = $nomeArquivo.'.REM';
  308. $arquivo->save($arrnome);
  309.  
  310. if($arquivo){
  311. foreach($_POST['id_venda'] as $key => $id_cliente){
  312. $id_venda = isset($_POST['id_venda'][$key])? $_POST['id_venda'][$key] :null;
  313. $up = mysqli_query($conexao,"UPDATE tblinvoices SET remessa = '1' WHERE id = '$id_venda'")or die(mysqli_error($conexao));
  314. }
  315. $dataNow = date("Y-m-d H:i:s");
  316. $grava = mysqli_query($conexao,"INSERT INTO remessas (data ,nome)VALUES('$dataNow', '$arrnome')") or die(mysqli_error($conexao));
  317. if($up == 1){
  318.  
  319. print"<META HTTP-EQUIV=REFRESH CONTENT='0; URL=../inicio.php pg=listaremessa'>
  320. <script type="text/javascript">
  321. alert("ARQUIVO DE REMESSA GERADO COM SUCESSO!");
  322. </script>";
  323.  
  324. }
  325. }
  326. mysqli_close($conexao);
  327. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement