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

$periodo_mes = $mes_atual;
$periodo_ano = $ano_atual;

if(isset($_GET['periodo']) && $_GET['periodo'] != ""){
  $filtro = explode('_', $_GET['periodo']);
  $periodo_mes = $filtro[0];
  $periodo_ano = $filtro[1];
}
if(isset($_POST['filtro']) && $_POST['filtro'] == "filtro"){
  $filtro = explode('-', $_POST['periodo']);
  $periodo_mes = $filtro[1];
  $periodo_ano = $filtro[0];
}
if(isset($_POST['periodo_mes']) && $_POST['periodo_mes'] != "" && isset($_POST['periodo_ano']) && $_POST['periodo_ano'] != ""){
  $periodo_mes = $_POST['periodo_mes'];
  $periodo_ano = $_POST['periodo_ano'];
}

if($periodo_mes<10){ $zero = '0'; }else{ $zero = ''; }

$data_inicio = '20'.$periodo_ano.'-'.$zero.$periodo_mes.'-01';
$ultimo_dia = date('t', strtotime($data_inicio));
$data_termino = '20'.$periodo_ano.'-'.$zero.$periodo_mes.'-'.$ultimo_dia;

// Registros
$sql_registros = $bd->getConexao()->prepare('
SELECT clubes_financeiro.*,
  clubes.nome as clube,
  clubes_financeiro_status.status as nomestatus,
  DATE_FORMAT(clubes_financeiro.data_pgto,"%d/%m/%Y") AS data_pagamento
FROM clubes_financeiro
  LEFT JOIN clubes ON clubes.id = clubes_financeiro.id_clube
  LEFT JOIN clubes_financeiro_status ON clubes_financeiro_status.id = clubes_financeiro.status
WHERE clubes_financeiro.data_pgto BETWEEN ("'.$data_inicio.'") AND ("'.$data_termino.'") AND clubes_financeiro.status = 4 AND clubes_financeiro.valor > 0 ORDER BY data_pgto ASC');
if( $sql_registros->execute() ) { $resul_registros = $sql_registros->fetchall(PDO::FETCH_ASSOC);}

?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <?php include('fncr-geral/html-head.php');?>
</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">Lista para o Banco</h3>
</div>

<section id="content" class="content-sidebar bg-white" style="padding-bottom: 100px">
<section class="main">
<br>
  <div class="col-lg-12">
    <section class="panel">
      <table class="table table-striped b-t text-small">
        <thead>
        <tr>
          <?php for($i=-4; $i<=2; $i++){

            $mes_echo = $periodo_mes+$i;
            $ano_echo = $periodo_ano;

            if($periodo_mes+$i <=0){
              $mes_echo = 12+$periodo_mes+$i;
              $ano_echo = $periodo_ano -1;
            }
            if($periodo_mes+$i >12){
              $mes_echo = $periodo_mes+$i-12;
              $ano_echo = $periodo_ano +1;
            }

            if($i==0){
              echo '<th class="text-center" style="font-size: 15px;background-color: #2d5360;color: #ffffff">';
            }else{
              echo '<th class="text-info text-center"><a href="lista_banco.php?periodo='.$mes_echo.'_'.$ano_echo.'">';
            }
            echo substr(meses($mes_echo), 0, 3)." / ".$ano_echo;
            echo '</a></th>';
          }?>
          <th class="text-info text-center" width="40%">
            <form method="post" action="" enctype="multipart/form-data">
              <input type="hidden" name="filtro" value="filtro" />
              <div class="col-lg-1 pull-right" style="padding: 2px;margin-right: 30px;">
                <a href="scripts/xls/relatorios.php?<?php echo 't=listabanco&di='.$data_inicio.'&df='.$data_termino?>" onClick="popUp=window.open(this.href,'popUp','width=200,height=200'); popUp.close();" class="btn btn-white btn-sm pull-right">.xls</a>
              </div>
              <div class="col-lg-1 pull-right" style="padding: 2px;margin-right: 30px;">
                <button type="submit" class="btn btn-sm">Filtrar</button>
              </div>
              <div class="col-lg-8 pull-right" style="margin-top: 2px">
                <input type="text" class="combodate form-control" data-format="YY-MM" data-template="MMMM YYYY" name="periodo" data-required="true">
              </div>
            </form>
          </th>
        </tr>
        </thead>
      </table>
    </section>
  </div>

  <div class="col-lg-12">
    <section class="panel">
      <div class="table-responsive">
        <table class="table table-striped b-t text-small">
          <thead>
          <tr>
            <th>Clube</th>
            <th class="text-center">M&ecirc;s</th>
            <th class="text-center">Valor</th>
            <th class="text-center">Pgt</th>
            <th width="100">Status</th>
          </tr>
          </thead>
          <tbody>
          <?php foreach($resul_registros as $linha_registros){ ?>
            <tr>
              <td class="text-info"><?php echo $linha_registros['clube']?></td>
              <td class="text-info text-center"><?php echo substr(meses($linha_registros['periodo_mes']), 0, 3)?></td>
              <td class="text-info text-center">R$ <?php echo echomoeda($linha_registros['valor'])?></td>
              <td class="text-info text-center"><?php echo $linha_registros['data_pagamento']?></td>
              <td class="text-info status-<?php echo $linha_registros['status']?>">
                <?php echo $linha_registros['nomestatus']?>
              </td>
            </tr>
          <?php } ?>
          </tbody>
        </table>
      </div>
    </section>
  </div>

</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;?>