<?php exit;
include('fncr-geral/configuracao_geral.php');
$pagina = "mensalidades";

$id_arq = $_GET['r'];

// ARQUIVO
$sql_arquivo = $bd->getConexao()->prepare('SELECT *, DATE_FORMAT(data,"%d/%m/%Y") AS envio FROM clubes_boletos_retornos WHERE id = :id_arq');
$sql_arquivo->bindValue(':id_arq', $id_arq, PDO::PARAM_STR);
if( $sql_arquivo->execute() ) { $resul_arquivo = $sql_arquivo->fetch(PDO::FETCH_ASSOC);}

require_once("boleto/retorno/vendor/autoload.php");

use ManoelCampos\RetornoBoleto\LeituraArquivo;
use ManoelCampos\RetornoBoleto\RetornoFactory;
use ManoelCampos\RetornoBoleto\RetornoInterface;
use ManoelCampos\RetornoBoleto\LinhaArquivo;

$registros = array();

$processarLinha1 = function (RetornoInterface $retorno, LinhaArquivo $linha) {
  global $registros;
  if($linha->dados["registro"] == $retorno->getIdDetalhe()){
    if(isset($linha->dados["segmento"]) && $linha->dados["segmento"]=="T"){


      /*
      $reg_sub = array(
        "nosso_numero"=>$linha->dados['nosso_numero'],
        "documento"=>$linha->dados['documento']
      );
      array_push($registros, $reg_sub);
      */
    }
  }
};

$fileName = "boleto/retorno/arquivos/".$resul_arquivo['arquivo'];
$cnab240 = RetornoFactory::getRetorno($fileName);
$leitura = new LeituraArquivo($processarLinha1, $cnab240);
$leitura->lerArquivoRetorno();


print_r($resul_registros);


?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <?php include('fncr-geral/html-head.php');?>

  <link rel="stylesheet" type="text/css" href="js/datatables2/media/css/jquery.dataTables.css">
  <script type="text/javascript" language="javascript" src="js/datatables2/media/js/jquery.dataTables.js"></script>

  <script type="text/javascript" language="javascript" class="init">

    $(document).ready(function() {
      $('#table_arquivos').DataTable({

        stateSave: false, // Salvar última pesquisa
        "dom": '<"top"fl>rt<"bottom"ip><"clear">', // Layout
        "pagingType": "full_numbers", // Modo Paginação
        "iDisplayLength": 10,

        "aoColumns": [
          null,
          { "orderSequence": [ "" ] },
          null,
          null,
          null,
          null
        ],

        "language": { // Tradução
          "lengthMenu": "Resultados por P&aacute;gina: _MENU_ ",
          "zeroRecords": "N&atilde;o existe Clubes para esta pesquisa",
          "info": "P&aacute;gina _PAGE_ de _PAGES_",
          "infoEmpty": "N&atilde;o existe Clubes para esta pesquisa",
          "infoFiltered": "(Filtrando de um total de _MAX_ Clubes)",
          "search": "Localizar Clubes: ",
          "paginate": {
            "first": "Primeira",
            "previous": "Anterior",
            "next": "Pr&oacute;xima",
            "last": "&Uacute;ltima"
          }
        }
      });
    });
  </script>

</head>
<body>

<!-- BARRA SUPERIOR -->
<?php include('barra-sup.php');?>
<!-- MENU PRINCIPAL -->
<?php include('menu.php');?>

<section id="content">

<div class="clearfix padder bg-fncr-clearfix">
<h3 class="m-b">Detalhes do Retorno</h3>
</div>

<section id="content" class="content-sidebar bg-white" style="padding-bottom: 100px">
<section class="main">
<br>

  <form class="m-b-none" method="post" action="" enctype="multipart/form-data">
    <input type="hidden" name="enviar" value="arquivo" />

    <div class="col-lg-12">
      <section class="panel">
        <header class="panel-heading">
          Arquivo: <strong style="font-size: 15px"><?php echo $resul_arquivo['arquivo']?></strong> (<?php echo $resul_arquivo['envio']?>)
        </header>
        <div class="table-responsive">
          <table id="table_arquivos" class="table table-striped b-t text-small">
            <thead>
            <tr>
              <th class="text-center" width="10" style="font-size: 11px">Reg.</th>
              <th class="text-center" width="100"></th>
              <th class="text-center" width="50">Data</th>
              <th class="text-center" width="400">Arquivo</th>
              <th class="text-center" width="100">Status</th>
              <th class="text-center" width="100">Usuario</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
          </table>
        </div>
      </section>
    </div>

  </form>

</section>
</section>
</section>

<!-- FOOTER -->
<?php include('footer.php');?>

<!-- app -->
<script src="js/app.js"></script>
<script src="js/app.plugin.js"></script>
<script src="js/app.data.js"></script>
<!-- Sparkline Chart -->
<script src="js/charts/sparkline/jquery.sparkline.min.js"></script>
<!-- Easy Pie Chart -->
<script src="js/charts/easypiechart/jquery.easy-pie-chart.js"></script>
  <!-- select2 -->
<script src="js/select2/select2.min.js"></script>
  <!-- fuelux -->
<script src="js/fuelux/fuelux.js"></script>
<!-- datepicker -->
<script src="js/datepicker/bootstrap-datepicker.js"></script>
<!-- slider -->
<script src="js/slider/bootstrap-slider.js"></script>
<!-- file input -->
<script src="js/file-input/bootstrap.file-input.js"></script>
<!-- combodate -->
<script src="js/combodate/moment.min.js"></script>
<script src="js/combodate/combodate.js"></script>
<!-- parsley -->
<script src="js/parsley/parsley.min.js"></script>

</body>
</html>
<?php $bd = null; $bd_fn = null;?>
