
<?php
 	
	$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>
                     Movimentações <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">ID</th>
				<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>
		        <th style="text-align: center">Data</th>
		        <th style="text-align: center">Opção</th>
			</tr>
		</thead>
		<tbody>
	    
   <?php
			
	$filtro = $_GET['filtro'];
	
	if($filtro == 1){		
		
	$f = '-'.date('m').'-';	
	$select_db->ExeRead(" * ",  'fid_movimentacao', "WHERE  mov_data LIKE '%' :g '%'  ", "g={$f}");
 	
	}else if($filtro == 2){

		$mes = date('n');
			
		$b = $mes -1;
		$e = '-0'.$b. '-';
		
		$f = '-'.date('m').'-';
		
	$select_db->ExeRead(" * ",  'fid_movimentacao', "WHERE  mov_data LIKE '%' :e '%' or mov_data LIKE '%' :g '%'  ", "e={$e}&g={$f}");
		
	}else{
		
	    $a = date('n')-2;
		$d = '-0'.$a. '-';
		
		$b = date('n')-1;
		$e = '-0'.$b. '-';
		
		$f = '-'.date('m').'-';
		
	$select_db->ExeRead(" * ",  'fid_movimentacao', "WHERE mov_data LIKE '%' :d '%' or mov_data LIKE '%' :e '%' or mov_data LIKE '%' :g '%'  ", "d={$d}&e={$e}&g={$f}");	
		
	}
						
	for($i=0;$i<count($select_db->getResult());$i++){
		
		$cpf             = $select_db->getResult()[$i]['cli_cpf'];
		$dat             = $select_db->getResult()[$i]['mov_data'];
		$total_pontos    = $select_db->getResult()[$i]['mov_pontos'];

		$cli = "'"  .   $select_db->getResult()[$i]['nome_cliente'] . "'";
		
		  echo '<tr class="color5 pre_'.$select_db->getResult()[$i]['mov_id'].'">
		   <td style="text-align: center;color:#333;" class="col-md-3">' .   $select_db->getResult()[$i]['mov_id'] . '</td>
		  <td style="text-align: center;color:#333;" class="col-md-3">' .   $select_db->getResult()[$i]['nome_cliente'] . '</td>
		   <td style="text-align: center;color:#333;" class="col-md-3">' .  $cpf  . '</td>
		   <td style="text-align: center;color:#333;" class="col-md-3">' .  $select_db->getResult()[$i]['email_cliente'] . '</td>
		    <td style="text-align: center;color:#333;" class="col-md-3">' . $select_db->getResult()[$i]['celular_cliente']  . '</td>
			<td style="text-align: center;color:#333;" class="col-md-3">' . $total_pontos . '</td>
			<td style="text-align: center;color:#333;" class="col-md-3">'.date('d/m/Y H:i:s', strtotime($dat)).'</td>
			<td style="text-align: center;color:#333;" class="col-md-3" onclick="deletarFrequente('. $select_db->getResult()[$i]['mov_id'] .','.$cli.')"><a class="btn btn-danger">Excluir</a></td>
			</tr>';
		
	  
	  }
	  
	?>

			<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>
    
    <script type="text/javascript">
	

		  function deletarFrequente(id,nome){
			  
			  c = confirm('Tem certeza que deseja deletar os pontos para esse Cliente? ' + nome);
			  
			  if(c){
				  
	  tr = '.pre_' + id;
				  
		$.ajax({
            type:   'GET',
             url:    BASE_URL,
             data:   'deletar-cliente-frequente=' + id,
             success: function(d){
				   alert(d);
                   $(tr).hide(500);
            }
        }); 
				  
				    
			  }
			  
		  }
		

</script>

    </div>