<?php 

include "includes/conexao.php";

$select_query = mysqli_query($con,"SELECT * FROM creditos");
$table = '
        <table>
        <tr>
        <th>Item</th>
          <th>Cliente</th>
           <th>Valor</th>
            <th>Tipo</th>
             <th>Prestacoes</th>
             <th>Taxa</th>
             <th>Prestacao</th>
             <th>Juros</th>
             <th>Total</th>
             <th>Agente de Vendas</th>
             <th>Previsao de pagamento</th>
             <th>Status</th>
             </tr>
        ';
        
        $item=1;
    while($data = mysqli_fetch_assoc($select_query)){
        
        $table.='
           <tr>
             <td>'.$item++.'</td>
             <td>'.$data['cliente'].'</td>
             <td>'.$data['valor'].'</td>
             <td>'.$data['tipo'].'</td>
             <td>'.$data['prestacoes'].'</td>
             <td>'.$data['taxas'].'</td>
             <td>'.$data['v_prest'].'</td>
             <td>'.$data['juros'].'</td>
             <td>'.$data['total'].'</td>
             <td>'.$data['vendedor'].'</td>
             <td>'.$data['previsao'].'</td>
             <td>'.$data['status'].'</td>
           
           </tr>
        
        
        
        ';
    }
    $table.='</table>';
    
    $select_query1 = mysqli_query($con,"SELECT * FROM pagamentos");
$table1 = '
        <table>
        <tr>
        <th>Item</th>
          <th>Cliente</th>
           <th>Valor Pago</th>
            <th>Data</th>
             <th>Saldo</th>
            <th>Status</th>
             </tr>
        ';
        
        $item=1;
    while($data1 = mysqli_fetch_assoc($select_query1)){
        
        $table1.='
           <tr>
             <td>'.$item++.'</td>
             <td>'.$data1['nome_cliente'].'</td>
             <td>'.$data1['valor_pago'].'</td>
             <td>'.$data1['data'].'</td>
             <td>'.$data1['saldo'].'</td>
              <td>'.$data1['status'].'</td>
           
           </tr>
        
        
        
        ';
    }
    $table1.='</table>';
    
    
    header("Content-Type:application/xls");
    header("Content-Disposition:attachment;filename=data.xls");
   
    echo '<h1>LISTA DE CREDITOS</h1>';
    echo $table;
    
    echo '<hr>';
    echo '<h1>LISTA DE PAGAMENTOS</h1>';
    echo $table1;


?>