<?php 
require_once("../../conexao.php");

$totalvalorF = 0;
$id_cliente = $_POST['id'];

$data_hoje = date('Y-m-d');
$data_amanha = date('Y/m/d', strtotime("+1 days",strtotime($data_hoje)));

echo <<<HTML

<small><table id="tab-compras" class="table table-striped table-light table-hover">
<thead>
<tr>
<th>Data Compra</th>
<th>Valor Compra</th>
<th>Tipo Pgto</th>			
</tr>
</thead>
<tbody>
HTML;


$total_valor = 0;
$query = $pdo->query("SELECT * from vendas where cliente = '$id_cliente' and status = 'Concluída' order by id desc ");
$res = $query->fetchAll(PDO::FETCH_ASSOC);
for($i=0; $i < @count($res); $i++){
	
	$id = $res[$i]['id'];
		$data = $res[$i]['data_lanc'];		
		$pagamento = $res[$i]['pagamento'];
		$valor = $res[$i]['subtotal'];
				
		
	
		$dataF = implode('/', array_reverse(explode('-', $data)));	
		$valorF = number_format($valor, 2, ',', '.');		

		$total_valor += $valor;
	

    $totalvalorF = number_format($total_valor, 2, ',', '.');
 		
echo <<<HTML
	<tr>
	<td>	
	{$dataF}
	</td>		
	<td>R$ {$valorF}</td>		
	<td>{$pagamento}</td>									
	
	</tr>
HTML;
} 
echo <<<HTML
</tbody>
</table>
<br>
<div align="right">Total Compras: <span class="text-success">R$ {$totalvalorF}</span> </div>
</small>
HTML;

?>






