
<?php
 
    /* CADASTROS RECENTES */
	$clientes_au  = array();
    $clientes     = array();

	$select_db->ExeRead("*",  'fid_clientes', "", "");
	$total_clientes = count($select_db->getResult());
    $select          = new Core_select;

	for($i=0;$i<$total_clientes;$i++){
	
	$cpf = $select_db->getResult()[$i]['fid_cpf'];
		
	$select->ExeRead("SUM(mov_pontos) as total",  'fid_movimentacao', "WHERE ( cli_cpf = :c )", "c={$cpf}");
		
	$clientes[$i]['nome']     = $select_db->getResult()[$i]['fid_nome'];
	$clientes[$i]['cpf']      = $select_db->getResult()[$i]['fid_cpf'];
	$clientes[$i]['email']    = $select_db->getResult()[$i]['fid_email'];
	$clientes[$i]['celular']  = $select_db->getResult()[$i]['fid_celular'];
	$clientes[$i]['pontos']   = $select->getResult()[0]['total'];
	$clientes_au[$select_db->getResult()[$i]['fid_cpf']] = $i;	
	
	}
	

	$filtro = $_GET['filtro'];
	
	if($filtro == 1){
		
		$d = '-'.date('m').'-';
			
	}else if($filtro == 2){
		
		$a = str_replace('0','',date('m'))-1;
		$d = '-0'.$a. '-';
		
	}else{
		
	    $a = str_replace('0','',date('m'))-2;
		$d = '-0'.$a. '-';
		
	}
	


	$select_db->ExeRead(" DISTINCT cli_cpf ",  'fid_movimentacao', "WHERE mov_data LIKE '%' :d '%'", "d={$d}");

	for($i=0;$i<count($select_db->getResult());$i++){
	
		if($clientes_au[$select_db->getResult()[$i]['cli_cpf']]['cpf'] != $select_db->getResult()[$i]['cli_cpf']){
		
		unset( $clientes[ $clientes_au[$select_db->getResult()[$i]['cli_cpf']] ]);
		
		}

	}
	
	$mes_extenso = array(
        '01' => 'Janeiro',
        '02' => 'Fevereiro',
        '03' => 'Marco',
        '04' => 'Abril',
        '05' => 'Maio',
        '06' => 'Junho',
        '07' => 'Julho',
        '08' => 'Agosto',
        '09' => 'Setembro',
        '10' => 'Outubro',
        '11' => 'Novembro',
        '12' => 'Dezembro'
    );

?>	
<div class="col-md-12">

           <div class="row" style="background-color: #e8e8e8; margin-bottom: 15px">
            <div class="col-md-9">
                <h3 style="margin: 0">
                    <i class="fa fa-user color1"></i>
                     Cliente Ausentes <span style="font-size: 12px"> mês de: <?php echo $mes_extenso[ date('m') ]; ?></span>
                </h3>
            </div>
            	<div class="col-md-3" style="margin-top:10px">
			<button type="button" class="simple-btn" onclick="TerminalAdmin.dashboard();">Voltar para Dashboard</button>
		</div>
     </div>
</div>
        
     <table class="table table-striped">
		<thead>
			<tr>
				<th style="text-align: center">Nome</th>
				<th style="text-align: center">CPF</th>
				<th style="text-align: center">E-mail</th>
				<th style="text-align: center">Celular</th>
				<th style="text-align: center">Pontos</th>
	
			</tr>
		</thead>
		<tbody>
	    
   <?php
	  
	  for($i=0;$i<count($clientes)+2;$i++){
		  
		if( isset($clientes[$i]) ):
		  echo '<tr class="color5">
		  <td style="text-align: center;color:#333;" class="col-md-3">' . $clientes[$i]['nome'] . '</td>
		   <td style="text-align: center;color:#333;" class="col-md-3">' . $clientes[$i]['cpf'] . '</td>
		   <td style="text-align: center;color:#333;" class="col-md-3">' . $clientes[$i]['email'] . '</td>
		    <td style="text-align: center;color:#333;" class="col-md-3">' . $clientes[$i]['celular'] . '</td>
			  <td style="text-align: center;color:#333;" class="col-md-3">' . $clientes[$i]['pontos'] . '</td>
			</tr>';
		  endif;
		  
	  }
	  
	?>
			<tr style="background-color: #1E90FF; color: #fff">
				<td colspan="5">&nbsp;</td>
				<td>Saldo Final</td>
				<td style="text-align: center"></td>
			</tr>
			
		</tbody>
		</table>

    </div>